jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c
changeset 5579 1a5e995a710b
parent 1739 ed98610896e7
child 5580 629274e4c99f
--- a/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c	Thu May 27 08:53:45 2010 -0700
+++ b/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c	Fri May 28 11:37:44 2010 -0700
@@ -71,7 +71,7 @@
 extern AwtGraphicsConfigDataPtr
     getGraphicsConfigFromComponentPeer(JNIEnv *env, jobject this);
 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
-static jint X11SD_InitWindow(JNIEnv *env, X11SDOps *xsdo);
+
 static int X11SD_FindClip(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
                           X11SDOps *xsdo);
 static int X11SD_ClipToRoot(SurfaceDataBounds *b, SurfaceDataBounds *bounds,
@@ -97,6 +97,54 @@
 
 #endif /* !HEADLESS */
 
+jboolean XShared_initIDs(JNIEnv *env, jboolean allowShmPixmaps)
+{
+#ifndef HEADLESS
+   union {
+        char c[4];
+        int i;
+    } endian;
+
+    endian.i = 0xff000000;
+    nativeByteOrder = (endian.c[0]) ? MSBFirst : LSBFirst;
+
+    dgaAvailable = JNI_FALSE;
+
+    cachedXImage = NULL;
+
+    if (sizeof(X11RIPrivate) > SD_RASINFO_PRIVATE_SIZE) {
+        JNU_ThrowInternalError(env, "Private RasInfo structure too large!");
+        return JNI_FALSE;
+    }
+
+#ifdef MITSHM
+    if (getenv("NO_AWT_MITSHM") == NULL &&
+        getenv("NO_J2D_MITSHM") == NULL) {
+        char * force;
+        TryInitMITShm(env, &useMitShmExt, &useMitShmPixmaps);
+
+        if(allowShmPixmaps) {
+          useMitShmPixmaps = (useMitShmPixmaps == CAN_USE_MITSHM);
+          force = getenv("J2D_PIXMAPS");
+          if (force != NULL) {
+              if (useMitShmPixmaps && (strcmp(force, "shared") == 0)) {
+                  forceSharedPixmaps = JNI_TRUE;
+              } else if (strcmp(force, "server") == 0) {
+                  useMitShmPixmaps = JNI_FALSE;
+              }
+          }
+        }else {
+          useMitShmPixmaps = JNI_FALSE;
+        }
+    }
+
+    return JNI_TRUE;
+#endif /* MITSHM */
+
+#endif /* !HEADLESS */
+}
+
+
 /*
  * Class:     sun_java2d_x11_X11SurfaceData
  * Method:    initIDs
@@ -107,30 +155,17 @@
                                            jclass XORComp, jboolean tryDGA)
 {
 #ifndef HEADLESS
+  if(XShared_initIDs(env, JNI_TRUE))
+  {
     void *lib = 0;
 
-    union {
-        char c[4];
-        int i;
-    } endian;
-
-    endian.i = 0xff000000;
-    nativeByteOrder = (endian.c[0]) ? MSBFirst : LSBFirst;
-
-    cachedXImage = NULL;
-
-    if (sizeof(X11RIPrivate) > SD_RASINFO_PRIVATE_SIZE) {
-        JNU_ThrowInternalError(env, "Private RasInfo structure too large!");
-        return;
-    }
-
     xorCompClass = (*env)->NewGlobalRef(env, XORComp);
 
     if (tryDGA && (getenv("NO_J2D_DGA") == NULL)) {
     /* we use RTLD_NOW because of bug 4032715 */
         lib = dlopen("libsunwjdga.so", RTLD_NOW);
     }
-    dgaAvailable = JNI_FALSE;
+
     if (lib != NULL) {
         JDgaStatus ret = JDGA_FAILED;
         void *sym = dlsym(lib, "JDgaLibInit");
@@ -149,24 +184,7 @@
             lib = NULL;
         }
     }
-
-#ifdef MITSHM
-    if (getenv("NO_AWT_MITSHM") == NULL &&
-        getenv("NO_J2D_MITSHM") == NULL) {
-        char * force;
-        TryInitMITShm(env, &useMitShmExt, &useMitShmPixmaps);
-        useMitShmPixmaps = (useMitShmPixmaps == CAN_USE_MITSHM);
-        force = getenv("J2D_PIXMAPS");
-        if (force != NULL) {
-            if (useMitShmPixmaps && (strcmp(force, "shared") == 0)) {
-                forceSharedPixmaps = JNI_TRUE;
-            } else if (strcmp(force, "server") == 0) {
-                useMitShmPixmaps = JNI_FALSE;
-            }
-        }
-    }
-#endif /* MITSHM */
-
+  }
 #endif /* !HEADLESS */
 }
 
@@ -176,7 +194,7 @@
  * Signature: ()Z
  */
 JNIEXPORT jboolean JNICALL
