From 2c1a870f56f54df3e96d68e3d5dadee0bcae7cb5 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 15 Nov 2010 01:53:00 +0100 Subject: NEWT: Make setVisible/reparentWindow return status more reliable (visibility, displayed) Ensure that at least one frame has been rendered after returning from the functions. This removes the hack of polling a while for a rendered frame. --- .../junit/newt/TestDisplayLifecycle01NEWT.java | 16 ++---- .../junit/newt/TestDisplayLifecycle02NEWT.java | 28 +++------ .../test/junit/newt/TestFocus01SwingAWTRobot.java | 3 +- .../test/junit/newt/TestFocus02SwingAWTRobot.java | 7 +-- .../test/junit/newt/TestGLWindows01NEWT.java | 2 - .../junit/newt/parenting/TestParenting01NEWT.java | 66 +++++++--------------- 6 files changed, 38 insertions(+), 84 deletions(-) (limited to 'src/junit/com/jogamp') diff --git a/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle01NEWT.java index dbe51174e..44b4e7325 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle01NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle01NEWT.java @@ -124,10 +124,6 @@ public class TestDisplayLifecycle01NEWT extends UITestCase { // lazy native creation sequence: Display, Screen and Window Assert.assertEquals(0, window.getTotalFrames()); window.setVisible(true); - int wait=0; - while(wait<10 && window.getTotalFrames()<1) { Thread.sleep(100); wait++; } - System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); - Assert.assertTrue(0 < window.getTotalFrames()); Assert.assertEquals(screen,window.getScreen()); Assert.assertEquals(1,Display.getActiveDisplayNumber()); @@ -138,6 +134,8 @@ public class TestDisplayLifecycle01NEWT extends UITestCase { Assert.assertEquals(true,screen.isNativeValid()); Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); while(window.getDuration()<1*durationPerTest) { window.display(); @@ -154,11 +152,9 @@ public class TestDisplayLifecycle01NEWT extends UITestCase { window.resetCounter(); Assert.assertEquals(0, window.getTotalFrames()); window.setVisible(true); - wait=0; - while(wait<10 && window.getTotalFrames()<1) { Thread.sleep(100); wait++; } - System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); Assert.assertTrue(0 < window.getTotalFrames()); while(window.getDuration()<2*durationPerTest) { @@ -190,10 +186,6 @@ public class TestDisplayLifecycle01NEWT extends UITestCase { // recover Window window.setVisible(true); - wait=0; - while(wait<10 && window.getTotalFrames()<1) { Thread.sleep(100); wait++; } - System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames()); - Assert.assertTrue(0 < window.getTotalFrames()); Assert.assertEquals(screen,window.getScreen()); Assert.assertEquals(1,Display.getActiveDisplayNumber()); @@ -204,6 +196,8 @@ public class TestDisplayLifecycle01NEWT extends UITestCase { Assert.assertEquals(true,screen.isNativeValid()); Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); while(window.getDuration()<1*durationPerTest) { window.display(); diff --git a/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle02NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle02NEWT.java index 9e0804a3d..7253b7353 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle02NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/TestDisplayLifecycle02NEWT.java @@ -111,10 +111,6 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { // lazy native creation sequence: Display, Screen and Window Assert.assertEquals(0, window.getTotalFrames()); window.setVisible(true); - int wait=0; - while(wait<10 && window.getTotalFrames()<1) { Thread.sleep(100); wait++; } - System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); - Assert.assertTrue(0 < window.getTotalFrames()); Assert.assertEquals(screen,window.getScreen()); Assert.assertEquals(1,Display.getActiveDisplayNumber()); @@ -126,6 +122,8 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { Assert.assertEquals(true,screen.isNativeValid()); Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); while(window.getDuration()<1*durationPerTest) { window.display(); @@ -142,11 +140,9 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { window.resetCounter(); Assert.assertEquals(0, window.getTotalFrames()); window.setVisible(true); - wait=0; - while(wait<10 && window.getTotalFrames()<1) { Thread.sleep(100); wait++; } - System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 1: "+window.getTotalFrames()); Assert.assertTrue(0 < window.getTotalFrames()); while(window.getDuration()<2*durationPerTest) { @@ -179,10 +175,6 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { // recover Window window.setVisible(true); - wait=0; - while(wait<10 && window.getTotalFrames()<1) { Thread.sleep(100); wait++; } - System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames()); - Assert.assertTrue(0 < window.getTotalFrames()); Assert.assertEquals(screen,window.getScreen()); Assert.assertEquals(1,Display.getActiveDisplayNumber()); @@ -194,6 +186,8 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { Assert.assertEquals(true,screen.isNativeValid()); Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(true,window.isVisible()); + System.err.println("Frames for setVisible(true) 2: "+window.getTotalFrames()); + Assert.assertTrue(0 < window.getTotalFrames()); while(window.getDuration()<1*durationPerTest) { window.display(); @@ -264,10 +258,6 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { // lazy native creation sequence: Display, Screen and Window Assert.assertEquals(0, window1.getTotalFrames()); window1.setVisible(true); - int wait=0; - while(wait<10 && window1.getTotalFrames()<1) { Thread.sleep(100); wait++; } - System.err.println("Frames for setVisible(true) 1: "+window1.getTotalFrames()); - Assert.assertTrue(0 < window1.getTotalFrames()); Assert.assertEquals(1,Display.getActiveDisplayNumber()); Assert.assertEquals(1,display.getReferenceCount()); @@ -278,13 +268,11 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { Assert.assertEquals(true,screen.isNativeValid()); Assert.assertEquals(true,window1.isNativeValid()); Assert.assertEquals(true,window1.isVisible()); + System.err.println("Frames for setVisible(true) 1: "+window1.getTotalFrames()); + Assert.assertTrue(0 < window1.getTotalFrames()); Assert.assertEquals(0, window2.getTotalFrames()); window2.setVisible(true); - wait=0; - while(wait<10 && window2.getTotalFrames()<1) { Thread.sleep(100); wait++; } - System.err.println("Frames for setVisible(true) 2: "+window2.getTotalFrames()); - Assert.assertTrue(0 < window2.getTotalFrames()); Assert.assertEquals(1,Display.getActiveDisplayNumber()); Assert.assertEquals(1,display.getReferenceCount()); @@ -295,6 +283,8 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { Assert.assertEquals(true,screen.isNativeValid()); Assert.assertEquals(true,window2.isNativeValid()); Assert.assertEquals(true,window2.isVisible()); + System.err.println("Frames for setVisible(true) 2: "+window2.getTotalFrames()); + Assert.assertTrue(0 < window2.getTotalFrames()); while(window1.getDuration()<1*durationPerTest) { window1.display(); diff --git a/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java b/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java index 1002fc9f8..49591aab8 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java +++ b/src/junit/com/jogamp/test/junit/newt/TestFocus01SwingAWTRobot.java @@ -144,8 +144,7 @@ public class TestFocus01SwingAWTRobot extends UITestCase { frame1.setVisible(true); Assert.assertTrue(AWTRobotUtil.toFront(robot, frame1)); - int wait=0; - while(wait<10 && glWindow1.getTotalFrames()<1) { Thread.sleep(100); wait++; } + Assert.assertTrue(glWindow1.isVisible()); System.out.println("Frames for initial setVisible(true): "+glWindow1.getTotalFrames()); Assert.assertTrue(0 < glWindow1.getTotalFrames()); diff --git a/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java b/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java index 3891f1565..af959a2eb 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java +++ b/src/junit/com/jogamp/test/junit/newt/TestFocus02SwingAWTRobot.java @@ -44,8 +44,6 @@ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; import java.util.ArrayList; -import java.util.List; -import java.util.Iterator; import javax.media.opengl.*; @@ -164,9 +162,8 @@ public class TestFocus02SwingAWTRobot extends UITestCase { jFrame1.setVisible(true); // from here on, we need to run modifications on EDT Assert.assertTrue(AWTRobotUtil.toFront(robot, jFrame1)); - int wait=0; - while(wait<10 && glWindow1.getTotalFrames()<1) { Thread.sleep(100); wait++; } - System.err.println("Frames for initial setVisible(true): "+glWindow1.getTotalFrames()); + Assert.assertTrue(glWindow1.isVisible()); + System.out.println("Frames for initial setVisible(true): "+glWindow1.getTotalFrames()); Assert.assertTrue(0 < glWindow1.getTotalFrames()); // Continuous animation .. diff --git a/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java index 112bb943c..279f2c370 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java @@ -99,8 +99,6 @@ public class TestGLWindows01NEWT extends UITestCase { glWindow.setVisible(true); Assert.assertEquals(true,glWindow.isVisible()); Assert.assertEquals(true,glWindow.isNativeValid()); - int wait=0; - while(wait<10 && glWindow.getTotalFrames()<1) { Thread.sleep(100); wait++; } System.out.println("Frames for initial setVisible(true): "+glWindow.getTotalFrames()); Assert.assertTrue(0 < glWindow.getTotalFrames()); 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 91d8856f0..b9182dbaa 100644 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java @@ -49,7 +49,7 @@ import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears; public class TestParenting01NEWT extends UITestCase { static int width, height; static long durationPerTest = 500; - static int frameWait = 2000; + static long waitAbout10FramesAt30fps = 10*34; // 10 frames @ 30fps static GLCapabilities glCaps; @BeforeClass @@ -118,10 +118,6 @@ public class TestParenting01NEWT extends UITestCase { Assert.assertEquals(0, glWindow1.getTotalFrames()); Assert.assertEquals(0, glWindow2.getTotalFrames()); glWindow1.setVisible(true); - int wait; - for(wait=0; wait