Skip to content
Permalink
Browse files
8259869: [macOS] Remove desktop module dependencies on JNF Reference …
…APIs

Backport-of: 92c2f08
  • Loading branch information
Vladimir Kempik committed Apr 8, 2021
1 parent 47ec3b8 commit df2818b97b0b7cb721ad214dd530591c4e934602
Showing with 146 additions and 134 deletions.
  1. +4 −7 src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m
  2. +3 −4 src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.h
  3. +23 −23 src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m
  4. +3 −3 src/java.desktop/macosx/native/libawt_lwawt/awt/CClipboard.m
  5. +6 −6 src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSource.m
  6. +6 −6 src/java.desktop/macosx/native/libawt_lwawt/awt/CDragSourceContextPeer.m
  7. +10 −10 src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m
  8. +1 −1 src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m
  9. +2 −2 src/java.desktop/macosx/native/libawt_lwawt/awt/CFileDialog.m
  10. +9 −10 src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsEnv.m
  11. +6 −6 src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m
  12. +1 −1 src/java.desktop/macosx/native/libawt_lwawt/awt/CMenuComponent.m
  13. +1 −1 src/java.desktop/macosx/native/libawt_lwawt/awt/CPopupMenu.m
  14. +2 −2 src/java.desktop/macosx/native/libawt_lwawt/awt/CTrayIcon.m
  15. +6 −6 src/java.desktop/macosx/native/libawt_lwawt/awt/ImageSurfaceData.m
  16. +20 −9 src/java.desktop/macosx/native/libawt_lwawt/awt/JavaAccessibilityAction.m
  17. +5 −3 src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m
  18. +12 −12 src/java.desktop/macosx/native/libawt_lwawt/awt/PrinterView.m
  19. +3 −3 src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.h
  20. +5 −3 src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m
  21. +18 −16 src/java.desktop/macosx/native/libosxui/ScreenMenu.m
@@ -121,7 +121,7 @@ - (void) dealloc {
{
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];

JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
(*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE);
fInputMethodLOCKABLE = NULL;
}

@@ -1363,14 +1363,10 @@ - (void)setInputMethod:(jobject)inputMethod

// Get rid of the old one
if (fInputMethodLOCKABLE) {
JNFDeleteGlobalRef(env, fInputMethodLOCKABLE);
(*env)->DeleteGlobalRef(env, fInputMethodLOCKABLE);
}

// Save a global ref to the new input method.
if (inputMethod != NULL)
fInputMethodLOCKABLE = JNFNewGlobalRef(env, inputMethod);
else
fInputMethodLOCKABLE = NULL;
fInputMethodLOCKABLE = inputMethod; // input method arg must be a GlobalRef

NSTextInputContext *curContxt = [NSTextInputContext currentInputContext];
kbdLayout = curContxt.selectedKeyboardInputSource;
@@ -1412,6 +1408,7 @@ - (void)abandonInput

NSRect rect = NSMakeRect(originX, originY, width, height);
jobject cPlatformView = (*env)->NewWeakGlobalRef(env, obj);
CHECK_EXCEPTION();