-Java_sun_java2d_x11_X11SurfaceData_isDrawableValid(JNIEnv *env, jobject this)
+Java_sun_java2d_x11_XSurfaceData_isDrawableValid(JNIEnv *env, jobject this)
 {
     jboolean ret = JNI_FALSE;
 
@@ -194,6 +212,21 @@
 }
 
 /*
+ * Class: sun_java2d_x11_X11SurfaceData
+ * Method: isShmPMAvailable
+ * Signature: ()Z
+ */
+JNIEXPORT jboolean JNICALL
+Java_sun_java2d_x11_X11SurfaceData_isShmPMAvailable(JNIEnv *env, jobject this)
+{
+#if defined(HEADLESS) || !defined(MITSHM)
+    return JNI_FALSE;
+#else
+    return useMitShmPixmaps;
+#endif /* HEADLESS, MITSHM */
+}
+
+/*
  * Class:     sun_java2d_x11_X11SurfaceData
  * Method:    isDgaAvailable
  * Signature: ()Z
@@ -208,30 +241,13 @@
 #endif /* HEADLESS */
 }
 
-
-/*
- * Class:     sun_java2d_x11_X11SurfaceData
- * Method:    isShmPMAvailable
- * Signature: ()Z
- */
-JNIEXPORT jboolean JNICALL
-Java_sun_java2d_x11_X11SurfaceData_isShmPMAvailable(JNIEnv *env, jobject this)
-{
-#if defined(HEADLESS) || !defined(MITSHM)
-    return JNI_FALSE;
-#else
-    return useMitShmPixmaps;
-#endif /* HEADLESS, MITSHM */
-}
-
-
 /*
  * Class:     sun_java2d_x11_X11SurfaceData
  * Method:    initOps
  * Signature: (Ljava/lang/Object;I)V
  */
 JNIEXPORT void JNICALL
-Java_sun_java2d_x11_X11SurfaceData_initOps(JNIEnv *env, jobject xsd,
+Java_sun_java2d_x11_XSurfaceData_initOps(JNIEnv *env, jobject xsd,
                                            jobject peer,
                                            jobject graphicsConfig, jint depth)
 {
@@ -304,6 +320,8 @@
     } else {
         xsdo->pixelmask = 0xff;
     }
+
+    xsdo->xrPic = None;
 #endif /* !HEADLESS */
 }
 
@@ -313,7 +331,7 @@
  * Signature: ()V
  */
 JNIEXPORT void JNICALL
-Java_sun_java2d_x11_X11SurfaceData_flushNativeSurface(JNIEnv *env, jobject xsd)
+Java_sun_java2d_x11_XSurfaceData_flushNativeSurface(JNIEnv *env, jobject xsd)
 {
 #ifndef HEADLESS
     SurfaceDataOps *ops = SurfaceData_GetOps(env, xsd);
@@ -384,6 +402,11 @@
         XFreeGC(awt_display, xsdo->cachedGC);
         xsdo->cachedGC = NULL;
     }
+
+    if(xsdo->xrPic != None) {
+      XRenderFreePicture(awt_display, xsdo->xrPic);
+    }
+
     AWT_UNLOCK();
 #endif /* !HEADLESS */
 }
@@ -393,7 +416,7 @@
  * Signature: ()V
  */
 JNIEXPORT void JNICALL
-Java_sun_java2d_x11_X11SurfaceData_setInvalid(JNIEnv *env, jobject xsd)
+Java_sun_java2d_x11_XSurfaceData_setInvalid(JNIEnv *env, jobject xsd)
 {
 #ifndef HEADLESS
     X11SDOps *xsdo = (X11SDOps *) SurfaceData_GetOps(env, xsd);
@@ -404,6 +427,63 @@
 #endif /* !HEADLESS */
 }
 
+
+jboolean XShared_initSurface(JNIEnv *env, X11SDOps *xsdo, jint depth, jint width, jint height, jlong drawable)
+{
+#ifndef HEADLESS
+
+    if (drawable != (jlong)0) {
+        /* Double-buffering */
+        xsdo->drawable = drawable;
+        xsdo->isPixmap = JNI_FALSE;
+    } else {
+        xsdo->isPixmap = JNI_TRUE;
+        /* REMIND: workaround for bug 4420220 on pgx32 boards:
+           don't use DGA with pixmaps unless USE_DGA_PIXMAPS is set.
+         */
+        xsdo->dgaAvailable = useDGAWithPixmaps;
+
+        xsdo->pmWidth = width;
+        xsdo->pmHeight = height;
+
+#ifdef MITSHM
+        xsdo->shmPMData.pmSize = width * height * depth;
+        xsdo->shmPMData.pixelsReadThreshold = width * height / 8;
+        if (forceSharedPixmaps) {
+            AWT_LOCK();
+            xsdo->drawable = X11SD_CreateSharedPixmap(xsdo);
+            AWT_UNLOCK();
+            if (xsdo->drawable) {
+                xsdo->shmPMData.usingShmPixmap = JNI_TRUE;
+                xsdo->shmPMData.shmPixmap = xsdo->drawable;
+                return JNI_TRUE;
+            }
+        }
+#endif /* MITSHM */
+
+        AWT_LOCK();
+        xsdo->drawable =
+            XCreatePixmap(awt_display,
+                          RootWindow(awt_display,
+                                     xsdo->configData->awt_visInfo.screen),
+                          width, height, depth);
+        AWT_UNLOCK();
+#ifdef MITSHM
+        xsdo->shmPMData.usingShmPixmap = JNI_FALSE;
+        xsdo->shmPMData.pixmap = xsdo->drawable;
+#endif /* MITSHM */
+    }
+    if (xsdo->drawable == 0) {
+        JNU_ThrowOutOfMemoryError(env,
+                                  "Can't create offscreen surface");
+        return JNI_FALSE;
+    }
+
+    return JNI_TRUE;
+#endif /* !HEADLESS */
+}
+
+
 /*
  * Class:     sun_java2d_x11_X11SurfaceData
  * Method:    initSurface
@@ -428,51 +508,8 @@
        8-bit visuals */
     xsdo->cData = xsdo->configData->color_data;
 
