diff options
author | Sven Gothel <[email protected]> | 2010-11-21 03:41:22 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-11-21 03:41:22 +0100 |
commit | 2aa296771e3e8dd6cf027f27b0455d1803244bfe (patch) | |
tree | 514c532f9ddff7f84e9e6fb75e883f04c71ec74f /src/junit | |
parent | 6f73de7c5bb85d0175c8dda7c55317923017bbe0 (diff) |
JOGL/NEWT: Animator fixes
Consider use cases with many drawables and no drawables at start,
this had to be reflected all over this patch set, implementation,
usage and test cases.
- GLAnimatorControl
- refine API doc / states
- add 'void remove(GLAutoDrawable drawable);'
- Animator*:
- using RecursiveLock 'stateSync' for all actions out of the big synchronized (animator) block:
- get status methods (thread, isPaused, ..), hence no more synchronized
- display drawables change, utilizing synced ArrayList swap
This removes the need for volatiles usage shouldPause/shouldStop within the display method.
- added blocking wait for state change for add(GLAutoDrawable)/remove(GLAutoDrawable) method
- remove flawed double checked locking in anim thread (pause/idle condition)
- thread is now a daemon thread, hence it won't hinder the JVM from shutdown
-
- Animator use change:
- Always resume after pause, except in case of final destroy -> NEWT invalidate / GLCanvas,
this considers use cases with many drawables and no drawables at start.
- GLDrawableHelper: Don't pause at implicit dispose()
Diffstat (limited to 'src/junit')
4 files changed, 104 insertions, 54 deletions
diff --git a/src/junit/com/jogamp/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java b/src/junit/com/jogamp/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java index 8f56f6f46..fef0e5ad6 100644 --- a/src/junit/com/jogamp/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java +++ b/src/junit/com/jogamp/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java @@ -256,20 +256,25 @@ public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase { Screen screen = win0.getScreen(); win0.setPosition(screen.getWidth()-150, 0); win0.addGLEventListener(new Gears()); - Animator anim0 = new Animator(win0); - anim0.start(); + Animator anim = new Animator(win0); + anim.start(); GLWindow win1 = GLWindow.create(caps); NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(win1); - Animator anim1 = new Animator(win1); - anim1.start(); + anim.add(win1); runTestGL(newtCanvasAWT, win1); win0.destroy(); - Assert.assertEquals(false, anim0.isAnimating()); + Assert.assertEquals(true, anim.isAnimating()); newtCanvasAWT.destroy(); - Assert.assertEquals(false, anim1.isAnimating()); + + win0.invalidate(); + Assert.assertEquals(true, anim.isAnimating()); + win1.invalidate(); + Assert.assertEquals(false, anim.isAnimating()); + + anim.stop(); System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test01NewtCanvasAWT(): End"); } @@ -280,6 +285,9 @@ public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase { GLProfile glp = GLProfile.getDefault(); GLCapabilities caps = new GLCapabilities(glp); + Animator anim = new Animator(); + anim.start(); + /** * Using GLCanvas _and_ NEWT side by side currently causes a deadlock * in AWT with AMD drivers ! @@ -290,23 +298,18 @@ public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase { Screen screen = win0.getScreen(); win0.setPosition(screen.getWidth()-150, 0); win0.addGLEventListener(new Gears()); - Animator anim0 = new Animator(win0); - anim0.start(); + anim.add(win0); */ GLCanvas glCanvas = new GLCanvas(caps); - Animator anim1 = new Animator(glCanvas); - anim1.start(); + anim.add(glCanvas); runTestGL(glCanvas, glCanvas); - Thread.sleep(100); // wait 1/10Hz to allow animation to be paused - Assert.assertEquals(false, anim1.isAnimating()); - /** win0.destroy(); - Assert.assertEquals(false, anim0.isAnimating()); + Assert.assertEquals(true, anim.isAnimating()); */ - + anim.stop(); System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.test02GLCanvas(): End"); } diff --git a/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java b/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java index e79d57a4f..a019de72d 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java +++ b/src/junit/com/jogamp/test/junit/newt/TestGLWindows02NEWTAnimated.java @@ -28,19 +28,11 @@ package com.jogamp.test.junit.newt; -import java.lang.reflect.*; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; import org.junit.Assert; -import org.junit.Before; import org.junit.BeforeClass; -import org.junit.After; -import org.junit.AfterClass; import org.junit.Test; -import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.opengl.util.Animator; @@ -131,7 +123,8 @@ public class TestGLWindows02NEWTAnimated extends UITestCase { Thread.sleep(100); } destroyWindow(window); - Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(true, animator.isAnimating()); + animator.stop(); } @Test @@ -146,7 +139,8 @@ public class TestGLWindows02NEWTAnimated extends UITestCase { } destroyWindow(window); destroyWindow(window); - Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(true, animator.isAnimating()); + animator.stop(); } @Test @@ -167,20 +161,44 @@ public class TestGLWindows02NEWTAnimated extends UITestCase { Assert.assertNotNull(window2); window2.setPosition(screen.getWidth()-width, 0); - Animator animator1 = new Animator(window1); - animator1.start(); - Animator animator2 = new Animator(window2); - animator2.start(); - while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) { + Animator animator = new Animator(); + Assert.assertEquals(false, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + animator.start(); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + animator.add(window1); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + animator.add(window2); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + while(animator.isAnimating() && animator.getDuration()<durationPerTest) { Thread.sleep(100); } + window1.invalidate(); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); - destroyWindow(window1); - Assert.assertEquals(false, animator1.isAnimating()); - - destroyWindow(window2); - Assert.assertEquals(false, animator2.isAnimating()); + while(animator.isAnimating() && animator.getDuration()<2*durationPerTest) { + Thread.sleep(100); + } + window2.invalidate(); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + animator.stop(); } + @Test public void testWindowDecor03TwoWinTwoDisplays() throws InterruptedException { GLCapabilities caps = new GLCapabilities(glp); @@ -204,19 +222,56 @@ public class TestGLWindows02NEWTAnimated extends UITestCase { Assert.assertNotNull(window2); window2.setPosition(screen2.getWidth()-width, 0); - Animator animator1 = new Animator(window1); - animator1.start(); - Animator animator2 = new Animator(window2); - animator2.start(); - while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) { + Animator animator = new Animator(); + Assert.assertEquals(false, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + animator.start(); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + animator.add(window1); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + animator.add(window2); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + while(animator.isAnimating() && animator.getDuration()<durationPerTest) { Thread.sleep(100); } - destroyWindow(window1); - Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + while(animator.isAnimating() && animator.getDuration()<2*durationPerTest) { + Thread.sleep(100); + } destroyWindow(window2); - Assert.assertEquals(false, animator2.isAnimating()); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + animator.pause(); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(true, animator.isPaused()); + + animator.resume(); + Assert.assertEquals(true, animator.isStarted()); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); + + animator.stop(); + Assert.assertEquals(false, animator.isStarted()); + Assert.assertEquals(false, animator.isAnimating()); + Assert.assertEquals(false, animator.isPaused()); } public static void setDemoFields(GLEventListener demo, GLWindow glWindow) { 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 1f45c6c1d..97589ed3a 100644 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java @@ -709,17 +709,7 @@ public class TestParenting01NEWT extends UITestCase { } System.err.println("durationPerTest: "+durationPerTest); String tstname = TestParenting01NEWT.class.getName(); - org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { - tstname, - "filtertrace=true", - "haltOnError=false", - "haltOnFailure=false", - "showoutput=true", - "outputtoformatters=true", - "logfailedtests=true", - "logtestlistenerevents=true", - "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", - "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + org.junit.runner.JUnitCore.main(tstname); } } diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java index 2c3455cb0..fd52c86a1 100644 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java +++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java @@ -216,6 +216,8 @@ public class TestParenting01aAWT extends UITestCase { Animator animator1 = new Animator(glWindow1); animator1.start(); + Assert.assertEquals(true, animator1.isStarted()); + Assert.assertEquals(true, animator1.isAnimating()); while(animator1.isAnimating() && animator1.getDuration()<durationPerTest) { Thread.sleep(100); } |