jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c
changeset 21939 5169fd314636
parent 19006 fcda25164f7d
child 24130 db72fc72f87b
equal deleted inserted replaced
21938:3a235a461503 21939:5169fd314636
   904 
   904 
   905 #ifdef MITSHM
   905 #ifdef MITSHM
   906 
   906 
   907 static jint canUseShmExt = UNSET_MITSHM;
   907 static jint canUseShmExt = UNSET_MITSHM;
   908 static jint canUseShmExtPixmaps = UNSET_MITSHM;
   908 static jint canUseShmExtPixmaps = UNSET_MITSHM;
       
   909 static jboolean xshmAttachFailed = JNI_FALSE;
       
   910 
       
   911 int XShmAttachXErrHandler(Display *display, XErrorEvent *xerr) {
       
   912     if (xerr->minor_code == X_ShmAttach) {
       
   913         xshmAttachFailed = JNI_TRUE;
       
   914     }
       
   915     return 0;
       
   916 }
       
   917 jboolean isXShmAttachFailed() {
       
   918     return xshmAttachFailed;
       
   919 }
       
   920 void resetXShmAttachFailed() {
       
   921     xshmAttachFailed = JNI_FALSE;
       
   922 }
   909 
   923 
   910 extern int mitShmPermissionMask;
   924 extern int mitShmPermissionMask;
   911 
   925 
   912 void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) {
   926 void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) {
   913     XShmSegmentInfo shminfo;
   927     XShmSegmentInfo shminfo;
   914     int XShmMajor, XShmMinor;
   928     int XShmMajor, XShmMinor;
   915     int a, b, c;
   929     int a, b, c;
   916     jboolean xShmAttachResult;
       
   917 
   930 
   918     AWT_LOCK();
   931     AWT_LOCK();
   919     if (canUseShmExt != UNSET_MITSHM) {
   932     if (canUseShmExt != UNSET_MITSHM) {
   920         *shmExt = canUseShmExt;
   933         *shmExt = canUseShmExt;
   921         *shmPixmaps = canUseShmExtPixmaps;
   934         *shmPixmaps = canUseShmExtPixmaps;
   955                            strerror(errno));
   968                            strerror(errno));
   956             return;
   969             return;
   957         }
   970         }
   958         shminfo.readOnly = True;
   971         shminfo.readOnly = True;
   959 
   972 
   960         xShmAttachResult = TryXShmAttach(env, awt_display, &shminfo);
   973         resetXShmAttachFailed();
       
   974         /**
       
   975          * The J2DXErrHandler handler will set xshmAttachFailed
       
   976          * to JNI_TRUE if any Shm error has occured.
       
   977          */
       
   978         EXEC_WITH_XERROR_HANDLER(XShmAttachXErrHandler,
       
   979                                  XShmAttach(awt_display, &shminfo));
       
   980 
   961         /**
   981         /**
   962          * Get rid of the id now to reduce chances of leaking
   982          * Get rid of the id now to reduce chances of leaking
   963          * system resources.
   983          * system resources.
   964          */
   984          */
   965         shmctl(shminfo.shmid, IPC_RMID, 0);
   985         shmctl(shminfo.shmid, IPC_RMID, 0);
   966 
   986 
   967         if (xShmAttachResult == JNI_TRUE) {
   987         if (isXShmAttachFailed() == JNI_FALSE) {
   968             canUseShmExt = CAN_USE_MITSHM;
   988             canUseShmExt = CAN_USE_MITSHM;
   969             /* check if we can use shared pixmaps */
   989             /* check if we can use shared pixmaps */
   970             XShmQueryVersion(awt_display, &XShmMajor, &XShmMinor,
   990             XShmQueryVersion(awt_display, &XShmMajor, &XShmMinor,
   971                              (Bool*)&canUseShmExtPixmaps);
   991                              (Bool*)&canUseShmExtPixmaps);
   972             canUseShmExtPixmaps = canUseShmExtPixmaps &&
   992             canUseShmExtPixmaps = canUseShmExtPixmaps &&
   976         shmdt(shminfo.shmaddr);
   996         shmdt(shminfo.shmaddr);
   977         *shmExt = canUseShmExt;
   997         *shmExt = canUseShmExt;
   978         *shmPixmaps = canUseShmExtPixmaps;
   998         *shmPixmaps = canUseShmExtPixmaps;
   979     }
   999     }
   980     AWT_UNLOCK();
  1000     AWT_UNLOCK();
   981 }
       
   982 
       
   983 /*
       
   984  * Must be called with the acquired AWT lock.
       
   985  */
       
   986 jboolean TryXShmAttach(JNIEnv *env, Display *display, XShmSegmentInfo *shminfo) {
       
   987     jboolean errorOccurredFlag = JNI_FALSE;
       
   988     jobject errorHandlerRef;
       
   989 
       
   990     /*
       
   991      * XShmAttachHandler will set its internal flag to JNI_TRUE, if any Shm error occurs.
       
   992      */
       
   993     EXEC_WITH_XERROR_HANDLER(env, "sun/awt/X11/XErrorHandler$XShmAttachHandler",
       
   994         "()Lsun/awt/X11/XErrorHandler$XShmAttachHandler;", JNI_TRUE,
       
   995         errorHandlerRef, errorOccurredFlag,
       
   996         XShmAttach(display, shminfo));
       
   997     return errorOccurredFlag == JNI_FALSE ? JNI_TRUE : JNI_FALSE;
       
   998 }
  1001 }
   999 #endif /* MITSHM */
  1002 #endif /* MITSHM */
  1000 
  1003 
  1001 /*
  1004 /*
  1002  * Class:     sun_awt_X11GraphicsEnvironment
  1005  * Class:     sun_awt_X11GraphicsEnvironment