< prev index next >

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

Print this page




 102  *
 103  * As of fix 4356756, AWT is Xinerama-aware.  X11GraphicsDevices are created for
 104  * each screen of a Xinerama setup, though X11 itself still only sees a single
 105  * display.
 106  * In many places where we talk to X11, a xinawareScreen variable is used to
 107  * pass the correct Display value, depending on the circumstances (a single
 108  * X display, multiple X displays, or a single X display with multiple
 109  * Xinerama screens).
 110  */
 111 
 112 #define MAXFRAMEBUFFERS 16
 113 typedef struct {
 114    int   screen_number;
 115    short x_org;
 116    short y_org;
 117    short width;
 118    short height;
 119 } XineramaScreenInfo;
 120 
 121 typedef XineramaScreenInfo* XineramaQueryScreensFunc(Display*, int*);
 122 static XineramaQueryScreensFunc* XineramaQueryScreens = NULL;
 123 Bool usingXinerama = False;

 124 
 125 JNIEXPORT void JNICALL
 126 Java_sun_awt_X11GraphicsConfig_initIDs (JNIEnv *env, jclass cls)
 127 {
 128     x11GraphicsConfigIDs.aData = NULL;
 129     x11GraphicsConfigIDs.bitsPerPixel = NULL;
 130 
 131     x11GraphicsConfigIDs.aData = (*env)->GetFieldID (env, cls, "aData", "J");
 132     CHECK_NULL(x11GraphicsConfigIDs.aData);
 133     x11GraphicsConfigIDs.bitsPerPixel = (*env)->GetFieldID (env, cls, "bitsPerPixel", "I");
 134     CHECK_NULL(x11GraphicsConfigIDs.bitsPerPixel);
 135 }
 136 
 137 #ifndef HEADLESS
 138 
 139 /*
 140  * XIOErrorHandler
 141  */
 142 static int xioerror_handler(Display *disp)
 143 {


 568 
 569     screenDataPtr->numConfigs = nConfig;
 570     screenDataPtr->configs = graphicsConfigs;
 571 
 572     AWT_UNLOCK ();
 573 }
 574 
 575 #ifndef HEADLESS
 576 
 577 /*
 578  * Checks if Xinerama is running and perform Xinerama-related initialization.
 579  */
 580 static void xineramaInit(void) {
 581     char* XinExtName = "XINERAMA";
 582     int32_t major_opcode, first_event, first_error;
 583     Bool gotXinExt = False;
 584     void* libHandle = NULL;
 585     int32_t locNumScr = 0;
 586     XineramaScreenInfo *xinInfo;
 587     char* XineramaQueryScreensName = "XineramaQueryScreens";

 588 
 589     gotXinExt = XQueryExtension(awt_display, XinExtName, &major_opcode,
 590                                 &first_event, &first_error);
 591 
 592     if (!gotXinExt) {
 593         DTRACE_PRINTLN("Xinerama extension is not available");
 594         return;
 595     }
 596 
 597     DTRACE_PRINTLN("Xinerama extension is available");
 598 
 599     /* load library */
 600     libHandle = dlopen(VERSIONED_JNI_LIB_NAME("Xinerama", "1"),
 601                        RTLD_LAZY | RTLD_GLOBAL);
 602     if (libHandle == NULL) {
 603 #if defined(_AIX)
 604         libHandle = dlopen("libXext.a(shr_64.o)", RTLD_MEMBER | RTLD_LAZY | RTLD_GLOBAL);
 605 #else
 606         libHandle = dlopen(JNI_LIB_NAME("Xinerama"), RTLD_LAZY | RTLD_GLOBAL);
 607 #endif
 608     }
 609     if (libHandle != NULL) {
 610         XineramaQueryScreens = (XineramaQueryScreensFunc*)
 611             dlsym(libHandle, XineramaQueryScreensName);
 612 
 613         if (XineramaQueryScreens == NULL) {
 614             DTRACE_PRINTLN("couldn't load XineramaQueryScreens symbol");
 615             dlclose(libHandle);
 616         } else {
 617             DTRACE_PRINTLN("calling XineramaQueryScreens func");
 618             xinInfo = (*XineramaQueryScreens)(awt_display, &locNumScr);
 619             if (xinInfo != NULL) {
 620                 if (locNumScr > XScreenCount(awt_display)) {
 621                     DTRACE_PRINTLN("Enabling Xinerama support");
 622                     usingXinerama = True;
 623                     /* set global number of screens */
 624                     DTRACE_PRINTLN1(" num screens = %i\n", locNumScr);
 625                     awt_numScreens = locNumScr;
 626                 } else {
 627                     DTRACE_PRINTLN("XineramaQueryScreens <= XScreenCount");







 628                 }
 629                 XFree(xinInfo);
 630             } else {
 631                 DTRACE_PRINTLN("calling XineramaQueryScreens didn't work");



 632             }


 633         }

 634     } else {
 635         DTRACE_PRINTLN1("\ncouldn't open shared library: %s\n", dlerror());
 636     }
 637 }
 638 #endif /* HEADLESS */
 639 
 640 Display *
 641 awt_init_Display(JNIEnv *env, jobject this)
 642 {
 643     jclass klass;
 644     Display *dpy;
 645     char errmsg[128];
 646     int i;
 647 
 648     if (awt_display) {
 649         return awt_display;
 650     }
 651 
 652     /* Load AWT lock-related methods in SunToolkit */
 653     klass = (*env)->FindClass(env, "sun/awt/SunToolkit");


1275     return colorModel;
1276 #endif /* !HEADLESS */
1277 }
1278 
1279 
1280 /*
1281  * Class:     sun_awt_X11GraphicsConfig
1282  * Method:    getBounds
1283  * Signature: ()Ljava/awt/Rectangle
1284  */
1285 JNIEXPORT jobject JNICALL
1286 Java_sun_awt_X11GraphicsConfig_pGetBounds(JNIEnv *env, jobject this, jint screen)
1287 {
1288 #ifdef HEADLESS
1289     return NULL;
1290 #else
1291     jclass clazz;
1292     jmethodID mid;
1293     jobject bounds = NULL;
1294     AwtGraphicsConfigDataPtr adata;
1295     int32_t locNumScr = 0;
1296     XineramaScreenInfo *xinInfo;
1297 
1298     adata = (AwtGraphicsConfigDataPtr)
1299         JNU_GetLongFieldAsPtr(env, this, x11GraphicsConfigIDs.aData);
1300 
1301     clazz = (*env)->FindClass(env, "java/awt/Rectangle");
1302     CHECK_NULL_RETURN(clazz, NULL);
1303     mid = (*env)->GetMethodID(env, clazz, "<init>", "(IIII)V");
1304     if (mid != NULL) {
1305         if (usingXinerama) {
1306             if (0 <= screen && screen < awt_numScreens) {
1307                 AWT_LOCK();
1308                 xinInfo = (*XineramaQueryScreens)(awt_display, &locNumScr);
1309                 AWT_UNLOCK();
1310                 if (xinInfo != NULL && locNumScr > 0) {
1311                     if (screen >= locNumScr) {
1312                         screen = 0; // fallback to the main screen
1313                     }
1314                     DASSERT(xinInfo[screen].screen_number == screen);
1315                     bounds = (*env)->NewObject(env, clazz, mid,
1316                                                xinInfo[screen].x_org,
1317                                                xinInfo[screen].y_org,
1318                                                xinInfo[screen].width,
1319                                                xinInfo[screen].height);
1320                     XFree(xinInfo);
1321                 }
1322             } else {
1323                 jclass exceptionClass = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
1324                 if (exceptionClass != NULL) {
1325                     (*env)->ThrowNew(env, exceptionClass, "Illegal screen index");
1326                 }
1327             }
1328         }
1329         if (!bounds) {
1330             // Xinerama cannot provide correct bounds, will try X11
1331             XWindowAttributes xwa;
1332             memset(&xwa, 0, sizeof(xwa));
1333 
1334             AWT_LOCK ();
1335             XGetWindowAttributes(awt_display,
1336                     RootWindow(awt_display, adata->awt_visInfo.screen),
1337                     &xwa);
1338             AWT_UNLOCK ();
1339 
1340             bounds = (*env)->NewObject(env, clazz, mid, 0, 0,
1341                     xwa.width, xwa.height);
1342         }
1343 
1344         if ((*env)->ExceptionOccurred(env)) {
1345             return NULL;
1346         }
1347     }
1348     return bounds;
1349 #endif /* !HEADLESS */
1350 }




 102  *
 103  * As of fix 4356756, AWT is Xinerama-aware.  X11GraphicsDevices are created for
 104  * each screen of a Xinerama setup, though X11 itself still only sees a single
 105  * display.
 106  * In many places where we talk to X11, a xinawareScreen variable is used to
 107  * pass the correct Display value, depending on the circumstances (a single
 108  * X display, multiple X displays, or a single X display with multiple
 109  * Xinerama screens).
 110  */
 111 
 112 #define MAXFRAMEBUFFERS 16
 113 typedef struct {
 114    int   screen_number;
 115    short x_org;
 116    short y_org;
 117    short width;
 118    short height;
 119 } XineramaScreenInfo;
 120 
 121 typedef XineramaScreenInfo* XineramaQueryScreensFunc(Display*, int*);
 122 
 123 Bool usingXinerama = False;
 124 XRectangle fbrects[MAXFRAMEBUFFERS];
 125 
 126 JNIEXPORT void JNICALL
 127 Java_sun_awt_X11GraphicsConfig_initIDs (JNIEnv *env, jclass cls)
 128 {
 129     x11GraphicsConfigIDs.aData = NULL;
 130     x11GraphicsConfigIDs.bitsPerPixel = NULL;
 131 
 132     x11GraphicsConfigIDs.aData = (*env)->GetFieldID (env, cls, "aData", "J");
 133     CHECK_NULL(x11GraphicsConfigIDs.aData);
 134     x11GraphicsConfigIDs.bitsPerPixel = (*env)->GetFieldID (env, cls, "bitsPerPixel", "I");
 135     CHECK_NULL(x11GraphicsConfigIDs.bitsPerPixel);
 136 }
 137 
 138 #ifndef HEADLESS
 139 
 140 /*
 141  * XIOErrorHandler
 142  */
 143 static int xioerror_handler(Display *disp)
 144 {


 569 
 570     screenDataPtr->numConfigs = nConfig;
 571     screenDataPtr->configs = graphicsConfigs;
 572 
 573     AWT_UNLOCK ();
 574 }
 575 
 576 #ifndef HEADLESS
 577 
 578 /*
 579  * Checks if Xinerama is running and perform Xinerama-related initialization.
 580  */
 581 static void xineramaInit(void) {
 582     char* XinExtName = "XINERAMA";
 583     int32_t major_opcode, first_event, first_error;
 584     Bool gotXinExt = False;
 585     void* libHandle = NULL;
 586     int32_t locNumScr = 0;
 587     XineramaScreenInfo *xinInfo;
 588     char* XineramaQueryScreensName = "XineramaQueryScreens";
 589     XineramaQueryScreensFunc* XineramaQueryScreens = NULL;
 590 
 591     gotXinExt = XQueryExtension(awt_display, XinExtName, &major_opcode,
 592                                 &first_event, &first_error);
 593 
 594     if (!gotXinExt) {
 595         DTRACE_PRINTLN("Xinerama extension is not available");
 596         return;
 597     }
 598 
 599     DTRACE_PRINTLN("Xinerama extension is available");
 600 
 601     /* load library */
 602     libHandle = dlopen(VERSIONED_JNI_LIB_NAME("Xinerama", "1"),
 603                        RTLD_LAZY | RTLD_GLOBAL);
 604     if (libHandle == NULL) {
 605 #if defined(_AIX)
 606         libHandle = dlopen("libXext.a(shr_64.o)", RTLD_MEMBER | RTLD_LAZY | RTLD_GLOBAL);
 607 #else
 608         libHandle = dlopen(JNI_LIB_NAME("Xinerama"), RTLD_LAZY | RTLD_GLOBAL);
 609 #endif
 610     }
 611     if (libHandle != NULL) {
 612         XineramaQueryScreens = (XineramaQueryScreensFunc*)
 613             dlsym(libHandle, XineramaQueryScreensName);
 614 
 615         if (XineramaQueryScreens != NULL) {



 616             DTRACE_PRINTLN("calling XineramaQueryScreens func");
 617             xinInfo = (*XineramaQueryScreens)(awt_display, &locNumScr);
 618             if (xinInfo != NULL && locNumScr > XScreenCount(awt_display)) {
 619                 int32_t idx;
 620                 DTRACE_PRINTLN("Enabling Xinerama support");
 621                 usingXinerama = True;
 622                 /* set global number of screens */
 623                 DTRACE_PRINTLN1(" num screens = %i\n", locNumScr);
 624                 awt_numScreens = locNumScr;
 625 
 626                 /* stuff values into fbrects */
 627                 for (idx = 0; idx < awt_numScreens; idx++) {
 628                     DASSERT(xinInfo[idx].screen_number == idx);
 629 
 630                     fbrects[idx].width = xinInfo[idx].width;
 631                     fbrects[idx].height = xinInfo[idx].height;
 632                     fbrects[idx].x = xinInfo[idx].x_org;
 633                     fbrects[idx].y = xinInfo[idx].y_org;
 634                 }

 635             } else {
 636                 DTRACE_PRINTLN((xinInfo == NULL) ?
 637                                "calling XineramaQueryScreens didn't work" :
 638                                "XineramaQueryScreens <= XScreenCount"
 639                                );
 640             }
 641         } else {
 642             DTRACE_PRINTLN("couldn't load XineramaQueryScreens symbol");
 643         }
 644         dlclose(libHandle);
 645     } else {
 646         DTRACE_PRINTLN1("\ncouldn't open shared library: %s\n", dlerror());
 647     }
 648 }
 649 #endif /* HEADLESS */
 650 
 651 Display *
 652 awt_init_Display(JNIEnv *env, jobject this)
 653 {
 654     jclass klass;
 655     Display *dpy;
 656     char errmsg[128];
 657     int i;
 658 
 659     if (awt_display) {
 660         return awt_display;
 661     }
 662 
 663     /* Load AWT lock-related methods in SunToolkit */
 664     klass = (*env)->FindClass(env, "sun/awt/SunToolkit");


1286     return colorModel;
1287 #endif /* !HEADLESS */
1288 }
1289 
1290 
1291 /*
1292  * Class:     sun_awt_X11GraphicsConfig
1293  * Method:    getBounds
1294  * Signature: ()Ljava/awt/Rectangle
1295  */
1296 JNIEXPORT jobject JNICALL
1297 Java_sun_awt_X11GraphicsConfig_pGetBounds(JNIEnv *env, jobject this, jint screen)
1298 {
1299 #ifdef HEADLESS
1300     return NULL;
1301 #else
1302     jclass clazz;
1303     jmethodID mid;
1304     jobject bounds = NULL;
1305     AwtGraphicsConfigDataPtr adata;


1306 
1307     adata = (AwtGraphicsConfigDataPtr)
1308         JNU_GetLongFieldAsPtr(env, this, x11GraphicsConfigIDs.aData);
1309 
1310     clazz = (*env)->FindClass(env, "java/awt/Rectangle");
1311     CHECK_NULL_RETURN(clazz, NULL);
1312     mid = (*env)->GetMethodID(env, clazz, "<init>", "(IIII)V");
1313     if (mid != NULL) {
1314         if (usingXinerama) {
1315             if (0 <= screen && screen < awt_numScreens) {
1316                 bounds = (*env)->NewObject(env, clazz, mid, fbrects[screen].x,
1317                                                             fbrects[screen].y,
1318                                                             fbrects[screen].width,
1319                                                             fbrects[screen].height);











1320             } else {
1321                 jclass exceptionClass = (*env)->FindClass(env, "java/lang/IllegalArgumentException");
1322                 if (exceptionClass != NULL) {
1323                     (*env)->ThrowNew(env, exceptionClass, "Illegal screen index");
1324                 }
1325             }
1326         } else {


1327             XWindowAttributes xwa;
1328             memset(&xwa, 0, sizeof(xwa));
1329 
1330             AWT_LOCK ();
1331             XGetWindowAttributes(awt_display,
1332                     RootWindow(awt_display, adata->awt_visInfo.screen),
1333                     &xwa);
1334             AWT_UNLOCK ();
1335 
1336             bounds = (*env)->NewObject(env, clazz, mid, 0, 0,
1337                     xwa.width, xwa.height);
1338         }
1339 
1340         if ((*env)->ExceptionOccurred(env)) {
1341             return NULL;
1342         }
1343     }
1344     return bounds;
1345 #endif /* !HEADLESS */
1346 }


< prev index next >