From 9b35c57425b0a5f6b789b9b43a62a8b64be51d86 Mon Sep 17 00:00:00 2001
From: Sven Gothel
* Since no native windowing system events are being processed, it is recommended
- * to handle at least {@link com.jogamp.newt.event.WindowListener#windowResized(com.jogamp.newt.event.WindowEvent) resize},
- * {@link com.jogamp.newt.event.WindowListener#windowDestroyNotify(com.jogamp.newt.event.WindowEvent) destroy-notify}
- * and maybe {@link com.jogamp.newt.event.WindowListener#windowRepaint(com.jogamp.newt.event.WindowUpdateEvent) repaint}.
- * The latter is only required if no {@link GLAnimatorControl} is being used.
- *
+ *
+ *
+ * See example {@link com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableDelegateNEWT TestGLAutoDrawableDelegateNEWT}. + *
*/ public class GLAutoDrawableDelegate extends GLAutoDrawableBase { public static final boolean DEBUG = Debug.debug("GLAutoDrawableDelegate"); @@ -52,36 +60,64 @@ public class GLAutoDrawableDelegate extends GLAutoDrawableBase { super((GLDrawableImpl)drawable, (GLContextImpl)context); } - public void defaultRepaintOp() { - super.defaultRepaintOp(); + // + // make protected methods accessible + // + + public void defaultWindowRepaintOp() { + super.defaultWindowRepaintOp(); + } + + public void defaultWindowResizedOp() { + super.defaultWindowResizedOp(); } - public void defaultReshapeOp() { - super.defaultReshapeOp(); + public void defaultWindowDestroyNotifyOp() { + super.defaultWindowDestroyNotifyOp(); } // // Complete GLAutoDrawable // + private RecursiveLock lock = LockFactory.createRecursiveLock(); // instance wide lock + /** * {@inheritDoc} *- * This implementation simply removes references to drawable and context. + * This implementation calls {@link #defaultDestroyOp()}. + *
+ *+ * User still needs to destroy the upstream window, which details are hidden from this aspect. *
*/ @Override public void destroy() { - drawable = null; - context = null; + lock.lock(); + try { + defaultDestroyOp(); + } finally { + lock.unlock(); + } } @Override public void display() { - if( null == drawable || !drawable.isRealized() || null == context ) { return; } - - // surface is locked/unlocked implicit by context's makeCurrent/release - helper.invokeGL(drawable, context, defaultDisplayAction, defaultInitAction); + if( sendDestroy ) { + sendDestroy=false; + destroy(); + return; + } + + lock.lock(); // sync: context/drawable could been recreated/destroyed while animating + try { + if( null != drawable && drawable.isRealized() && null != context ) { + // surface is locked/unlocked implicit by context's makeCurrent/release + helper.invokeGL(drawable, context, defaultDisplayAction, defaultInitAction); + } + } finally { + lock.unlock(); + } } // -- cgit v1.2.3