From 28b0df6c300494a2b54c07fdf43ef04f5f1b0073 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 8 Sep 2011 03:43:54 +0200 Subject: Destruction of GLAutoDrawable shall not remove them from AnimatorControl (due to recreation) ; NEWT/Window: Remove isValid() API entry - always true! Destruction of GLAutoDrawable shall not remove them from AnimatorControl (due to recreation) - Completes commit b65e1e76d413b70e5593173e6bd36d30675554a6 - WindowImpl: - volatile: windowHandle/visible fields (memeory sync critical) - destroy must set visible := false, to avoid immediate recreation via a display call of another thread, ie an animator. NEWT/Window: Remove isValid() API entry - always true! - NEWT/Window's can always be recreated. - redundancy in API is even worse than redundancy in impl. :) --- src/newt/classes/com/jogamp/newt/Window.java | 12 +-- .../classes/com/jogamp/newt/awt/NewtCanvasAWT.java | 8 +- .../classes/com/jogamp/newt/opengl/GLWindow.java | 28 ++---- src/newt/classes/jogamp/newt/OffscreenWindow.java | 2 +- src/newt/classes/jogamp/newt/WindowImpl.java | 107 ++++++++------------- .../newt/awt/event/AWTParentWindowAdapter.java | 42 ++++---- 6 files changed, 72 insertions(+), 127 deletions(-) (limited to 'src/newt/classes') diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index ac8311a9a..84f2f0294 100644 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -54,18 +54,9 @@ public interface Window extends NativeWindow, WindowClosingProtocol { // Lifecycle // - /** - * @return True if native window is valid, can be created or recovered. - * Otherwise false, ie this window is unrecoverable due to a destroy(true) call. - * - * @see #destroy(boolean) - * @see #setVisible(boolean) - */ - boolean isValid(); - /** * @return true if the native window handle is valid and ready to operate, ie - * if the native window has been created, otherwise false. + * if the native window has been created via {@link #setVisible(boolean) setVisible(true)}, otherwise false. * * @see #setVisible(boolean) * @see #destroy(boolean) @@ -102,6 +93,7 @@ public interface Window extends NativeWindow, WindowClosingProtocol { /** * Destroy the Window and it's children, incl. native destruction.
* The Window can be recreate via {@link #setVisible(boolean) setVisible(true)}. + *

Visibility is set to false.

*

* This method invokes {@link Screen#removeReference()} after it's own destruction,
* which will issue {@link Screen#destroy()} if the reference count becomes 0.
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index 5c242d0e7..51a43d86c 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -159,16 +159,12 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto if( null != newtChild ) { if(attach) { awtAdapter = new AWTParentWindowAdapter(newtChild).addTo(this); - if(newtChild.isValid()) { - newtChild.addWindowListener(clearAWTMenusOnNewtFocus); - } + newtChild.addWindowListener(clearAWTMenusOnNewtFocus); newtChild.setFocusAction(focusAction); // enable AWT focus traversal newtChildCloseOp = newtChild.setDefaultCloseOperation(WindowClosingProtocol.DO_NOTHING_ON_CLOSE); awtWindowClosingProtocol.addClosingListenerOneShot(); } else { - if(newtChild.isValid()) { - newtChild.removeWindowListener(clearAWTMenusOnNewtFocus); - } + newtChild.removeWindowListener(clearAWTMenusOnNewtFocus); newtChild.setFocusAction(null); newtChild.setDefaultCloseOperation(newtChildCloseOp); awtWindowClosingProtocol.removeClosingListener(); diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 638e4a462..bde4373d1 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -66,7 +66,7 @@ import com.jogamp.opengl.JoglVersion; *

*/ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer, FPSCounter { - private WindowImpl window; + private final WindowImpl window; /** * Constructor. Do not call this directly -- use {@link #create()} instead. @@ -298,10 +298,6 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer, FPSC window.setTopLevelSize(width, height); } - public final boolean isValid() { - return window.isValid(); - } - public final boolean isNativeValid() { return window.isNativeValid(); } @@ -511,28 +507,20 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer, FPSC } public void display() { - display(false); - } - - public void display(boolean forceReshape) { - if( null == window ) { return; } - - if(sendDestroy || ( null!=window && window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED ) ) { + if( !isNativeValid() || !isVisible() ) { return; } + + if(sendDestroy || ( window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED ) ) { sendDestroy=false; destroy(); return; } - - if( null == context && isVisible() && 0 default - protected boolean fullscreen = false, visible = false, hasFocus = false; + protected boolean fullscreen = false, hasFocus = false; protected int width = 128, height = 128, x = 0, y = 0; // client-area size/pos w/o insets protected Insets insets = new Insets(); // insets of decoration (if top-level && decorated) @@ -272,7 +274,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer setTitleImpl(title); } // always flag visible, - // allowing to retry if visible && 0 == windowHandle + // allowing to retry if visible && !isNativeValid() setVisibleImpl(true, x, y, width, height); } } finally { @@ -283,7 +285,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer if(DEBUG_IMPLEMENTATION) { System.err.println("Window.createNative() END ("+getThreadName()+", "+this+")"); } - return 0 != windowHandle ; + return isNativeValid() ; } private void removeScreenReference() { @@ -625,11 +627,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer // public final boolean isNativeValid() { - return null != getScreen() && 0 != getWindowHandle() ; - } - - public final boolean isValid() { - return null != getScreen() ; + return 0 != windowHandle ; } public final Screen getScreen() { @@ -656,7 +654,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } } - if(0==windowHandle && visible) { + if(!isNativeValid() && visible) { if( 00) { + if(isNativeValid() && visible && null!=childWindows && childWindows.size()>0) { synchronized(childWindowsLock) { for(int i = 0; i < childWindows.size(); i++ ) { NativeWindow nw = childWindows.get(i); @@ -710,19 +708,17 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } public void setVisible(boolean visible) { - if(isValid()) { - if( 0==windowHandle && visible && 0>=width*height ) { - // fast-path: not realized yet, make visible, but zero size - return; - } + if( !isNativeValid() && visible && 0>=width*height ) { + // fast-path: not realized yet, make visible, but zero size + return; + } - if(DEBUG_IMPLEMENTATION) { - String msg = "Window setVisible: START ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+this.visible+" -> "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentWindow "+(null!=parentWindow); - System.err.println(msg); - Thread.dumpStack(); - } - runOnEDTIfAvail(true, new VisibleAction(visible)); + if(DEBUG_IMPLEMENTATION) { + String msg = "Window setVisible: START ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+this.visible+" -> "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentWindow "+(null!=parentWindow); + System.err.println(msg); + Thread.dumpStack(); } + runOnEDTIfAvail(true, new VisibleAction(visible)); } protected final void setVisibleImpl(boolean visible, int x, int y, int width, int height) { @@ -745,15 +741,15 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer String msg = "Window setSize: START "+WindowImpl.this.width+"x"+WindowImpl.this.height+" -> "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible "+visible; System.err.println(msg); } - if ( 0 != windowHandle && 0>=width*height && visible ) { + if ( isNativeValid() && 0>=width*height && visible ) { visibleAction=1; // invisible WindowImpl.this.width = 0; WindowImpl.this.height = 0; - } else if ( 0 == windowHandle && 0