From 2aa296771e3e8dd6cf027f27b0455d1803244bfe Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 21 Nov 2010 03:41:22 +0100 Subject: 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() --- ...TestSwingAWTRobotUsageBeforeJOGLInitBug411.java | 33 +++--- .../junit/newt/TestGLWindows02NEWTAnimated.java | 111 +++++++++++++++------ .../junit/newt/parenting/TestParenting01NEWT.java | 12 +-- .../junit/newt/parenting/TestParenting01aAWT.java | 2 + 4 files changed, 104 insertions(+), 54 deletions(-) (limited to 'src/junit/com') 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()