diff options
author | Sven Gothel <[email protected]> | 2012-07-04 18:02:11 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-07-04 18:02:11 +0200 |
commit | 9b35c57425b0a5f6b789b9b43a62a8b64be51d86 (patch) | |
tree | 04a4e082e00fd4d313346aa8dfc2ce4e5d3ab145 /src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java | |
parent | eed8508ae1132e5f45f788e9cb3f3d5a1050ac70 (diff) |
GLAutoDrawable* refinement of abstraction / generalization - API Change!
- GLAutoDrawable (compat change - recompile):
- 'void invoke(boolean wait, GLRunnable glRunnable)' -> 'boolean invoke(boolean wait, GLRunnable glRunnable)'
Allows notifying caller whether the task has been executed or at least enqueued.
- GLAutoDrawable add 'GLEventListener removeGLEventListener(int index)'
- This allow one to remove a specific GLEventListener and reusing it (return value).
- GLDrawableImpl remove 'destroy()' to favor 'setRealized(false)'
- Using more common code of GLAutoDrawableBase, i.e. GLPbufferImpl can use defaultDestroyOp().
- Removes redundancy of methods
- GLAutoDrawableBase/Delegate
- better 'default' names to emphasize it's purpose, adding API doc
- includes more generic functionality
- defaultWindowDestroyNotify()
- defaultDestroyOp()
- TestGLAutoDrawableDelegateNEWT demonstrates a simple example w/ all window events handled.
- Fix TestParenting01cSwingAWT's threading use (gl disturbance thread)
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java')
-rw-r--r-- | src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java | 83 |
1 files changed, 74 insertions, 9 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java b/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java index 3f50fe420..5c6d7446a 100644 --- a/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java +++ b/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java @@ -31,6 +31,8 @@ package jogamp.opengl; import java.io.PrintStream; import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.WindowClosingProtocol; +import javax.media.nativewindow.WindowClosingProtocol.WindowClosingMode; import javax.media.opengl.FPSCounter; import javax.media.opengl.GL; import javax.media.opengl.GLAnimatorControl; @@ -76,7 +78,8 @@ public abstract class GLAutoDrawableBase implements GLAutoDrawable, FPSCounter { /** Returns the delegated GLDrawable */ public final GLDrawable getDelegatedDrawable() { return drawable; } - protected void defaultRepaintOp() { + /** Default implementation to handle repaint events from the windowing system */ + protected void defaultWindowRepaintOp() { if( null != drawable && drawable.isRealized() ) { if( !drawable.getNativeSurface().isSurfaceLockedByOtherThread() && !helper.isAnimatorAnimating() ) { display(); @@ -84,16 +87,74 @@ public abstract class GLAutoDrawableBase implements GLAutoDrawable, FPSCounter { } } - protected void defaultReshapeOp() { + /** Default implementation to handle resize events from the windowing system */ + protected void defaultWindowResizedOp() { if( null!=drawable ) { if(DEBUG) { System.err.println("GLAutoDrawableBase.sizeChanged: ("+Thread.currentThread().getName()+"): "+getWidth()+"x"+getHeight()+" - surfaceHandle 0x"+Long.toHexString(getNativeSurface().getSurfaceHandle())); } sendReshape = true; - defaultRepaintOp(); + defaultWindowRepaintOp(); } } - + + /** Default implementation to handle destroy notifications from the windowing system */ + protected void defaultWindowDestroyNotifyOp() { + final NativeSurface ns = getNativeSurface(); + final boolean shallClose; + if(ns instanceof WindowClosingProtocol) { + shallClose = WindowClosingMode.DISPOSE_ON_CLOSE == ((WindowClosingProtocol)ns).getDefaultCloseOperation(); + } else { + shallClose = true; + } + if( shallClose ) { + // Is an animator thread perform rendering? + if (helper.isExternalAnimatorRunning()) { + // Pause animations before initiating safe destroy. + final GLAnimatorControl ctrl = helper.getAnimator(); + final boolean isPaused = ctrl.pause(); + destroy(); + if(isPaused) { + ctrl.resume(); + } + } else if (null != ns && ns.isSurfaceLockedByOtherThread()) { + // surface is locked by another thread + // Flag that destroy should be performed on the next + // attempt to display. + sendDestroy = true; + } else { + // Without an external thread animating or locking the + // surface, we are safe. + destroy (); + } + } + } + + /** + * Default implementation to destroys the drawable and context of this GLAutoDrawable: + * <ul> + * <li>issues the GLEventListener dispose call, if drawable and context are valid</li> + * <li>destroys the GLContext, if valid</li> + * <li>destroys the GLDrawable, if valid</li> + * </ul> + */ + protected void defaultDestroyOp() { + if( null != drawable && drawable.isRealized() ) { + if( null != context && context.isCreated() ) { + // Catch dispose GLExceptions by GLEventListener, just 'print' them + // so we can continue with the destruction. + try { + helper.disposeGL(this, drawable, context, null); + } catch (GLException gle) { + gle.printStackTrace(); + } + } + drawable.setRealized(false); + } + context = null; + drawable = null; + } + // // GLAutoDrawable // @@ -157,8 +218,7 @@ public abstract class GLAutoDrawableBase implements GLAutoDrawable, FPSCounter { } @Override - public final void addGLEventListener(int index, GLEventListener listener) - throws IndexOutOfBoundsException { + public final void addGLEventListener(int index, GLEventListener listener) throws IndexOutOfBoundsException { helper.addGLEventListener(index, listener); } @@ -166,7 +226,12 @@ public abstract class GLAutoDrawableBase implements GLAutoDrawable, FPSCounter { public final void removeGLEventListener(GLEventListener listener) { helper.removeGLEventListener(listener); } - + + @Override + public GLEventListener removeGLEventListener(int index) throws IndexOutOfBoundsException { + return helper.removeGLEventListener(index); + } + @Override public final void setAnimator(GLAnimatorControl animatorControl) throws GLException { @@ -179,8 +244,8 @@ public abstract class GLAutoDrawableBase implements GLAutoDrawable, FPSCounter { } @Override - public final void invoke(boolean wait, GLRunnable glRunnable) { - helper.invoke(this, wait, glRunnable); + public final boolean invoke(boolean wait, GLRunnable glRunnable) { + return helper.invoke(this, wait, glRunnable); } @Override |