< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m

Print this page
rev 54094 : 8257853: Remove dependencies on JNF's JNI utility functions in AWT and 2D code
rev 54096 : 8259651: [macOS] Replace JNF_COCOA_ENTER/EXIT macros
rev 54097 : 8259869: [macOS] Remove desktop module dependencies on JNF Reference APIs
rev 54098 : 8260616: Removing remaining JNF dependencies in the java.desktop module
8259729: Missed JNFInstanceOf -> IsInstanceOf conversion

@@ -28,12 +28,12 @@
 #import "java_awt_Transparency.h"
 #import "java_awt_image_BufferedImage.h"
 #import "sun_awt_image_BufImgSurfaceData.h"
 #import "sun_java2d_OSXOffScreenSurfaceData.h"
 
-#import "jni_util.h"
-#import <JavaNativeFoundation/JavaNativeFoundation.h>
+#import "ThreadUtilities.h"
+#import "JNIUtilities.h"
 
 #import "BufImgSurfaceData.h"
 
 //#define DEBUG 1
 #if defined DEBUG

@@ -101,20 +101,13 @@
 static jfieldID        rgbID;
 static jfieldID        mapSizeID;
 static jfieldID        CMpDataID;
 static jfieldID        allGrayID;
 
-
-static JNF_CLASS_CACHE(jc_OSXOffScreenSurfaceData, "sun/java2d/OSXOffScreenSurfaceData");
-static JNF_MEMBER_CACHE(jm_syncFromCustom, jc_OSXOffScreenSurfaceData, "syncFromCustom", "()V");
-static JNF_MEMBER_CACHE(jm_syncToCustom, jc_OSXOffScreenSurfaceData, "syncToCustom", "()V");
-static JNF_CLASS_CACHE(jc_BufferedImage, "java/awt/image/BufferedImage");
-static JNF_MEMBER_CACHE(jm_SurfaceData, jc_BufferedImage, "sData", "Lsun/java2d/SurfaceData;");
-static JNF_CLASS_CACHE(jc_IndexColorModel, "java/awt/image/IndexColorModel");
-static JNF_MEMBER_CACHE(jm_rgb, jc_IndexColorModel, "rgb", "[I");
-static JNF_MEMBER_CACHE(jm_transparency, jc_IndexColorModel, "transparency", "I");
-static JNF_MEMBER_CACHE(jm_transparent_index, jc_IndexColorModel, "transparent_index", "I");
+static jclass jc_OSXOffScreenSurfaceData = NULL;
+#define GET_OSXOSD_CLASS() \
+    GET_CLASS(jc_OSXOffScreenSurfaceData, "sun/java2d/OSXOffScreenSurfaceData");
 
 CGColorSpaceRef gColorspaceRGB = NULL;
 CGColorSpaceRef gColorspaceGray = NULL;
 
 IMAGE_SURFACE_INLINE void PrintImageInfo(ImageSDOps* isdo)

