aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-03-13 07:12:59 +0100
committerSven Gothel <[email protected]>2013-03-13 07:12:59 +0100
commite2506d7663b752f00f0a98f793ebad52e65bd1e3 (patch)
tree66e669f22824892aec2d157aca5c384f1bd348c4 /src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java
parentc225285e09f0a29fca418601bf1aa07cafb54339 (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/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java')
-rw-r--r--src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java b/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java
index ad67f8281..cab768e3a 100644
--- a/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java
+++ b/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java
@@ -68,6 +68,8 @@ public abstract class GLAutoDrawableBase implements GLAutoDrawable, FPSCounter {
protected volatile GLDrawableImpl drawable; // volatile: avoid locking for read-only access
protected GLContextImpl context;
+ protected boolean preserveGLELSAtDestroy;
+ protected GLEventListenerState glels;
protected final boolean ownsDevice;
protected int additionalCtxCreationFlags = 0;
protected volatile boolean sendReshape = false; // volatile: maybe written by WindowManager thread w/o locking
@@ -88,6 +90,8 @@ public abstract class GLAutoDrawableBase implements GLAutoDrawable, FPSCounter {
public GLAutoDrawableBase(GLDrawableImpl drawable, GLContextImpl context, boolean ownsDevice) {
this.drawable = drawable;
this.context = context;
+ this.preserveGLELSAtDestroy = false;
+ this.glels = null;
this.ownsDevice = ownsDevice;
if(null != context && null != drawable) {
context.setGLDrawable(drawable, false);
@@ -97,6 +101,54 @@ public abstract class GLAutoDrawableBase implements GLAutoDrawable, FPSCounter {
/** Returns the recursive lock object of the upstream implementation, which synchronizes multithreaded access. */
protected abstract RecursiveLock getLock();
+
+
+ /**
+ * If set to <code>true</code>, the next {@link #destroy()} operation will
+ * {@link #pullGLEventListenerState() pull} to preserve the {@link GLEventListenerState}.
+ */
+ public final void setPreserveGLStateAtDestroy(boolean value) {
+ preserveGLELSAtDestroy = value;
+ }
+
+ /**
+ * Pulls the {@link GLEventListenerState} from this {@link GLAutoDrawable}.
+ *
+ * @return <code>true</code> if the {@link GLEventListenerState} is pulled successfully from this {@link GLAutoDrawable},
+ * otherwise <code>false</code>.
+ *
+ * @throws IllegalStateException if the {@link GLEventListenerState} is already pulled
+ *
+ * @see #pushGLEventListenerState()
+ */
+ protected final boolean pullGLEventListenerState() throws IllegalStateException {
+ if( null != glels ) {
+ throw new IllegalStateException("GLEventListenerState already pulled");
+ }
+ if( null != context && context.isCreated() ) {
+ glels = GLEventListenerState.moveFrom(this);
+ return null != glels;
+ }
+ return false;
+ }
+
+ /**
+ * Pushes a previously {@link #pullGLEventListenerState() pulled} {@link GLEventListenerState} to this {@link GLAutoDrawable}.
+ *
+ * @return <code>true</code> if the {@link GLEventListenerState} was previously {@link #pullGLEventListenerState() pulled}
+ * and is pushed successfully to this {@link GLAutoDrawable},
+ * otherwise <code>false</code>.
+ *
+ * @see #pullGLEventListenerState()
+ */
+ protected final boolean pushGLEventListenerState() {
+ if( null != glels ) {
+ glels.moveTo(this);
+ glels = null;
+ return true;
+ }
+ return false;
+ }
/** Default implementation to handle repaint events from the windowing system */
protected final void defaultWindowRepaintOp() {
@@ -229,6 +281,10 @@ public abstract class GLAutoDrawableBase implements GLAutoDrawable, FPSCounter {
* In such case call <code>super.destroyImplInLock</code> first.</p>
*/
protected void destroyImplInLock() {
+ if( preserveGLELSAtDestroy ) {
+ preserveGLELSAtDestroy = false;
+ pullGLEventListenerState();
+ }
if( null != context ) {
if( context.isCreated() ) {
// Catch dispose GLExceptions by GLEventListener, just 'print' them