< 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,37 ****
* questions.
*/
#import "AWT_debug.h"
! #import "jni_util.h"
#import "ThreadUtilities.h"
- #import <JavaNativeFoundation/JavaNativeFoundation.h>
-
#define MAX_DISPLAYS 64
/*
* Class: sun_awt_CGraphicsEnvironment
* Method: getDisplayIDs
--- 23,35 ----
* questions.
*/
#import "AWT_debug.h"
! #import "JNIUtilities.h"
#import "ThreadUtilities.h"
#define MAX_DISPLAYS 64
/*
* Class: sun_awt_CGraphicsEnvironment
* Method: getDisplayIDs
*** 41,67 ****
Java_sun_awt_CGraphicsEnvironment_getDisplayIDs
(JNIEnv *env, jclass class)
{
jintArray ret = NULL;
! JNF_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"];
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"];
return NULL;
}
CGDisplayCount i;
CGDisplayCount displayActiveCount = 0; //Active and sleeping.
--- 39,61 ----
Java_sun_awt_CGraphicsEnvironment_getDisplayIDs
(JNIEnv *env, jclass class)
{
jintArray ret = NULL;
! JNI_COCOA_ENTER(env);
/* Get the count */
CGDisplayCount displayCount;
if (CGGetOnlineDisplayList(MAX_DISPLAYS, NULL, &displayCount) != kCGErrorSuccess) {
! 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) {
! JNU_ThrowInternalError(env, "CGGetOnlineDisplayList() failed to get display list");
return NULL;
}
CGDisplayCount i;
CGDisplayCount displayActiveCount = 0; //Active and sleeping.
*** 72,82 ****
displays[i] = kCGNullDirectDisplay;
}
}
/* Allocate a java array for display identifiers */
! ret = JNFNewIntArray(env, displayActiveCount);
/* Initialize and return the backing int array */
assert(sizeof(jint) >= sizeof(CGDirectDisplayID));
jint *elems = (*env)->GetIntArrayElements(env, ret, 0);
CHECK_NULL_RETURN(elems, NULL);
--- 66,77 ----
displays[i] = kCGNullDirectDisplay;
}
}
/* Allocate a java array for display identifiers */
! 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,98 ****
}
}
(*env)->ReleaseIntArrayElements(env, ret, elems, 0);
! JNF_COCOA_EXIT(env);
return ret;
}
/*
--- 83,93 ----
}
}
(*env)->ReleaseIntArrayElements(env, ret, elems, 0);
! JNI_COCOA_EXIT(env);
return ret;
}
/*
*** 115,136 ****
{
if (flags == kCGDisplayBeginConfigurationFlag) return;
[ThreadUtilities performOnMainThreadWaiting:NO block:^() {
! JNFPerformEnvBlock(JNFThreadDetachImmediately, ^(JNIEnv *env) {
! JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)userInfo;
! jobject graphicsEnv = [wrapper jObjectWithEnv:env];
if (graphicsEnv == NULL) return; // ref already GC'd
! static JNF_CLASS_CACHE(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment");
! static JNF_MEMBER_CACHE(jm_displayReconfiguration,
jc_CGraphicsEnvironment, "_displayReconfiguration","(IZ)V");
! JNFCallVoidMethod(env, graphicsEnv, jm_displayReconfiguration,
(jint) display, (jboolean) flags & kCGDisplayRemoveFlag);
(*env)->DeleteLocalRef(env, graphicsEnv);
! });
}];
}
/*
* Class: sun_awt_CGraphicsEnvironment
--- 110,131 ----
{
if (flags == kCGDisplayBeginConfigurationFlag) return;
[ThreadUtilities performOnMainThreadWaiting:NO block:^() {
! JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
! jobject cgeRef = (jobject)userInfo;
! jobject graphicsEnv = (*env)->NewLocalRef(env, cgeRef);
if (graphicsEnv == NULL) return; // ref already GC'd
! DECLARE_CLASS(jc_CGraphicsEnvironment, "sun/awt/CGraphicsEnvironment");
! DECLARE_METHOD(jm_displayReconfiguration,
jc_CGraphicsEnvironment, "_displayReconfiguration","(IZ)V");
! (*env)->CallVoidMethod(env, graphicsEnv, jm_displayReconfiguration,
(jint) display, (jboolean) flags & kCGDisplayRemoveFlag);
(*env)->DeleteLocalRef(env, graphicsEnv);
! CHECK_EXCEPTION();
}];
}
/*
* Class: sun_awt_CGraphicsEnvironment
*** 141,165 ****
Java_sun_awt_CGraphicsEnvironment_registerDisplayReconfiguration
(JNIEnv *env, jobject this)
{
jlong ret = 0L;
! JNF_COCOA_ENTER(env);
! JNFWeakJObjectWrapper *wrapper = [[JNFWeakJObjectWrapper wrapperWithJObject:this withEnv:env] retain];
/* Register the callback */
! if (CGDisplayRegisterReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) {
! [JNFException raise:env
! as:kInternalError
! reason:"CGDisplayRegisterReconfigurationCallback() failed"];
return 0L;
}
! ret = ptr_to_jlong(wrapper);
! JNF_COCOA_EXIT(env);
return ret;
}
/*
--- 136,158 ----
Java_sun_awt_CGraphicsEnvironment_registerDisplayReconfiguration
(JNIEnv *env, jobject this)
{
jlong ret = 0L;
! JNI_COCOA_ENTER(env);
! jobject cgeRef = (*env)->NewWeakGlobalRef(env, this);
/* Register the callback */
! if (CGDisplayRegisterReconfigurationCallback(&displaycb_handle, cgeRef) != kCGErrorSuccess) {
! JNU_ThrowInternalError(env, "CGDisplayRegisterReconfigurationCallback() failed");
return 0L;
}
! ret = ptr_to_jlong(cgeRef);
! JNI_COCOA_EXIT(env);
return ret;
}
/*
*** 169,191 ****
*/
JNIEXPORT void JNICALL
Java_sun_awt_CGraphicsEnvironment_deregisterDisplayReconfiguration
(JNIEnv *env, jobject this, jlong p)
{
! JNF_COCOA_ENTER(env);
! JNFWeakJObjectWrapper *wrapper = (JNFWeakJObjectWrapper *)jlong_to_ptr(p);
! if (!wrapper) return;
/* Remove the registration */
! if (CGDisplayRemoveReconfigurationCallback(&displaycb_handle, wrapper) != kCGErrorSuccess) {
! [JNFException raise:env
! as:kInternalError
! reason:"CGDisplayRemoveReconfigurationCallback() failed, leaking the callback context!"];
return;
}
! [wrapper setJObject:NULL withEnv:env]; // more efficient to pre-clear
! [wrapper release];
! JNF_COCOA_EXIT(env);
}
--- 162,181 ----
*/
JNIEXPORT void JNICALL
Java_sun_awt_CGraphicsEnvironment_deregisterDisplayReconfiguration
(JNIEnv *env, jobject this, jlong p)
{
! JNI_COCOA_ENTER(env);
! jobject cgeRef = (jobject)jlong_to_ptr(p);
! if (!cgeRef) return;
/* Remove the registration */
! if (CGDisplayRemoveReconfigurationCallback(&displaycb_handle, cgeRef) != kCGErrorSuccess) {
! JNU_ThrowInternalError(env, "CGDisplayRemoveReconfigurationCallback() failed, leaking the callback context!");
return;
}
! (*env)->DeleteWeakGlobalRef(env, cgeRef);
! JNI_COCOA_EXIT(env);
}
< prev index next >