jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c
changeset 17679 a81555868357
parent 14160 249b30c4dea8
child 18253 4323a5fe8bc4
child 18135 d9be76f1a19c
equal deleted inserted replaced
17678:ec24ad8455ec 17679:a81555868357
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   756         JNU_ThrowByName(env, "java/awt/AWTError", errmsg);
   756         JNU_ThrowByName(env, "java/awt/AWTError", errmsg);
   757         return NULL;
   757         return NULL;
   758     }
   758     }
   759 
   759 
   760     XSetIOErrorHandler(xioerror_handler);
   760     XSetIOErrorHandler(xioerror_handler);
       
   761     JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XErrorHandlerUtil", "init", "(J)V",
       
   762         ptr_to_jlong(awt_display));
   761 
   763 
   762     /* set awt_numScreens, and whether or not we're using Xinerama */
   764     /* set awt_numScreens, and whether or not we're using Xinerama */
   763     xineramaInit();
   765     xineramaInit();
   764 
   766 
   765     if (!usingXinerama) {
   767     if (!usingXinerama) {
   902 
   904 
   903 #ifdef MITSHM
   905 #ifdef MITSHM
   904 
   906 
   905 static jint canUseShmExt = UNSET_MITSHM;
   907 static jint canUseShmExt = UNSET_MITSHM;
   906 static jint canUseShmExtPixmaps = UNSET_MITSHM;
   908 static jint canUseShmExtPixmaps = UNSET_MITSHM;
   907 static jboolean xshmAttachFailed = JNI_FALSE;
       
   908 
       
   909 int J2DXErrHandler(Display *display, XErrorEvent *xerr) {
       
   910     int ret = 0;
       
   911     if (xerr->minor_code == X_ShmAttach) {
       
   912         xshmAttachFailed = JNI_TRUE;
       
   913     } else {
       
   914         ret = (*xerror_saved_handler)(display, xerr);
       
   915     }
       
   916     return ret;
       
   917 }
       
   918 jboolean isXShmAttachFailed() {
       
   919     return xshmAttachFailed;
       
   920 }
       
   921 void resetXShmAttachFailed() {
       
   922     xshmAttachFailed = JNI_FALSE;
       
   923 }
       
   924 
   909 
   925 void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) {
   910 void TryInitMITShm(JNIEnv *env, jint *shmExt, jint *shmPixmaps) {
   926     XShmSegmentInfo shminfo;
   911     XShmSegmentInfo shminfo;
   927     int XShmMajor, XShmMinor;
   912     int XShmMajor, XShmMinor;
   928     int a, b, c;
   913     int a, b, c;
       
   914     jboolean xShmAttachResult;
   929 
   915 
   930     AWT_LOCK();
   916     AWT_LOCK();
   931     if (canUseShmExt != UNSET_MITSHM) {
   917     if (canUseShmExt != UNSET_MITSHM) {
   932         *shmExt = canUseShmExt;
   918         *shmExt = canUseShmExt;
   933         *shmPixmaps = canUseShmExtPixmaps;
   919         *shmPixmaps = canUseShmExtPixmaps;
   961                            strerror(errno));
   947                            strerror(errno));
   962             return;
   948             return;
   963         }
   949         }
   964         shminfo.readOnly = True;
   950         shminfo.readOnly = True;
   965 
   951 
   966         resetXShmAttachFailed();
   952         xShmAttachResult = TryXShmAttach(env, awt_display, &shminfo);
   967         /**
       
   968          * The J2DXErrHandler handler will set xshmAttachFailed
       
   969          * to JNI_TRUE if any Shm error has occured.
       
   970          */
       
   971         EXEC_WITH_XERROR_HANDLER(J2DXErrHandler,
       
   972                                  XShmAttach(awt_display, &shminfo));
       
   973 
       
   974         /**
   953         /**
   975          * Get rid of the id now to reduce chances of leaking
   954          * Get rid of the id now to reduce chances of leaking
   976          * system resources.
   955          * system resources.
   977          */
   956          */
   978         shmctl(shminfo.shmid, IPC_RMID, 0);
   957         shmctl(shminfo.shmid, IPC_RMID, 0);
   979 
   958 
   980         if (isXShmAttachFailed() == JNI_FALSE) {
   959         if (xShmAttachResult == JNI_TRUE) {
   981             canUseShmExt = CAN_USE_MITSHM;
   960             canUseShmExt = CAN_USE_MITSHM;
   982             /* check if we can use shared pixmaps */
   961             /* check if we can use shared pixmaps */
   983             XShmQueryVersion(awt_display, &XShmMajor, &XShmMinor,
   962             XShmQueryVersion(awt_display, &XShmMajor, &XShmMinor,
   984                              (Bool*)&canUseShmExtPixmaps);
   963                              (Bool*)&canUseShmExtPixmaps);
   985             canUseShmExtPixmaps = canUseShmExtPixmaps &&
   964             canUseShmExtPixmaps = canUseShmExtPixmaps &&
   989         shmdt(shminfo.shmaddr);
   968         shmdt(shminfo.shmaddr);
   990         *shmExt = canUseShmExt;
   969         *shmExt = canUseShmExt;
   991         *shmPixmaps = canUseShmExtPixmaps;
   970         *shmPixmaps = canUseShmExtPixmaps;
   992     }
   971     }
   993     AWT_UNLOCK();
   972     AWT_UNLOCK();
       
   973 }
       
   974 
       
   975 /*
       
   976  * Must be called with the acquired AWT lock.
       
   977  */
       
   978 jboolean TryXShmAttach(JNIEnv *env, Display *display, XShmSegmentInfo *shminfo) {
       
   979     jboolean errorOccurredFlag = JNI_FALSE;
       
   980     jobject errorHandlerRef;
       
   981 
       
   982     /*
       
   983      * XShmAttachHandler will set its internal flag to JNI_TRUE, if any Shm error occurs.
       
   984      */
       
   985     EXEC_WITH_XERROR_HANDLER(env, "sun/awt/X11/XErrorHandler$XShmAttachHandler",
       
   986         "()Lsun/awt/X11/XErrorHandler$XShmAttachHandler;", JNI_TRUE,
       
   987         errorHandlerRef, errorOccurredFlag,
       
   988         XShmAttach(display, shminfo));
       
   989     return errorOccurredFlag == JNI_FALSE ? JNI_TRUE : JNI_FALSE;
   994 }
   990 }
   995 #endif /* MITSHM */
   991 #endif /* MITSHM */
   996 
   992 
   997 /*
   993 /*
   998  * Class:     sun_awt_X11GraphicsEnvironment
   994  * Class:     sun_awt_X11GraphicsEnvironment