diff options
author | Sven Gothel <[email protected]> | 2013-03-13 07:12:59 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-03-13 07:12:59 +0100 |
commit | e2506d7663b752f00f0a98f793ebad52e65bd1e3 (patch) | |
tree | 66e669f22824892aec2d157aca5c384f1bd348c4 /src/newt/classes/jogamp | |
parent | c225285e09f0a29fca418601bf1aa07cafb54339 (diff) |
Bug 665: Allow re-association of GLContext/GLEventListener to a GLDrawable (Part 5)
- GLAutoDrawableBase:
- Add 'setPreserveGLStateAtDestroy(..)' to preserve the GLEventListenerState at destroy() operation,
and impl. details pullGLEventListenerState()/pushGLEventListenerState().
pullGLEventListenerState() is called automatic at destroyImplInLock(),
where pushGLEventListenerState() has to be called after drawable realization
instead of context creation.
- Note/TODO: Method will become public in GLAutoDrawable in general!
- NEWT/GLWindow:
- Use GLEventListenerState preservation for reparenting case w/ destruction,
i.e. keep GLContext/GLEventListener alive while reparenting in recreation mode.
Scenario: NewtCanvasAWT Child <-> Top on OSX w/ CALayer
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r-- | src/newt/classes/jogamp/newt/WindowImpl.java | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index af0bde179..dfaa55679 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -222,6 +222,12 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer */ void setVisibleActionPost(boolean visible, boolean nativeWindowCreated); + /** + * Notifies the receiver to preserve resources (GL, ..) + * for the next destroy*() calls (only). + */ + void setPreserveResourcesAtDestroy(); + /** * Invoked before Window destroy action, * allows releasing of resources depending on the native Window.<br> @@ -953,6 +959,13 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer runOnEDTIfAvail(true, destroyAction); } + protected void destroy(boolean preserveResources) { + if( preserveResources && null != WindowImpl.this.lifecycleHook ) { + WindowImpl.this.lifecycleHook.setPreserveResourcesAtDestroy(); + } + destroy(); + } + /** * @param cWin child window, must not be null * @param pWin parent window, may be null @@ -1053,9 +1066,9 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer if(null==newParentWindowNEWT) { throw new NativeWindowException("Reparenting with non NEWT Window type only available after it's realized: "+newParentWindow); } - // Destroy this window and use parent's Screen. + // Destroy this window and use parent's Screen, while trying to preserve resources. // It may be created properly when the parent is made visible. - destroy(); + destroy(true); setScreen( (ScreenImpl) newParentWindowNEWT.getScreen() ); operation = ReparentOperation.ACTION_NATIVE_CREATION_PENDING; } else if(newParentWindow != getParent()) { @@ -1078,9 +1091,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer operation = ReparentOperation.ACTION_NATIVE_CREATION_PENDING; } } else if ( forceDestroyCreate || !NewtFactory.isScreenCompatible(newParentWindow, screen) ) { - // Destroy this window, may create a new compatible Screen/Display, - // and mark it for creation. - destroy(); + // Destroy this window, may create a new compatible Screen/Display, while trying to preserve resources. + destroy(true); if(null!=newParentWindowNEWT) { setScreen( (ScreenImpl) newParentWindowNEWT.getScreen() ); } else { @@ -1109,8 +1121,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer // Already Top Window operation = ReparentOperation.ACTION_NOP; } else if( !isNativeValid() || forceDestroyCreate ) { - // Destroy this window and mark it for [pending] creation. - destroy(); + // Destroy this window and mark it for [pending] creation, while trying to preserve resources. + destroy(true); if( 0 < width && 0 < height ) { operation = ReparentOperation.ACTION_NATIVE_CREATION; } else { @@ -1213,11 +1225,11 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } if(!ok) { - // native reparent failed -> try creation + // native reparent failed -> try creation, while trying to preserve resources. if(DEBUG_IMPLEMENTATION) { System.err.println("Window.reparent: native reparenting failed ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+" -> "+toHexString(newParentWindowHandle)+" - Trying recreation"); } - destroy(); + destroy(true); operation = ReparentOperation.ACTION_NATIVE_CREATION ; } } |