From 1c02f0eeb539ff5de7259b822893ab63a9cc3ab0 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 23 Sep 2010 16:30:25 +0200 Subject: NEWT: Changed Lifecycle of Display/Screen (part 4) - Reparenting - Tests - Adapted tests to API changes - Notably new Display lifecycle / Reparenting tests: - TestDisplayLifecycle01NEWT - Tests display lifecycle - TestParenting01NEWT - Tests various reparenting cases (native/recreate) - TestParenting01bAWT - Tests Animator/FPSAnimator with reparenting (AWT/Newt) - Other changes: - TestGearsNEWT: Added 'on-the-fly' KeyAdapter inducing a GLRunnable into the GLWindow for fullscreen toggle. - --- .../test/junit/jogl/acore/TestGLProfile01NEWT.java | 2 +- .../junit/jogl/demos/gl2/gears/TestGearsNEWT.java | 21 +- .../demos/gl2/gears/TestGearsNewtAWTWrapper.java | 2 +- .../junit/jogl/drawable/TestDrawable01NEWT.java | 3 +- .../TestTransformFeedbackVeryingsBug407NEWT.java | 3 +- .../junit/jogl/offscreen/TestOffscreen01NEWT.java | 12 +- .../junit/newt/TestDisplayLifecycle01NEWT.java | 34 +- .../test/junit/newt/TestGLWindows01NEWT.java | 97 ++++-- .../junit/newt/TestGLWindows02NEWTAnimated.java | 12 +- .../test/junit/newt/TestListenerCom01AWT.java | 2 +- .../jogamp/test/junit/newt/TestWindows01NEWT.java | 3 +- .../test/junit/newt/parenting/GLRunnableDummy.java | 1 - .../junit/newt/parenting/TestParenting01NEWT.java | 373 +++++++++++++++++---- .../junit/newt/parenting/TestParenting01aAWT.java | 8 +- .../junit/newt/parenting/TestParenting01bAWT.java | 34 +- .../junit/newt/parenting/TestParenting01cAWT.java | 14 +- .../newt/parenting/TestParenting01cSwingAWT.java | 2 +- .../junit/newt/parenting/TestParenting02AWT.java | 2 +- .../junit/newt/parenting/TestParenting02NEWT.java | 5 +- 19 files changed, 488 insertions(+), 142 deletions(-) (limited to 'src/junit/com/jogamp') diff --git a/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01NEWT.java index 2c43fbe66..12e016654 100644 --- a/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01NEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/acore/TestGLProfile01NEWT.java @@ -141,7 +141,7 @@ public class TestGLProfile01NEWT { protected void dumpVersion(GLProfile glp) { GLCapabilities caps = new GLCapabilities(glp); - GLWindow glWindow = GLWindow.create(caps, false); + GLWindow glWindow = GLWindow.create(caps); Assert.assertNotNull(glWindow); glWindow.setTitle("TestGLProfile01NEWT"); diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java index 91eb6f4a0..2424ff381 100644 --- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNEWT.java @@ -64,7 +64,7 @@ public class TestGearsNEWT { } protected void runTestGL(GLCapabilities caps) throws InterruptedException { - GLWindow glWindow = GLWindow.create(caps, false); + GLWindow glWindow = GLWindow.create(caps); Assert.assertNotNull(glWindow); glWindow.setTitle("Gears NEWT Test"); @@ -73,8 +73,23 @@ public class TestGearsNEWT { Animator animator = new Animator(glWindow); QuitAdapter quitAdapter = new QuitAdapter(); - glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter)); - glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter)); + //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter)); + //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter)); + glWindow.addKeyListener(quitAdapter); + glWindow.addWindowListener(quitAdapter); + + final GLWindow f_glWindow = glWindow; + glWindow.addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent e) { + if(e.getKeyChar()=='f') { + f_glWindow.invoke(false, new GLRunnable() { + public void run(GLAutoDrawable drawable) { + GLWindow win = (GLWindow)drawable; + win.setFullscreen(!win.isFullscreen()); + } }); + } + } + }); glWindow.setSize(width, height); glWindow.setVisible(true); diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNewtAWTWrapper.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNewtAWTWrapper.java index 42842936a..6ae3691d5 100644 --- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNewtAWTWrapper.java +++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/TestGearsNewtAWTWrapper.java @@ -67,7 +67,7 @@ public class TestGearsNewtAWTWrapper { protected void runTestGL(GLCapabilities caps) throws InterruptedException { Display nDisplay = NewtFactory.createDisplay(NativeWindowFactory.TYPE_AWT, null); // local display Screen nScreen = NewtFactory.createScreen(NativeWindowFactory.TYPE_AWT, nDisplay, 0); // screen 0 - Window nWindow = NewtFactory.createWindow(NativeWindowFactory.TYPE_AWT, nScreen, caps, false); + Window nWindow = NewtFactory.createWindow(NativeWindowFactory.TYPE_AWT, nScreen, caps); GLWindow glWindow = GLWindow.create(nWindow); Assert.assertNotNull(glWindow); diff --git a/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java index cbcd07679..089d90362 100644 --- a/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/drawable/TestDrawable01NEWT.java @@ -90,8 +90,9 @@ public class TestDrawable01NEWT { Screen screen = NewtFactory.createScreen(display, 0); // screen 0 Assert.assertNotNull(screen); - window = NewtFactory.createWindow(screen, caps, onscreen && undecorated); + window = NewtFactory.createWindow(screen, caps); Assert.assertNotNull(window); + window.setUndecorated(onscreen && undecorated); window.setSize(width, height); window.setVisible(true); // System.out.println("Created: "+window); diff --git a/src/junit/com/jogamp/test/junit/jogl/glsl/TestTransformFeedbackVeryingsBug407NEWT.java b/src/junit/com/jogamp/test/junit/jogl/glsl/TestTransformFeedbackVeryingsBug407NEWT.java index c90001f85..361d16613 100644 --- a/src/junit/com/jogamp/test/junit/jogl/glsl/TestTransformFeedbackVeryingsBug407NEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/glsl/TestTransformFeedbackVeryingsBug407NEWT.java @@ -60,7 +60,8 @@ public class TestTransformFeedbackVeryingsBug407NEWT { Display display = NewtFactory.createDisplay(null); // local display Screen screen = NewtFactory.createScreen(display, 0); // screen 0 - window = NewtFactory.createWindow(screen, caps, true); + window = NewtFactory.createWindow(screen, caps); + window.setUndecorated(true); window.setSize(800, 600); window.setVisible(true); diff --git a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java index 5324c2d82..9718374c7 100644 --- a/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/offscreen/TestOffscreen01NEWT.java @@ -87,7 +87,7 @@ public class TestOffscreen01NEWT { Assert.assertNotNull(display); Screen screen = NewtFactory.createScreen(display, 0); // screen 0 Assert.assertNotNull(screen); - Window window = NewtFactory.createWindow(screen, caps, false /* undecorated */); + Window window = NewtFactory.createWindow(screen, caps); Assert.assertNotNull(window); window.setSize(width, height); GLWindow glWindow = GLWindow.create(window); @@ -192,7 +192,7 @@ public class TestOffscreen01NEWT { for(i=0; i5); Assert.assertTrue(caps.getBlueBits()>5); @@ -130,11 +132,19 @@ public class TestGLWindows01NEWT { return glWindow; } - static void destroyWindow(GLWindow glWindow, boolean deep) { + static void destroyWindow(GLWindow glWindow, Screen screen, Display display, boolean unrecoverable) { if(null!=glWindow) { - glWindow.destroy(deep); + glWindow.destroy(unrecoverable); Assert.assertEquals(false,glWindow.isNativeValid()); } + if(null!=screen) { + screen.destroy(); + Assert.assertEquals(false,screen.isNativeValid()); + } + if(null!=display) { + display.destroy(); + Assert.assertEquals(false,display.isNativeValid()); + } } @Test @@ -163,7 +173,7 @@ public class TestGLWindows01NEWT { Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(false,window.isVisible()); - destroyWindow(window, true); + destroyWindow(window, null, null, true); } @Test @@ -192,7 +202,7 @@ public class TestGLWindows01NEWT { Assert.assertEquals(true,window.isNativeValid()); Assert.assertEquals(false,window.isVisible()); - destroyWindow(window, true); + destroyWindow(window, null, null, true); } @Test @@ -203,11 +213,12 @@ public class TestGLWindows01NEWT { true /* onscreen */, false /* undecorated */, false /*addGLEventListenerAfterVisible*/); System.out.println("Created: "+window); - while(window.getDuration()5); Assert.assertTrue(caps.getBlueBits()>5); @@ -158,7 +160,7 @@ public class TestGLWindows02NEWTAnimated { Assert.assertNotNull(display1); Display display2 = NewtFactory.createDisplay(null); // local display Assert.assertNotNull(display2); - Assert.assertEquals(display1, display2); // must be equal: same thread - same display + Assert.assertNotSame(display1, display2); Screen screen1 = NewtFactory.createScreen(display1, 0); // screen 0 Assert.assertNotNull(screen1); @@ -190,7 +192,7 @@ public class TestGLWindows02NEWTAnimated { public static void setDemoFields(GLEventListener demo, GLWindow glWindow) { Assert.assertNotNull(demo); Assert.assertNotNull(glWindow); - if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getInnerWindow())) { + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow)) { MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); } } diff --git a/src/junit/com/jogamp/test/junit/newt/TestListenerCom01AWT.java b/src/junit/com/jogamp/test/junit/newt/TestListenerCom01AWT.java index 2159ecda5..b98ed2f4d 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestListenerCom01AWT.java +++ b/src/junit/com/jogamp/test/junit/newt/TestListenerCom01AWT.java @@ -128,7 +128,7 @@ public class TestListenerCom01AWT { public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); Assert.assertNotNull(glWindow); - Window window = glWindow.getInnerWindow(); + Window window = glWindow.getWindow(); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); diff --git a/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java index be917ecea..22ec08903 100644 --- a/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/TestWindows01NEWT.java @@ -62,8 +62,9 @@ public class TestWindows01NEWT { // // Create native windowing resources .. X11/Win/OSX // - Window window = NewtFactory.createWindow(screen, caps, onscreen && undecorated); + Window window = NewtFactory.createWindow(screen, caps); Assert.assertNotNull(window); + window.setUndecorated(onscreen && undecorated); window.setSize(width, height); Assert.assertEquals(false,window.isNativeValid()); Assert.assertEquals(false,window.isVisible()); diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/GLRunnableDummy.java b/src/junit/com/jogamp/test/junit/newt/parenting/GLRunnableDummy.java index f951253f4..2459c8687 100644 --- a/src/junit/com/jogamp/test/junit/newt/parenting/GLRunnableDummy.java +++ b/src/junit/com/jogamp/test/junit/newt/parenting/GLRunnableDummy.java @@ -54,5 +54,4 @@ public class GLRunnableDummy implements GLRunnable { d*=-1f; } } - } 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 fdeb09604..56b9f2876 100644 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java @@ -26,7 +26,6 @@ * or implied, of JogAmp Community. */ - package com.jogamp.test.junit.newt.parenting; import java.lang.reflect.*; @@ -63,7 +62,6 @@ public class TestParenting01NEWT { static int width, height; static long durationPerTest = 500; - static long waitReparent = 0; static GLCapabilities glCaps; @BeforeClass @@ -128,7 +126,17 @@ public class TestParenting01NEWT { Assert.assertEquals(0,Display.getActiveDisplayNumber()); // visible test + Assert.assertEquals(0, glWindow1.getTotalFrames()); + Assert.assertEquals(0, glWindow2.getTotalFrames()); glWindow1.setVisible(true); + int wait; + for(wait=0; wait<10 && ( glWindow2.getTotalFrames()<1 || glWindow1.getTotalFrames()<1 ); wait++) { + Thread.sleep(100); + } + System.err.println("Frames for setVisible(true): A1: "+glWindow1.getTotalFrames()+", B1: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + Assert.assertEquals(true, glWindow1.isVisible()); Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertEquals(true, glWindow2.isVisible()); @@ -146,24 +154,78 @@ public class TestParenting01NEWT { Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertEquals(false, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); + Assert.assertEquals(0, glWindow1.getTotalFrames()); + glWindow1.resetPerfCounter(); + glWindow2.resetPerfCounter(); + Assert.assertEquals(0, glWindow1.getTotalFrames()); + Assert.assertEquals(0, glWindow2.getTotalFrames()); glWindow1.setVisible(true); + for(wait=0; wait<10 && ( glWindow2.getTotalFrames()<1 || glWindow1.getTotalFrames()<1 ); wait++) { + Thread.sleep(100); + } + System.err.println("Frames for setVisible(true): A2: "+glWindow1.getTotalFrames()+", B2: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + Assert.assertEquals(true, glWindow1.isVisible()); Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); + glWindow1.resetPerfCounter(); + glWindow2.resetPerfCounter(); Animator animator1 = new Animator(glWindow1); animator1.start(); + Assert.assertEquals(true, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertNotNull(animator1.getThread()); Animator animator2 = new Animator(glWindow2); animator2.start(); + Assert.assertEquals(true, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertNotNull(animator2.getThread()); while(animator1.isAnimating() && animator1.getDuration() glWindow1: compatible Assert.assertEquals(true, glWindow2.isVisible()); - glWindow2.reparentWindow(glWindow1); + reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate); + Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); + for(wait=0; wait<10 && glWindow2.getTotalFrames()<1; wait++) { Thread.sleep(100); } + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); Assert.assertSame(glWindow1,glWindow2.getParentNativeWindow()); - Assert.assertNotSame(screen1,glWindow2.getScreen()); - Assert.assertNotSame(display1,glWindow2.getScreen().getDisplay()); Assert.assertEquals(1,display1.getReferenceCount()); Assert.assertEquals(true,display1.isNativeValid()); Assert.assertNotNull(display1.getEDTUtil()); Assert.assertEquals(true,display1.getEDTUtil().isRunning()); - Assert.assertEquals(1,screen1.getReferenceCount()); Assert.assertEquals(true,screen1.isNativeValid()); - - Assert.assertEquals(1,display2.getReferenceCount()); - Assert.assertEquals(true,display2.isNativeValid()); Assert.assertNotNull(display2.getEDTUtil()); - Assert.assertEquals(true,display2.getEDTUtil().isRunning()); - Assert.assertEquals(1,screen2.getReferenceCount()); - Assert.assertEquals(true,screen2.isNativeValid()); - - Assert.assertEquals(2,Display.getActiveDisplayNumber()); + if(Window.ReparentAction.ACTION_NATIVE_REPARENTING >= reparentAction) { + Assert.assertNotSame(screen1,glWindow2.getScreen()); + Assert.assertNotSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(1,screen1.getReferenceCount()); + Assert.assertEquals(1,display2.getReferenceCount()); + Assert.assertEquals(true,display2.isNativeValid()); + Assert.assertEquals(true,display2.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen2.getReferenceCount()); + Assert.assertEquals(true,screen2.isNativeValid()); + Assert.assertEquals(2,Display.getActiveDisplayNumber()); + } else { + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(0,display2.getReferenceCount()); + Assert.assertEquals(false,display2.isNativeValid()); + Assert.assertEquals(false,display2.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen2.getReferenceCount()); + Assert.assertEquals(false,screen2.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + } break; case 1: // glWindow2 --> top Assert.assertEquals(true, glWindow2.isVisible()); - glWindow2.reparentWindow(null); + + reparentAction = glWindow2.reparentWindow(null, reparentRecreate); + Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); + for(wait=0; wait<10 && glWindow2.getTotalFrames()<1; wait++) { Thread.sleep(100); } + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); Assert.assertNull(glWindow2.getParentNativeWindow()); - Assert.assertNotSame(screen1,glWindow2.getScreen()); - Assert.assertNotSame(display1,glWindow2.getScreen().getDisplay()); Assert.assertEquals(1,display1.getReferenceCount()); Assert.assertEquals(true,display1.isNativeValid()); Assert.assertNotNull(display1.getEDTUtil()); Assert.assertEquals(true,display1.getEDTUtil().isRunning()); - Assert.assertEquals(1,screen1.getReferenceCount()); Assert.assertEquals(true,screen1.isNativeValid()); - - Assert.assertEquals(1,display2.getReferenceCount()); - Assert.assertEquals(true,display2.isNativeValid()); Assert.assertNotNull(display2.getEDTUtil()); - Assert.assertEquals(true,display2.getEDTUtil().isRunning()); - Assert.assertEquals(1,screen2.getReferenceCount()); - Assert.assertEquals(true,screen2.isNativeValid()); + if(Window.ReparentAction.ACTION_NATIVE_REPARENTING >= reparentAction) { + Assert.assertNotSame(screen1,glWindow2.getScreen()); + Assert.assertNotSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(1,screen1.getReferenceCount()); + Assert.assertEquals(1,display2.getReferenceCount()); + Assert.assertEquals(true,display2.isNativeValid()); + Assert.assertEquals(true,display2.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen2.getReferenceCount()); + Assert.assertEquals(true,screen2.isNativeValid()); + Assert.assertEquals(2,Display.getActiveDisplayNumber()); + } else { + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(0,display2.getReferenceCount()); + Assert.assertEquals(false,display2.isNativeValid()); + Assert.assertEquals(false,display2.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen2.getReferenceCount()); + Assert.assertEquals(false,screen2.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + } - Assert.assertEquals(2,Display.getActiveDisplayNumber()); break; } state++; } animator1.stop(); Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); animator2.stop(); Assert.assertEquals(false, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertEquals(null, animator2.getThread()); // pre-destroy check (both valid and running) Assert.assertEquals(1,display1.getReferenceCount()); Assert.assertEquals(true,display1.isNativeValid()); Assert.assertNotNull(display1.getEDTUtil()); Assert.assertEquals(true,display1.getEDTUtil().isRunning()); - Assert.assertEquals(1,screen1.getReferenceCount()); - Assert.assertEquals(true,screen1.isNativeValid()); - - Assert.assertEquals(1,display2.getReferenceCount()); - Assert.assertEquals(true,display2.isNativeValid()); Assert.assertNotNull(display2.getEDTUtil()); - Assert.assertEquals(true,display2.getEDTUtil().isRunning()); - Assert.assertEquals(1,screen2.getReferenceCount()); - Assert.assertEquals(true,screen2.isNativeValid()); - - Assert.assertEquals(2,Display.getActiveDisplayNumber()); - + if(!reparentRecreate) { + Assert.assertEquals(1,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertEquals(1,display2.getReferenceCount()); + Assert.assertEquals(true,display2.isNativeValid()); + Assert.assertEquals(true,display2.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen2.getReferenceCount()); + Assert.assertEquals(true,screen2.isNativeValid()); + Assert.assertEquals(2,Display.getActiveDisplayNumber()); + } else { + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertEquals(0,display2.getReferenceCount()); + Assert.assertEquals(false,display2.isNativeValid()); + Assert.assertEquals(false,display2.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen2.getReferenceCount()); + Assert.assertEquals(false,screen2.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + } - // destroy glWindow1 - glWindow1.destroy(true); - Assert.assertEquals(false, glWindow1.isValid()); - Assert.assertEquals(true , glWindow2.isValid()); + // destroy glWindow2 + glWindow2.destroy(true); + Assert.assertEquals(true, glWindow1.isValid()); + Assert.assertEquals(false, glWindow2.isValid()); - Assert.assertEquals(0,display1.getReferenceCount()); - Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); Assert.assertNotNull(display1.getEDTUtil()); - Assert.assertEquals(false,display1.getEDTUtil().isRunning()); - Assert.assertEquals(0,screen1.getReferenceCount()); - Assert.assertEquals(false,screen1.isNativeValid()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(1,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); - Assert.assertEquals(1,display2.getReferenceCount()); - Assert.assertEquals(true,display2.isNativeValid()); + Assert.assertEquals(0,display2.getReferenceCount()); + Assert.assertEquals(false,display2.isNativeValid()); Assert.assertNotNull(display2.getEDTUtil()); - Assert.assertEquals(true,display2.getEDTUtil().isRunning()); - Assert.assertEquals(1,screen2.getReferenceCount()); - Assert.assertEquals(true,screen2.isNativeValid()); + Assert.assertEquals(false,display2.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen2.getReferenceCount()); + Assert.assertEquals(false,screen2.isNativeValid()); Assert.assertEquals(1,Display.getActiveDisplayNumber()); // destroy glWindow1 - glWindow2.destroy(true); + glWindow1.destroy(true); Assert.assertEquals(false, glWindow1.isValid()); Assert.assertEquals(false, glWindow2.isValid()); @@ -456,26 +597,86 @@ public class TestParenting01NEWT { } @Test - public void testWindowParenting03ReparentWin2Top() throws InterruptedException { + public void testWindowParenting03ReparentWin2TopReparentRecreate() throws InterruptedException { + testWindowParenting03ReparentWin2TopImpl(true); + } + + @Test + public void testWindowParenting03ReparentWin2TopReparentNative() throws InterruptedException { + testWindowParenting03ReparentWin2TopImpl(false); + } + + protected void testWindowParenting03ReparentWin2TopImpl(boolean reparentRecreate) throws InterruptedException { int x = 0; int y = 0; NEWTEventFiFo eventFifo = new NEWTEventFiFo(); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Display display1 = null; + Screen screen1 = null; + Display display2 = null; + Screen screen2 = null; + GLWindow glWindow1 = GLWindow.create(glCaps); + screen1 = glWindow1.getScreen(); + display1 = screen1.getDisplay(); glWindow1.setTitle("testWindowParenting03ReparentWin2Top"); glWindow1.setSize(640, 480); GLEventListener demo1 = new RedSquare(); setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); + Assert.assertEquals(true,display1.getDestroyWhenUnused()); + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(false,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + GLWindow glWindow2 = GLWindow.create(glWindow1, glCaps); + screen2 = glWindow2.getScreen(); + display2 = screen2.getDisplay(); glWindow2.setSize(320, 240); GLEventListener demo2 = new Gears(); setDemoFields(demo2, glWindow2, false); glWindow2.addGLEventListener(demo2); + Assert.assertEquals(true,display2.getDestroyWhenUnused()); + Assert.assertEquals(0,display2.getReferenceCount()); + Assert.assertEquals(false,display2.isNativeValid()); + Assert.assertNotNull(display2.getEDTUtil()); + Assert.assertEquals(true,display2.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen2.getReferenceCount()); + Assert.assertEquals(false,screen2.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + + Assert.assertEquals(0, glWindow1.getTotalFrames()); + Assert.assertEquals(0, glWindow2.getTotalFrames()); glWindow1.setVisible(true); + int wait; + for(wait=0; wait<10 && ( glWindow2.getTotalFrames()<1 || glWindow1.getTotalFrames()<1 ); wait++) { + Thread.sleep(100); + } + System.err.println("Frames for setVisible(): A1: "+glWindow1.getTotalFrames()+", B1: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow1.getTotalFrames()); + + Assert.assertEquals(true,display1.getDestroyWhenUnused()); + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertSame(glWindow1,glWindow2.getParentNativeWindow()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); Animator animator1 = new Animator(glWindow1); animator1.start(); @@ -483,48 +684,99 @@ public class TestParenting01NEWT { animator2.start(); int state = 0; + int reparentAction; while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) { Thread.sleep(durationPerTest); switch(state) { case 0: Assert.assertEquals(true, glWindow2.isVisible()); - glWindow2.reparentWindow(null); + reparentAction = glWindow2.reparentWindow(null, reparentRecreate); + Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); + for(wait=0; wait<10 && glWindow2.getTotalFrames()<1; wait++) { Thread.sleep(100); } + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B2: "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); Assert.assertNull(glWindow2.getParentNativeWindow()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); break; case 1: Assert.assertEquals(true, glWindow2.isVisible()); - glWindow2.reparentWindow(glWindow1); + reparentAction = glWindow2.reparentWindow(glWindow1, reparentRecreate); + Assert.assertTrue(Window.ReparentAction.ACTION_INVALID < reparentAction); + for(wait=0; wait<10 && glWindow2.getTotalFrames()<1; wait++) { Thread.sleep(100); } + System.err.println("Frames for reparentWindow(parent, "+reparentRecreate+"): "+reparentAction+", B3 "+glWindow2.getTotalFrames()); + Assert.assertTrue(0 < glWindow2.getTotalFrames()); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); Assert.assertSame(glWindow1,glWindow2.getParentNativeWindow()); + Assert.assertSame(screen1,glWindow2.getScreen()); + Assert.assertSame(display1,glWindow2.getScreen().getDisplay()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); break; } state++; } animator1.stop(); Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); animator2.stop(); Assert.assertEquals(false, animator2.isAnimating()); + Assert.assertEquals(false, animator2.isPaused()); + Assert.assertEquals(null, animator2.getThread()); - glWindow1.destroy(true); + Assert.assertEquals(true,display1.getDestroyWhenUnused()); + Assert.assertEquals(1,display1.getReferenceCount()); + Assert.assertEquals(true,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(true,display1.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen1.getReferenceCount()); + Assert.assertEquals(true,screen1.isNativeValid()); + Assert.assertSame(glWindow1,glWindow2.getParentNativeWindow()); + Assert.assertSame(screen1,glWindow2.getScreen()); + + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + glWindow1.destroy(true); // should destroy both windows, actually, since glWindow2 is a child Assert.assertEquals(false, glWindow1.isValid()); Assert.assertEquals(false, glWindow2.isValid()); + + Assert.assertEquals(true,display1.getDestroyWhenUnused()); + Assert.assertEquals(0,display1.getReferenceCount()); + Assert.assertEquals(false,display1.isNativeValid()); + Assert.assertNotNull(display1.getEDTUtil()); + Assert.assertEquals(false,display1.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen1.getReferenceCount()); + Assert.assertEquals(false,screen1.isNativeValid()); + + Assert.assertEquals(true,display2.getDestroyWhenUnused()); + Assert.assertEquals(0,display2.getReferenceCount()); + Assert.assertEquals(false,display2.isNativeValid()); + Assert.assertNotNull(display2.getEDTUtil()); + Assert.assertEquals(false,display2.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen2.getReferenceCount()); + Assert.assertEquals(false,screen2.isNativeValid()); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + glWindow2.destroy(true); Assert.assertEquals(false, glWindow1.isValid()); Assert.assertEquals(false, glWindow2.isValid()); + + Assert.assertEquals(0,Display.getActiveDisplayNumber()); } public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); - Assert.assertNotNull(glWindow); - Window window = glWindow.getInnerWindow(); + Assert.assertNotNull(glWindow); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); } - if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getWindow())) { MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); } } @@ -541,10 +793,9 @@ public class TestParenting01NEWT { for(int i=0; i0) { + animator1 = new FPSAnimator(glWindow1, fps); + } else { + animator1 = new Animator(glWindow1); + } animator1.start(); - int state = 0; - while(animator1.isAnimating() && animator1.getDuration()<3*durationPerTest) { + int state; + for(state=0; state<3; state++) { Thread.sleep(durationPerTest); switch(state) { case 0: @@ -131,11 +147,15 @@ public class TestParenting01bAWT { frame1.add(newtCanvasAWT, BorderLayout.CENTER); break; } - state++; } + Assert.assertEquals(true, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertNotNull(animator1.getThread()); animator1.stop(); Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); frame1.dispose(); frame2.dispose(); @@ -145,7 +165,7 @@ public class TestParenting01bAWT { public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); Assert.assertNotNull(glWindow); - Window window = glWindow.getInnerWindow(); + Window window = glWindow.getWindow(); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); diff --git a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java index 669ff0a42..5bba968a6 100644 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java +++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01cAWT.java @@ -50,7 +50,6 @@ import java.awt.Dimension; import javax.media.opengl.*; import javax.media.nativewindow.*; -import com.jogamp.opengl.util.Animator; import com.jogamp.newt.*; import com.jogamp.newt.event.*; import com.jogamp.newt.opengl.*; @@ -82,6 +81,7 @@ public class TestParenting01cAWT { public void testWindowParenting01CreateVisibleDestroy1() throws InterruptedException { int x = 0; int y = 0; + int i; NEWTEventFiFo eventFifo = new NEWTEventFiFo(); @@ -123,7 +123,7 @@ public class TestParenting01cAWT { frame1.setVisible(true); Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParentNativeWindow()); - while(glWindow1.getDuration()