< prev index next >

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

Print this page

        

@@ -117,12 +117,13 @@
    short width;
    short height;
 } XineramaScreenInfo;
 
 typedef XineramaScreenInfo* XineramaQueryScreensFunc(Display*, int*);
-static XineramaQueryScreensFunc* XineramaQueryScreens = NULL;
+
 Bool usingXinerama = False;
+XRectangle fbrects[MAXFRAMEBUFFERS];
 
 JNIEXPORT void JNICALL
 Java_sun_awt_X11GraphicsConfig_initIDs (JNIEnv *env, jclass cls)
 {
     x11GraphicsConfigIDs.aData = NULL;

@@ -583,10 +584,11 @@
     Bool gotXinExt = False;
     void* libHandle = NULL;
     int32_t locNumScr = 0;
     XineramaScreenInfo *xinInfo;
     char* XineramaQueryScreensName = "XineramaQueryScreens";
+    XineramaQueryScreensFunc* XineramaQueryScreens = NULL;
 
     gotXinExt = XQueryExtension(awt_display, XinExtName, &major_opcode,
                                 &first_event, &first_error);
 
     if (!gotXinExt) {

@@ -608,31 +610,40 @@
     }
     if (libHandle != NULL) {
         XineramaQueryScreens = (XineramaQueryScreensFunc*)
             dlsym(libHandle, XineramaQueryScreensName);
 
-        if (XineramaQueryScreens == NULL) {
-            DTRACE_PRINTLN("couldn't load XineramaQueryScreens symbol");
-            dlclose(libHandle);
-        } else {
+        if (XineramaQueryScreens != NULL) {
             DTRACE_PRINTLN("calling XineramaQueryScreens func");
             xinInfo = (*XineramaQueryScreens)(awt_display, &locNumScr);
-            if (xinInfo != NULL) {
-                if (locNumScr > XScreenCount(awt_display)) {
-                    DTRACE_PRINTLN("Enabling Xinerama support");
-                    usingXinerama = True;
-                    /* set global number of screens */
-                    DTRACE_PRINTLN1(" num screens = %i\n", locNumScr);
-                    awt_numScreens = locNumScr;
-                } else {
-                    DTRACE_PRINTLN("XineramaQueryScreens <= XScreenCount");
+            if (xinInfo != NULL && locNumScr > XScreenCount(awt_display)) {
+                int32_t idx;
+                DTRACE_PRINTLN("Enabling Xinerama support");
+                usingXinerama = True;
+                /* set global number of screens */
+                DTRACE_PRINTLN1(" num screens = %i\n", locNumScr);
+                awt_numScreens = locNumScr;
+
+                /* stuff values into fbrects */
+                for (idx = 0; idx < awt_numScreens; idx++) {
+                    DASSERT(xinInfo[idx].screen_number == idx);
+
+                    fbrects[idx].width = xinInfo[idx].width;
+                    fbrects[idx].height = xinInfo[idx].height;
+                    fbrects[idx].x = xinInfo[idx].x_org;
+                    fbrects[idx].y = xinInfo[idx].y_org;
                 }
-                XFree(xinInfo);
             } else {
-                DTRACE_PRINTLN("calling XineramaQueryScreens didn't work");
+                DTRACE_PRINTLN((xinInfo == NULL) ?
+                               "calling XineramaQueryScreens didn't work" :
+                               "XineramaQueryScreens <= XScreenCount"
+                               );
             }
+        } else {
+            DTRACE_PRINTLN("couldn't load XineramaQueryScreens symbol");
         }
+        dlclose(libHandle);
     } else {
         DTRACE_PRINTLN1("\ncouldn't open shared library: %s\n", dlerror());
     }
 }
 #endif /* HEADLESS */

@@ -1290,46 +1301,31 @@
 #else
     jclass clazz;
     jmethodID mid;
     jobject bounds = NULL;
     AwtGraphicsConfigDataPtr adata;
-    int32_t locNumScr = 0;
-    XineramaScreenInfo *xinInfo;
 
     adata = (AwtGraphicsConfigDataPtr)
         JNU_GetLongFieldAsPtr(env, this, x11GraphicsConfigIDs.aData);
 
     clazz = (*env)->FindClass(env, "java/awt/Rectangle");
     CHECK_NULL_RETURN(clazz, NULL);
     mid = (*env)->GetMethodID(env, clazz, "<init>", "(IIII)V");
     if (mid != NULL) {
         if (usingXinerama) {
             if (0 <= screen && screen < awt_numScreens) {
-                AWT_LOCK();
-                xinInfo = (*XineramaQueryScreens)(awt_display, &locNumScr);
-                AWT_UNLOCK();
-                if (xinInfo != NULL && locNumScr > 0) {
-                    if (screen >= locNumScr) {
-                        screen = 0; // fallback to the main screen
-                    }
-                    DASSERT(xinInfo[screen].screen_number == screen);
-                    bounds = (*env)->NewObject(env, clazz, mid,
-                                               xinInfo[screen].x_org,
-                                               xinInfo[screen].y_org,
-                                               xinInfo[screen].width,
-                                               xinInfo[screen].height);
-                    XFree(xinInfo);
-                }
+                bounds = (*env)->NewObject(env, clazz, mid, fbrects[screen].x,
+                                                            fbrects[screen].y,
+                                                            fbrects[screen].width,
+                                                            fbrects[screen].height);
             } else {
                 jclass exceptionClass = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
                 if (exceptionClass != NULL) {
                     (*env)->ThrowNew(env, exceptionClass, "Illegal screen index");
                 }
             }
-        }
-        if (!bounds) {
-            // Xinerama cannot provide correct bounds, will try X11
+        } else {
             XWindowAttributes xwa;
             memset(&xwa, 0, sizeof(xwa));
 
             AWT_LOCK ();
             XGetWindowAttributes(awt_display,
< prev index next >