-    if (drawable != (jlong)0) {
-        /* Double-buffering */
-        xsdo->drawable = drawable;
-        xsdo->isPixmap = JNI_FALSE;
-    } else {
-        xsdo->isPixmap = JNI_TRUE;
-        /* REMIND: workaround for bug 4420220 on pgx32 boards:
-           don't use DGA with pixmaps unless USE_DGA_PIXMAPS is set.
-         */
-        xsdo->dgaAvailable = useDGAWithPixmaps;
-
-        xsdo->pmWidth = width;
-        xsdo->pmHeight = height;
-
-#ifdef MITSHM
-        xsdo->shmPMData.pmSize = width * height * depth;
-        xsdo->shmPMData.pixelsReadThreshold = width * height / 8;
-        if (forceSharedPixmaps) {
-            AWT_LOCK();
-            xsdo->drawable = X11SD_CreateSharedPixmap(xsdo);
-            AWT_UNLOCK();
-            if (xsdo->drawable) {
-                xsdo->shmPMData.usingShmPixmap = JNI_TRUE;
-                xsdo->shmPMData.shmPixmap = xsdo->drawable;
-                return;
-            }
-        }
-#endif /* MITSHM */
-
-        AWT_LOCK();
-        xsdo->drawable =
-            XCreatePixmap(awt_display,
-                          RootWindow(awt_display,
-                                     xsdo->configData->awt_visInfo.screen),
-                          width, height, depth);
-        AWT_UNLOCK();
-#ifdef MITSHM
-        xsdo->shmPMData.usingShmPixmap = JNI_FALSE;
-        xsdo->shmPMData.pixmap = xsdo->drawable;
-#endif /* MITSHM */
-    }
-    if (xsdo->drawable == 0) {
-        JNU_ThrowOutOfMemoryError(env,
-                                  "Can't create offscreen surface");
-    }
+    XShared_initSurface(env, xsdo, depth, width, height, drawable);
+    xsdo->xrPic = NULL;
 #endif /* !HEADLESS */
 }
 
@@ -718,7 +755,7 @@
 }
 #endif /* MITSHM */
 
-static jint X11SD_InitWindow(JNIEnv *env, X11SDOps *xsdo)
+jint X11SD_InitWindow(JNIEnv *env, X11SDOps *xsdo)
 {
     if (xsdo->isPixmap == JNI_TRUE) {
         return SD_FAILURE;
@@ -1568,7 +1605,7 @@
  * Signature: (I)J
  */
 JNIEXPORT jlong JNICALL
-Java_sun_java2d_x11_X11SurfaceData_XCreateGC
+Java_sun_java2d_x11_XSurfaceData_XCreateGC
     (JNIEnv *env, jclass xsd, jlong pXSData)
 {
     jlong ret;
@@ -1598,7 +1635,7 @@
  * Signature: (JIIIILsun/java2d/pipe/Region;)V
  */
 JNIEXPORT void JNICALL
-Java_sun_java2d_x11_X11SurfaceData_XResetClip
+Java_sun_java2d_x11_XSurfaceData_XResetClip
     (JNIEnv *env, jclass xsd, jlong xgc)
 {
 #ifndef HEADLESS
@@ -1613,7 +1650,7 @@
  * Signature: (JIIIILsun/java2d/pipe/Region;)V
  */
 JNIEXPORT void JNICALL
-Java_sun_java2d_x11_X11SurfaceData_XSetClip
+Java_sun_java2d_x11_XSurfaceData_XSetClip
     (JNIEnv *env, jclass xsd, jlong xgc,
      jint x1, jint y1, jint x2, jint y2,
      jobject complexclip)
@@ -1688,7 +1725,7 @@
  * Signature: (JZ)V
  */
 JNIEXPORT void JNICALL
-Java_sun_java2d_x11_X11SurfaceData_XSetGraphicsExposures
+Java_sun_java2d_x11_XSurfaceData_XSetGraphicsExposures
     (JNIEnv *env, jclass xsd, jlong xgc, jboolean needExposures)
 {
 #ifndef HEADLESS