summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-09-13 15:27:43 +0200
committerSven Gothel <[email protected]>2014-09-14 01:20:24 +0200
commit6119c8adbb8f2f8acda470ef82b5032342c8f142 (patch)
tree026e23eb933914f930868ba6a5ea0fabeee61a28 /src/jogl/classes/com/jogamp/opengl/util
parentec60c85314927adaacd57a56c7cfdd74c2634ce3 (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/classes/com/jogamp/opengl/util')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/Animator.java14
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java13
2 files changed, 15 insertions, 12 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 &gt; <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