From a3cb6bb14f410f67fccf5ccd4cd7ecc66f448389 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 5 Oct 2012 06:31:08 +0200 Subject: Fix Bug 572 (2nd time): GLCanvas.validateGLDrawable() @ display() and reshape() ; GLCanvas.reshape() only if drawble valid ; GLCanvas.validateGLDrawable() also test isDisplayable() ; Fix size validation ; resizeOffscreenDrawable(..) don't validate 'safe' size 1x1 - GLCanvas.validateGLDrawable() @ display() and reshape() To help users using GLCanvas w/ having a realized GLCanvas/Drawable, validateGLDrawable() is also called at reshape(). This shall ensure a valid drawable after even a non AWT-EDT issued first setVisible(). - GLCanvas.reshape() only if drawble valid Otherwise offscreen reshape attempts would happen even on unrealized drawable, which is not necessary. - GLCanvas.validateGLDrawable() also test isDisplayable() To make sure the native peer is valid, also test isDisplayable() - Fix size validation Since we have experienced odd size like 0 x -41 test each component, i.e. 0 < width && 0 < height. This is done through all JOGL/NEWT components. - resizeOffscreenDrawable(..) don't validate 'safe' size 1x1 In case method is called w/ odd size, i.e. 0 x -41, the safe size 1x1 is used. However, we cannot validate this size. Dump WARNING if odd size is detected. --- .../classes/javax/media/opengl/awt/GLCanvas.java | 60 +++++++++++----------- 1 file changed, 31 insertions(+), 29 deletions(-) (limited to 'src/jogl/classes/javax/media/opengl/awt') diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 335322be9..4bdae7135 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -440,6 +440,12 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing @Override public void display() { + if( !validateGLDrawable() ) { + if(DEBUG) { + System.err.println(getThreadName()+": Info: GLCanvas display - skipped GL render, drawable not valid yet"); + } + return; // not yet available .. + } Threading.invoke(true, displayOnEDTAction, getTreeLock()); awtWindowClosingProtocol.addClosingListenerOneShot(); } @@ -489,7 +495,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing (int) ((getHeight() + bounds.getHeight()) / 2)); return; } - if( ! this.helper.isAnimatorAnimating() ) { + if( ! this.helper.isExternalAnimatorAnimating() ) { display(); } } @@ -570,30 +576,29 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing if( _drawable.isRealized() ) { return true; } - if (!Beans.isDesignTime() && - 0 < _drawable.getWidth() * _drawable.getHeight() ) { - // make sure drawable realization happens on AWT EDT, due to AWTTree lock - AWTEDTExecutor.singleton.invoke(getTreeLock(), true, setRealizedOnEDTAction); - if( _drawable.isRealized() ) { - sendReshape=true; // ensure a reshape is being send .. - if(DEBUG) { - System.err.println(getThreadName()+": Realized Drawable: "+_drawable.toString()); - Thread.dumpStack(); + final RecursiveLock _lock = lock; + _lock.lock(); + try { + if (!Beans.isDesignTime() && isDisplayable() && + 0 < _drawable.getWidth() && 0 < _drawable.getHeight() ) { + // make sure drawable realization happens on AWT EDT, due to AWTTree lock + AWTEDTExecutor.singleton.invoke(getTreeLock(), true, setRealizedOnEDTAction); + if( _drawable.isRealized() ) { + sendReshape=true; // ensure a reshape is being send .. + if(DEBUG) { + System.err.println(getThreadName()+": Realized Drawable: "+_drawable.toString()); + Thread.dumpStack(); + } + return true; } - return true; } + } finally { + _lock.unlock(); } } return false; } - private Runnable setRealizedOnEDTAction = new Runnable() { - @Override - public void run() { - final GLDrawable _drawable = drawable; - if ( null != _drawable && 0 < _drawable.getWidth() * _drawable.getHeight() ) { - _drawable.setRealized(true); - } - } }; + private Runnable setRealizedOnEDTAction = new Runnable() { public void run() { drawable.setRealized(true); } }; /**

Overridden to track when this component is removed from a container. Subclasses which override this method must call @@ -640,11 +645,12 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing synchronized (getTreeLock()) { // super.reshape(..) claims tree lock, so we do extend it's lock over reshape super.reshape(x, y, width, height); - GLDrawableImpl _drawable = drawable; - if( null != _drawable ) { - if(DEBUG) { - System.err.println("GLCanvas.sizeChanged: ("+Thread.currentThread().getName()+"): "+width+"x"+height+" - surfaceHandle 0x"+Long.toHexString(getNativeSurface().getSurfaceHandle())); - } + if(DEBUG) { + System.err.println("GLCanvas.sizeChanged: ("+Thread.currentThread().getName()+"): "+width+"x"+height+" - surfaceHandle 0x"+Long.toHexString(getNativeSurface().getSurfaceHandle())); + // Thread.dumpStack(); + } + if( validateGLDrawable() ) { + final GLDrawableImpl _drawable = drawable; if( ! _drawable.getChosenGLCapabilities().isOnscreen() ) { final RecursiveLock _lock = lock; _lock.lock(); @@ -984,11 +990,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing final RecursiveLock _lock = lock; _lock.lock(); try { - if( validateGLDrawable() ) { - helper.invokeGL(drawable, context, displayAction, initAction); - } else if(DEBUG) { - System.err.println(getThreadName()+": Info: GLCanvas display - skipped GL render, drawable not valid yet"); - } + helper.invokeGL(drawable, context, displayAction, initAction); } finally { _lock.unlock(); } -- cgit v1.2.3