[ThreadUtilities performOnMainThreadWaiting:YES block:^(){

@@ -32,11 +32,10 @@
#import "LWCToolkit.h"

@class AWTView;
@class JNFWeakJObjectWrapper;

@interface AWTWindow : NSObject <NSWindowDelegate> {
@private
JNFWeakJObjectWrapper *javaPlatformWindow;
jobject javaPlatformWindow; /* This is a weak ref. Always copy to a local ref before using */
CMenuBar *javaMenuBar;
NSSize javaMinSize;
NSSize javaMaxSize;
@@ -53,7 +52,7 @@
// An instance of either AWTWindow_Normal or AWTWindow_Panel
@property (nonatomic, retain) NSWindow *nsWindow;

@property (nonatomic, retain) JNFWeakJObjectWrapper *javaPlatformWindow;
@property (nonatomic) jobject javaPlatformWindow;
@property (nonatomic, retain) CMenuBar *javaMenuBar;
@property (nonatomic, retain) AWTWindow *ownerWindow;
@property (nonatomic) NSSize javaMinSize;
@@ -65,7 +64,7 @@
@property (nonatomic) BOOL isMinimizing;
@property (nonatomic) BOOL keyNotificationRecd;

- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)javaPlatformWindow
- (id) initWithPlatformWindow:(jobject)javaPlatformWindow
ownerWindow:owner
styleBits:(jint)styleBits
frameRect:(NSRect)frameRect
@@ -116,7 +116,7 @@ - (void)postGesture:(NSEvent *)event as:(jint)type a:(jdouble)a b:(jdouble)b {
AWT_ASSERT_APPKIT_THREAD;

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [((AWTWindow *)self.delegate).javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, ((AWTWindow *)self.delegate).javaPlatformWindow);
if (platformWindow != NULL) {
// extract the target AWT Window object out of the CPlatformWindow
GET_CPLATFORM_WINDOW_CLASS();
@@ -281,7 +281,7 @@ - (void) setPropertiesForStyleBits:(jint)bits mask:(jint)mask {
}
}

- (id) initWithPlatformWindow:(JNFWeakJObjectWrapper *)platformWindow
- (id) initWithPlatformWindow:(jobject)platformWindow
ownerWindow:owner
styleBits:(jint)bits
frameRect:(NSRect)rect
@@ -482,7 +482,7 @@ - (void) dealloc {
AWT_ASSERT_APPKIT_THREAD;

JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
[self.javaPlatformWindow setJObject:nil withEnv:env];
(*env)->DeleteWeakGlobalRef(env, self.javaPlatformWindow);
self.javaPlatformWindow = nil;
self.nsWindow = nil;
self.ownerWindow = nil;
@@ -494,7 +494,7 @@ - (BOOL) isBlocked {
BOOL isBlocked = NO;

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS_RETURN(isBlocked);
DECLARE_METHOD_RETURN(jm_isBlocked, jc_CPlatformWindow, "isBlocked", "()Z", isBlocked);
@@ -511,7 +511,7 @@ - (BOOL) isSimpleWindowOwnedByEmbeddedFrame {
BOOL isSimpleWindowOwnedByEmbeddedFrame = NO;

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS_RETURN(NO);
DECLARE_METHOD_RETURN(jm_isBlocked, jc_CPlatformWindow, "isSimpleWindowOwnedByEmbeddedFrame", "()Z", NO);
@@ -532,7 +532,7 @@ + (BOOL) isJavaPlatformWindowVisible:(NSWindow *)window {
[AWTToolkit eventCountPlusPlus];

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [awtWindow.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, awtWindow.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS_RETURN(isVisible);
DECLARE_METHOD_RETURN(jm_isVisible, jc_CPlatformWindow, "isVisible", "()Z", isVisible)
@@ -603,7 +603,7 @@ - (BOOL) canBecomeMainWindow {
[AWTToolkit eventCountPlusPlus];

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS_RETURN(NO);
DECLARE_METHOD_RETURN(jm_checkBlockingAndOrder, jc_CPlatformWindow, "checkBlockingAndOrder", "()Z", NO);
@@ -632,7 +632,7 @@ - (void) _deliverMoveResizeEvent {
// the bounds of the window to avoid the Dock or remain on screen.
[AWTToolkit eventCountPlusPlus];
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow == NULL) {
// TODO: create generic AWT assert
}
@@ -710,7 +710,7 @@ - (void) _deliverIconify:(BOOL)iconify {

[AWTToolkit eventCountPlusPlus];
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_deliverIconify, jc_CPlatformWindow, "deliverIconify", "(Z)V");
@@ -726,7 +726,7 @@ - (void)windowWillMiniaturize:(NSNotification *)notification {
self.isMinimizing = YES;

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowWillMiniaturize, jc_CPlatformWindow, "windowWillMiniaturize", "()V");
@@ -757,9 +757,9 @@ - (void)windowDidDeminiaturize:(NSNotification *)notification {
- (void) _deliverWindowFocusEvent:(BOOL)focused oppositeWindow:(AWTWindow *)opposite {
//AWT_ASSERT_APPKIT_THREAD;
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
jobject oppositeWindow = [opposite.javaPlatformWindow jObjectWithEnv:env];
jobject oppositeWindow = (*env)->NewLocalRef(env, opposite.javaPlatformWindow);
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_deliverWindowFocusEvent, jc_CPlatformWindow, "deliverWindowFocusEvent", "(ZLsun/lwawt/macosx/CPlatformWindow;)V");
(*env)->CallVoidMethod(env, platformWindow, jm_deliverWindowFocusEvent, (jboolean)focused, oppositeWindow);
@@ -788,7 +788,7 @@ - (void) windowDidBecomeMain: (NSNotification *) notification {
}

JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowDidBecomeMain, jc_CPlatformWindow, "windowDidBecomeMain", "()V");
@@ -904,7 +904,7 @@ - (BOOL)windowShouldClose:(id)sender {
AWT_ASSERT_APPKIT_THREAD;
[AWTToolkit eventCountPlusPlus];
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS_RETURN(NO);
DECLARE_METHOD_RETURN(jm_deliverWindowClosingEvent, jc_CPlatformWindow, "deliverWindowClosingEvent", "()V", NO);
@@ -922,7 +922,7 @@ - (void)_notifyFullScreenOp:(jint)op withEnv:(JNIEnv *)env {
"handleFullScreenEventFromNative", "(Ljava/awt/Window;I)V");
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_FIELD(jf_target, jc_CPlatformWindow, "target", "Ljava/awt/Window;");
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
jobject awtWindow = (*env)->GetObjectField(env, platformWindow, jf_target);
if (awtWindow != NULL) {
@@ -939,7 +939,7 @@ - (void)windowWillEnterFullScreen:(NSNotification *)notification {
JNIEnv *env = [ThreadUtilities getJNIEnv];
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowWillEnterFullScreen, jc_CPlatformWindow, "windowWillEnterFullScreen", "()V");
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
(*env)->CallVoidMethod(env, platformWindow, jm_windowWillEnterFullScreen);
CHECK_EXCEPTION();
@@ -952,7 +952,7 @@ - (void)windowDidEnterFullScreen:(NSNotification *)notification {
JNIEnv *env = [ThreadUtilities getJNIEnv];
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowDidEnterFullScreen, jc_CPlatformWindow, "windowDidEnterFullScreen", "()V");
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
(*env)->CallVoidMethod(env, platformWindow, jm_windowDidEnterFullScreen);
CHECK_EXCEPTION();
@@ -971,7 +971,7 @@ - (void)windowWillExitFullScreen:(NSNotification *)notification {
jm_windowWillExitFullScreen = (*env)->GetMethodID(env, jc_CPlatformWindow, "windowWillExitFullScreen", "()V");
}
CHECK_NULL(jm_windowWillExitFullScreen);
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
(*env)->CallVoidMethod(env, platformWindow, jm_windowWillExitFullScreen);
CHECK_EXCEPTION();
@@ -982,7 +982,7 @@ - (void)windowWillExitFullScreen:(NSNotification *)notification {

- (void)windowDidExitFullScreen:(NSNotification *)notification {
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_windowDidExitFullScreen, jc_CPlatformWindow, "windowDidExitFullScreen", "()V");
@@ -1001,7 +1001,7 @@ - (void)sendEvent:(NSEvent *)event {
// in front of its nearest parent.
if (self.ownerWindow != nil) {
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
GET_CPLATFORM_WINDOW_CLASS();
DECLARE_METHOD(jm_orderAboveSiblings, jc_CPlatformWindow, "orderAboveSiblings", "()V");
@@ -1020,7 +1020,7 @@ - (void)sendEvent:(NSEvent *)event {
// Check if the click happened in the non-client area (title bar)
if (p.y >= (frame.origin.y + contentRect.size.height)) {
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
jobject platformWindow = [self.javaPlatformWindow jObjectWithEnv:env];
jobject platformWindow = (*env)->NewLocalRef(env, self.javaPlatformWindow);
if (platformWindow != NULL) {
// Currently, no need to deliver the whole NSEvent.
GET_CPLATFORM_WINDOW_CLASS();
@@ -1103,7 +1103,7 @@ + (AWTWindow *) lastKeyWindow {

JNI_COCOA_ENTER(env);

JNFWeakJObjectWrapper *platformWindow = [JNFWeakJObjectWrapper wrapperWithJObject:obj withEnv:env];
jobject platformWindow = (*env)->NewWeakGlobalRef(env, obj);
NSView *contentView = OBJC(contentViewPtr);
NSRect frameRect = NSMakeRect(x, y, w, h);
AWTWindow *owner = [OBJC(ownerPtr) delegate];
@@ -1544,7 +1544,7 @@ + (AWTWindow *) lastKeyWindow {
[ThreadUtilities performOnMainThreadWaiting:YES block:^{
AWTWindow *awtWindow = [AWTWindow getTopmostWindowUnderMouse];
if (awtWindow != nil) {
topmostWindowUnderMouse = [awtWindow.javaPlatformWindow jObject];
topmostWindowUnderMouse = awtWindow.javaPlatformWindow;
}
}];

@@ -66,9 +66,9 @@ - (void)declareTypes:(NSArray*)types withOwner:(jobject)owner jniEnv:(JNIEnv*)en
@synchronized(self) {
if (owner != NULL) {
if (self.clipboardOwner != NULL) {
JNFDeleteGlobalRef(env, self.clipboardOwner);
(*env)->DeleteGlobalRef(env, self.clipboardOwner);
}
self.clipboardOwner = JNFNewGlobalRef(env, owner);
self.clipboardOwner = (*env)->NewGlobalRef(env, owner);
}
}
[ThreadUtilities performOnMainThreadWaiting:YES block:^() {
@@ -101,7 +101,7 @@ - (void)checkPasteboard:(id)sender {
if (self.clipboardOwner) {
(*env)->CallVoidMethod(env, self.clipboardOwner, jm_lostOwnership); // AWT_THREADING Safe (event)
CHECK_EXCEPTION();
JNFDeleteGlobalRef(env, self.clipboardOwner);
(*env)->DeleteGlobalRef(env, self.clipboardOwner);
self.clipboardOwner = NULL;
}
}
@@ -169,32 +169,32 @@ - (void)removeFromView:(JNIEnv *)env

// Clean up JNI refs
if (fComponent != NULL) {
JNFDeleteGlobalRef(env, fComponent);
(*env)->DeleteGlobalRef(env, fComponent);
fComponent = NULL;
}

if (fDragSourceContextPeer != NULL) {
JNFDeleteGlobalRef(env, fDragSourceContextPeer);
(*env)->DeleteGlobalRef(env, fDragSourceContextPeer);
fDragSourceContextPeer = NULL;
}

if (fTransferable != NULL) {
JNFDeleteGlobalRef(env, fTransferable);
(*env)->DeleteGlobalRef(env, fTransferable);
fTransferable = NULL;
}

if (fTriggerEvent != NULL) {
JNFDeleteGlobalRef(env, fTriggerEvent);
(*env)->DeleteGlobalRef(env, fTriggerEvent);
fTriggerEvent = NULL;
}

if (fFormats != NULL) {
JNFDeleteGlobalRef(env, fFormats);
(*env)->DeleteGlobalRef(env, fFormats);
fFormats = NULL;
}

if (fFormatMap != NULL) {
JNFDeleteGlobalRef(env, fFormatMap);
(*env)->DeleteGlobalRef(env, fFormatMap);
fFormatMap = NULL;
}

@@ -50,12 +50,12 @@
JNI_COCOA_ENTER(env);

// Global references are disposed when the DragSource is removed
jobject gComponent = JNFNewGlobalRef(env, jcomponent);
jobject gDragSourceContextPeer = JNFNewGlobalRef(env, jthis);
jobject gTransferable = JNFNewGlobalRef(env, jtransferable);
jobject gTriggerEvent = JNFNewGlobalRef(env, jtrigger);
jlongArray gFormats = JNFNewGlobalRef(env, jformats);
jobject gFormatMap = JNFNewGlobalRef(env, jformatmap);
jobject gComponent = (*env)->NewGlobalRef(env, jcomponent);
jobject gDragSourceContextPeer = (*env)->NewGlobalRef(env, jthis);
jobject gTransferable = (*env)->NewGlobalRef(env, jtransferable);
jobject gTriggerEvent = (*env)->NewGlobalRef(env, jtrigger);
jlongArray gFormats = (*env)->NewGlobalRef(env, jformats);
jobject gFormatMap = (*env)->NewGlobalRef(env, jformatmap);

[ThreadUtilities performOnMainThreadWaiting:YES block:^(){
dragSource = [[CDragSource alloc] init:gDragSourceContextPeer

1 comment on commit df2818b

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on df2818b Apr 8, 2021

Please sign in to comment.