< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.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

@@ -23,15 +23,13 @@
  * questions.
  */
 
 #import "AWT_debug.h"
 
-#import "jni_util.h"
+#import "JNIUtilities.h"
 #import "ThreadUtilities.h"
 
-#import <JavaNativeFoundation/JavaNativeFoundation.h>
-
 #define MAX_DISPLAYS 64
 
 /*
  * Class:     sun_awt_CGraphicsEnvironment
  * Method:    getDisplayIDs

@@ -41,27 +39,23 @@
 Java_sun_awt_CGraphicsEnvironment_getDisplayIDs
 (JNIEnv *env, jclass class)
 {
     jintArray ret = NULL;
 
-JNF_COCOA_ENTER(env);
+JNI_COCOA_ENTER(env);
 
     /* Get the count */
     CGDisplayCount displayCount;
     if (CGGetOnlineDisplayList(MAX_DISPLAYS, NULL, &displayCount) != kCGErrorSuccess) {
-        [JNFException raise:env
-                         as:kInternalError
-                     reason:"CGGetOnlineDisplayList() failed to get display count"];
+        JNU_ThrowInternalError(env, "CGGetOnlineDisplayList() failed to get display count");
         return NULL;
     }
 
     /* Allocate an array and get the size list of display Ids */
     CGDirectDisplayID displays[MAX_DISPLAYS];
     if (CGGetOnlineDisplayList(displayCount, displays, &displayCount) != kCGErrorSuccess) {
-        [JNFException raise:env
-                         as:kInternalError
-                     reason:"CGGetOnlineDisplayList() failed to get display list"];
+        JNU_ThrowInternalError(env, "CGGetOnlineDisplayList() failed to get display list");
         return NULL;
     }
 
     CGDisplayCount i;
     CGDisplayCount displayActiveCount = 0; //Active and sleeping.

@@ -72,11 +66,12 @@
             displays[i] = kCGNullDirectDisplay;
         }
     }
 
     /* Allocate a java array for display identifiers */
-    ret = JNFNewIntArray(env, displayActiveCount);
+    ret = (*env)->NewIntArray(env, displayActiveCount);
+    CHECK_NULL_RETURN(ret, NULL);
 
     /* Initialize and return the backing int array */
     assert(sizeof(jint) >= sizeof(CGDirectDisplayID));
     jint *elems = (*env)->GetIntArrayElements(env, ret, 0);
     CHECK_NULL_RETURN(elems, NULL);

@@ -88,11 +83,11 @@
         }
     }
 
     (*env)->ReleaseIntArrayElements(env, ret, elems, 0);
 
-JNF_COCOA_EXIT(env);
+JNI_COCOA_EXIT(env);
 
     return ret;
 }
 
 /*

@@ -115,22 +110,22 @@
 {
     if (flags == kCGDisplayBeginConfigurationFlag) return;
 
     [ThreadUtilities performOnMainThreadWaiting:NO block:^() {
 
-        JNFPerformEnvBlock(JNFThreadDetachImmediately, ^(JNIEnv *env) {
-            JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)userInfo;
+        JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
+        jobject cgeRef = (jobject)userInfo;
 
-            jobject graphicsEnv = [wrapper jObjectWithEnv:env];
+        jobject graphicsEnv = (*env)->NewLocalRef(env, cgeRef);
             if (graphicsEnv == NULL) return; // ref already GC'd
-            static JNF_CLASS_CACHE(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment");
-            static JNF_MEMBER_CACHE(jm_displayReconfiguration,
+        DECLARE_CLASS(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment");
+        DECLARE_METHOD(jm_displayReconfiguration,
                     jc_CGraphicsEnvironment, "_displayReconfiguration","(IZ)V");
-            JNFCallVoidMethod(env, graphicsEnv, jm_displayReconfiguration,
+        (*env)->CallVoidMethod(env, graphicsEnv, jm_displayReconfiguration,
                     (jint) display, (jboolean) flags & kCGDisplayRemoveFlag);
             (*env)->DeleteLocalRef(env, graphicsEnv);
-        });
+        CHECK_EXCEPTION();
     }];
 }
 
 /*
  * Class:     sun_awt_CGraphicsEnvironment

@@ -141,25 +136,23 @@
 Java_sun_awt_CGraphicsEnvironment_registerDisplayReconfiguration
 (JNIEnv *env, jobject this)
 {
     jlong ret = 0L;
 
-JNF_COCOA_ENTER(env);
+JNI_COCOA_ENTER(env);
 
-    JNFWeakJObjectWrapper *wrapper = [[JNFWeakJObjectWrapper wrapperWithJObject:this withEnv:env] retain];
+    jobject cgeRef = (*env)->NewWeakGlobalRef(env, this);
 
     /* Register the callback */
-    if (CGDisplayRegisterReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) {
-        [JNFException raise:env
-                         as:kInternalError
-                     reason:"CGDisplayRegisterReconfigurationCallback() failed"];
+    if (CGDisplayRegisterReconfigurationCallback(&displaycb_handle, cgeRef) != kCGErrorSuccess) {
+        JNU_ThrowInternalError(env, "CGDisplayRegisterReconfigurationCallback() failed");
         return 0L;
     }
 
-    ret = ptr_to_jlong(wrapper);
+    ret = ptr_to_jlong(cgeRef);
 
-JNF_COCOA_EXIT(env);
+JNI_COCOA_EXIT(env);
 
     return ret;
 }
 
 /*

@@ -169,23 +162,20 @@
  */
 JNIEXPORT void JNICALL
 Java_sun_awt_CGraphicsEnvironment_deregisterDisplayReconfiguration
 (JNIEnv *env, jobject this, jlong p)
 {
-JNF_COCOA_ENTER(env);
+JNI_COCOA_ENTER(env);
 
-    JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)jlong_to_ptr(p);
-    if (!wrapper) return;
+    jobject cgeRef = (jobject)jlong_to_ptr(p);
+    if (!cgeRef) return;
 
     /* Remove the registration */
-    if (CGDisplayRemoveReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) {
-        [JNFException raise:env
-                         as:kInternalError
-                     reason:"CGDisplayRemoveReconfigurationCallback() failed, leaking the callback context!"];
+    if (CGDisplayRemoveReconfigurationCallback(&displaycb_handle, cgeRef) != kCGErrorSuccess) {
+        JNU_ThrowInternalError(env, "CGDisplayRemoveReconfigurationCallback() failed, leaking the callback context!");
         return;
     }
 
-    [wrapper setJObject:NULL withEnv:env]; // more efficient to pre-clear
-    [wrapper release];
+    (*env)->DeleteWeakGlobalRef(env, cgeRef);
 
-JNF_COCOA_EXIT(env);
+JNI_COCOA_EXIT(env);
 }
< prev index next >