< prev index next >

src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c

Print this page
rev 52666 : 8214343: Handle the absence of Xrandr more generically
Reviewed-by:


  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "jni_util.h"
  27 #include "awt_p.h"
  28 #include "awt.h"
  29 #include "color.h"
  30 #include <java_awt_DisplayMode.h>
  31 #include <sun_awt_X11GraphicsEnvironment.h>
  32 #include <sun_awt_X11GraphicsDevice.h>
  33 #include <sun_awt_X11GraphicsConfig.h>
  34 #ifndef HEADLESS
  35 #include <X11/extensions/Xdbe.h>
  36 #include <X11/XKBlib.h>
  37 #ifndef _AIX
  38 #include <X11/extensions/Xrandr.h>
  39 #endif
  40 #include "GLXGraphicsConfig.h"
  41 #endif /* !HEADLESS */
  42 
  43 #include <jni.h>
  44 #include <jni_util.h>
  45 #include <jvm.h>
  46 #include <jvm_md.h>
  47 #include <jlong.h>
  48 #include "systemScale.h"
  49 #include <stdlib.h>
  50 
  51 #include "awt_GraphicsEnv.h"
  52 #include "awt_util.h"
  53 #include "gdefs.h"
  54 #include <dlfcn.h>
  55 #include "Trace.h"
  56 
  57 #ifdef NETSCAPE