@@ -190,11 +183,15 @@
 IMAGE_SURFACE_INLINE void customPixelsFromJava(JNIEnv *env, ImageSDOps *isdo)
 {
 PRINT("    customPixelsFromJava")
 
     SurfaceDataOps *sdo = (SurfaceDataOps*)isdo;
-    JNFCallVoidMethod(env, sdo->sdObject, jm_syncFromCustom); // AWT_THREADING Safe (known object)
+    GET_OSXOSD_CLASS();
+    DECLARE_METHOD(jm_syncFromCustom, jc_OSXOffScreenSurfaceData, "syncFromCustom", "()V");
+
+    (*env)->CallVoidMethod(env, sdo->sdObject, jm_syncFromCustom); // AWT_THREADING Safe (known object)
+    CHECK_EXCEPTION();
 }
 
 IMAGE_SURFACE_INLINE void copyBits(jint w, jint h, jint javaPixelsBytesPerRow, Pixel8bit *pixelsSrc, jint dstPixelsBytesPerRow, Pixel8bit *pixelsDst)
 {
 PRINT("    copyBits")

@@ -421,11 +418,14 @@
 IMAGE_SURFACE_INLINE void customPixelsToJava(JNIEnv *env, ImageSDOps *isdo)
 {
 PRINT("    customPixelsToJava")
 
     SurfaceDataOps *sdo = (SurfaceDataOps*)isdo;
-    JNFCallVoidMethod(env, sdo->sdObject, jm_syncToCustom); // AWT_THREADING Safe (known object)
+    GET_OSXOSD_CLASS();
+    DECLARE_METHOD(jm_syncToCustom, jc_OSXOffScreenSurfaceData, "syncToCustom", "()V");
+    (*env)->CallVoidMethod(env, sdo->sdObject, jm_syncToCustom); // AWT_THREADING Safe (known object)
+    CHECK_EXCEPTION();
 }
 
 IMAGE_SURFACE_INLINE void removeAlphaPre_32bit(jint w, jint h, jint javaPixelsBytesPerRow, jint javaPixelBytes, Pixel32bit *pixelsSrc)
 {
 PRINT("    removeAlphaPre_32bit")

@@ -1238,11 +1238,11 @@
 {
 PRINT("xorSurfacePixels")
 
     jboolean handled = JNI_FALSE;
 
-JNF_COCOA_ENTER(env);
+JNI_COCOA_ENTER(env);
     ImageSDOps* srcIsdo = LockImagePixels(env, srcIsd);
     ImageSDOps* dstIsdo = LockImagePixels(env, dstIsd);
 
     if ((x < 0) || (y < 0) || (x+w > dstIsdo->width) || (y+h > dstIsdo->height) || (w > srcIsdo->width) || (h > srcIsdo->height))
     {

@@ -1317,20 +1317,20 @@
     }
 
     UnlockImagePixels(env, srcIsdo);
     UnlockImagePixels(env, dstIsdo);
 
-JNF_COCOA_EXIT(env);
+JNI_COCOA_EXIT(env);
     return handled;
 }
 
 IMAGE_SURFACE_INLINE jboolean clearSurfacePixels(JNIEnv *env, jobject bisd, jint w, jint h)
 {
 PRINT("clearSurfacePixels")
     jboolean handled = JNI_FALSE;
 
-JNF_COCOA_ENTER(env);
+JNI_COCOA_ENTER(env);
 
     ImageSDOps *isdo = LockImagePixels(env, bisd);
 
     if (isdo->type == java_awt_image_BufferedImage_TYPE_INT_ARGB_PRE)
     {

@@ -1358,11 +1358,11 @@
 
         handled = JNI_TRUE;
     }
     UnlockImagePixels(env, isdo);
 
-JNF_COCOA_EXIT(env);
+JNI_COCOA_EXIT(env);
 
     return handled;
 }
 
 static void ImageSD_startCGContext(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType)

@@ -1449,11 +1449,11 @@
     {
         free(qsdo->graphicsStateInfo.batchedLines);
         qsdo->graphicsStateInfo.batchedLines = NULL;
     }
 
-    JNFDeleteGlobalRef(env, qsdo->javaGraphicsStatesObjects);
+    (*env)->DeleteGlobalRef(env, qsdo->javaGraphicsStatesObjects);
 
     if (qsdo->cgRef != NULL)
     {
         CGContextRelease(qsdo->cgRef);
         qsdo->cgRef = NULL;

@@ -1481,16 +1481,16 @@
         free(isdo->lutData);
         isdo->indexedColorTable = NULL;
     }
     if (isdo->array != NULL)
     {
-        JNFDeleteGlobalRef(env, isdo->array);
+        (*env)->DeleteGlobalRef(env, isdo->array);
         isdo->array = NULL;
     }
     if (isdo->icm != NULL)
     {
-        JNFDeleteGlobalRef(env, isdo->icm);
+        (*env)->DeleteGlobalRef(env, isdo->icm);
         isdo->icm = NULL;
     }
 
     if (isdo->nsRef) {
         [isdo->nsRef release];

@@ -1620,24 +1620,30 @@
     gColorspaceRGB = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
     gColorspaceGray = CGColorSpaceCreateWithName(kCGColorSpaceGenericGray);
 //fprintf(stderr, "gColorspaceRGB=%p, gColorspaceGray=%p\n", gColorspaceRGB, gColorspaceGray);
 }
 
+static jclass jc_BufferedImage = NULL;
+static jfieldID jm_SurfaceData = NULL;
+
 JNIEXPORT jobject JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_getSurfaceData
     (JNIEnv *env, jclass bisd, jobject bufImg)
 {
 PRINT("getSurfaceData")
-
-    return JNFGetObjectField(env, bufImg, jm_SurfaceData);
+    GET_CLASS_RETURN(jc_BufferedImage, "java/awt/image/BufferedImage", NULL);
+    GET_FIELD_RETURN(jm_SurfaceData, jc_BufferedImage, "sData", "Lsun/java2d/SurfaceData;", NULL);
+    return (*env)->GetObjectField(env, bufImg, jm_SurfaceData);
 }
 
 JNIEXPORT void JNICALL Java_sun_java2d_OSXOffScreenSurfaceData_setSurfaceData
     (JNIEnv *env, jclass bisd, jobject bufImg, jobject sData)
 {
 PRINT("setSurfaceData")
 
-    JNFSetObjectField(env, bufImg, jm_SurfaceData, sData);
+    GET_CLASS(jc_BufferedImage, "java/awt/image/BufferedImage");
+    GET_FIELD(jm_SurfaceData, jc_BufferedImage, "sData", "Lsun/java2d/SurfaceData;");
+    (*env)->SetObjectField(env, bufImg, jm_SurfaceData, sData);
 }
 
 static jint ImageSD_Lock(JNIEnv *env, SurfaceDataOps *ops, SurfaceDataRasInfo *pRasInfo, jint lockflags)
 {
     ImageSDOps *isdo = (ImageSDOps*)ops;

@@ -1839,17 +1845,17 @@
     }
     isdo->isSubImage                    = (offset%scanStride != 0) || (scanStride != (pixelStride*width));
 
     // parameters specifying this image given to us from Java
     isdo->javaImageInfo                    = (jint*)((*env)->GetDirectBufferAddress(env, jImageInfo));
-    isdo->array                            = (array != NULL) ? JNFNewGlobalRef(env, array) : NULL;
+    isdo->array                            = (array != NULL) ? (*env)->NewGlobalRef(env, array) : NULL;
     isdo->offset                        = offset;
     isdo->width                            = width;
     isdo->height                        = height;
     isdo->javaPixelBytes                = pixelStride;
     isdo->javaPixelsBytesPerRow            = scanStride;
-    isdo->icm                            = (icm != NULL) ? JNFNewGlobalRef(env, icm) : NULL;
+    isdo->icm                            = (icm != NULL) ? (*env)->NewGlobalRef(env, icm) : NULL;
     isdo->type                            = type;
 
     if ((isdo->javaImageInfo[sun_java2d_OSXOffScreenSurfaceData_kImageStolenIndex] == 1) ||
         (isdo->type == java_awt_image_BufferedImage_TYPE_CUSTOM))
     {

@@ -1861,19 +1867,28 @@
     isdo->indexedColorTable                = NULL;
     isdo->lutData                        = NULL;
     isdo->lutDataSize                    = 0;
     if ((type == java_awt_image_BufferedImage_TYPE_BYTE_INDEXED) && ((*env)->IsSameObject(env, icm, NULL) == NO))
     {
-        jarray lutarray = JNFGetObjectField(env, icm, jm_rgb);
+        static jclass jc_IndexColorModel = NULL;
+        if (jc_IndexColorModel == NULL) {
+            jc_IndexColorModel = (*env)->FindClass(env, "java/awt/image/IndexColorModel");
+        }
+        CHECK_NULL(jc_IndexColorModel);
+        DECLARE_FIELD(jm_rgb, jc_IndexColorModel, "rgb", "[I");
+        DECLARE_FIELD(jm_transparency, jc_IndexColorModel, "transparency", "I");
+        DECLARE_FIELD(jm_transparent_index, jc_IndexColorModel, "transparent_index", "I");
+
+        jarray lutarray = (*env)->GetObjectField(env, icm, jm_rgb);
         isdo->lutDataSize = (*env)->GetArrayLength(env, lutarray);
         if (isdo->lutDataSize > 0)
         {
-            jint transparency = JNFGetIntField(env, icm, jm_transparency);
+            jint transparency = (*env)->GetIntField(env, icm, jm_transparency);
             jint transparent_index = -1;
             if (transparency == java_awt_Transparency_BITMASK)
             {
-                transparent_index = JNFGetIntField(env, icm, jm_transparent_index);
+                transparent_index = (*env)->GetIntField(env, icm, jm_transparent_index);
             }
 
             Pixel32bit* lutdata = (Pixel32bit*)((*env)->GetPrimitiveArrayCritical(env, lutarray, NULL));
             if (lutdata != NULL)
             {

@@ -1944,11 +1959,11 @@
     QuartzSDOps *qsdo = (QuartzSDOps*)isdo;
     qsdo->BeginSurface                    = ImageSD_startCGContext;
     qsdo->FinishSurface                    = ImageSD_finishCGContext;
 
     qsdo->javaGraphicsStates            = (jint*)((*env)->GetDirectBufferAddress(env, jGraphicsState));
-    qsdo->javaGraphicsStatesObjects        = JNFNewGlobalRef(env, jGraphicsStateObject);
+    qsdo->javaGraphicsStatesObjects        = (*env)->NewGlobalRef(env, jGraphicsStateObject);
 
     qsdo->graphicsStateInfo.batchedLines = NULL;
     qsdo->graphicsStateInfo.batchedLinesCount = 0;
 
     SurfaceDataOps *sdo = (SurfaceDataOps*)qsdo;
< prev index next >