< prev index next >

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

Print this page




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) {


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 


1878 #endif /* HEADLESS */
1879 }
1880 
1881 /*
1882  * Class:     sun_awt_X11GraphicsDevice
1883  * Method:    getCurrentDisplayMode
1884  * Signature: (I)Ljava/awt/DisplayMode;
1885  */
1886 JNIEXPORT jobject JNICALL
1887 Java_sun_awt_X11GraphicsDevice_getCurrentDisplayMode
1888     (JNIEnv* env, jclass x11gd, jint screen)
1889 {
1890 #ifdef HEADLESS
1891     return NULL;
1892 #else
1893     XRRScreenConfiguration *config;
1894     jobject displayMode = NULL;
1895 
1896     AWT_LOCK();
1897 
1898     if (screen < ScreenCount(awt_display)) {










































1899 
1900         config = awt_XRRGetScreenInfo(awt_display,
1901                                       RootWindow(awt_display, screen));
1902         if (config != NULL) {
1903             Rotation rotation;
1904             short curRate;
1905             SizeID curSizeIndex;
1906             XRRScreenSize *sizes;
1907             int nsizes;
1908 
1909             curSizeIndex = awt_XRRConfigCurrentConfiguration(config, &rotation);
1910             sizes = awt_XRRConfigSizes(config, &nsizes);
1911             curRate = awt_XRRConfigCurrentRate(config);
1912 
1913             if ((sizes != NULL) &&
1914                 (curSizeIndex < nsizes))
1915             {
1916                 XRRScreenSize curSize = sizes[curSizeIndex];
1917                 displayMode = X11GD_CreateDisplayMode(env,
1918                                                       curSize.width,


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);




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 typedef XRRCrtcInfo* (*XRRGetCrtcInfoType)(Display *dpy,
1671                                     XRRScreenResources *resources, RRCrtc crtc);
1672 
1673 typedef void (*XRRFreeCrtcInfoType)(XRRCrtcInfo *crtcInfo);
1674 
1675 static XRRQueryVersionType               awt_XRRQueryVersion;
1676 static XRRGetScreenInfoType              awt_XRRGetScreenInfo;
1677 static XRRFreeScreenConfigInfoType       awt_XRRFreeScreenConfigInfo;
1678 static XRRConfigRatesType                awt_XRRConfigRates;
1679 static XRRConfigCurrentRateType          awt_XRRConfigCurrentRate;
1680 static XRRConfigSizesType                awt_XRRConfigSizes;
1681 static XRRConfigCurrentConfigurationType awt_XRRConfigCurrentConfiguration;
1682 static XRRSetScreenConfigAndRateType     awt_XRRSetScreenConfigAndRate;
1683 static XRRConfigRotationsType            awt_XRRConfigRotations;
1684 static XRRGetScreenResourcesType         awt_XRRGetScreenResources;
1685 static XRRFreeScreenResourcesType        awt_XRRFreeScreenResources;
1686 static XRRGetOutputInfoType              awt_XRRGetOutputInfo;
1687 static XRRFreeOutputInfoType             awt_XRRFreeOutputInfo;
1688 static XRRGetCrtcInfoType                awt_XRRGetCrtcInfo;
1689 static XRRFreeCrtcInfoType               awt_XRRFreeCrtcInfo;
1690 
1691 #define LOAD_XRANDR_FUNC(f) \
1692     do { \
1693         awt_##f = (f##Type)dlsym(pLibRandR, #f); \
1694         if (awt_##f == NULL) { \
1695             J2dRlsTraceLn1(J2D_TRACE_ERROR, \
1696                            "X11GD_InitXrandrFuncs: Could not load %s", #f); \
1697             dlclose(pLibRandR); \
1698             return JNI_FALSE; \
1699         } \
1700     } while (0)
1701 
1702 static jboolean
1703 X11GD_InitXrandrFuncs(JNIEnv *env)
1704 {
1705     int rr_maj_ver = 0, rr_min_ver = 0;
1706 
1707     void *pLibRandR = dlopen(VERSIONED_JNI_LIB_NAME("Xrandr", "2"),
1708                              RTLD_LAZY | RTLD_LOCAL);
1709     if (pLibRandR == NULL) {


1745         if ((rr_maj_ver == 1 && rr_min_ver <= 2) && awt_numScreens > 1) {
1746             J2dRlsTraceLn(J2D_TRACE_INFO, "X11GD_InitXrandrFuncs: Can't use Xrandr. "
1747                           "Multiple screens in use");
1748             dlclose(pLibRandR);
1749             return JNI_FALSE;
1750         }
1751     }
1752 
1753     LOAD_XRANDR_FUNC(XRRGetScreenInfo);
1754     LOAD_XRANDR_FUNC(XRRFreeScreenConfigInfo);
1755     LOAD_XRANDR_FUNC(XRRConfigRates);
1756     LOAD_XRANDR_FUNC(XRRConfigCurrentRate);
1757     LOAD_XRANDR_FUNC(XRRConfigSizes);
1758     LOAD_XRANDR_FUNC(XRRConfigCurrentConfiguration);
1759     LOAD_XRANDR_FUNC(XRRSetScreenConfigAndRate);
1760     LOAD_XRANDR_FUNC(XRRConfigRotations);
1761     LOAD_XRANDR_FUNC(XRRGetScreenResources);
1762     LOAD_XRANDR_FUNC(XRRFreeScreenResources);
1763     LOAD_XRANDR_FUNC(XRRGetOutputInfo);
1764     LOAD_XRANDR_FUNC(XRRFreeOutputInfo);
1765     LOAD_XRANDR_FUNC(XRRGetCrtcInfo);
1766     LOAD_XRANDR_FUNC(XRRFreeCrtcInfo);
1767 
1768     return JNI_TRUE;
1769 }
1770 
1771 static jobject
1772 X11GD_CreateDisplayMode(JNIEnv *env, jint width, jint height,
1773                         jint bitDepth, jint refreshRate)
1774 {
1775     jclass displayModeClass;
1776     jmethodID cid;
1777     jint validRefreshRate = refreshRate;
1778 
1779     displayModeClass = (*env)->FindClass(env, "java/awt/DisplayMode");
1780     CHECK_NULL_RETURN(displayModeClass, NULL);
1781     if (JNU_IsNull(env, displayModeClass)) {
1782         JNU_ThrowInternalError(env,
1783                                "Could not get display mode class");
1784         return NULL;
1785     }
1786 


1887 #endif /* HEADLESS */
1888 }
1889 
1890 /*
1891  * Class:     sun_awt_X11GraphicsDevice
1892  * Method:    getCurrentDisplayMode
1893  * Signature: (I)Ljava/awt/DisplayMode;
1894  */
1895 JNIEXPORT jobject JNICALL
1896 Java_sun_awt_X11GraphicsDevice_getCurrentDisplayMode
1897     (JNIEnv* env, jclass x11gd, jint screen)
1898 {
1899 #ifdef HEADLESS
1900     return NULL;
1901 #else
1902     XRRScreenConfiguration *config;
1903     jobject displayMode = NULL;
1904 
1905     AWT_LOCK();
1906 
1907     if (usingXinerama && XScreenCount(awt_display) > 0) {
1908         XRRScreenResources *res = awt_XRRGetScreenResources(awt_display,
1909                                                     RootWindow(awt_display, 0));
1910         if (res) {
1911             if (res->noutput > screen) {
1912                 XRROutputInfo *output_info = awt_XRRGetOutputInfo(awt_display,
1913                                                      res, res->outputs[screen]);
1914                 if (output_info) {
1915                     if (output_info->crtc) {
1916                         XRRCrtcInfo *crtc_info =
1917                                     awt_XRRGetCrtcInfo (awt_display, res,
1918                                                         output_info->crtc);
1919                         if (crtc_info) {
1920                             if (crtc_info->mode) {
1921                                 int i;
1922                                 for (i = 0; i < res->nmode; i++) {
1923                                     XRRModeInfo *mode = &res->modes[i];
1924                                     if (mode->id == crtc_info->mode) {
1925                                         float rate = 0;
1926                                         if (mode->hTotal && mode->vTotal) {
1927                                              rate = ((float)mode->dotClock /
1928                                                     ((float)mode->hTotal *
1929                                                     (float)mode->vTotal));
1930                                         }
1931                                         displayMode = X11GD_CreateDisplayMode(
1932                                                            env,
1933                                                            mode->width,
1934                                                            mode->height,
1935                                                            BIT_DEPTH_MULTI,
1936                                                            (int)(rate +.2));
1937                                         break;
1938                                     }
1939                                 }
1940                             }
1941                             awt_XRRFreeCrtcInfo(crtc_info);
1942                         }
1943                     }
1944                     awt_XRRFreeOutputInfo(output_info);
1945                 }
1946             }
1947             awt_XRRFreeScreenResources(res);
1948         }
1949     } else {
1950 
1951         config = awt_XRRGetScreenInfo(awt_display,
1952                                       RootWindow(awt_display, screen));
1953         if (config != NULL) {
1954             Rotation rotation;
1955             short curRate;
1956             SizeID curSizeIndex;
1957             XRRScreenSize *sizes;
1958             int nsizes;
1959 
1960             curSizeIndex = awt_XRRConfigCurrentConfiguration(config, &rotation);
1961             sizes = awt_XRRConfigSizes(config, &nsizes);
1962             curRate = awt_XRRConfigCurrentRate(config);
1963 
1964             if ((sizes != NULL) &&
1965                 (curSizeIndex < nsizes))
1966             {
1967                 XRRScreenSize curSize = sizes[curSizeIndex];
1968                 displayMode = X11GD_CreateDisplayMode(env,
1969                                                       curSize.width,


1988  * Signature: (ILjava/util/ArrayList;)V
1989  */
1990 JNIEXPORT void JNICALL
1991 Java_sun_awt_X11GraphicsDevice_enumDisplayModes
1992     (JNIEnv* env, jclass x11gd,
1993      jint screen, jobject arrayList)
1994 {
1995 #ifndef HEADLESS
1996 
1997     AWT_LOCK();
1998 
1999     if (usingXinerama && XScreenCount(awt_display) > 0) {
2000         XRRScreenResources *res = awt_XRRGetScreenResources(awt_display,
2001                                                     RootWindow(awt_display, 0));
2002         if (res) {
2003            if (res->noutput > screen) {
2004                 XRROutputInfo *output_info = awt_XRRGetOutputInfo(awt_display,
2005                                                      res, res->outputs[screen]);
2006                 if (output_info) {
2007                     int i;
2008                     for (i = 0; i < output_info->nmode; i++) {
2009                         RRMode m = output_info->modes[i];
2010                         int j;
2011                         XRRModeInfo *mode;
2012                         for (j = 0; j < res->nmode; j++) {
2013                             mode = &res->modes[j];
2014                             if (mode->id == m) {
2015                                  float rate = 0;
2016                                  if (mode->hTotal && mode->vTotal) {
2017                                      rate = ((float)mode->dotClock /
2018                                                    ((float)mode->hTotal *
2019                                                           (float)mode->vTotal));
2020                                  }
2021                                  X11GD_AddDisplayMode(env, arrayList,
2022                                         mode->width, mode->height,
2023                                               BIT_DEPTH_MULTI, (int)(rate +.2));
2024                                  break;
2025                             }
2026                         }
2027                     }
2028                     awt_XRRFreeOutputInfo(output_info);


< prev index next >