1610     if (XineramaSolarisCenterFunc != NULL) {
1611         (XineramaSolarisCenterFunc)(awt_display, 0, &x, &y);
1612         point = JNU_NewObjectByName(env, "java/awt/Point","(II)V", x, y);
1613         DASSERT(point);
1614     } else {
1615         DTRACE_PRINTLN("unable to call XineramaSolarisCenterFunc: symbol is null");
1616     }
1617     AWT_FLUSH_UNLOCK();
1618 #endif /* __linux __ || MACOSX */
1619 #endif /* HEADLESS */
1620     return point;
1621 }
1622 
1623 
1624 /**
1625  * Begin DisplayMode/FullScreen support
1626  */
1627 
1628 #ifndef HEADLESS
1629 
1630 #ifndef _AIX
1631 
1632 #define BIT_DEPTH_MULTI java_awt_DisplayMode_BIT_DEPTH_MULTI
1633 #define REFRESH_RATE_UNKNOWN java_awt_DisplayMode_REFRESH_RATE_UNKNOWN
1634 
1635 typedef Status
1636     (*XRRQueryVersionType) (Display *dpy, int *major_versionp, int *minor_versionp);
1637 typedef XRRScreenConfiguration*
1638     (*XRRGetScreenInfoType)(Display *dpy, Drawable root);
1639 typedef void
1640     (*XRRFreeScreenConfigInfoType)(XRRScreenConfiguration *config);
1641 typedef short*
1642     (*XRRConfigRatesType)(XRRScreenConfiguration *config,
1643                           int sizeID, int *nrates);
1644 typedef short
1645     (*XRRConfigCurrentRateType)(XRRScreenConfiguration *config);
1646 typedef XRRScreenSize*
1647     (*XRRConfigSizesType)(XRRScreenConfiguration *config,
1648                           int *nsizes);
1649 typedef SizeID
1650     (*XRRConfigCurrentConfigurationType)(XRRScreenConfiguration *config,


1817         jmethodID mid;
1818         arrayListClass = (*env)->GetObjectClass(env, arrayList);
1819         if (JNU_IsNull(env, arrayListClass)) {
1820             JNU_ThrowInternalError(env,
1821                                    "Could not get class java.util.ArrayList");
1822             return;
1823         }
1824         mid = (*env)->GetMethodID(env, arrayListClass, "add",
1825                                   "(Ljava/lang/Object;)Z");
1826         CHECK_NULL(mid);
1827         if (mid == NULL) {
1828             JNU_ThrowInternalError(env,
1829                 "Could not get method java.util.ArrayList.add()");
1830             return;
1831         }
1832         (*env)->CallObjectMethod(env, arrayList, mid, displayMode);
1833         (*env)->DeleteLocalRef(env, displayMode);
1834     }
1835 }
1836 
1837 #endif /* !_AIX */
1838 
1839 static void
1840 X11GD_SetFullscreenMode(Window win, jboolean enabled)
1841 {
1842     Atom wmState = XInternAtom(awt_display, "_NET_WM_STATE", False);
1843     Atom wmStateFs = XInternAtom(awt_display,
1844                                  "_NET_WM_STATE_FULLSCREEN", False);
1845     XWindowAttributes attr;
1846     XEvent event;
1847 
1848     if (wmState == None || wmStateFs == None
1849             || !XGetWindowAttributes(awt_display, win, &attr)) {
1850         return;
1851     }
1852 
1853     memset(&event, 0, sizeof(event));
1854     event.xclient.type = ClientMessage;
1855     event.xclient.message_type = wmState;
1856     event.xclient.display = awt_display;
1857     event.xclient.window = win;
1858     event.xclient.format = 32;
1859     event.xclient.data.l[0] = enabled ? 1 : 0; // 1==add, 0==remove
1860     event.xclient.data.l[1] = wmStateFs;
1861 
1862     XSendEvent(awt_display, attr.root, False,
1863                SubstructureRedirectMask | SubstructureNotifyMask,
1864                &event);
1865     XSync(awt_display, False);
1866 }
1867 #endif /* !HEADLESS */
1868 
1869 /*
1870  * Class:     sun_awt_X11GraphicsDevice
1871  * Method:    initXrandrExtension
1872  * Signature: ()Z
1873  */
1874 JNIEXPORT jboolean JNICALL
1875 Java_sun_awt_X11GraphicsDevice_initXrandrExtension
1876     (JNIEnv *env, jclass x11gd)
1877 {
1878 #if defined(HEADLESS) || defined(_AIX)
1879     return JNI_FALSE;
1880 #else
1881     int opcode = 0, firstEvent = 0, firstError = 0;
1882     jboolean ret;
1883 
1884     AWT_LOCK();
1885     ret = (jboolean)XQueryExtension(awt_display, "RANDR",
1886                                     &opcode, &firstEvent, &firstError);
1887     if (ret) {
1888         ret = X11GD_InitXrandrFuncs(env);
1889     }
1890     AWT_FLUSH_UNLOCK();
1891 
1892     return ret;
1893 #endif /* HEADLESS */
1894 }
1895 
1896 /*
1897  * Class:     sun_awt_X11GraphicsDevice
1898  * Method:    getCurrentDisplayMode
1899  * Signature: (I)Ljava/awt/DisplayMode;
1900  */
1901 JNIEXPORT jobject JNICALL
1902 Java_sun_awt_X11GraphicsDevice_getCurrentDisplayMode
1903     (JNIEnv* env, jclass x11gd, jint screen)
1904 {
1905 #if defined(HEADLESS) || defined(_AIX)
1906     return NULL;
1907 #else
1908     XRRScreenConfiguration *config;
1909     jobject displayMode = NULL;
1910 
1911     AWT_LOCK();
1912 
1913     if (usingXinerama && XScreenCount(awt_display) > 0) {
1914         XRRScreenResources *res = awt_XRRGetScreenResources(awt_display,
1915                                                     RootWindow(awt_display, 0));
1916         if (res) {
1917             if (res->noutput > screen) {
1918                 XRROutputInfo *output_info = awt_XRRGetOutputInfo(awt_display,
1919                                                      res, res->outputs[screen]);
1920                 if (output_info) {
1921                     if (output_info->crtc) {
1922                         XRRCrtcInfo *crtc_info =
1923                                     awt_XRRGetCrtcInfo (awt_display, res,
1924                                                         output_info->crtc);
1925                         if (crtc_info) {


1981             awt_XRRFreeScreenConfigInfo(config);
1982         }
1983     }
1984 
1985     AWT_FLUSH_UNLOCK();
1986 
1987     return displayMode;
1988 #endif /* HEADLESS */
1989 }
1990 
1991 /*
1992  * Class:     sun_awt_X11GraphicsDevice
1993  * Method:    enumDisplayModes
1994  * Signature: (ILjava/util/ArrayList;)V
1995  */
1996 JNIEXPORT void JNICALL
1997 Java_sun_awt_X11GraphicsDevice_enumDisplayModes
1998     (JNIEnv* env, jclass x11gd,
1999      jint screen, jobject arrayList)
2000 {
2001 #if !defined(HEADLESS) && !defined(_AIX)
2002 
2003     AWT_LOCK();
2004 
2005     if (usingXinerama && XScreenCount(awt_display) > 0) {
2006         XRRScreenResources *res = awt_XRRGetScreenResources(awt_display,
2007                                                     RootWindow(awt_display, 0));
2008         if (res) {
2009            if (res->noutput > screen) {
2010                 XRROutputInfo *output_info = awt_XRRGetOutputInfo(awt_display,
2011                                                      res, res->outputs[screen]);
2012                 if (output_info) {
2013                     int i;
2014                     for (i = 0; i < output_info->nmode; i++) {
2015                         RRMode m = output_info->modes[i];
2016                         int j;
2017                         XRRModeInfo *mode;
2018                         for (j = 0; j < res->nmode; j++) {
2019                             mode = &res->modes[j];
2020                             if (mode->id == m) {
2021                                  float rate = 0;


2069             }
2070 ret1:
2071             awt_XRRFreeScreenConfigInfo(config);
2072         }
2073     }
2074 
2075     AWT_FLUSH_UNLOCK();
2076 #endif /* !HEADLESS */
2077 }
2078 
2079 /*
2080  * Class:     sun_awt_X11GraphicsDevice
2081  * Method:    configDisplayMode
2082  * Signature: (IIII)V
2083  */
2084 JNIEXPORT void JNICALL
2085 Java_sun_awt_X11GraphicsDevice_configDisplayMode
2086     (JNIEnv* env, jclass x11gd,
2087      jint screen, jint width, jint height, jint refreshRate)
2088 {
2089 #if !defined(HEADLESS) && !defined(_AIX)
2090     jboolean success = JNI_FALSE;
2091     XRRScreenConfiguration *config;
2092     Drawable root;
2093     Rotation currentRotation = RR_Rotate_0;
2094 
2095     AWT_LOCK();
2096 
2097     root = RootWindow(awt_display, screen);
2098     config = awt_XRRGetScreenInfo(awt_display, root);
2099     if (config != NULL) {
2100         jboolean foundConfig = JNI_FALSE;
2101         int chosenSizeIndex = -1;
2102         short chosenRate = -1;
2103         int nsizes;
2104         XRRScreenSize *sizes = awt_XRRConfigSizes(config, &nsizes);
2105         awt_XRRConfigRotations(config, &currentRotation);
2106 
2107         if (sizes != NULL) {
2108             int i, j;
2109 


2186  */
2187 JNIEXPORT void JNICALL
2188 Java_sun_awt_X11GraphicsDevice_exitFullScreenExclusive
2189     (JNIEnv* env, jclass x11gd,
2190      jlong window)
2191 {
2192 #ifndef HEADLESS
2193     Window win = (Window)window;
2194 
2195     AWT_LOCK();
2196     X11GD_SetFullscreenMode(win, JNI_FALSE);
2197     AWT_UNLOCK();
2198 #endif /* !HEADLESS */
2199 }
2200 
2201 /**
2202  * End DisplayMode/FullScreen support
2203  */
2204 
2205 static char *get_output_screen_name(JNIEnv *env, int screen) {
2206 #ifdef _AIX
2207     return NULL;
2208 #else
2209     if (!awt_XRRGetScreenResources || !awt_XRRGetOutputInfo) {
2210         return NULL;
2211     }
2212     char *name = NULL;
2213     AWT_LOCK();
2214     int scr = 0, out = 0;
2215     if (usingXinerama && XScreenCount(awt_display) > 0) {
2216         out = screen;
2217     } else {
2218         scr = screen;
2219     }
2220 
2221     XRRScreenResources *res = awt_XRRGetScreenResources(awt_display,
2222                                                   RootWindow(awt_display, scr));
2223     if (res) {
2224        if (res->noutput > out) {
2225             XRROutputInfo *output_info = awt_XRRGetOutputInfo(awt_display,
2226                                                         res, res->outputs[out]);
2227             if (output_info) {
2228                 if (output_info->name) {
2229                     name = strdup(output_info->name);
2230                 }
2231                 awt_XRRFreeOutputInfo(output_info);
2232             }
2233         }
2234         awt_XRRFreeScreenResources(res);
2235     }
2236     AWT_UNLOCK();
2237     return name;
2238 #endif /* _AIX */
2239 }
2240 
2241 /*
2242  * Class:     sun_awt_X11GraphicsDevice
2243  * Method:    getNativeScaleFactor
2244  * Signature: (I)D
2245  */
2246 JNIEXPORT jdouble JNICALL
2247 Java_sun_awt_X11GraphicsDevice_getNativeScaleFactor
2248     (JNIEnv *env, jobject this, jint screen) {
2249     // in case of Xinerama individual screen scales are not supported
2250     char *name = get_output_screen_name(env, usingXinerama ? 0 : screen);
2251     double scale = getNativeScaleFactor(name);
2252     if (name) {
2253         free(name);
2254     }
2255     return scale;
2256 }


  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "jni_util.h"
  27 #include "awt_p.h"
  28 #include "awt.h"
  29 #include "color.h"
  30 #include <java_awt_DisplayMode.h>
  31 #include <sun_awt_X11GraphicsEnvironment.h>
  32 #include <sun_awt_X11GraphicsDevice.h>
  33 #include <sun_awt_X11GraphicsConfig.h>
  34 #ifndef HEADLESS
  35 #include <X11/extensions/Xdbe.h>
  36 #include <X11/XKBlib.h>
  37 #ifndef NO_XRANDR
  38 #include <X11/extensions/Xrandr.h>
  39 #endif
  40 #include "GLXGraphicsConfig.h"
  41 #endif /* !HEADLESS */
  42 
  43 #include <jni.h>
  44 #include <jni_util.h>
  45 #include <jvm.h>
  46 #include <jvm_md.h>
  47 #include <jlong.h>
  48 #include "systemScale.h"
  49 #include <stdlib.h>
  50 
  51 #include "awt_GraphicsEnv.h"
  52 #include "awt_util.h"
  53 #include "gdefs.h"
  54 #include <dlfcn.h>
  55 #include "Trace.h"
  56 
  57 #ifdef NETSCAPE


1610     if (XineramaSolarisCenterFunc != NULL) {
1611         (XineramaSolarisCenterFunc)(awt_display, 0, &x, &y);
1612         point = JNU_NewObjectByName(env, "java/awt/Point","(II)V", x, y);
1613         DASSERT(point);
1614     } else {
1615         DTRACE_PRINTLN("unable to call XineramaSolarisCenterFunc: symbol is null");
1616     }
1617     AWT_FLUSH_UNLOCK();
1618 #endif /* __linux __ || MACOSX */
1619 #endif /* HEADLESS */
1620     return point;
1621 }
1622 
1623 
1624 /**
1625  * Begin DisplayMode/FullScreen support
1626  */
1627 
1628 #ifndef HEADLESS
1629 
1630 #ifndef NO_XRANDR
1631 
1632 #define BIT_DEPTH_MULTI java_awt_DisplayMode_BIT_DEPTH_MULTI
1633 #define REFRESH_RATE_UNKNOWN java_awt_DisplayMode_REFRESH_RATE_UNKNOWN
1634 
1635 typedef Status
1636     (*XRRQueryVersionType) (Display *dpy, int *major_versionp, int *minor_versionp);
1637 typedef XRRScreenConfiguration*
1638     (*XRRGetScreenInfoType)(Display *dpy, Drawable root);
1639 typedef void
1640     (*XRRFreeScreenConfigInfoType)(XRRScreenConfiguration *config);
1641 typedef short*
1642     (*XRRConfigRatesType)(XRRScreenConfiguration *config,
1643                           int sizeID, int *nrates);
1644 typedef short
1645     (*XRRConfigCurrentRateType)(XRRScreenConfiguration *config);
1646 typedef XRRScreenSize*
1647     (*XRRConfigSizesType)(XRRScreenConfiguration *config,
1648                           int *nsizes);
1649 typedef SizeID
1650     (*XRRConfigCurrentConfigurationType)(XRRScreenConfiguration *config,


1817         jmethodID mid;
1818         arrayListClass = (*env)->GetObjectClass(env, arrayList);
1819         if (JNU_IsNull(env, arrayListClass)) {
1820             JNU_ThrowInternalError(env,
1821                                    "Could not get class java.util.ArrayList");
1822             return;
1823         }
1824         mid = (*env)->GetMethodID(env, arrayListClass, "add",
1825                                   "(Ljava/lang/Object;)Z");
1826         CHECK_NULL(mid);
1827         if (mid == NULL) {
1828             JNU_ThrowInternalError(env,
1829                 "Could not get method java.util.ArrayList.add()");
1830             return;
1831         }
1832         (*env)->CallObjectMethod(env, arrayList, mid, displayMode);
1833         (*env)->DeleteLocalRef(env, displayMode);
1834     }
1835 }
1836 
1837 #endif /* !NO_XRANDR */
1838 
1839 static void
1840 X11GD_SetFullscreenMode(Window win, jboolean enabled)
1841 {
1842     Atom wmState = XInternAtom(awt_display, "_NET_WM_STATE", False);
1843     Atom wmStateFs = XInternAtom(awt_display,
1844                                  "_NET_WM_STATE_FULLSCREEN", False);
1845     XWindowAttributes attr;
1846     XEvent event;
1847 
1848     if (wmState == None || wmStateFs == None
1849             || !XGetWindowAttributes(awt_display, win, &attr)) {
1850         return;
1851     }
1852 
1853     memset(&event, 0, sizeof(event));
1854     event.xclient.type = ClientMessage;
1855     event.xclient.message_type = wmState;
1856     event.xclient.display = awt_display;
1857     event.xclient.window = win;
1858     event.xclient.format = 32;
1859     event.xclient.data.l[0] = enabled ? 1 : 0; // 1==add, 0==remove
1860     event.xclient.data.l[1] = wmStateFs;
1861 
1862     XSendEvent(awt_display, attr.root, False,
1863                SubstructureRedirectMask | SubstructureNotifyMask,
1864                &event);
1865     XSync(awt_display, False);
1866 }
1867 #endif /* !HEADLESS */
1868 
1869 /*
1870  * Class:     sun_awt_X11GraphicsDevice
1871  * Method:    initXrandrExtension
1872  * Signature: ()Z
1873  */
1874 JNIEXPORT jboolean JNICALL
1875 Java_sun_awt_X11GraphicsDevice_initXrandrExtension
1876     (JNIEnv *env, jclass x11gd)
1877 {
1878 #if defined(HEADLESS) || defined(NO_XRANDR)
1879     return JNI_FALSE;
1880 #else
1881     int opcode = 0, firstEvent = 0, firstError = 0;
1882     jboolean ret;
1883 
1884     AWT_LOCK();
1885     ret = (jboolean)XQueryExtension(awt_display, "RANDR",
1886                                     &opcode, &firstEvent, &firstError);
1887     if (ret) {
1888         ret = X11GD_InitXrandrFuncs(env);
1889     }
1890     AWT_FLUSH_UNLOCK();
1891 
1892     return ret;
1893 #endif /* HEADLESS */
1894 }
1895 
1896 /*
1897  * Class:     sun_awt_X11GraphicsDevice
1898  * Method:    getCurrentDisplayMode
1899  * Signature: (I)Ljava/awt/DisplayMode;
1900  */
1901 JNIEXPORT jobject JNICALL
1902 Java_sun_awt_X11GraphicsDevice_getCurrentDisplayMode
1903     (JNIEnv* env, jclass x11gd, jint screen)
1904 {
1905 #if defined(HEADLESS) || defined(NO_XRANDR)
1906     return NULL;
1907 #else
1908     XRRScreenConfiguration *config;
1909     jobject displayMode = NULL;
1910 
1911     AWT_LOCK();
1912 
1913     if (usingXinerama && XScreenCount(awt_display) > 0) {
1914         XRRScreenResources *res = awt_XRRGetScreenResources(awt_display,
1915                                                     RootWindow(awt_display, 0));
1916         if (res) {
1917             if (res->noutput > screen) {
1918                 XRROutputInfo *output_info = awt_XRRGetOutputInfo(awt_display,
1919                                                      res, res->outputs[screen]);
1920                 if (output_info) {
1921                     if (output_info->crtc) {
1922                         XRRCrtcInfo *crtc_info =
1923                                     awt_XRRGetCrtcInfo (awt_display, res,
1924                                                         output_info->crtc);
1925                         if (crtc_info) {


1981             awt_XRRFreeScreenConfigInfo(config);
1982         }
1983     }
1984 
1985     AWT_FLUSH_UNLOCK();
1986 
1987     return displayMode;
1988 #endif /* HEADLESS */
1989 }
1990 
1991 /*
1992  * Class:     sun_awt_X11GraphicsDevice
1993  * Method:    enumDisplayModes
1994  * Signature: (ILjava/util/ArrayList;)V
1995  */
1996 JNIEXPORT void JNICALL
1997 Java_sun_awt_X11GraphicsDevice_enumDisplayModes
1998     (JNIEnv* env, jclass x11gd,
1999      jint screen, jobject arrayList)
2000 {
2001 #if !defined(HEADLESS) && !defined(NO_XRANDR)
2002 
2003     AWT_LOCK();
2004 
2005     if (usingXinerama && XScreenCount(awt_display) > 0) {
2006         XRRScreenResources *res = awt_XRRGetScreenResources(awt_display,
2007                                                     RootWindow(awt_display, 0));
2008         if (res) {
2009            if (res->noutput > screen) {
2010                 XRROutputInfo *output_info = awt_XRRGetOutputInfo(awt_display,
2011                                                      res, res->outputs[screen]);
2012                 if (output_info) {
2013                     int i;
2014                     for (i = 0; i < output_info->nmode; i++) {
2015                         RRMode m = output_info->modes[i];
2016                         int j;
2017                         XRRModeInfo *mode;
2018                         for (j = 0; j < res->nmode; j++) {
2019                             mode = &res->modes[j];
2020                             if (mode->id == m) {
2021                                  float rate = 0;


2069             }
2070 ret1:
2071             awt_XRRFreeScreenConfigInfo(config);
2072         }
2073     }
2074 
2075     AWT_FLUSH_UNLOCK();
2076 #endif /* !HEADLESS */
2077 }
2078 
2079 /*
2080  * Class:     sun_awt_X11GraphicsDevice
2081  * Method:    configDisplayMode
2082  * Signature: (IIII)V
2083  */
2084 JNIEXPORT void JNICALL
2085 Java_sun_awt_X11GraphicsDevice_configDisplayMode
2086     (JNIEnv* env, jclass x11gd,
2087      jint screen, jint width, jint height, jint refreshRate)
2088 {
2089 #if !defined(HEADLESS) && !defined(NO_XRANDR)
2090     jboolean success = JNI_FALSE;
2091     XRRScreenConfiguration *config;
2092     Drawable root;
2093     Rotation currentRotation = RR_Rotate_0;
2094 
2095     AWT_LOCK();
2096 
2097     root = RootWindow(awt_display, screen);
2098     config = awt_XRRGetScreenInfo(awt_display, root);
2099     if (config != NULL) {
2100         jboolean foundConfig = JNI_FALSE;
2101         int chosenSizeIndex = -1;
2102         short chosenRate = -1;
2103         int nsizes;
2104         XRRScreenSize *sizes = awt_XRRConfigSizes(config, &nsizes);
2105         awt_XRRConfigRotations(config, &currentRotation);
2106 
2107         if (sizes != NULL) {
2108             int i, j;
2109 


2186  */
2187 JNIEXPORT void JNICALL
2188 Java_sun_awt_X11GraphicsDevice_exitFullScreenExclusive
2189     (JNIEnv* env, jclass x11gd,
2190      jlong window)
2191 {
2192 #ifndef HEADLESS
2193     Window win = (Window)window;
2194 
2195     AWT_LOCK();
2196     X11GD_SetFullscreenMode(win, JNI_FALSE);
2197     AWT_UNLOCK();
2198 #endif /* !HEADLESS */
2199 }
2200 
2201 /**
2202  * End DisplayMode/FullScreen support
2203  */
2204 
2205 static char *get_output_screen_name(JNIEnv *env, int screen) {
2206 #ifdef NO_XRANDR
2207     return NULL;
2208 #else
2209     if (!awt_XRRGetScreenResources || !awt_XRRGetOutputInfo) {
2210         return NULL;
2211     }
2212     char *name = NULL;
2213     AWT_LOCK();
2214     int scr = 0, out = 0;
2215     if (usingXinerama && XScreenCount(awt_display) > 0) {
2216         out = screen;
2217     } else {
2218         scr = screen;
2219     }
2220 
2221     XRRScreenResources *res = awt_XRRGetScreenResources(awt_display,
2222                                                   RootWindow(awt_display, scr));
2223     if (res) {
2224        if (res->noutput > out) {
2225             XRROutputInfo *output_info = awt_XRRGetOutputInfo(awt_display,
2226                                                         res, res->outputs[out]);
2227             if (output_info) {
2228                 if (output_info->name) {
2229                     name = strdup(output_info->name);
2230                 }
2231                 awt_XRRFreeOutputInfo(output_info);
2232             }
2233         }
2234         awt_XRRFreeScreenResources(res);
2235     }
2236     AWT_UNLOCK();
2237     return name;
2238 #endif /* NO_XRANDR */
2239 }
2240 
2241 /*
2242  * Class:     sun_awt_X11GraphicsDevice
2243  * Method:    getNativeScaleFactor
2244  * Signature: (I)D
2245  */
2246 JNIEXPORT jdouble JNICALL
2247 Java_sun_awt_X11GraphicsDevice_getNativeScaleFactor
2248     (JNIEnv *env, jobject this, jint screen) {
2249     // in case of Xinerama individual screen scales are not supported
2250     char *name = get_output_screen_name(env, usingXinerama ? 0 : screen);
2251     double scale = getNativeScaleFactor(name);
2252     if (name) {
2253         free(name);
2254     }
2255     return scale;
2256 }
< prev index next >