37 #ifndef NO_XRANDR 38 #include <X11/extensions/Xrandr.h> 39 #endif 40 #include "GLXGraphicsConfig.h" 41 #endif /* !HEADLESS */ 42 43 #include <jni.h> 44 #include <jni_util.h> 45 #include <jvm.h> 46 #include <jvm_md.h> 47 #include <jlong.h> 48 #include "systemScale.h" 49 #include <stdlib.h> 50 51 #include "awt_GraphicsEnv.h" 52 #include "awt_util.h" 53 #include "gdefs.h" 54 #include <dlfcn.h> 55 #include "Trace.h" 56 57 #ifdef NETSCAPE 58 #include <signal.h> 59 extern int awt_init_xt; 60 #endif 61 62 #ifndef HEADLESS 63 64 int awt_numScreens; /* Xinerama-aware number of screens */ 65 66 AwtScreenDataPtr x11Screens; 67 68 /* 69 * Set in initDisplay() to indicate whether we should attempt to initialize 70 * GLX for the default configuration. 71 */ 72 static jboolean glxRequested = JNI_FALSE; 73 74 #endif /* !HEADLESS */ 75 76 #ifdef HEADLESS 77 #define Display void 78 #endif /* HEADLESS */ 79 80 Display *awt_display; 81 135 136 #else /* SOLARIS */ 137 typedef Status XineramaGetInfoFunc(Display* display, int screen_number, 138 XRectangle* framebuffer_rects, unsigned char* framebuffer_hints, 139 int* num_framebuffers); 140 #endif 141 142 Bool usingXinerama = False; 143 XRectangle fbrects[MAXFRAMEBUFFERS]; 144 145 JNIEXPORT void JNICALL 146 Java_sun_awt_X11GraphicsConfig_initIDs (JNIEnv *env, jclass cls) 147 { 148 x11GraphicsConfigIDs.aData = NULL; 149 x11GraphicsConfigIDs.bitsPerPixel = NULL; 150 151 x11GraphicsConfigIDs.aData = (*env)->GetFieldID (env, cls, "aData", "J"); 152 CHECK_NULL(x11GraphicsConfigIDs.aData); 153 x11GraphicsConfigIDs.bitsPerPixel = (*env)->GetFieldID (env, cls, "bitsPerPixel", "I"); 154 CHECK_NULL(x11GraphicsConfigIDs.bitsPerPixel); 155 156 if (x11GraphicsConfigIDs.aData == NULL || 157 x11GraphicsConfigIDs.bitsPerPixel == NULL) { 158 159 JNU_ThrowNoSuchFieldError(env, "Can't find a field"); 160 return; 161 } 162 } 163 164 #ifndef HEADLESS 165 166 /* 167 * XIOErrorHandler 168 */ 169 static int xioerror_handler(Display *disp) 170 { 171 if (awtLockInited) { 172 if (errno == EPIPE) { 173 jio_fprintf(stderr, "X connection to %s host broken (explicit kill or server shutdown)\n", XDisplayName(NULL)); 174 } 175 /*SignalError(lockedee->lastpc, lockedee, "fp/ade/gui/GUIException", "I/O error"); */ 176 } 177 return 0; 178 } 179 180 static AwtGraphicsConfigDataPtr 181 findWithTemplate(XVisualInfo *vinfo, 687 DTRACE_PRINTLN("Xinerama extension is not available"); 688 return; 689 } 690 691 DTRACE_PRINTLN("Xinerama extension is available"); 692 #if defined(__linux__) || defined(MACOSX) 693 xinerama_init_linux(); 694 #else /* Solaris */ 695 xinerama_init_solaris(); 696 #endif /* __linux__ || MACOSX */ 697 } 698 #endif /* HEADLESS */ 699 700 Display * 701 awt_init_Display(JNIEnv *env, jobject this) 702 { 703 jclass klass; 704 Display *dpy; 705 char errmsg[128]; 706 int i; 707 #ifdef NETSCAPE 708 sigset_t alarm_set, oldset; 709 #endif 710 711 if (awt_display) { 712 return awt_display; 713 } 714 715 #ifdef NETSCAPE 716 /* Disable interrupts during XtOpenDisplay to avoid bugs in unix os select 717 code: some unix systems don't implement SA_RESTART properly and 718 because of this, select returns with EINTR. Most implementations of 719 gethostbyname don't cope with EINTR properly and as a result we get 720 stuck (forever) in the gethostbyname code 721 */ 722 sigemptyset(&alarm_set); 723 sigaddset(&alarm_set, SIGALRM); 724 sigprocmask(SIG_BLOCK, &alarm_set, &oldset); 725 #endif 726 727 /* Load AWT lock-related methods in SunToolkit */ 728 klass = (*env)->FindClass(env, "sun/awt/SunToolkit"); 729 if (klass == NULL) return NULL; 730 GET_STATIC_METHOD(klass, awtLockMID, "awtLock", "()V"); 731 GET_STATIC_METHOD(klass, awtUnlockMID, "awtUnlock", "()V"); 732 GET_STATIC_METHOD(klass, awtWaitMID, "awtLockWait", "(J)V"); 733 GET_STATIC_METHOD(klass, awtNotifyMID, "awtLockNotify", "()V"); 734 GET_STATIC_METHOD(klass, awtNotifyAllMID, "awtLockNotifyAll", "()V"); 735 tkClass = (*env)->NewGlobalRef(env, klass); 736 awtLockInited = JNI_TRUE; 737 738 if (getenv("_AWT_IGNORE_XKB") != NULL && 739 strlen(getenv("_AWT_IGNORE_XKB")) > 0) { 740 if (XkbIgnoreExtension(True)) { 741 printf("Ignoring XKB.\n"); 742 } 743 } 744 745 dpy = awt_display = XOpenDisplay(NULL); 746 #ifdef NETSCAPE 747 sigprocmask(SIG_SETMASK, &oldset, NULL); 748 #endif 749 if (!dpy) { 750 jio_snprintf(errmsg, 751 sizeof(errmsg), 752 "Can't connect to X11 window server using '%s' as the value of the DISPLAY variable.", 753 (getenv("DISPLAY") == NULL) ? ":0.0" : getenv("DISPLAY")); 754 JNU_ThrowByName(env, "java/awt/AWTError", errmsg); 755 return NULL; 756 } 757 758 XSetIOErrorHandler(xioerror_handler); 759 JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", "init", "(J)V", 760 ptr_to_jlong(awt_display)); 761 JNU_CHECK_EXCEPTION_RETURN(env, NULL); 762 763 /* set awt_numScreens, and whether or not we're using Xinerama */ 764 xineramaInit(); 765 766 if (!usingXinerama) { 767 awt_numScreens = XScreenCount(awt_display); 768 } | 37 #ifndef NO_XRANDR 38 #include <X11/extensions/Xrandr.h> 39 #endif 40 #include "GLXGraphicsConfig.h" 41 #endif /* !HEADLESS */ 42 43 #include <jni.h> 44 #include <jni_util.h> 45 #include <jvm.h> 46 #include <jvm_md.h> 47 #include <jlong.h> 48 #include "systemScale.h" 49 #include <stdlib.h> 50 51 #include "awt_GraphicsEnv.h" 52 #include "awt_util.h" 53 #include "gdefs.h" 54 #include <dlfcn.h> 55 #include "Trace.h" 56 57 #ifndef HEADLESS 58 59 int awt_numScreens; /* Xinerama-aware number of screens */ 60 61 AwtScreenDataPtr x11Screens; 62 63 /* 64 * Set in initDisplay() to indicate whether we should attempt to initialize 65 * GLX for the default configuration. 66 */ 67 static jboolean glxRequested = JNI_FALSE; 68 69 #endif /* !HEADLESS */ 70 71 #ifdef HEADLESS 72 #define Display void 73 #endif /* HEADLESS */ 74 75 Display *awt_display; 76 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 136 137 Bool usingXinerama = False; 138 XRectangle fbrects[MAXFRAMEBUFFERS]; 139 140 JNIEXPORT void JNICALL 141 Java_sun_awt_X11GraphicsConfig_initIDs (JNIEnv *env, jclass cls) 142 { 143 x11GraphicsConfigIDs.aData = NULL; 144 x11GraphicsConfigIDs.bitsPerPixel = NULL; 145 146 x11GraphicsConfigIDs.aData = (*env)->GetFieldID (env, cls, "aData", "J"); 147 CHECK_NULL(x11GraphicsConfigIDs.aData); 148 x11GraphicsConfigIDs.bitsPerPixel = (*env)->GetFieldID (env, cls, "bitsPerPixel", "I"); 149 CHECK_NULL(x11GraphicsConfigIDs.bitsPerPixel); 150 } 151 152 #ifndef HEADLESS 153 154 /* 155 * XIOErrorHandler 156 */ 157 static int xioerror_handler(Display *disp) 158 { 159 if (awtLockInited) { 160 if (errno == EPIPE) { 161 jio_fprintf(stderr, "X connection to %s host broken (explicit kill or server shutdown)\n", XDisplayName(NULL)); 162 } 163 /*SignalError(lockedee->lastpc, lockedee, "fp/ade/gui/GUIException", "I/O error"); */ 164 } 165 return 0; 166 } 167 168 static AwtGraphicsConfigDataPtr 169 findWithTemplate(XVisualInfo *vinfo, 675 DTRACE_PRINTLN("Xinerama extension is not available"); 676 return; 677 } 678 679 DTRACE_PRINTLN("Xinerama extension is available"); 680 #if defined(__linux__) || defined(MACOSX) 681 xinerama_init_linux(); 682 #else /* Solaris */ 683 xinerama_init_solaris(); 684 #endif /* __linux__ || MACOSX */ 685 } 686 #endif /* HEADLESS */ 687 688 Display * 689 awt_init_Display(JNIEnv *env, jobject this) 690 { 691 jclass klass; 692 Display *dpy; 693 char errmsg[128]; 694 int i; 695 696 if (awt_display) { 697 return awt_display; 698 } 699 700 /* Load AWT lock-related methods in SunToolkit */ 701 klass = (*env)->FindClass(env, "sun/awt/SunToolkit"); 702 if (klass == NULL) return NULL; 703 GET_STATIC_METHOD(klass, awtLockMID, "awtLock", "()V"); 704 GET_STATIC_METHOD(klass, awtUnlockMID, "awtUnlock", "()V"); 705 GET_STATIC_METHOD(klass, awtWaitMID, "awtLockWait", "(J)V"); 706 GET_STATIC_METHOD(klass, awtNotifyMID, "awtLockNotify", "()V"); 707 GET_STATIC_METHOD(klass, awtNotifyAllMID, "awtLockNotifyAll", "()V"); 708 tkClass = (*env)->NewGlobalRef(env, klass); 709 awtLockInited = JNI_TRUE; 710 711 if (getenv("_AWT_IGNORE_XKB") != NULL && 712 strlen(getenv("_AWT_IGNORE_XKB")) > 0) { 713 if (XkbIgnoreExtension(True)) { 714 printf("Ignoring XKB.\n"); 715 } 716 } 717 718 dpy = awt_display = XOpenDisplay(NULL); 719 if (!dpy) { 720 jio_snprintf(errmsg, 721 sizeof(errmsg), 722 "Can't connect to X11 window server using '%s' as the value of the DISPLAY variable.", 723 (getenv("DISPLAY") == NULL) ? ":0.0" : getenv("DISPLAY")); 724 JNU_ThrowByName(env, "java/awt/AWTError", errmsg); 725 return NULL; 726 } 727 728 XSetIOErrorHandler(xioerror_handler); 729 JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", "init", "(J)V", 730 ptr_to_jlong(awt_display)); 731 JNU_CHECK_EXCEPTION_RETURN(env, NULL); 732 733 /* set awt_numScreens, and whether or not we're using Xinerama */ 734 xineramaInit(); 735 736 if (!usingXinerama) { 737 awt_numScreens = XScreenCount(awt_display); 738 } |