diff options
Diffstat (limited to 'src/jogl/classes')
4 files changed, 22 insertions, 21 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java b/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java index 93b75e70b..26d299663 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/util/AWTAnimatorImpl.java @@ -164,7 +164,7 @@ class AWTAnimatorImpl implements AnimatorBase.AnimatorImpl { } }; - public boolean skipWaitForCompletion(Thread thread) { - return ((Thread.currentThread() == thread) || EventQueue.isDispatchThread()); + public boolean blockUntilDone(Thread thread) { + return ((Thread.currentThread() != thread) && !EventQueue.isDispatchThread()); } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/Animator.java b/src/jogl/classes/com/jogamp/opengl/util/Animator.java index 47f0ea586..a9023886d 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/Animator.java +++ b/src/jogl/classes/com/jogamp/opengl/util/Animator.java @@ -59,8 +59,8 @@ import javax.media.opengl.GLAutoDrawable; */ public class Animator extends AnimatorBase { - /** timeout in milliseconds, 20 frames @ 60Hz, limiting {@link #finishLifecycleAction(Condition)} */ - private static long TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION = 20*16; + /** timeout in milliseconds, 15 frames @ 60Hz = 240ms, limiting {@link #finishLifecycleAction(Condition)} */ + private static final long TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION = 15*16; protected ThreadGroup threadGroup; private Runnable runnable; @@ -243,21 +243,22 @@ public class Animator extends AnimatorBase { // dependencies on the Animator's internal thread. Currently we // use a couple of heuristics to determine whether we should do // the blocking wait(). - boolean to = false; - boolean doWait = !impl.skipWaitForCompletion(animThread); - if (doWait) { - while (!to && condition.result()) { - long td = System.currentTimeMillis(); - try { - wait(TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION); - } catch (InterruptedException ie) { } - to = (System.currentTimeMillis() - td) >= TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION; - } + long remaining = impl.blockUntilDone(animThread) ? TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION : 0; + while (remaining>0 && condition.result()) { + long td = System.currentTimeMillis(); + try { + wait(remaining); + } catch (InterruptedException ie) { } + remaining -= (System.currentTimeMillis() - td) ; } if(DEBUG) { - System.err.println("finishLifecycleAction(" + condition.getClass().getName() + "): finished - waited " + doWait + + if(remaining<0) { + System.err.println("finishLifecycleAction(" + condition.getClass().getName() + "): ++++++ timeout reached ++++++ "); + } + System.err.println("finishLifecycleAction(" + condition.getClass().getName() + "): finished "+ + "- waited " + (TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION-remaining) + "/" + TO_WAIT_FOR_FINISH_LIFECYCLE_ACTION + ", started: " + isStartedImpl() +", animating: " + isAnimatingImpl() + - ", paused: " + isPausedImpl() + ", drawables " + drawables.size() + ", timedout "+to); + ", paused: " + isPausedImpl() + ", drawables " + drawables.size()); } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java index e84a9bf78..9bea27f45 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java +++ b/src/jogl/classes/com/jogamp/opengl/util/AnimatorBase.java @@ -56,7 +56,7 @@ public abstract class AnimatorBase implements GLAnimatorControl { public interface AnimatorImpl { void display(ArrayList<GLAutoDrawable> drawables, boolean ignoreExceptions, boolean printExceptions); - boolean skipWaitForCompletion(Thread thread); + boolean blockUntilDone(Thread thread); } protected ArrayList<GLAutoDrawable> drawables = new ArrayList<GLAutoDrawable>(); @@ -101,7 +101,7 @@ public abstract class AnimatorBase implements GLAnimatorControl { if(paused) { resume(); } - if(!impl.skipWaitForCompletion(animThread)) { + if(impl.blockUntilDone(animThread)) { while(isStarted() && !isPaused() && !isAnimating()) { try { wait(); @@ -123,7 +123,7 @@ public abstract class AnimatorBase implements GLAnimatorControl { if(paused) { resume(); } - if(!impl.skipWaitForCompletion(animThread)) { + if(impl.blockUntilDone(animThread)) { while(isStarted() && drawablesEmpty && isAnimating()) { try { wait(); diff --git a/src/jogl/classes/com/jogamp/opengl/util/DefaultAnimatorImpl.java b/src/jogl/classes/com/jogamp/opengl/util/DefaultAnimatorImpl.java index bad268f70..23b0845ee 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/DefaultAnimatorImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/util/DefaultAnimatorImpl.java @@ -60,7 +60,7 @@ class DefaultAnimatorImpl implements AnimatorBase.AnimatorImpl { } } - public boolean skipWaitForCompletion(Thread thread) { - return (Thread.currentThread() == thread); + public boolean blockUntilDone(Thread thread) { + return (Thread.currentThread() != thread); } } |