From 999e1ca3ec1a406d3dba65f0bae79054580fb287 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 2 Jan 2020 04:44:19 +0100 Subject: Bug 1393: MacOS: getLocationOnScreen w/ JAWT Parent: Use parent's unblocking specialization On MacOS, commit 12eed5d38616d23b6e8e2e5b497dfc2f54d90c90 replaced all parent.getLocationOnScreen(..) calls with OSXUtil.GetLocationOnScreen(parentHandle, ..) avoiding the EDT + Appkit Deadlock with native parenting. On MacOS AWT and JAWT are using offscreen CALayer since Java >= 1.7.0, therefor the MacOSXJAWTWindow's native window handle can't be used to gather the screen position via OSXUtil. However, the JAWT Window specialization MacOSXJAWTWindow implements a non-locking code-path and we can decide to use it by querying the general interface OffscreenLayerOption. --- .../classes/jogamp/newt/driver/macosx/WindowDriver.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/newt/classes') diff --git a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java index 53e05d8a0..18d1ebafa 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java @@ -39,6 +39,7 @@ import com.jogamp.nativewindow.AbstractGraphicsConfiguration; import com.jogamp.nativewindow.GraphicsConfigurationFactory; import com.jogamp.nativewindow.NativeWindow; import com.jogamp.nativewindow.NativeWindowException; +import com.jogamp.nativewindow.OffscreenLayerOption; import com.jogamp.nativewindow.MutableSurface; import com.jogamp.nativewindow.ScalableSurface; import com.jogamp.nativewindow.VisualIDHolder; @@ -523,6 +524,11 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl private Point getLocationOnScreenByParent(final int x, final int y, final NativeWindow parent) { // return new Point(x, y).translate( parent.getLocationOnScreen(null) ); // Bug 1393: deadlock AppKit + EDT + + // If parent is JAWT on OSX (offscreen), we need to query its non-blocking position + if( parent instanceof OffscreenLayerOption && ((OffscreenLayerOption)parent).isOffscreenLayerSurfaceEnabled() ) { + return new Point(x, y).translate( parent.getLocationOnScreen(null) ); // uses non-blocking specialization + } return new Point(x, y).translate( OSXUtil.GetLocationOnScreen(parent.getWindowHandle(), 0, 0) ); // non-blocking } @@ -542,7 +548,13 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl // screen position -> rel child window position final Point absPos = new Point(newX, newY); // final Point parentOnScreen = parent.getLocationOnScreen(null); // Bug 1393: deadlock AppKit + EDT - final Point parentOnScreen = OSXUtil.GetLocationOnScreen(parent.getWindowHandle(), 0, 0); // non-blocking + final Point parentOnScreen; + if( parent instanceof OffscreenLayerOption && ((OffscreenLayerOption)parent).isOffscreenLayerSurfaceEnabled() ) { + // If parent is JAWT on OSX (offscreen), we need to query its non-blocking position + parentOnScreen = parent.getLocationOnScreen(null); // uses non-blocking specialization + } else { + parentOnScreen = OSXUtil.GetLocationOnScreen(parent.getWindowHandle(), 0, 0); // non-blocking + } absPos.translate( parentOnScreen.scale(-1, -1) ); if(DEBUG_IMPLEMENTATION) { System.err.println("MacWindow.positionChanged.1 (Screen Pos - CHILD): ("+getThreadName()+"): (defer: "+defer+") "+getX()+"/"+getY()+" -> absPos "+newX+"/"+newY+", parentOnScreen "+parentOnScreen+" -> "+absPos); -- cgit v1.2.3