src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c
changeset 54409 94986cf5e969
parent 54405 93b37d7435e8
parent 54312 0223b7b8a1c5
child 54856 4fcc1f1d7dd8
equal deleted inserted replaced
54408:8fe16bf92ebd 54409:94986cf5e969
   115  * operation on both OSes.  Until then, some of the Xinerama-related code
   115  * operation on both OSes.  Until then, some of the Xinerama-related code
   116  * is ifdef'd appropriately.  -bchristi, 7/12/01
   116  * is ifdef'd appropriately.  -bchristi, 7/12/01
   117  */
   117  */
   118 
   118 
   119 #define MAXFRAMEBUFFERS 16
   119 #define MAXFRAMEBUFFERS 16
   120 #if defined(__linux__) || defined(MACOSX)
   120 #if defined(__solaris__)
       
   121 typedef Status XineramaGetInfoFunc(Display* display, int screen_number,
       
   122          XRectangle* framebuffer_rects, unsigned char* framebuffer_hints,
       
   123          int* num_framebuffers);
       
   124 #else /* Linux, Mac, AIX */
   121 typedef struct {
   125 typedef struct {
   122    int   screen_number;
   126    int   screen_number;
   123    short x_org;
   127    short x_org;
   124    short y_org;
   128    short y_org;
   125    short width;
   129    short width;
   126    short height;
   130    short height;
   127 } XineramaScreenInfo;
   131 } XineramaScreenInfo;
   128 
   132 
   129 typedef XineramaScreenInfo* XineramaQueryScreensFunc(Display*, int*);
   133 typedef XineramaScreenInfo* XineramaQueryScreensFunc(Display*, int*);
   130 
       
   131 #else /* SOLARIS */
       
   132 typedef Status XineramaGetInfoFunc(Display* display, int screen_number,
       
   133          XRectangle* framebuffer_rects, unsigned char* framebuffer_hints,
       
   134          int* num_framebuffers);
       
   135 #endif
   134 #endif
   136 
   135 
   137 Bool usingXinerama = False;
   136 Bool usingXinerama = False;
   138 XRectangle fbrects[MAXFRAMEBUFFERS];
   137 XRectangle fbrects[MAXFRAMEBUFFERS];
   139 
   138 
   411 
   410 
   412     // Only use the RENDER extension if it is available on the X server
   411     // Only use the RENDER extension if it is available on the X server
   413     if (XQueryExtension(awt_display, "RENDER",
   412     if (XQueryExtension(awt_display, "RENDER",
   414                         &major_opcode, &first_event, &first_error))
   413                         &major_opcode, &first_event, &first_error))
   415     {
   414     {
       
   415         DTRACE_PRINTLN("RENDER extension available");
   416         xrenderLibHandle = dlopen("libXrender.so.1", RTLD_LAZY | RTLD_GLOBAL);
   416         xrenderLibHandle = dlopen("libXrender.so.1", RTLD_LAZY | RTLD_GLOBAL);
   417 
   417 
   418 #ifdef MACOSX
   418 #ifdef MACOSX
   419 #define XRENDER_LIB "/usr/X11/lib/libXrender.dylib"
   419 #define XRENDER_LIB "/usr/X11/lib/libXrender.dylib"
   420 #else
   420 #else
   424         if (xrenderLibHandle == NULL) {
   424         if (xrenderLibHandle == NULL) {
   425             xrenderLibHandle = dlopen(XRENDER_LIB,
   425             xrenderLibHandle = dlopen(XRENDER_LIB,
   426                                       RTLD_LAZY | RTLD_GLOBAL);
   426                                       RTLD_LAZY | RTLD_GLOBAL);
   427         }
   427         }
   428 
   428 
   429 #ifndef __linux__ /* SOLARIS */
   429 #if defined(__solaris__)
   430         if (xrenderLibHandle == NULL) {
   430         if (xrenderLibHandle == NULL) {
   431             xrenderLibHandle = dlopen("/usr/lib/libXrender.so.1",
   431             xrenderLibHandle = dlopen("/usr/lib/libXrender.so.1",
   432                                       RTLD_LAZY | RTLD_GLOBAL);
   432                                       RTLD_LAZY | RTLD_GLOBAL);
   433         }
   433         }
       
   434 #elif defined(_AIX)
       
   435         if (xrenderLibHandle == NULL) {
       
   436             xrenderLibHandle = dlopen("libXrender.a(libXrender.so.0)",
       
   437                                       RTLD_MEMBER | RTLD_LAZY | RTLD_GLOBAL);
       
   438         }
   434 #endif
   439 #endif
   435 
       
   436         if (xrenderLibHandle != NULL) {
   440         if (xrenderLibHandle != NULL) {
       
   441             DTRACE_PRINTLN("Loaded libXrender");
   437             xrenderFindVisualFormat =
   442             xrenderFindVisualFormat =
   438                 (XRenderFindVisualFormatFunc*)dlsym(xrenderLibHandle,
   443                 (XRenderFindVisualFormatFunc*)dlsym(xrenderLibHandle,
   439                                                     "XRenderFindVisualFormat");
   444                                                     "XRenderFindVisualFormat");
   440         }
   445             if (xrenderFindVisualFormat == NULL) {
       
   446                 DTRACE_PRINTLN1("Can't find 'XRenderFindVisualFormat' in libXrender (%s)", dlerror());
       
   447             }
       
   448         } else {
       
   449             DTRACE_PRINTLN1("Can't load libXrender (%s)", dlerror());
       
   450         }
       
   451     } else {
       
   452         DTRACE_PRINTLN("RENDER extension NOT available");
   441     }
   453     }
   442 
   454 
   443     for (i = 0; i < nTrue; i++) {
   455     for (i = 0; i < nTrue; i++) {
   444         if (XVisualIDFromVisual(pVITrue[i].visual) ==
   456         if (XVisualIDFromVisual(pVITrue[i].visual) ==
   445             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual) ||
   457             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual) ||
   451         }
   463         }
   452         graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
   464         graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
   453         graphicsConfigs [ind]->awt_depth = pVITrue [i].depth;
   465         graphicsConfigs [ind]->awt_depth = pVITrue [i].depth;
   454         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVITrue [i],
   466         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVITrue [i],
   455                 sizeof (XVisualInfo));
   467                 sizeof (XVisualInfo));
   456        if (xrenderFindVisualFormat != NULL) {
   468         if (xrenderFindVisualFormat != NULL) {
   457             XRenderPictFormat *format = xrenderFindVisualFormat (awt_display,
   469             XRenderPictFormat *format = xrenderFindVisualFormat (awt_display,
   458                     pVITrue [i].visual);
   470                                                                  pVITrue [i].visual);
   459             if (format &&
   471             if (format &&
   460                 format->type == PictTypeDirect &&
   472                 format->type == PictTypeDirect &&
   461                 format->direct.alphaMask)
   473                 format->direct.alphaMask)
   462             {
   474             {
       
   475                 DTRACE_PRINTLN1("GraphicsConfig[%d] supports Translucency", ind);
   463                 graphicsConfigs [ind]->isTranslucencySupported = 1;
   476                 graphicsConfigs [ind]->isTranslucencySupported = 1;
   464                 memcpy(&graphicsConfigs [ind]->renderPictFormat, format,
   477                 memcpy(&graphicsConfigs [ind]->renderPictFormat, format,
   465                         sizeof(*format));
   478                         sizeof(*format));
       
   479             } else {
       
   480                 DTRACE_PRINTLN1(format ?
       
   481                                 "GraphicsConfig[%d] has no Translucency support" :
       
   482                                 "Error calling 'XRenderFindVisualFormat'", ind);
   466             }
   483             }
   467         }
   484        }
   468     }
   485     }
   469 
   486 
   470     if (xrenderLibHandle != NULL) {
   487     if (xrenderLibHandle != NULL) {
   471         dlclose(xrenderLibHandle);
   488         dlclose(xrenderLibHandle);
   472         xrenderLibHandle = NULL;
   489         xrenderLibHandle = NULL;
   568 
   585 
   569     AWT_UNLOCK ();
   586     AWT_UNLOCK ();
   570 }
   587 }
   571 
   588 
   572 #ifndef HEADLESS
   589 #ifndef HEADLESS
   573 #if defined(__linux__) || defined(MACOSX)
   590 #if defined(__linux__) || defined(MACOSX) || defined(_AIX)
   574 static void xinerama_init_linux()
   591 static void xinerama_init_linux()
   575 {
   592 {
   576     void* libHandle = NULL;
   593     void* libHandle = NULL;
   577     int32_t locNumScr = 0;
   594     int32_t locNumScr = 0;
   578     XineramaScreenInfo *xinInfo;
   595     XineramaScreenInfo *xinInfo;
   581 
   598 
   582     /* load library */
   599     /* load library */
   583     libHandle = dlopen(VERSIONED_JNI_LIB_NAME("Xinerama", "1"),
   600     libHandle = dlopen(VERSIONED_JNI_LIB_NAME("Xinerama", "1"),
   584                        RTLD_LAZY | RTLD_GLOBAL);
   601                        RTLD_LAZY | RTLD_GLOBAL);
   585     if (libHandle == NULL) {
   602     if (libHandle == NULL) {
       
   603 #if defined(_AIX)
       
   604         libHandle = dlopen("libXext.a(shr_64.o)", RTLD_MEMBER | RTLD_LAZY | RTLD_GLOBAL);
       
   605 #else
   586         libHandle = dlopen(JNI_LIB_NAME("Xinerama"), RTLD_LAZY | RTLD_GLOBAL);
   606         libHandle = dlopen(JNI_LIB_NAME("Xinerama"), RTLD_LAZY | RTLD_GLOBAL);
       
   607 #endif
   587     }
   608     }
   588     if (libHandle != NULL) {
   609     if (libHandle != NULL) {
   589         XineramaQueryScreens = (XineramaQueryScreensFunc*)
   610         XineramaQueryScreens = (XineramaQueryScreensFunc*)
   590             dlsym(libHandle, XineramaQueryScreensName);
   611             dlsym(libHandle, XineramaQueryScreensName);
   591 
   612 
   592         if (XineramaQueryScreens != NULL) {
   613         if (XineramaQueryScreens != NULL) {
   593             DTRACE_PRINTLN("calling XineramaQueryScreens func on Linux");
   614             DTRACE_PRINTLN("calling XineramaQueryScreens func");
   594             xinInfo = (*XineramaQueryScreens)(awt_display, &locNumScr);
   615             xinInfo = (*XineramaQueryScreens)(awt_display, &locNumScr);
   595             if (xinInfo != NULL && locNumScr > XScreenCount(awt_display)) {
   616             if (xinInfo != NULL && locNumScr > XScreenCount(awt_display)) {
   596                 int32_t idx;
   617                 int32_t idx;
   597                 DTRACE_PRINTLN("Enabling Xinerama support");
   618                 DTRACE_PRINTLN("Enabling Xinerama support");
   598                 usingXinerama = True;
   619                 usingXinerama = True;
   608                     fbrects[idx].height = xinInfo[idx].height;
   629                     fbrects[idx].height = xinInfo[idx].height;
   609                     fbrects[idx].x = xinInfo[idx].x_org;
   630                     fbrects[idx].x = xinInfo[idx].x_org;
   610                     fbrects[idx].y = xinInfo[idx].y_org;
   631                     fbrects[idx].y = xinInfo[idx].y_org;
   611                 }
   632                 }
   612             } else {
   633             } else {
   613                 DTRACE_PRINTLN("calling XineramaQueryScreens didn't work");
   634                 DTRACE_PRINTLN((xinInfo == NULL) ?
       
   635                                "calling XineramaQueryScreens didn't work" :
       
   636                                "XineramaQueryScreens <= XScreenCount"
       
   637                                );
   614             }
   638             }
   615         } else {
   639         } else {
   616             DTRACE_PRINTLN("couldn't load XineramaQueryScreens symbol");
   640             DTRACE_PRINTLN("couldn't load XineramaQueryScreens symbol");
   617         }
   641         }
   618         dlclose(libHandle);
   642         dlclose(libHandle);
   619     } else {
   643     } else {
   620         DTRACE_PRINTLN1("\ncouldn't open shared library: %s\n", dlerror());
   644         DTRACE_PRINTLN1("\ncouldn't open shared library: %s\n", dlerror());
   621     }
   645     }
   622 }
   646 }
   623 #endif
   647 #elif defined(__solaris__)
   624 #if !defined(__linux__) && !defined(MACOSX) /* Solaris */
       
   625 static void xinerama_init_solaris()
   648 static void xinerama_init_solaris()
   626 {
   649 {
   627     void* libHandle = NULL;
   650     void* libHandle = NULL;
   628     unsigned char fbhints[MAXFRAMEBUFFERS];
   651     unsigned char fbhints[MAXFRAMEBUFFERS];
   629     int32_t locNumScr = 0;
   652     int32_t locNumScr = 0;
   675         DTRACE_PRINTLN("Xinerama extension is not available");
   698         DTRACE_PRINTLN("Xinerama extension is not available");
   676         return;
   699         return;
   677     }
   700     }
   678 
   701 
   679     DTRACE_PRINTLN("Xinerama extension is available");
   702     DTRACE_PRINTLN("Xinerama extension is available");
   680 #if defined(__linux__) || defined(MACOSX)
   703 #if defined(__solaris__)
       
   704     xinerama_init_solaris();
       
   705 #else /* Linux, Mac, AIX */
   681     xinerama_init_linux();
   706     xinerama_init_linux();
   682 #else /* Solaris */
   707 #endif
   683     xinerama_init_solaris();
       
   684 #endif /* __linux__ || MACOSX */
       
   685 }
   708 }
   686 #endif /* HEADLESS */
   709 #endif /* HEADLESS */
   687 
   710 
   688 Display *
   711 Display *
   689 awt_init_Display(JNIEnv *env, jobject this)
   712 awt_init_Display(JNIEnv *env, jobject this)