diff options
author | Sven Gothel <[email protected]> | 2019-09-09 09:29:43 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-09-09 09:29:43 +0200 |
commit | b12a80e386b12d9d8fa63cf07124f8da989dcd04 (patch) | |
tree | 836b6f9b5e29bbeb56d8d3006d230fea000bf658 /src/newt/classes/jogamp | |
parent | db843e65c6b93d720438c7e751413c0556f51a6e (diff) |
Bug 1393: Run orderFront0(=setVisible) async off-thread on AppKit after sync AppKit NSWindow creation
MacOS 10.14.6 + OpenJDK11U produces occasional freezes on AppKit Main Thread
Latest manual tests after resolving Bug 1389
disclosed a few occasional freezes using NEWT + Java11.
These are related to probable AWT changes since Java8,
as these do not occur with Java8.
Fix: Spun off orderFront0(=setVisible) async off-thread on AppKit after sync AppKit NSWindow creation.
This fix also aligns the macos createWindow code with the new simplified ios implementation,
see commit 004c67c73a0309158c30929cd0d6513e23f34803
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/ios/WindowDriver.java | 14 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java | 71 |
2 files changed, 49 insertions, 36 deletions
diff --git a/src/newt/classes/jogamp/newt/driver/ios/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/ios/WindowDriver.java index d8ec75c36..b7ecc23d6 100644 --- a/src/newt/classes/jogamp/newt/driver/ios/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/ios/WindowDriver.java @@ -756,8 +756,7 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl !offscreenInstance && 0 != ( STATE_MASK_ALWAYSONBOTTOM & flags), !offscreenInstance && 0 != ( STATE_MASK_VISIBLE & flags), surfaceHandle); - final long uiView = IOSUtil.GetUIView(newWin[0], true); - surfaceHandle = uiView; + surfaceHandle = IOSUtil.GetUIView(newWin[0], true); if( offscreenInstance ) { orderOut0(0!=parentWinHandle ? parentWinHandle : newWin[0]); @@ -770,6 +769,17 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl throw new NativeWindowException("Could not create native window "+Thread.currentThread().getName()+" "+this); } setWindowHandle( newWin[0] ); + /** + * TODO: Validate whether visibility shall also be handled async on IOS as on OSX + if( !offscreenInstance && 0 != ( STATE_MASK_VISIBLE & flags) ) { + IOSUtil.RunOnMainThread(false, false, new Runnable() { + @Override + public void run() { + orderFront0( newWin[0] ); + } + + }); + } */ } catch (final Exception ie) { ie.printStackTrace(); } diff --git a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java index 1c6102f88..937c11a5c 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/WindowDriver.java @@ -733,37 +733,27 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl final int flags) { final long parentWinHandle = getParentWindowHandle(); - final long preWinHandle = getWindowHandle(); + final long oldWinHandle = getWindowHandle(); if(DEBUG_IMPLEMENTATION) { System.err.println("MacWindow.createWindow on thread "+Thread.currentThread().getName()+ ": offscreen "+offscreenInstance+", recreate "+recreate+ ", pS "+pS+", "+width+"x"+height+", state "+getReconfigStateMaskString(flags)+ - ", preWinHandle "+toHexString(preWinHandle)+", parentWin "+toHexString(parentWinHandle)+ + ", preWinHandle "+toHexString(oldWinHandle)+", parentWin "+toHexString(parentWinHandle)+ ", surfaceHandle "+toHexString(surfaceHandle)); // Thread.dumpStack(); } try { - if( 0 != preWinHandle ) { + if( 0 != oldWinHandle ) { setWindowHandle(0); if( 0 == surfaceHandle ) { throw new NativeWindowException("Internal Error - create w/ window, but no Newt NSView"); } - OSXUtil.RunOnMainThread(false, false /* kickNSApp */, new Runnable() { - @Override - public void run() { - changeContentView0(parentWinHandle, preWinHandle, 0); - close0( preWinHandle ); - } }); } else { if( 0 != surfaceHandle ) { throw new NativeWindowException("Internal Error - create w/o window, but has Newt NSView"); } - surfaceHandle = createView0(pS.getX(), pS.getY(), width, height); - if( 0 == surfaceHandle ) { - throw new NativeWindowException("Could not create native view "+Thread.currentThread().getName()+" "+this); - } } final int windowStyle; @@ -784,41 +774,54 @@ public class WindowDriver extends WindowImpl implements MutableSurface, DriverCl OSXUtil.RunOnMainThread(true, false /* kickNSApp */, new Runnable() { @Override public void run() { - newWin[0] = createWindow0( pS.getX(), pS.getY(), width, height, + /** + * Does everything at once, same as original code path: + * 1) if oldWinHandle: changeContentView (detaching view) + close0(oldWindHandle) + * 2) create new window + * 3) create new view if previous didn't exist (oldWinHandle) + * 4) changeContentView (attaching view) etc .. + */ + final boolean isOpaque = getGraphicsConfiguration().getChosenCapabilities().isBackgroundOpaque() && !offscreenInstance; + newWin[0] = createWindow1( oldWinHandle, parentWinHandle, pS.getX(), pS.getY(), width, height, reqPixelScale[0] /* HiDPI uniformPixelScale */, 0 != ( STATE_MASK_FULLSCREEN & flags), - windowStyle, - NSBackingStoreBuffered, surfaceHandle); - if ( newWin[0] != 0 ) { - final boolean isOpaque = getGraphicsConfiguration().getChosenCapabilities().isBackgroundOpaque() && !offscreenInstance; - initWindow0( parentWinHandle, newWin[0], pS.getX(), pS.getY(), width, height, reqPixelScale[0] /* HiDPI uniformPixelScale */, - isOpaque, - !offscreenInstance && 0 != ( STATE_MASK_ALWAYSONTOP & flags), - !offscreenInstance && 0 != ( STATE_MASK_ALWAYSONBOTTOM & flags), - !offscreenInstance && 0 != ( STATE_MASK_VISIBLE & flags), - surfaceHandle); - if( offscreenInstance ) { - orderOut0(0!=parentWinHandle ? parentWinHandle : newWin[0]); - } else { - setTitle0(newWin[0], getTitle()); - } + windowStyle, NSBackingStoreBuffered, + isOpaque, + !offscreenInstance && 0 != ( STATE_MASK_ALWAYSONTOP & flags), + !offscreenInstance && 0 != ( STATE_MASK_ALWAYSONBOTTOM & flags), + !offscreenInstance && 0 != ( STATE_MASK_VISIBLE & flags), + surfaceHandle); + surfaceHandle = OSXUtil.GetNSView(newWin[0]); + + if( offscreenInstance ) { + orderOut0(0!=parentWinHandle ? parentWinHandle : newWin[0]); + } else { + setTitle0(newWin[0], getTitle()); } } }); - if ( newWin[0] == 0 ) { + if ( newWin[0] == 0 || 0 == surfaceHandle ) { throw new NativeWindowException("Could not create native window "+Thread.currentThread().getName()+" "+this); } setWindowHandle( newWin[0] ); + if( !offscreenInstance && 0 != ( STATE_MASK_VISIBLE & flags) ) { + OSXUtil.RunOnMainThread(false, false, new Runnable() { + @Override + public void run() { + orderFront0( newWin[0] ); + } + + }); + } } catch (final Exception ie) { ie.printStackTrace(); } } protected static native boolean initIDs0(); - private native long createView0(int x, int y, int w, int h); - private native long createWindow0(int x, int y, int w, int h, boolean fullscreen, int windowStyle, int backingStoreType, long view); /** Must be called on Main-Thread */ - private native void initWindow0(long parentWindow, long window, int x, int y, int w, int h, float reqPixelScale, - boolean opaque, boolean atop, boolean abottom, boolean visible, long view); + private native long createWindow1(long oldWindow, long parentWindow, int x, int y, int w, int h, float reqPixelScale, + boolean fullscreen, int windowStyle, int backingStoreType, + boolean opaque, boolean atop, boolean abottom, boolean visible, long view); private native int getDisplayID0(long window); private native void setPixelScale0(long window, long view, float reqPixelScale); |