diff options
18 files changed, 550 insertions, 206 deletions
diff --git a/make/scripts/java-run-all.sh b/make/scripts/java-run-all.sh index 0d7e5b21d..3728ee2e4 100755 --- a/make/scripts/java-run-all.sh +++ b/make/scripts/java-run-all.sh @@ -46,7 +46,7 @@ uname -a | grep -i Darwin && MOSX=1 # D_ARGS="-Dnewt.debug=all" # D_ARGS="-Dnewt.debug.Window" # D_ARGS="-Dnewt.debug.Display" -# D_ARGS="-Dnewt.debug.Window -Dnewt.debug.Display" +D_ARGS="-Dnewt.debug.Window -Dnewt.debug.Display" # D_ARGS="-Dnewt.debug.Window -Dnewt.debug.TestEDTMainThread" # D_ARGS="-Dnewt.debug.TestEDTMainThread" # D_ARGS="-Djogl.debug=all -Djogl.debug.DynamicLookup=true -Djogamp.debug.NativeLibrary=true" diff --git a/make/scripts/java-win32-dbg.bat b/make/scripts/java-win32-dbg.bat index 0a2020ee5..1021e2457 100755 --- a/make/scripts/java-win32-dbg.bat +++ b/make/scripts/java-win32-dbg.bat @@ -1,8 +1,8 @@ set BLD_SUB=build-win32
-set J2RE_HOME=c:\jre1.6.0_20_x32
-set JAVA_HOME=c:\jdk1.6.0_20_x32
-set ANT_PATH=C:\apache-ant-1.8.0
+set J2RE_HOME=c:\jre1.6.0_21_x32
+set JAVA_HOME=c:\jdk1.6.0_21_x32
+set ANT_PATH=C:\apache-ant-1.8.1
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw\bin;%PATH%
diff --git a/make/scripts/java-win32.bat b/make/scripts/java-win32.bat index 977f39f0f..ab3518649 100755 --- a/make/scripts/java-win32.bat +++ b/make/scripts/java-win32.bat @@ -1,8 +1,8 @@ set BLD_SUB=build-win32
-set J2RE_HOME=c:\jre1.6.0_20_x32
-set JAVA_HOME=c:\jdk1.6.0_20_x32
-set ANT_PATH=C:\apache-ant-1.8.0
+set J2RE_HOME=c:\jre1.6.0_21_x32
+set JAVA_HOME=c:\jdk1.6.0_21_x32
+set ANT_PATH=C:\apache-ant-1.8.1
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw\bin;%PATH%
diff --git a/make/scripts/java-win64-dbg.bat b/make/scripts/java-win64-dbg.bat index a80ec9bdf..0b34ee348 100755 --- a/make/scripts/java-win64-dbg.bat +++ b/make/scripts/java-win64-dbg.bat @@ -1,8 +1,8 @@ set BLD_SUB=build-win64
-set J2RE_HOME=c:\jre1.6.0_20_x64
-set JAVA_HOME=c:\jdk1.6.0_20_x64
-set ANT_PATH=C:\apache-ant-1.8.0
+set J2RE_HOME=c:\jre1.6.0_21_x64
+set JAVA_HOME=c:\jdk1.6.0_21_x64
+set ANT_PATH=C:\apache-ant-1.8.1
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw\bin;%PATH%
diff --git a/make/scripts/java-win64.bat b/make/scripts/java-win64.bat index 7ce87574d..eb40ca40c 100755 --- a/make/scripts/java-win64.bat +++ b/make/scripts/java-win64.bat @@ -1,8 +1,8 @@ set BLD_SUB=build-win64
-set J2RE_HOME=c:\jre1.6.0_20_x64
-set JAVA_HOME=c:\jdk1.6.0_20_x64
-set ANT_PATH=C:\apache-ant-1.8.0
+set J2RE_HOME=c:\jre1.6.0_21_x64
+set JAVA_HOME=c:\jdk1.6.0_21_x64
+set ANT_PATH=C:\apache-ant-1.8.1
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw\bin;%PATH%
diff --git a/make/scripts/make.jogl.all.win32.bat b/make/scripts/make.jogl.all.win32.bat index 528e153aa..9f93e5a0b 100755 --- a/make/scripts/make.jogl.all.win32.bat +++ b/make/scripts/make.jogl.all.win32.bat @@ -1,8 +1,8 @@ set THISDIR="C:\JOGL"
-set J2RE_HOME=c:\jre1.6.0_20_x32
-set JAVA_HOME=c:\jdk1.6.0_20_x32
-set ANT_PATH=C:\apache-ant-1.8.0
+set J2RE_HOME=c:\jre1.6.0_21_x32
+set JAVA_HOME=c:\jdk1.6.0_21_x32
+set ANT_PATH=C:\apache-ant-1.8.1
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw\bin;%PATH%
diff --git a/make/scripts/make.jogl.all.win64.bat b/make/scripts/make.jogl.all.win64.bat index b8d8cc662..8dd932df4 100755 --- a/make/scripts/make.jogl.all.win64.bat +++ b/make/scripts/make.jogl.all.win64.bat @@ -1,8 +1,8 @@ set THISDIR="C:\JOGL"
-set J2RE_HOME=c:\jre1.6.0_20_x64
-set JAVA_HOME=c:\jdk1.6.0_20_x64
-set ANT_PATH=C:\apache-ant-1.8.0
+set J2RE_HOME=c:\jre1.6.0_21_x64
+set JAVA_HOME=c:\jdk1.6.0_21_x64
+set ANT_PATH=C:\apache-ant-1.8.1
set PATH=%JAVA_HOME%\bin;%ANT_PATH%\bin;c:\mingw64\bin;c:\mingw\bin;%PATH%
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 ad03f010c..fdeb09604 100644 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01NEWT.java @@ -78,6 +78,10 @@ public class TestParenting01NEWT { int x = 0; int y = 0; + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Display display = null; + Screen screen = null; + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); GLWindow glWindow1 = GLWindow.create(glCaps); @@ -85,6 +89,17 @@ public class TestParenting01NEWT { Assert.assertEquals(false, glWindow1.isVisible()); Assert.assertEquals(false, glWindow1.isNativeValid()); Assert.assertNull(glWindow1.getParentNativeWindow()); + screen = glWindow1.getScreen(); + display = screen.getDisplay(); + Assert.assertEquals(true,display.getDestroyWhenUnused()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + glWindow1.setTitle("testWindowParenting01CreateVisibleDestroy"); glWindow1.setSize(640, 480); GLEventListener demo1 = new RedSquare(); @@ -95,23 +110,43 @@ public class TestParenting01NEWT { Assert.assertNotNull(glWindow2); Assert.assertEquals(false, glWindow2.isVisible()); Assert.assertEquals(false, glWindow2.isNativeValid()); - Assert.assertEquals(glWindow1,glWindow2.getParentNativeWindow()); + Assert.assertSame(glWindow1,glWindow2.getParentNativeWindow()); + Assert.assertSame(screen,glWindow2.getScreen()); + Assert.assertSame(display,glWindow2.getScreen().getDisplay()); glWindow2.setSize(320, 240); GLEventListener demo2 = new Gears(); setDemoFields(demo2, glWindow2, false); glWindow2.addGLEventListener(demo2); + Assert.assertEquals(true,display.getDestroyWhenUnused()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); // GLWindow -> invoke .. + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + // visible test glWindow1.setVisible(true); Assert.assertEquals(true, glWindow1.isVisible()); Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + glWindow1.setVisible(false); Assert.assertEquals(false, glWindow1.isVisible()); Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertEquals(false, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); + glWindow1.setVisible(true); Assert.assertEquals(true, glWindow1.isVisible()); Assert.assertEquals(true, glWindow1.isNativeValid()); @@ -130,23 +165,85 @@ public class TestParenting01NEWT { animator2.stop(); Assert.assertEquals(false, animator2.isAnimating()); - glWindow1.destroy(); // false + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + glWindow2.destroy(); // can be recreated, refs are hold + Assert.assertEquals(true, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow1.isValid()); + Assert.assertEquals(false, glWindow2.isVisible()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertEquals(true, glWindow2.isValid()); + + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + glWindow1.destroy(); // can be recreated, refs are hold Assert.assertEquals(false, glWindow1.isVisible()); Assert.assertEquals(false, glWindow1.isNativeValid()); Assert.assertEquals(true, glWindow1.isValid()); - Assert.assertEquals(false, glWindow2.isVisible()); Assert.assertEquals(false, glWindow2.isNativeValid()); Assert.assertEquals(true, glWindow2.isValid()); - glWindow1.destroy(true); - Assert.assertEquals(false, glWindow1.isValid()); - Assert.assertEquals(false, glWindow2.isValid()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + // recreation .. + glWindow1.setVisible(true); + Assert.assertEquals(true, glWindow1.isVisible()); + Assert.assertEquals(true, glWindow1.isNativeValid()); + Assert.assertEquals(true, glWindow2.isVisible()); + Assert.assertEquals(true, glWindow2.isNativeValid()); + Assert.assertEquals(1,display.getReferenceCount()); + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(true,display.getEDTUtil().isRunning()); + Assert.assertEquals(2,screen.getReferenceCount()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(1,Display.getActiveDisplayNumber()); + + // cannot be recreated, will drop Display/Screen refs + glWindow1.destroy(true); + Assert.assertEquals(false, glWindow1.isValid()); + Assert.assertEquals(false, glWindow1.isNativeValid()); + Assert.assertEquals(false, glWindow2.isValid()); + Assert.assertEquals(false, glWindow2.isNativeValid()); + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); // test double destroy .. glWindow2.destroy(true); Assert.assertEquals(false, glWindow2.isValid()); + + Assert.assertEquals(0,display.getReferenceCount()); + Assert.assertEquals(false,display.isNativeValid()); + Assert.assertNotNull(display.getEDTUtil()); + Assert.assertEquals(false,display.getEDTUtil().isRunning()); + Assert.assertEquals(0,screen.getReferenceCount()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(0,Display.getActiveDisplayNumber()); } @Test @@ -154,6 +251,12 @@ public class TestParenting01NEWT { int x = 0; int y = 0; + Assert.assertEquals(0,Display.getActiveDisplayNumber()); + Display display1 = null; + Screen screen1 = null; + Display display2 = null; + Screen screen2 = null; + NEWTEventFiFo eventFifo = new NEWTEventFiFo(); GLWindow glWindow1 = GLWindow.create(glCaps); @@ -162,15 +265,63 @@ public class TestParenting01NEWT { GLEventListener demo1 = new RedSquare(); setDemoFields(demo1, glWindow1, false); glWindow1.addGLEventListener(demo1); + screen1 = glWindow1.getScreen(); + display1 = screen1.getDisplay(); + + 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(glCaps); glWindow2.setSize(320, 240); GLEventListener demo2 = new Gears(); setDemoFields(demo2, glWindow2, false); glWindow2.addGLEventListener(demo2); + screen2 = glWindow2.getScreen(); + display2 = screen2.getDisplay(); + + 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()); + + Assert.assertNotSame(screen1, screen2); + Assert.assertNotSame(display1, display2); glWindow1.setVisible(true); + 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,Display.getActiveDisplayNumber()); + glWindow2.setVisible(true); + 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()); Animator animator1 = new Animator(glWindow1); animator1.start(); @@ -182,18 +333,58 @@ public class TestParenting01NEWT { Thread.sleep(durationPerTest); switch(state) { case 0: + // glWindow2 -- child --> glWindow1: compatible Assert.assertEquals(true, glWindow2.isVisible()); - glWindow2.reparentWindow(glWindow1, null); + glWindow2.reparentWindow(glWindow1); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); - Assert.assertEquals(glWindow1,glWindow2.getParentNativeWindow()); + 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()); + break; + case 1: + // glWindow2 --> top Assert.assertEquals(true, glWindow2.isVisible()); - glWindow2.reparentWindow(null, null); + glWindow2.reparentWindow(null); 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()); + + Assert.assertEquals(2,Display.getActiveDisplayNumber()); break; } state++; @@ -203,12 +394,65 @@ public class TestParenting01NEWT { animator2.stop(); Assert.assertEquals(false, animator2.isAnimating()); + // 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()); + + + // destroy glWindow1 glWindow1.destroy(true); Assert.assertEquals(false, glWindow1.isValid()); Assert.assertEquals(true , glWindow2.isValid()); + + 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(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(1,Display.getActiveDisplayNumber()); + + // destroy glWindow1 glWindow2.destroy(true); Assert.assertEquals(false, glWindow1.isValid()); Assert.assertEquals(false, glWindow2.isValid()); + + 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,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()); } @Test @@ -244,17 +488,17 @@ public class TestParenting01NEWT { switch(state) { case 0: Assert.assertEquals(true, glWindow2.isVisible()); - glWindow2.reparentWindow(null, null); + glWindow2.reparentWindow(null); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); Assert.assertNull(glWindow2.getParentNativeWindow()); break; case 1: Assert.assertEquals(true, glWindow2.isVisible()); - glWindow2.reparentWindow(glWindow1, null); + glWindow2.reparentWindow(glWindow1); Assert.assertEquals(true, glWindow2.isVisible()); Assert.assertEquals(true, glWindow2.isNativeValid()); - Assert.assertEquals(glWindow1,glWindow2.getParentNativeWindow()); + Assert.assertSame(glWindow1,glWindow2.getParentNativeWindow()); break; } state++; 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 5d4ddc153..fa04edd50 100644 --- a/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java +++ b/src/junit/com/jogamp/test/junit/newt/parenting/TestParenting01aAWT.java @@ -258,12 +258,12 @@ public class TestParenting01aAWT { Thread.sleep(durationPerTest); switch(state) { case 0: - glWindow1.reparentWindow(null, null); + glWindow1.reparentWindow(null); Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertNull(glWindow1.getParentNativeWindow()); break; case 1: - glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow(), null); + glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow()); Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParentNativeWindow()); break; @@ -313,12 +313,12 @@ public class TestParenting01aAWT { Thread.sleep(durationPerTest); switch(state) { case 0: - glWindow1.reparentWindow(null, null); + glWindow1.reparentWindow(null); Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertNull(glWindow1.getParentNativeWindow()); break; case 1: - glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow(), null); + glWindow1.reparentWindow(newtCanvasAWT.getNativeWindow()); Assert.assertEquals(true, glWindow1.isNativeValid()); Assert.assertEquals(newtCanvasAWT.getNativeWindow(),glWindow1.getParentNativeWindow()); break; diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/RecursiveToolkitLock.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/RecursiveToolkitLock.java index 236ef0754..b676f6996 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/RecursiveToolkitLock.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/RecursiveToolkitLock.java @@ -9,7 +9,7 @@ public class RecursiveToolkitLock { private Thread owner = null; private int recursionCount = 0; private Exception lockedStack = null; - private static final long timeout = 3000; // maximum wait 3s + private static final long timeout = 300000; // maximum wait 3s private static final boolean TRACE_LOCK = false; public Exception getLockedStack() { diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java index 1c1fdd7ec..3d91a5f0f 100644 --- a/src/newt/classes/com/jogamp/newt/Display.java +++ b/src/newt/classes/com/jogamp/newt/Display.java @@ -127,7 +127,7 @@ public abstract class Display { protected synchronized final void createNative() { if(null==aDevice) { if(DEBUG) { - System.out.println("Display.createNative() START ("+getThreadName()+", "+this+")"); + System.err.println("Display.createNative() START ("+getThreadName()+", "+this+")"); } final Display f_dpy = this; runOnEDTIfAvail(true, new Runnable() { @@ -138,7 +138,7 @@ public abstract class Display { throw new RuntimeException("Display.createNative() failed to instanciate an AbstractGraphicsDevice"); } if(DEBUG) { - System.out.println("Display.createNative() END ("+getThreadName()+", "+this+")"); + System.err.println("Display.createNative() END ("+getThreadName()+", "+this+")"); } synchronized(displayList) { displaysActive++; @@ -217,7 +217,7 @@ public abstract class Display { protected synchronized final int addReference() { if(DEBUG) { - System.out.println("Display.addReference() ("+Display.getThreadName()+"): "+refCount+" -> "+(refCount+1)); + System.err.println("Display.addReference() ("+Display.getThreadName()+"): "+refCount+" -> "+(refCount+1)); } if ( 0 == refCount ) { createNative(); @@ -231,7 +231,7 @@ public abstract class Display { protected synchronized final int removeReference() { if(DEBUG) { - System.out.println("Display.removeReference() ("+Display.getThreadName()+"): "+refCount+" -> "+(refCount-1)); + System.err.println("Display.removeReference() ("+Display.getThreadName()+"): "+refCount+" -> "+(refCount-1)); } refCount--; if(0==refCount && destroyWhenUnused) { diff --git a/src/newt/classes/com/jogamp/newt/NewtFactory.java b/src/newt/classes/com/jogamp/newt/NewtFactory.java index 12dadc310..7c610c1b8 100644 --- a/src/newt/classes/com/jogamp/newt/NewtFactory.java +++ b/src/newt/classes/com/jogamp/newt/NewtFactory.java @@ -40,8 +40,11 @@ import java.util.Iterator; import com.jogamp.common.jvm.JVMUtil; import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.impl.Debug; public abstract class NewtFactory { + public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window"); + // Work-around for initialization order problems on Mac OS X // between native Newt and (apparently) Fmod static { @@ -141,22 +144,30 @@ public abstract class NewtFactory { } Screen screen = null; - AbstractGraphicsConfiguration nParentConfig = nParentWindow.getGraphicsConfiguration(); - if(null!=nParentConfig) { - AbstractGraphicsScreen nParentScreen = nParentConfig.getScreen(); - AbstractGraphicsDevice nParentDevice = nParentScreen.getDevice(); - Display display = NewtFactory.createDisplay(type, nParentDevice.getHandle()); - screen = NewtFactory.createScreen(type, display, nParentScreen.getIndex()); + Window parentWindow = null; + + if ( nParentWindow instanceof Window ) { + // use parent NEWT Windows Display/Screen + parentWindow = (Window) nParentWindow ; + screen = parentWindow.getScreen(); } else { - Display display = NewtFactory.createDisplay(type, null); // local display - screen = NewtFactory.createScreen(type, display, 0); // screen 0 + // create a Display/Screen compatible to the NativeWindow + AbstractGraphicsConfiguration nParentConfig = nParentWindow.getGraphicsConfiguration(); + if(null!=nParentConfig) { + AbstractGraphicsScreen nParentScreen = nParentConfig.getScreen(); + AbstractGraphicsDevice nParentDevice = nParentScreen.getDevice(); + Display display = NewtFactory.createDisplay(type, nParentDevice.getHandle()); + screen = NewtFactory.createScreen(type, display, nParentScreen.getIndex()); + } else { + Display display = NewtFactory.createDisplay(type, null); // local display + screen = NewtFactory.createScreen(type, display, 0); // screen 0 + } + screen.setDestroyWhenUnused(true); } - screen.setDestroyWhenUnused(true); final Window win = createWindowImpl(type, nParentWindow, screen, caps, undecorated); win.setSize(nParentWindow.getWidth(), nParentWindow.getHeight()); - if ( nParentWindow instanceof Window ) { - Window parentWindow = (Window) nParentWindow ; + if ( null != parentWindow ) { parentWindow.getInnerWindow().addChild(win); win.setVisible(parentWindow.isVisible()); } @@ -234,5 +245,57 @@ public abstract class NewtFactory { return false; } + public static boolean isScreenCompatible(NativeWindow parent, Screen childScreen) { + // Get parent's NativeWindow details + AbstractGraphicsConfiguration parentConfig = (AbstractGraphicsConfiguration) parent.getGraphicsConfiguration(); + AbstractGraphicsScreen parentScreen = (AbstractGraphicsScreen) parentConfig.getScreen(); + AbstractGraphicsDevice parentDevice = (AbstractGraphicsDevice) parentScreen.getDevice(); + + Display childDisplay = childScreen.getDisplay(); + String parentDisplayName = childDisplay.validateDisplayName(null, parentDevice.getHandle()); + String childDisplayName = childDisplay.getName(); + if( ! parentDisplayName.equals( childDisplayName ) ) { + return false; + } + + if( parentScreen.getIndex() != childScreen.getIndex() ) { + return false; + } + return true; + } + + public static Screen createCompatibleScreen(NativeWindow parent) { + return createCompatibleScreen(parent, null); + } + + public static Screen createCompatibleScreen(NativeWindow parent, Screen childScreen) { + // Get parent's NativeWindow details + AbstractGraphicsConfiguration parentConfig = (AbstractGraphicsConfiguration) parent.getGraphicsConfiguration(); + AbstractGraphicsScreen parentScreen = (AbstractGraphicsScreen) parentConfig.getScreen(); + AbstractGraphicsDevice parentDevice = (AbstractGraphicsDevice) parentScreen.getDevice(); + + if(null != childScreen) { + // check if child Display/Screen is compatible already + Display childDisplay = childScreen.getDisplay(); + String parentDisplayName = childDisplay.validateDisplayName(null, parentDevice.getHandle()); + String childDisplayName = childDisplay.getName(); + boolean displayEqual = parentDisplayName.equals( childDisplayName ); + boolean screenEqual = parentScreen.getIndex() == childScreen.getIndex(); + if(DEBUG_IMPLEMENTATION) { + System.err.println("NewtFactory.createCompatibleScreen: Display: "+ + parentDisplayName+" =? "+childDisplayName+" : "+displayEqual+"; Screen: "+ + parentScreen.getIndex()+" =? "+childScreen.getIndex()+" : "+screenEqual); + } + if( displayEqual && screenEqual ) { + // match: display/screen + return childScreen; + } + } + + // Prep NEWT's Display and Screen according to the parent + final String type = NativeWindowFactory.getNativeWindowType(true); + Display display = NewtFactory.createDisplay(type, parentDevice.getHandle()); + return NewtFactory.createScreen(type, display, parentScreen.getIndex()); + } } diff --git a/src/newt/classes/com/jogamp/newt/Screen.java b/src/newt/classes/com/jogamp/newt/Screen.java index e9697647d..d25da86d8 100644 --- a/src/newt/classes/com/jogamp/newt/Screen.java +++ b/src/newt/classes/com/jogamp/newt/Screen.java @@ -70,7 +70,7 @@ public abstract class Screen { usrWidth = Debug.getIntProperty("newt.ws.swidth", true, localACC); usrHeight = Debug.getIntProperty("newt.ws.sheight", true, localACC); if(usrWidth>0 || usrHeight>0) { - System.out.println("User screen size "+usrWidth+"x"+usrHeight); + System.err.println("User screen size "+usrWidth+"x"+usrHeight); } } Class screenClass = getScreenClass(type); @@ -86,7 +86,7 @@ public abstract class Screen { protected synchronized final void createNative() { if(null == aScreen) { if(DEBUG) { - System.out.println("Screen.createNative() START ("+Display.getThreadName()+", "+this+")"); + System.err.println("Screen.createNative() START ("+Display.getThreadName()+", "+this+")"); } display.addReference(); createNativeImpl(); @@ -94,7 +94,7 @@ public abstract class Screen { throw new RuntimeException("Screen.createNative() failed to instanciate an AbstractGraphicsScreen"); } if(DEBUG) { - System.out.println("Screen.createNative() END ("+Display.getThreadName()+", "+this+")"); + System.err.println("Screen.createNative() END ("+Display.getThreadName()+", "+this+")"); } } } @@ -109,7 +109,7 @@ public abstract class Screen { protected synchronized final int addReference() { if(DEBUG) { - System.out.println("Screen.addReference() ("+Display.getThreadName()+"): "+refCount+" -> "+(refCount+1)); + System.err.println("Screen.addReference() ("+Display.getThreadName()+"): "+refCount+" -> "+(refCount+1)); } if ( 0 == refCount ) { createNative(); @@ -122,7 +122,7 @@ public abstract class Screen { protected synchronized final int removeReference() { if(DEBUG) { - System.out.println("Screen.removeReference() ("+Display.getThreadName()+"): "+refCount+" -> "+(refCount-1)); + System.err.println("Screen.removeReference() ("+Display.getThreadName()+"): "+refCount+" -> "+(refCount-1)); } refCount--; if(0==refCount && getDestroyWhenUnused()) { @@ -149,7 +149,7 @@ public abstract class Screen { protected abstract void closeNativeImpl(); protected void setScreenSize(int w, int h) { - System.out.println("Detected screen size "+w+"x"+h); + System.err.println("Detected screen size "+w+"x"+h); width=w; height=h; } @@ -187,6 +187,10 @@ public abstract class Screen { return (usrHeight>0) ? usrHeight : (height>0) ? height : 480; } + public String toString() { + return "NEWT-Screen[idx "+idx+", refCount "+refCount+", "+aScreen+", "+display+"]"; + } + protected Display display; protected int idx; protected AbstractGraphicsScreen aScreen; diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index 3f07e63de..67374cc00 100644 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -53,6 +53,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer public static final boolean DEBUG_KEY_EVENT = Debug.debug("Window.KeyEvent"); public static final boolean DEBUG_WINDOW_EVENT = Debug.debug("Window.WindowEvent"); public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window"); + public static final boolean DEBUG_TEST_REPARENT_INCOMPATIBLE = Debug.isPropertyDefined("newt.test.reparent.incompatible", true); // Workaround for initialization order problems on Mac OS X // between native Newt and (apparently) Fmod -- if Fmod is @@ -135,6 +136,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer } protected Screen screen; + protected boolean screenReferenced = false; protected NativeWindow parentNativeWindow; protected long parentWindowHandle; @@ -150,26 +152,24 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer protected String title = "Newt Window"; protected boolean undecorated = false; - protected boolean screenRefAdded = false; private final boolean createNative() { if( null==screen || 0!=windowHandle || !visible ) { return 0 != windowHandle ; } if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.createNative() START ("+getThreadName()+", "+this+")"); + System.err.println("Window.createNative() START ("+getThreadName()+", "+this+")"); } if(validateParentWindowHandle()) { - if(!screenRefAdded) { - // only once .. at 1st creation - screenRefAdded = true; - getScreen().addReference(); + if(!screenReferenced) { + screenReferenced = true; + screen.addReference(); } createNativeImpl(); setVisibleImpl(true); } if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.createNative() END ("+getThreadName()+", "+this+")"); + System.err.println("Window.createNative() END ("+getThreadName()+", "+this+")"); } return 0 != windowHandle ; } @@ -196,7 +196,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer } } catch (NativeWindowException nwe) { if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.getNativeWindowHandle: not successful yet: "+nwe); + System.err.println("Window.getNativeWindowHandle: not successful yet: "+nwe); } } finally { if(locked) { @@ -204,7 +204,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer } } if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.getNativeWindowHandle: locked "+locked+", "+nativeWindow); + System.err.println("Window.getNativeWindowHandle: locked "+locked+", "+nativeWindow); } } return handle; @@ -406,6 +406,12 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer */ public void destroy(boolean unrecoverable) { if(isValid()) { + if(DEBUG_IMPLEMENTATION) { + String msg = new String("Window.destroy(unrecoverable: "+unrecoverable+") START "+getThreadName()+", "+this); + //System.err.println(msg); + Exception ee = new Exception(msg); + ee.printStackTrace(); + } runOnEDTIfAvail(true, new DestroyAction(unrecoverable)); } } @@ -418,15 +424,11 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer public void run() { windowLock(); try { - if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.destroy(unrecoverable: "+unrecoverable+") START "+getThreadName()+", "+Window.this); - } - // Childs first .. synchronized(childWindowsLock) { for(Iterator i = childWindows.iterator(); i.hasNext(); ) { NativeWindow nw = (NativeWindow) i.next(); - System.out.println("Window.destroy(unrecoverable: "+unrecoverable+") CHILD BEGIN"); + System.err.println("Window.destroy(unrecoverable: "+unrecoverable+") CHILD BEGIN"); if(nw instanceof Window) { ((Window)nw).sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY); if(unrecoverable) { @@ -435,7 +437,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer } else { nw.destroy(); } - System.out.println("Window.destroy(unrecoverable: "+unrecoverable+") CHILD END"); + System.err.println("Window.destroy(unrecoverable: "+unrecoverable+") CHILD END"); } } @@ -451,20 +453,12 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer mouseListeners = new ArrayList(); keyListeners = new ArrayList(); } - Screen scr = null; if( null != screen && 0 != windowHandle ) { - scr = screen; closeNativeImpl(); } invalidate(unrecoverable); - if(unrecoverable) { - if(null!=scr) { - // only once .. at final destruction - scr.removeReference(); - } - } if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.destroy(unrecoverable: "+unrecoverable+") END "+getThreadName()+", "+Window.this); + System.err.println("Window.destroy(unrecoverable: "+unrecoverable+") END "+getThreadName()+", "+Window.this); } } finally { windowUnlock(); @@ -496,21 +490,27 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer * @see #destroy() * @see #destroy(boolean) */ - public void invalidate(boolean unrecoverable) { + protected void invalidate(boolean unrecoverable) { windowLock(); try{ if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { String msg = new String("!!! Window Invalidate(unrecoverable: "+unrecoverable+") "+getThreadName()); - //System.out.println(msg); - Exception e = new Exception(msg); - e.printStackTrace(); + System.err.println(msg); + // Exception e = new Exception(msg); + // e.printStackTrace(); } windowHandle = 0; visible = false; fullscreen = false; if(unrecoverable) { + System.err.println("Window.invalidate: 1 "+screen); + if(null!=screen) { + screenReferenced = false; + screen.removeReference(); + } screen = null; + System.err.println("Window.invalidate: 2 "+screen); parentWindowHandle = 0; parentNativeWindow = null; caps = null; @@ -640,30 +640,109 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer } class ReparentAction implements Runnable { + /** No native reparenting action */ + static final int ACTION_NONE = 0; + + /** Change Window tree only */ + static final int ACTION_SOFT_REPARENTING = 1; + + /** Native reparenting incl. Window tree */ + static final int ACTION_NATIVE_REPARENTING = 2; + + /** Native window creation after tree change - instead of reparenting. */ + static final int ACTION_NATIVE_CREATION = 3; + NativeWindow newParent; - Screen newScreen; - public ReparentAction(NativeWindow newParent, Screen newScreen) { + public ReparentAction(NativeWindow newParent) { this.newParent = newParent; - this.newScreen = newScreen; } public void run() { windowLock(); try{ - if ( 0 == windowHandle && null != newScreen ) { - screen = newScreen; + Window newParentWindow = null; + if(newParent instanceof Window) { + newParentWindow = (Window) newParent; } + + int reparentAction = -1; // ensure it's set long newParentHandle = 0 ; + if(null!=newParent) { + // Case: Child Window newParentHandle = getNativeWindowHandle(newParent); - if ( 0 == newParentHandle ) { - return; // bail out .. not ready yet + if(0 == newParentHandle) { + // Case: Parent's native window not realized yet + if(null==newParentWindow) { + throw new NativeWindowException("Parent not NEWT Window and not realized yet: "+newParent); + } + // Destroy this window (handle screen + native) and use parent's Screen. + // It may be created properly when the parent is made visible. + destroy(false); + screen = newParentWindow.getScreen(); + reparentAction = ACTION_SOFT_REPARENTING; + } else if(newParent != parentNativeWindow) { + // Case: Parent's native window realized and changed + if( !isNativeValid() ) { + // May create a new compatible Screen/Display and + // mark it for creation. + if(null!=newParentWindow) { + screen = newParentWindow.getScreen(); + } else { + Screen newScreen = NewtFactory.createCompatibleScreen(newParent, screen); + if( screen != newScreen ) { + // auto destroy on-the-fly created Screen/Display + newScreen.setDestroyWhenUnused(true); + screen = newScreen; + } + } + reparentAction = ACTION_NATIVE_CREATION; + } else if ( DEBUG_TEST_REPARENT_INCOMPATIBLE || !NewtFactory.isScreenCompatible(newParent, screen) ) { + // Destroy this window (handle screen + native) and + // may create a new compatible Screen/Display and + // mark it for creation. + destroy(false); + if(null!=newParentWindow) { + screen = newParentWindow.getScreen(); + } else { + screen = NewtFactory.createCompatibleScreen(newParent, screen); + screen.setDestroyWhenUnused(true); + } + reparentAction = ACTION_NATIVE_CREATION; + } else { + // Mark it for native reparenting + reparentAction = ACTION_NATIVE_REPARENTING; + } + } else { + // Case: Parent's native window realized and not changed + reparentAction = ACTION_NONE; + } + } else { + // Case: Top Window + if( 0 == parentWindowHandle ) { + // Already Top Window + reparentAction = ACTION_NONE; + } else { + // Mark it for native reparenting + reparentAction = ACTION_NATIVE_REPARENTING; + } + } + + if ( ACTION_NONE > reparentAction ) { + throw new NativeWindowException("Internal Error: reparentAction not set"); + } + + if( ACTION_NONE == reparentAction ) { + if(DEBUG_IMPLEMENTATION) { + System.err.println("reparent: NO CHANGE ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+" -> "+toHexString(newParentHandle)+", visible "+visible+", parentNativeWindow "+(null!=parentNativeWindow)); } + return; } if(DEBUG_IMPLEMENTATION) { - System.out.println("reparent: START ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+" -> "+toHexString(newParentHandle)+", visible "+visible+", parentNativeWindow "+(null!=parentNativeWindow)); + System.err.println("reparent: START ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+" -> "+toHexString(newParentHandle)+", reparentAction "+reparentAction+", visible "+visible+", parentNativeWindow "+(null!=parentNativeWindow)); } + // rearrange window tree if(null!=parentNativeWindow && parentNativeWindow instanceof Window) { ((Window)parentNativeWindow).getInnerWindow().removeChild(Window.this); } @@ -672,7 +751,13 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer ((Window)parentNativeWindow).getInnerWindow().addChild(Window.this); } - if(newParentHandle != parentWindowHandle) { + if( ACTION_SOFT_REPARENTING == reparentAction ) { + return; + } + + if( ACTION_NATIVE_REPARENTING == reparentAction ) { + Display display = screen.getDisplay(); + parentWindowHandle = newParentHandle; if(0!=parentWindowHandle) { // reset position to 0/0 within parent space @@ -685,28 +770,38 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer if(wasVisible) { Window.this.visible = false; setVisibleImpl(false); - getScreen().getDisplay().dispatchMessages(); // status up2date + display.dispatchMessages(); // status up2date } - boolean reparentRes = false; - reparentRes = reparentWindowImpl(); - getScreen().getDisplay().dispatchMessages(); // status up2date - if(!reparentRes) { - parentWindowHandle = 0; - - // do it the hard way .. reconstruction with setVisible(true) - if( 0 != windowHandle ) { - destroy(false); + boolean ok = reparentWindowImpl(); + display.dispatchMessages(); // status up2date + if ( !ok ) { + // native reparent failed -> try creation + if(DEBUG_IMPLEMENTATION) { + System.err.println("reparent: native reparenting failed ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)+" -> "+toHexString(newParentHandle)+" - Trying recreation"); + } + destroy(false); + Window.this.visible = wasVisible; + reparentAction = ACTION_NATIVE_CREATION ; + } else { + if(wasVisible) { + Window.this.visible = true; + setVisibleImpl(true); + requestFocusImpl(); + display.dispatchMessages(); // status up2date } - } else if(wasVisible) { - Window.this.visible = true; - setVisibleImpl(true); - requestFocusImpl(); - getScreen().getDisplay().dispatchMessages(); // status up2date + } + } + + // not-else: re-entrance via reparentAction value change possible + if( ACTION_NATIVE_CREATION == reparentAction ) { + if(isVisible()) { + setVisible(true); // native creation + screen.getDisplay().dispatchMessages(); // status up2date } } if(DEBUG_IMPLEMENTATION) { - System.out.println("reparentWindow: END ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+", visible: "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentNativeWindow "+(null!=parentNativeWindow)); + System.err.println("reparentWindow: END ("+getThreadName()+") windowHandle "+toHexString(windowHandle)+", visible: "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentNativeWindow "+(null!=parentNativeWindow)); } } finally { windowUnlock(); @@ -722,13 +817,11 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer * In case the new parent is not null and a Window, * this window is added to it's list of children.<br></P> * - * @param newParent the new parent NativeWindow. If null, this Window becomes a top level window. - * @param newScreen if not null and this window handle is not yet set - * this Screen is being used. + * @param newParent The new parent NativeWindow. If null, this Window becomes a top level window. */ - public void reparentWindow(NativeWindow newParent, Screen newScreen) { + public void reparentWindow(NativeWindow newParent) { if(isValid()) { - runOnEDTIfAvail(true, new ReparentAction(newParent, newScreen)); + runOnEDTIfAvail(true, new ReparentAction(newParent)); if( isVisible() ) { sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener windowRepaint(0, 0, getWidth(), getHeight()); @@ -779,7 +872,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer } if(DEBUG_IMPLEMENTATION) { - System.out.println("Window setVisible: END ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+Window.this.visible); + System.err.println("Window setVisible: END ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+Window.this.visible); } } finally { windowUnlock(); @@ -815,7 +908,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer public void setVisible(boolean visible) { if(DEBUG_IMPLEMENTATION) { String msg = new String("Window setVisible: START ("+getThreadName()+") "+x+"/"+y+" "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible: "+this.visible+" -> "+visible+", parentWindowHandle "+toHexString(parentWindowHandle)+", parentNativeWindow "+(null!=parentNativeWindow)); - //System.out.println(msg); + //System.err.println(msg); Exception ee = new Exception(msg); ee.printStackTrace(); } @@ -852,9 +945,9 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer try{ if(DEBUG_IMPLEMENTATION) { String msg = new String("Window setSize: START "+this.width+"x"+this.height+" -> "+width+"x"+height+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)+", visible "+visible); - //System.out.println(msg); - Exception e = new Exception(msg); - e.printStackTrace(); + System.err.println(msg); + // Exception e = new Exception(msg); + // e.printStackTrace(); } if (width != this.width || this.height != height) { if(!fullscreen) { @@ -878,7 +971,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer } } if(DEBUG_IMPLEMENTATION) { - System.out.println("Window setSize: END "+this.width+"x"+this.height+", visibleAction "+visibleAction); + System.err.println("Window setSize: END "+this.width+"x"+this.height+", visibleAction "+visibleAction); } } finally { windowUnlock(); @@ -903,7 +996,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer windowLock(); try{ if(DEBUG_IMPLEMENTATION) { - System.out.println("Window setPosition: "+this.x+"/"+this.y+" -> "+x+"/"+y+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)); + System.err.println("Window setPosition: "+this.x+"/"+this.y+" -> "+x+"/"+y+", fs "+fullscreen+", windowHandle "+toHexString(windowHandle)); } if ( this.x != x || this.y != y ) { if(!fullscreen) { @@ -945,7 +1038,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer h = nfs_height; } if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.out.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h+", "+isUndecorated()); + System.err.println("X11Window fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h+", "+isUndecorated()); } this.fullscreen = fullscreen; setFullscreenImpl(fullscreen, x, y, w, h); @@ -1016,7 +1109,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer return true; } if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.windowRepaint: "+e); + System.err.println("Window.windowRepaint: "+e); // Exception ee = new Exception("Window.windowRepaint: "+e); // ee.printStackTrace(); } @@ -1139,7 +1232,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer return; // .. invalid .. } if(DEBUG_MOUSE_EVENT) { - System.out.println("doMouseEvent: enqueue"+enqueue+", wait "+wait+", "+MouseEvent.getEventTypeString(eventType)+ + System.err.println("doMouseEvent: enqueue"+enqueue+", wait "+wait+", "+MouseEvent.getEventTypeString(eventType)+ ", mod "+modifiers+", pos "+x+"/"+y+", button "+button); } if(button<0||button>MouseEvent.BUTTON_NUMBER) { @@ -1186,7 +1279,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer doEvent(enqueue, wait, e); if(null!=eClicked) { if(DEBUG_MOUSE_EVENT) { - System.out.println("doMouseEvent: synthesized MOUSE_CLICKED event"); + System.err.println("doMouseEvent: synthesized MOUSE_CLICKED event"); } doEvent(enqueue, wait, eClicked); } @@ -1246,7 +1339,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer protected void consumeMouseEvent(MouseEvent e) { if(DEBUG_MOUSE_EVENT) { - System.out.println("consumeMouseEvent: event: "+e); + System.err.println("consumeMouseEvent: event: "+e); } for(Iterator i = mouseListeners.iterator(); i.hasNext(); ) { @@ -1349,7 +1442,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer protected void consumeKeyEvent(KeyEvent e) { if(DEBUG_KEY_EVENT) { - System.out.println("consumeKeyEvent: "+e); + System.err.println("consumeKeyEvent: "+e); } for(Iterator i = keyListeners.iterator(); i.hasNext(); ) { KeyListener l = (KeyListener) i.next(); @@ -1437,7 +1530,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer protected void consumeWindowEvent(WindowEvent e) { if(DEBUG_WINDOW_EVENT) { - System.out.println("consumeWindowEvent: "+e); + System.err.println("consumeWindowEvent: "+e); } for(Iterator i = windowListeners.iterator(); i.hasNext(); ) { WindowListener l = (WindowListener) i.next(); @@ -1473,7 +1566,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer */ protected void focusChanged(boolean focusGained) { if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.focusChanged: "+focusGained); + System.err.println("Window.focusChanged: "+focusGained); } if (focusGained) { sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); @@ -1484,7 +1577,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer protected void visibleChanged(boolean visible) { if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.visibleChanged ("+getThreadName()+"): "+this.visible+" -> "+visible+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)); + System.err.println("Window.visibleChanged ("+getThreadName()+"): "+this.visible+" -> "+visible+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)); // Exception e = new Exception("Window.visibleChanged ("+getThreadName()+"): "+this.visible+" -> "+visible+" - windowHandle "+toHexString(windowHandle)+" parentWindowHandle "+toHexString(parentWindowHandle)); // e.printStackTrace(); } @@ -1493,7 +1586,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer protected void sizeChanged(int newWidth, int newHeight) { if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.sizeChanged: "+width+"x"+height+" -> "+newWidth+"x"+newHeight); + System.err.println("Window.sizeChanged: "+width+"x"+height+" -> "+newWidth+"x"+newHeight); } if(width != newWidth || height != newHeight) { width = newWidth; @@ -1508,7 +1601,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer protected void positionChanged(int newX, int newY) { if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.positionChanged: "+x+"/"+y+" -> "+newX+"/"+newY); + System.err.println("Window.positionChanged: "+x+"/"+y+" -> "+newX+"/"+newY); } if( 0==parentWindowHandle && ( x != newX || y != newY ) ) { x = newX; @@ -1532,7 +1625,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer protected void windowDestroyNotify() { if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.windowDestroyNotify START "+getThreadName()); + System.err.println("Window.windowDestroyNotify START "+getThreadName()); } enqueueWindowEvent(false, WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY); @@ -1542,13 +1635,13 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer } if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.windowDestroyeNotify END "+getThreadName()); + System.err.println("Window.windowDestroyeNotify END "+getThreadName()); } } protected void windowDestroyed() { if(DEBUG_IMPLEMENTATION) { - System.out.println("Window.windowDestroyed "+getThreadName()); + System.err.println("Window.windowDestroyed "+getThreadName()); } invalidate(); } diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index a342f9ba6..51b218aec 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -49,6 +49,7 @@ import com.jogamp.newt.event.MouseEvent; import com.jogamp.newt.event.MouseAdapter; import com.jogamp.newt.Screen; import com.jogamp.newt.Window; +import com.jogamp.newt.NewtFactory; import com.jogamp.newt.impl.Debug; public class NewtCanvasAWT extends java.awt.Canvas { @@ -91,7 +92,7 @@ public class NewtCanvasAWT extends java.awt.Canvas { public final boolean result = false; // NEWT shall always proceed requesting the native focus public void run() { if(DEBUG) { - System.out.println("FocusActionImpl.run() "+Window.getThreadName()); + System.err.println("FocusActionImpl.run() "+Window.getThreadName()); } NewtCanvasAWT.this.requestFocusAWTParent(); } @@ -180,16 +181,7 @@ public class NewtCanvasAWT extends java.awt.Canvas { } setSize(cont.getWidth(), cont.getHeight()); newtChild.setSize(cont.getWidth(), cont.getHeight()); - - Screen screen = null; - if( !newtChild.isNativeValid() ) { - Screen currentScreen = newtChild.getScreen(); - screen = NewtFactoryAWT.createCompatibleScreen(parent, currentScreen); - if( currentScreen != screen ) { - screen.setDestroyWhenUnused(true); - } - } - newtChild.reparentWindow(parent, screen); + newtChild.reparentWindow(parent); newtChild.setVisible(true); setWindowAdapter(true); newtChild.sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener @@ -199,7 +191,7 @@ public class NewtCanvasAWT extends java.awt.Canvas { setWindowAdapter(false); parent = null; newtChild.setVisible(false); - newtChild.reparentWindow(null, null); + newtChild.reparentWindow(null); } } diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java index 5c28f8452..b28d41f7c 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java @@ -77,63 +77,9 @@ public class NewtFactoryAWT extends NewtFactory { AWTGraphicsConfiguration.create(awtComp, (Capabilities) capsRequested.clone(), capsRequested); NativeWindow awtNative = NativeWindowFactory.getNativeWindow(awtComp, config); // a JAWTWindow if(DEBUG_IMPLEMENTATION) { - System.out.println("NewtFactoryAWT.getNativeWindow: "+awtComp+" -> "+awtNative); + System.err.println("NewtFactoryAWT.getNativeWindow: "+awtComp+" -> "+awtNative); } return awtNative; } - - public static Screen createCompatibleScreen(NativeWindow parent) { - return createCompatibleScreen(parent, null); - } - - public static Screen createCompatibleScreen(NativeWindow parent, Screen childScreen) { - // Get parent's NativeWindow details - AWTGraphicsConfiguration parentConfig = (AWTGraphicsConfiguration) parent.getGraphicsConfiguration(); - AWTGraphicsScreen parentScreen = (AWTGraphicsScreen) parentConfig.getScreen(); - AWTGraphicsDevice parentDevice = (AWTGraphicsDevice) parentScreen.getDevice(); - - final String type = NativeWindowFactory.getNativeWindowType(true); - - if(null != childScreen) { - // check if child Display/Screen is compatible already - Display childDisplay = childScreen.getDisplay(); - String parentDisplayName = childDisplay.validateDisplayName(null, parentDevice.getHandle()); - String childDisplayName = childDisplay.getName(); - boolean displayEqual = parentDisplayName.equals( childDisplayName ); - boolean screenEqual = parentScreen.getIndex() == childScreen.getIndex(); - if(DEBUG_IMPLEMENTATION) { - System.out.println("NewtFactoryAWT.createCompatibleScreen: Display: "+ - parentDisplayName+" =? "+childDisplayName+" : "+displayEqual+"; Screen: "+ - parentScreen.getIndex()+" =? "+childScreen.getIndex()+" : "+screenEqual); - } - if( displayEqual && screenEqual ) { - // match: display/screen - return childScreen; - } - } - - // Prep NEWT's Display and Screen according to the parent - Display display = NewtFactory.createDisplay(type, parentDevice.getHandle()); - return NewtFactory.createScreen(type, display, parentScreen.getIndex()); - } - - public static boolean isScreenCompatible(NativeWindow parent, Screen childScreen) { - // Get parent's NativeWindow details - AWTGraphicsConfiguration parentConfig = (AWTGraphicsConfiguration) parent.getGraphicsConfiguration(); - AWTGraphicsScreen parentScreen = (AWTGraphicsScreen) parentConfig.getScreen(); - AWTGraphicsDevice parentDevice = (AWTGraphicsDevice) parentScreen.getDevice(); - - Display childDisplay = childScreen.getDisplay(); - String parentDisplayName = childDisplay.validateDisplayName(null, parentDevice.getHandle()); - String childDisplayName = childDisplay.getName(); - if( ! parentDisplayName.equals( childDisplayName ) ) { - return false; - } - - if( parentScreen.getIndex() != childScreen.getIndex() ) { - return false; - } - return true; - } } diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 2aca37cab..0eb0f1571 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -224,8 +224,8 @@ public class GLWindow extends Window implements GLAutoDrawable { shouldNotCallThis(); } - public void reparentWindow(NativeWindow newParent, Screen newScreen) { - window.reparentWindow(newParent, newScreen); + public void reparentWindow(NativeWindow newParent) { + window.reparentWindow(newParent); } class VisibleAction implements Runnable { diff --git a/src/newt/classes/com/jogamp/newt/util/DefaultEDTUtil.java b/src/newt/classes/com/jogamp/newt/util/DefaultEDTUtil.java index 96bfc50e0..4c0df11fc 100644 --- a/src/newt/classes/com/jogamp/newt/util/DefaultEDTUtil.java +++ b/src/newt/classes/com/jogamp/newt/util/DefaultEDTUtil.java @@ -125,8 +125,10 @@ public class DefaultEDTUtil implements EDTUtil { } // wait until task finished, if requested // and no stop() call slipped through. - if( wait && !shouldStop ) { + if( wait && isRunning() ) { try { + // JAU FIXME + System.out.println(Thread.currentThread()+": Wait on Task. EDT: "+edt); rTaskLock.wait(); } catch (InterruptedException ie) { throwable = ie; |