1640 typedef short
1641 (*XRRConfigCurrentRateType)(XRRScreenConfiguration *config);
1642 typedef XRRScreenSize*
1643 (*XRRConfigSizesType)(XRRScreenConfiguration *config,
1644 int *nsizes);
1645 typedef SizeID
1646 (*XRRConfigCurrentConfigurationType)(XRRScreenConfiguration *config,
1647 Rotation *rotation);
1648 typedef Status
1649 (*XRRSetScreenConfigAndRateType)(Display *dpy,
1650 XRRScreenConfiguration *config,
1651 Drawable draw,
1652 int size_index,
1653 Rotation rotation,
1654 short rate,
1655 Time timestamp);
1656 typedef Rotation
1657 (*XRRConfigRotationsType)(XRRScreenConfiguration *config,
1658 Rotation *current_rotation);
1659
1660 static XRRQueryVersionType awt_XRRQueryVersion;
1661 static XRRGetScreenInfoType awt_XRRGetScreenInfo;
1662 static XRRFreeScreenConfigInfoType awt_XRRFreeScreenConfigInfo;
1663 static XRRConfigRatesType awt_XRRConfigRates;
1664 static XRRConfigCurrentRateType awt_XRRConfigCurrentRate;
1665 static XRRConfigSizesType awt_XRRConfigSizes;
1666 static XRRConfigCurrentConfigurationType awt_XRRConfigCurrentConfiguration;
1667 static XRRSetScreenConfigAndRateType awt_XRRSetScreenConfigAndRate;
1668 static XRRConfigRotationsType awt_XRRConfigRotations;
1669
1670 #define LOAD_XRANDR_FUNC(f) \
1671 do { \
1672 awt_##f = (f##Type)dlsym(pLibRandR, #f); \
1673 if (awt_##f == NULL) { \
1674 J2dRlsTraceLn1(J2D_TRACE_ERROR, \
1675 "X11GD_InitXrandrFuncs: Could not load %s", #f); \
1676 dlclose(pLibRandR); \
1677 return JNI_FALSE; \
1678 } \
1679 } while (0)
1680
1681 static jboolean
1682 X11GD_InitXrandrFuncs(JNIEnv *env)
1683 {
1684 int rr_maj_ver = 0, rr_min_ver = 0;
1685
1686 void *pLibRandR = dlopen(VERSIONED_JNI_LIB_NAME("Xrandr", "2"),
1687 RTLD_LAZY | RTLD_LOCAL);
1688 if (pLibRandR == NULL) {
1720 /*
1721 * REMIND: Fullscreen mode doesn't work quite right with multi-monitor
1722 * setups and RANDR 1.2.
1723 */
1724 if ((rr_maj_ver == 1 && rr_min_ver <= 2) && awt_numScreens > 1) {
1725 J2dRlsTraceLn(J2D_TRACE_INFO, "X11GD_InitXrandrFuncs: Can't use Xrandr. "
1726 "Multiple screens in use");
1727 dlclose(pLibRandR);
1728 return JNI_FALSE;
1729 }
1730 }
1731
1732 LOAD_XRANDR_FUNC(XRRGetScreenInfo);
1733 LOAD_XRANDR_FUNC(XRRFreeScreenConfigInfo);
1734 LOAD_XRANDR_FUNC(XRRConfigRates);
1735 LOAD_XRANDR_FUNC(XRRConfigCurrentRate);
1736 LOAD_XRANDR_FUNC(XRRConfigSizes);
1737 LOAD_XRANDR_FUNC(XRRConfigCurrentConfiguration);
1738 LOAD_XRANDR_FUNC(XRRSetScreenConfigAndRate);
1739 LOAD_XRANDR_FUNC(XRRConfigRotations);
1740
1741 return JNI_TRUE;
1742 }
1743
1744 static jobject
1745 X11GD_CreateDisplayMode(JNIEnv *env, jint width, jint height,
1746 jint bitDepth, jint refreshRate)
1747 {
1748 jclass displayModeClass;
1749 jmethodID cid;
1750 jint validRefreshRate = refreshRate;
1751
1752 displayModeClass = (*env)->FindClass(env, "java/awt/DisplayMode");
1753 CHECK_NULL_RETURN(displayModeClass, NULL);
1754 if (JNU_IsNull(env, displayModeClass)) {
1755 JNU_ThrowInternalError(env,
1756 "Could not get display mode class");
1757 return NULL;
1758 }
1759
1907 }
1908 }
1909
1910 AWT_FLUSH_UNLOCK();
1911
1912 return displayMode;
1913 #endif /* HEADLESS */
1914 }
1915
1916 /*
1917 * Class: sun_awt_X11GraphicsDevice
1918 * Method: enumDisplayModes
1919 * Signature: (ILjava/util/ArrayList;)V
1920 */
1921 JNIEXPORT void JNICALL
1922 Java_sun_awt_X11GraphicsDevice_enumDisplayModes
1923 (JNIEnv* env, jclass x11gd,
1924 jint screen, jobject arrayList)
1925 {
1926 #ifndef HEADLESS
1927 XRRScreenConfiguration *config;
1928
1929 AWT_LOCK();
1930
1931 config = awt_XRRGetScreenInfo(awt_display,
1932 RootWindow(awt_display, screen));
1933 if (config != NULL) {
1934 int nsizes, i, j;
1935 XRRScreenSize *sizes = awt_XRRConfigSizes(config, &nsizes);
1936
1937 if (sizes != NULL) {
1938 for (i = 0; i < nsizes; i++) {
1939 int nrates;
1940 XRRScreenSize size = sizes[i];
1941 short *rates = awt_XRRConfigRates(config, i, &nrates);
1942
1943 for (j = 0; j < nrates; j++) {
1944 X11GD_AddDisplayMode(env, arrayList,
1945 size.width,
1946 size.height,
1947 BIT_DEPTH_MULTI,
1948 rates[j]);
1949 if ((*env)->ExceptionCheck(env)) {
1950 break;
1951 }
1952 }
1953 }
1954 }
1955
1956 awt_XRRFreeScreenConfigInfo(config);
1957 }
1958
1959 AWT_FLUSH_UNLOCK();
1960 #endif /* !HEADLESS */
1961 }
1962
1963 /*
1964 * Class: sun_awt_X11GraphicsDevice
1965 * Method: configDisplayMode
1966 * Signature: (IIII)V
1967 */
1968 JNIEXPORT void JNICALL
1969 Java_sun_awt_X11GraphicsDevice_configDisplayMode
1970 (JNIEnv* env, jclass x11gd,
1971 jint screen, jint width, jint height, jint refreshRate)
1972 {
1973 #ifndef HEADLESS
1974 jboolean success = JNI_FALSE;
1975 XRRScreenConfiguration *config;
1976 Drawable root;
|
1640 typedef short
1641 (*XRRConfigCurrentRateType)(XRRScreenConfiguration *config);
1642 typedef XRRScreenSize*
1643 (*XRRConfigSizesType)(XRRScreenConfiguration *config,
1644 int *nsizes);
1645 typedef SizeID
1646 (*XRRConfigCurrentConfigurationType)(XRRScreenConfiguration *config,
1647 Rotation *rotation);
1648 typedef Status
1649 (*XRRSetScreenConfigAndRateType)(Display *dpy,
1650 XRRScreenConfiguration *config,
1651 Drawable draw,
1652 int size_index,
1653 Rotation rotation,
1654 short rate,
1655 Time timestamp);
1656 typedef Rotation
1657 (*XRRConfigRotationsType)(XRRScreenConfiguration *config,
1658 Rotation *current_rotation);
1659
1660 typedef XRRScreenResources* (*XRRGetScreenResourcesType)(Display *dpy,
1661 Window window);
1662
1663 typedef void (*XRRFreeScreenResourcesType)(XRRScreenResources *resources);
1664
1665 typedef XRROutputInfo * (*XRRGetOutputInfoType)(Display *dpy,
1666 XRRScreenResources *resources, RROutput output);
1667
1668 typedef void (*XRRFreeOutputInfoType)(XRROutputInfo *outputInfo);
1669
1670 static XRRQueryVersionType awt_XRRQueryVersion;
1671 static XRRGetScreenInfoType awt_XRRGetScreenInfo;
1672 static XRRFreeScreenConfigInfoType awt_XRRFreeScreenConfigInfo;
1673 static XRRConfigRatesType awt_XRRConfigRates;
1674 static XRRConfigCurrentRateType awt_XRRConfigCurrentRate;
1675 static XRRConfigSizesType awt_XRRConfigSizes;
1676 static XRRConfigCurrentConfigurationType awt_XRRConfigCurrentConfiguration;
1677 static XRRSetScreenConfigAndRateType awt_XRRSetScreenConfigAndRate;
1678 static XRRConfigRotationsType awt_XRRConfigRotations;
1679 static XRRGetScreenResourcesType awt_XRRGetScreenResources;
1680 static XRRFreeScreenResourcesType awt_XRRFreeScreenResources;
1681 static XRRGetOutputInfoType awt_XRRGetOutputInfo;
1682 static XRRFreeOutputInfoType awt_XRRFreeOutputInfo;
1683
1684 #define LOAD_XRANDR_FUNC(f) \
1685 do { \
1686 awt_##f = (f##Type)dlsym(pLibRandR, #f); \
1687 if (awt_##f == NULL) { \
1688 J2dRlsTraceLn1(J2D_TRACE_ERROR, \
1689 "X11GD_InitXrandrFuncs: Could not load %s", #f); \
1690 dlclose(pLibRandR); \
1691 return JNI_FALSE; \
1692 } \
1693 } while (0)
1694
1695 static jboolean
1696 X11GD_InitXrandrFuncs(JNIEnv *env)
1697 {
1698 int rr_maj_ver = 0, rr_min_ver = 0;
1699
1700 void *pLibRandR = dlopen(VERSIONED_JNI_LIB_NAME("Xrandr", "2"),
1701 RTLD_LAZY | RTLD_LOCAL);
1702 if (pLibRandR == NULL) {
1734 /*
1735 * REMIND: Fullscreen mode doesn't work quite right with multi-monitor
1736 * setups and RANDR 1.2.
1737 */
1738 if ((rr_maj_ver == 1 && rr_min_ver <= 2) && awt_numScreens > 1) {
1739 J2dRlsTraceLn(J2D_TRACE_INFO, "X11GD_InitXrandrFuncs: Can't use Xrandr. "
1740 "Multiple screens in use");
1741 dlclose(pLibRandR);
1742 return JNI_FALSE;
1743 }
1744 }
1745
1746 LOAD_XRANDR_FUNC(XRRGetScreenInfo);
1747 LOAD_XRANDR_FUNC(XRRFreeScreenConfigInfo);
1748 LOAD_XRANDR_FUNC(XRRConfigRates);
1749 LOAD_XRANDR_FUNC(XRRConfigCurrentRate);
1750 LOAD_XRANDR_FUNC(XRRConfigSizes);
1751 LOAD_XRANDR_FUNC(XRRConfigCurrentConfiguration);
1752 LOAD_XRANDR_FUNC(XRRSetScreenConfigAndRate);
1753 LOAD_XRANDR_FUNC(XRRConfigRotations);
1754 LOAD_XRANDR_FUNC(XRRGetScreenResources);
1755 LOAD_XRANDR_FUNC(XRRFreeScreenResources);
1756 LOAD_XRANDR_FUNC(XRRGetOutputInfo);
1757 LOAD_XRANDR_FUNC(XRRFreeOutputInfo);
1758
1759 return JNI_TRUE;
1760 }
1761
1762 static jobject
1763 X11GD_CreateDisplayMode(JNIEnv *env, jint width, jint height,
1764 jint bitDepth, jint refreshRate)
1765 {
1766 jclass displayModeClass;
1767 jmethodID cid;
1768 jint validRefreshRate = refreshRate;
1769
1770 displayModeClass = (*env)->FindClass(env, "java/awt/DisplayMode");
1771 CHECK_NULL_RETURN(displayModeClass, NULL);
1772 if (JNU_IsNull(env, displayModeClass)) {
1773 JNU_ThrowInternalError(env,
1774 "Could not get display mode class");
1775 return NULL;
1776 }
1777
1925 }
1926 }
1927
1928 AWT_FLUSH_UNLOCK();
1929
1930 return displayMode;
1931 #endif /* HEADLESS */
1932 }
1933
1934 /*
1935 * Class: sun_awt_X11GraphicsDevice
1936 * Method: enumDisplayModes
1937 * Signature: (ILjava/util/ArrayList;)V
1938 */
1939 JNIEXPORT void JNICALL
1940 Java_sun_awt_X11GraphicsDevice_enumDisplayModes
1941 (JNIEnv* env, jclass x11gd,
1942 jint screen, jobject arrayList)
1943 {
1944 #ifndef HEADLESS
1945
1946 AWT_LOCK();
1947
1948 if (usingXinerama && XScreenCount(awt_display) > 0) {
1949 XRRScreenResources *res = awt_XRRGetScreenResources(awt_display,
1950 RootWindow(awt_display, 0));
1951 if (res) {
1952 if (res->noutput > screen) {
1953 XRROutputInfo *output_info = awt_XRRGetOutputInfo(awt_display,
1954 res, res->outputs[screen]);
1955 if (output_info) {
1956 int i;
1957 for (i = 0; i < res->nmode; i++) {
1958 RRMode m = output_info->modes[i];
1959 int j;
1960 XRRModeInfo *mode;
1961 for (j = 0; j < res->nmode; j++) {
1962 mode = &res->modes[j];
1963 if (mode->id == m) {
1964 float rate = 0;
1965 if (mode->hTotal && mode->vTotal) {
1966 rate = ((float)mode->dotClock /
1967 ((float)mode->hTotal *
1968 (float)mode->vTotal));
1969 }
1970 X11GD_AddDisplayMode(env, arrayList,
1971 mode->width, mode->height,
1972 BIT_DEPTH_MULTI, (int)(rate +.2));
1973 break;
1974 }
1975 }
1976 }
1977 awt_XRRFreeOutputInfo(output_info);
1978 }
1979 }
1980 awt_XRRFreeScreenResources(res);
1981 }
1982 } else {
1983 XRRScreenConfiguration *config;
1984
1985 config = awt_XRRGetScreenInfo(awt_display,
1986 RootWindow(awt_display, screen));
1987 if (config != NULL) {
1988 int nsizes, i, j;
1989 XRRScreenSize *sizes = awt_XRRConfigSizes(config, &nsizes);
1990
1991 if (sizes != NULL) {
1992 for (i = 0; i < nsizes; i++) {
1993 int nrates;
1994 XRRScreenSize size = sizes[i];
1995 short *rates = awt_XRRConfigRates(config, i, &nrates);
1996
1997 for (j = 0; j < nrates; j++) {
1998 X11GD_AddDisplayMode(env, arrayList,
1999 size.width,
2000 size.height,
2001 BIT_DEPTH_MULTI,
2002 rates[j]);
2003 if ((*env)->ExceptionCheck(env)) {
2004 break;
2005 }
2006 }
2007 }
2008 }
2009
2010 awt_XRRFreeScreenConfigInfo(config);
2011 }
2012 }
2013
2014 AWT_FLUSH_UNLOCK();
2015 #endif /* !HEADLESS */
2016 }
2017
2018 /*
2019 * Class: sun_awt_X11GraphicsDevice
2020 * Method: configDisplayMode
2021 * Signature: (IIII)V
2022 */
2023 JNIEXPORT void JNICALL
2024 Java_sun_awt_X11GraphicsDevice_configDisplayMode
2025 (JNIEnv* env, jclass x11gd,
2026 jint screen, jint width, jint height, jint refreshRate)
2027 {
2028 #ifndef HEADLESS
2029 jboolean success = JNI_FALSE;
2030 XRRScreenConfiguration *config;
2031 Drawable root;
|