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. :) --- .../classes/javax/media/opengl/awt/GLJPanel.java | 2 - 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 ++++---- ...TestSwingAWTRobotUsageBeforeJOGLInitBug411.java | 14 ++- .../junit/newt/TestGLWindows02NEWTAnimated.java | 17 +++- .../junit/newt/TestWindowClosingProtocol01AWT.java | 2 + .../newt/TestWindowClosingProtocol03NewtAWT.java | 31 ++++-- 11 files changed, 121 insertions(+), 144 deletions(-) (limited to 'src') diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index 76d982813..92be62b4d 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -280,8 +280,6 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing if(null!=animator) { if(regenerate) { animatorPaused = animator.pause(); - } else { - animator.remove(this); } } 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 NOP / HIDE (default) @@ -78,6 +87,7 @@ public class TestWindowClosingProtocol03NewtAWT extends UITestCase { Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, false)); Assert.assertEquals(true, frame.isDisplayable()); + Assert.assertEquals(false, frame.isVisible()); Assert.assertEquals(true, newtCanvas.isValid()); Assert.assertEquals(true, newtCanvas.isDisplayable()); Assert.assertEquals(true, glWindow.isNativeValid()); @@ -88,8 +98,10 @@ public class TestWindowClosingProtocol03NewtAWT extends UITestCase { public void run() { frame.setVisible(true); } }); - Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); - + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true)); + Assert.assertEquals(true, frame.isDisplayable()); + Assert.assertEquals(true, frame.isVisible()); + // // close with op (JFrame): DISPOSE_ON_CLOSE -- newtCanvas -- glWindow --> dispose // @@ -100,6 +112,7 @@ public class TestWindowClosingProtocol03NewtAWT extends UITestCase { Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, true)); Assert.assertEquals(false, frame.isDisplayable()); + Assert.assertEquals(false, frame.isVisible()); Assert.assertEquals(false, newtCanvas.isValid()); Assert.assertEquals(false, newtCanvas.isDisplayable()); Assert.assertEquals(false, glWindow.isNativeValid()); -- cgit v1.2.3