diff options
author | Sven Gothel <[email protected]> | 2010-11-22 12:46:19 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-11-22 12:46:19 +0100 |
commit | 4c3e9e258fae1161949dd14828c09f387bfd53d9 (patch) | |
tree | a8b287153f6afbf166db85506af4c3790590663d /src | |
parent | 6a3ccca96e6d4c27c372b4b9ba1e8fcee6def402 (diff) |
GLAnimatorControl pause()/resume() don't fail fast, return a boolean instead to simplify usage.
Diffstat (limited to 'src')
7 files changed, 34 insertions, 32 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/Animator.java b/src/jogl/classes/com/jogamp/opengl/util/Animator.java index 2d4727bba..31abe099d 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/Animator.java +++ b/src/jogl/classes/com/jogamp/opengl/util/Animator.java @@ -294,9 +294,9 @@ public class Animator extends AnimatorBase { } Condition waitForStoppedCondition = new WaitForStoppedCondition(); - public synchronized void pause() { + public synchronized boolean pause() { if ( !isStartedImpl() || pauseIssued ) { - throw new GLException("Pause: Invalid state (started "+isStartedImpl()+" (true), paused "+pauseIssued+" (false) )"); + return false; } stateSync.lock(); try { @@ -306,6 +306,7 @@ public class Animator extends AnimatorBase { } notifyAll(); finishLifecycleAction(waitForPausedCondition); + return true; } private class WaitForPausedCondition implements Condition { public boolean result() { @@ -315,9 +316,9 @@ public class Animator extends AnimatorBase { } Condition waitForPausedCondition = new WaitForPausedCondition(); - public synchronized void resume() { + public synchronized boolean resume() { if ( !isStartedImpl() || !pauseIssued ) { - throw new GLException("Resume: Invalid state (started "+isStartedImpl()+" (true), paused "+pauseIssued+" (true) )"); + return false; } stateSync.lock(); try { @@ -327,6 +328,7 @@ public class Animator extends AnimatorBase { } notifyAll(); finishLifecycleAction(waitForResumeCondition); + return true; } private class WaitForResumeCondition implements Condition { public boolean result() { diff --git a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java index 447c72709..6bac1646b 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java +++ b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java @@ -170,9 +170,9 @@ public class FPSAnimator extends AnimatorBase { } } - public synchronized void pause() { + public synchronized boolean pause() { if (timer == null) { - throw new GLException("Not running"); + return false; } stateSync.lock(); try { @@ -183,17 +183,19 @@ public class FPSAnimator extends AnimatorBase { } finally { stateSync.unlock(); } + return true; } - public synchronized void resume() { + public synchronized boolean resume() { if (timer == null) { - throw new GLException("Not running"); + return false; } stateSync.lock(); try { startTask(); } finally { stateSync.unlock(); - } + } + return true; } } diff --git a/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java b/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java index 98d7bc48b..0282b3ad0 100644 --- a/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java +++ b/src/jogl/classes/javax/media/opengl/GLAnimatorControl.java @@ -32,8 +32,8 @@ package javax.media.opengl; * An animator control interface, * which implementation may drive a {@link javax.media.opengl.GLAutoDrawable} animation. * <P> - * Note that the methods {@link #start()}, {@link #stop()}, {@link #pause()} and {@link #resume()} - * shall be implemented to fail-fast, ie {@link #start()} fails if not started, etc. + * Note that the methods {@link #start()} and {@link #stop()} + * shall be implemented fail-fast, ie {@link #start()} fails if not started, etc. * This way an implementation can find implementation errors faster. */ public interface GLAnimatorControl { @@ -157,11 +157,12 @@ public interface GLAnimatorControl { * or in some cases from an implementation-internal thread like the * AWT event queue thread. * + * @return false if if not started or already paused, otherwise true + * * @see #resume() * @see #isAnimating() - * @throws GLException if not started or already paused */ - void pause(); + boolean pause(); /** * Resumes animation if paused. @@ -173,11 +174,12 @@ public interface GLAnimatorControl { * <P> * If resumed, all counters (time, frames, ..) are reset to zero. * + * @return false if if not started or not paused, otherwise true + * * @see #pause() * @see #isAnimating() - * @throws GLException if not started or not paused */ - void resume(); + boolean resume(); /** * Removes a drawable from the animator's list of rendering drawables.<br> diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 265c7ff49..b2d919eaf 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -351,10 +351,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { GLAnimatorControl animator = getAnimator(); if(null!=animator) { if(regenerate) { - if(animator.isStarted() && !animator.isPaused()) { - animator.pause(); - animatorPaused = true; - } + animatorPaused = animator.pause(); } else { animator.remove(this); } diff --git a/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java b/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java index a019de72d..34e4f6430 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java +++ b/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java @@ -258,12 +258,12 @@ public class TestGLWindows02NEWTAnimated extends UITestCase { Assert.assertEquals(true, animator.isAnimating()); Assert.assertEquals(false, animator.isPaused()); - animator.pause(); + Assert.assertEquals(true, animator.pause()); Assert.assertEquals(true, animator.isStarted()); Assert.assertEquals(false, animator.isAnimating()); Assert.assertEquals(true, animator.isPaused()); - animator.resume(); + Assert.assertEquals(true, animator.resume()); Assert.assertEquals(true, animator.isStarted()); Assert.assertEquals(true, animator.isAnimating()); Assert.assertEquals(false, animator.isPaused()); diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java index 97589ed3a..21c0a479c 100644 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java @@ -171,22 +171,22 @@ public class TestParenting01NEWT extends UITestCase { Assert.assertTrue(0 < glWindow1.getTotalFrames()); Assert.assertTrue(0 < glWindow2.getTotalFrames()); - animator1.pause(); + Assert.assertEquals(true, animator1.pause()); Assert.assertEquals(false, animator1.isAnimating()); Assert.assertEquals(true, animator1.isPaused()); Assert.assertNotNull(animator1.getThread()); - animator2.pause(); + Assert.assertEquals(true, animator2.pause()); Assert.assertEquals(false, animator2.isAnimating()); Assert.assertEquals(true, animator2.isPaused()); Assert.assertNotNull(animator2.getThread()); glWindow1.resetCounter(); glWindow2.resetCounter(); - animator1.resume(); + Assert.assertEquals(true, animator1.resume()); Assert.assertEquals(true, animator1.isAnimating()); Assert.assertEquals(false, animator1.isPaused()); Assert.assertNotNull(animator1.getThread()); - animator2.resume(); + Assert.assertEquals(true, animator2.resume()); Assert.assertEquals(true, animator2.isAnimating()); Assert.assertEquals(false, animator2.isPaused()); Assert.assertNotNull(animator2.getThread()); diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index da22a6217..0f96facbd 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -89,11 +89,11 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { if (GLWindow.this.helper.isExternalAnimatorRunning()) { // Pause animations before initiating safe destroy. GLAnimatorControl ctrl = GLWindow.this.helper.getAnimator(); - ctrl.pause(); - + boolean isPaused = ctrl.pause(); destroy(); - - ctrl.resume(); + if(isPaused) { + ctrl.resume(); + } } else if (GLWindow.this.window.isSurfaceLockedByOtherThread()) { // Surface is locked by another thread // Flag that destroy should be performed on the next @@ -386,9 +386,8 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { public synchronized boolean pauseRenderingAction() { boolean animatorPaused = false; GLAnimatorControl ctrl = GLWindow.this.getAnimator(); - if ( null!=ctrl && ctrl.isStarted() && !ctrl.isPaused()) { - animatorPaused = true; - ctrl.pause(); + if ( null!=ctrl ) { + animatorPaused = ctrl.pause(); } return animatorPaused; } |