diff options
author | Sven Gothel <[email protected]> | 2014-09-13 15:27:43 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-09-13 15:27:43 +0200 |
commit | 424066616b085b36d88a39d56a618ea57cebc9e9 (patch) | |
tree | 18ab7d68f6eb681fd1ace15807a66bf04155cda1 /src/jogl | |
parent | 6363fccee219ce238b0b2ded39c116e2bc8613d5 (diff) |
AnimatorBase.finishLifecycleAction(): Non blocking call shall return true, success - otherwise pause()/.. return value is inconsistent.
Caller of e.g. pause() running on the anim-thread or AWT-EDT (AWTAnimatorImpl)
will be non-blocking.
Before this change, a non-blocking simply did not wait until the 'hold' condition is reached
and returned its negated value.
This ofc is 'false', indicated unsuccessful operation.
Caller use the return value to determine whether the call actually paused (or ..)
the animator. Despite the non-blocking nature, the pause state was set, even if not reached.
Hence a resume() would be required to continue operation after a temporary pause.
+++
This change ignores the non-blocking nature's unmet condition.
finishLifecycleAction() returns !nok || !blocking,
i.e. either true for the reached condition (blocking) or true if non-blocking.
Blocking calls with unmet condition still return false.
+++
In case an animated GLAutoDrawableis being pulled after a non-blocking animator pause() call,
the GLAutoDrawable's implementation thread-safety must ensure proper operation.
+++
Diffstat (limited to 'src/jogl')
3 files changed, 19 insertions, 14 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/Animator.java b/src/jogl/classes/com/jogamp/opengl/util/Animator.java index d9a957199..4d61adaa6 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/Animator.java +++ b/src/jogl/classes/com/jogamp/opengl/util/Animator.java @@ -62,7 +62,7 @@ public class Animator extends AnimatorBase { private Runnable runnable; private boolean runAsFastAsPossible; protected boolean isAnimating; - protected boolean pauseIssued; + protected volatile boolean pauseIssued; protected volatile boolean stopIssued; /** @@ -149,7 +149,7 @@ public class Animator extends AnimatorBase { synchronized (Animator.this) { // Pause; Also don't consume CPU unless there is work to be done and not paused boolean ectCleared = false; - while (!stopIssued && (pauseIssued || drawablesEmpty)) { + while ( !stopIssued && ( pauseIssued || drawablesEmpty ) ) { if( drawablesEmpty ) { pauseIssued = true; } @@ -193,7 +193,7 @@ public class Animator extends AnimatorBase { Animator.this.notifyAll(); } } // sync Animator.this - if (!stopIssued) { + if ( !pauseIssued && !stopIssued ) { try { display(); } catch (final UncaughtAnimatorException dre) { @@ -202,10 +202,10 @@ public class Animator extends AnimatorBase { isAnimating = false; break; // end animation loop } - } - if (!stopIssued && !runAsFastAsPossible) { - // Avoid swamping the CPU - Thread.yield(); + if ( !runAsFastAsPossible ) { + // Avoid swamping the CPU + Thread.yield(); + } } } } catch( final ThreadDeath td) { diff --git a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java index 8b4e125fc..539d81beb 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java +++ b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java @@ -85,8 +85,8 @@ public abstract class AnimatorBase implements GLAnimatorControl { * @param printExceptions * @throws UncaughtAnimatorException as caused by {@link GLAutoDrawable#display()} */ - void display(ArrayList<GLAutoDrawable> drawables, boolean ignoreExceptions, boolean printExceptions) throws UncaughtAnimatorException; - boolean blockUntilDone(Thread thread); + void display(final ArrayList<GLAutoDrawable> drawables, final boolean ignoreExceptions, final boolean printExceptions) throws UncaughtAnimatorException; + boolean blockUntilDone(final Thread thread); } protected int modeBits; @@ -559,7 +559,8 @@ public abstract class AnimatorBase implements GLAnimatorControl { * @param waitCondition method will wait until TO is reached or {@link Condition#eval() waitCondition.eval()} returns <code>false</code>. * @param pollPeriod if <code>0</code>, method will wait until TO is reached or being notified. * if > <code>0</code>, method will wait for the given <code>pollPeriod</code> in milliseconds. - * @return <code>true</code> if {@link Condition#eval() waitCondition.eval()} returned <code>false</code>, otherwise <code>false</code>. + * @return <code>true</code> if {@link Condition#eval() waitCondition.eval()} returned <code>false</code> + * or if {@link AnimatorImpl#blockUntilDone(Thread) non-blocking}. Otherwise returns <code>false</code>. */ protected final synchronized boolean finishLifecycleAction(final Condition waitCondition, long pollPeriod) { /** @@ -572,6 +573,7 @@ public abstract class AnimatorBase implements GLAnimatorControl { final boolean blocking; long remaining; boolean nok; + if( impl.blockUntilDone(animThread) ) { blocking = true; remaining = TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION; @@ -605,12 +607,13 @@ public abstract class AnimatorBase implements GLAnimatorControl { nok = waitCondition.eval(); } } + final boolean res = !nok || !blocking; if(DEBUG || blocking && nok) { // Info only if DEBUG or ( blocking && not-ok ) ; !blocking possible if AWT if( blocking && remaining<=0 && nok ) { System.err.println("finishLifecycleAction(" + waitCondition.getClass().getName() + "): ++++++ timeout reached ++++++ " + getThreadName()); } System.err.println("finishLifecycleAction(" + waitCondition.getClass().getName() + "): OK "+(!nok)+ - "- pollPeriod "+pollPeriod+", blocking "+blocking+ + "- pollPeriod "+pollPeriod+", blocking "+blocking+" -> res "+res+ ", waited " + (blocking ? ( TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION - remaining ) : 0 ) + "/" + TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION + " - " + getThreadName()); System.err.println(" - "+toString()); @@ -618,7 +621,7 @@ public abstract class AnimatorBase implements GLAnimatorControl { Thread.dumpStack(); } } - return !nok; + return res; } @Override diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index 78310c654..3b24cc2af 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -471,10 +471,12 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing } if (backend != null && backend.getContext() != null) { - boolean animatorPaused = false; + final boolean animatorPaused; final GLAnimatorControl animator = getAnimator(); if(null!=animator) { animatorPaused = animator.pause(); + } else { + animatorPaused = false; } if(backend.getContext().isCreated()) { @@ -486,7 +488,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing isInitialized = false; } - if(animatorPaused) { + if( animatorPaused ) { animator.resume(); } } |