diff options
Diffstat (limited to 'src/test')
102 files changed, 3746 insertions, 402 deletions
diff --git a/src/test/com/jogamp/opengl/test/android/NEWTElektronActivity.java b/src/test/com/jogamp/opengl/test/android/NEWTElektronActivity.java index 21eb8af2d..74419e564 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTElektronActivity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTElektronActivity.java @@ -62,7 +62,7 @@ public class NEWTElektronActivity extends NewtBaseActivity { setContentView(getWindow(), glWindow); glWindow.addGLEventListener(new ElektronenMultiplizierer()); - glWindow.getWindow().getScreen().addScreenModeListener(new ScreenModeListener() { + glWindow.getScreen().addScreenModeListener(new ScreenModeListener() { public void screenModeChangeNotify(ScreenMode sm) { } public void screenModeChanged(ScreenMode sm, boolean success) { System.err.println("ScreenMode Changed: "+sm); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTGearsES1Activity.java b/src/test/com/jogamp/opengl/test/android/NEWTGearsES1Activity.java index 337dafc71..ba861d012 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTGearsES1Activity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTGearsES1Activity.java @@ -62,7 +62,7 @@ public class NEWTGearsES1Activity extends NewtBaseActivity { setContentView(getWindow(), glWindow); glWindow.addGLEventListener(new GearsES1(1)); - glWindow.getWindow().getScreen().addScreenModeListener(new ScreenModeListener() { + glWindow.getScreen().addScreenModeListener(new ScreenModeListener() { public void screenModeChangeNotify(ScreenMode sm) { } public void screenModeChanged(ScreenMode sm, boolean success) { System.err.println("ScreenMode Changed: "+sm); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java index 6abb0b354..89ecf4cb9 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2Activity.java @@ -65,7 +65,7 @@ public class NEWTGearsES2Activity extends NewtBaseActivity { GearsES2 demo = new GearsES2(0); // demo.enableAndroidTrace(true); glWindow.addGLEventListener(demo); - glWindow.getWindow().getScreen().addScreenModeListener(new ScreenModeListener() { + glWindow.getScreen().addScreenModeListener(new ScreenModeListener() { public void screenModeChangeNotify(ScreenMode sm) { } public void screenModeChanged(ScreenMode sm, boolean success) { System.err.println("ScreenMode Changed: "+sm); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2TransActivity.java b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2TransActivity.java index 691151ef3..d6b7507a3 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTGearsES2TransActivity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTGearsES2TransActivity.java @@ -61,7 +61,7 @@ public class NEWTGearsES2TransActivity extends NewtBaseActivity { setContentView(getWindow(), glWindow); glWindow.addGLEventListener(new GearsES2(1)); - glWindow.getWindow().getScreen().addScreenModeListener(new ScreenModeListener() { + glWindow.getScreen().addScreenModeListener(new ScreenModeListener() { public void screenModeChangeNotify(ScreenMode sm) { } public void screenModeChanged(ScreenMode sm, boolean success) { System.err.println("ScreenMode Changed: "+sm); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTGraphUI1pActivity.java b/src/test/com/jogamp/opengl/test/android/NEWTGraphUI1pActivity.java index 83f35879b..1efedcd6d 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTGraphUI1pActivity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTGraphUI1pActivity.java @@ -61,7 +61,7 @@ public class NEWTGraphUI1pActivity extends NewtBaseActivity { setContentView(getWindow(), glWindow); glWindow.addGLEventListener(new GPUUISceneGLListener0A(0)); - glWindow.getWindow().getScreen().addScreenModeListener(new ScreenModeListener() { + glWindow.getScreen().addScreenModeListener(new ScreenModeListener() { public void screenModeChangeNotify(ScreenMode sm) { } public void screenModeChanged(ScreenMode sm, boolean success) { System.err.println("ScreenMode Changed: "+sm); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTGraphUI2pActivity.java b/src/test/com/jogamp/opengl/test/android/NEWTGraphUI2pActivity.java index 17924d43d..39fb5e2cc 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTGraphUI2pActivity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTGraphUI2pActivity.java @@ -62,7 +62,7 @@ public class NEWTGraphUI2pActivity extends NewtBaseActivity { setContentView(getWindow(), glWindow); glWindow.addGLEventListener(new GPUUISceneGLListener0A(Region.VBAA_RENDERING_BIT)); - glWindow.getWindow().getScreen().addScreenModeListener(new ScreenModeListener() { + glWindow.getScreen().addScreenModeListener(new ScreenModeListener() { public void screenModeChangeNotify(ScreenMode sm) { } public void screenModeChanged(ScreenMode sm, boolean success) { System.err.println("ScreenMode Changed: "+sm); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES1Activity.java b/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES1Activity.java index 24b4eaf0c..99d7fd723 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES1Activity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES1Activity.java @@ -61,7 +61,7 @@ public class NEWTRedSquareES1Activity extends NewtBaseActivity { setContentView(getWindow(), glWindow); glWindow.addGLEventListener(new RedSquareES1(1)); - glWindow.getWindow().getScreen().addScreenModeListener(new ScreenModeListener() { + glWindow.getScreen().addScreenModeListener(new ScreenModeListener() { public void screenModeChangeNotify(ScreenMode sm) { } public void screenModeChanged(ScreenMode sm, boolean success) { System.err.println("ScreenMode Changed: "+sm); diff --git a/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES2Activity.java b/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES2Activity.java index 51cddd523..804e627a5 100644 --- a/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES2Activity.java +++ b/src/test/com/jogamp/opengl/test/android/NEWTRedSquareES2Activity.java @@ -64,7 +64,7 @@ public class NEWTRedSquareES2Activity extends NewtBaseActivity { final RedSquareES2 demo = new RedSquareES2(0); // demo.enableAndroidTrace(true); glWindow.addGLEventListener(demo); - glWindow.getWindow().getScreen().addScreenModeListener(new ScreenModeListener() { + glWindow.getScreen().addScreenModeListener(new ScreenModeListener() { public void screenModeChangeNotify(ScreenMode sm) { } public void screenModeChanged(ScreenMode sm, boolean success) { System.err.println("ScreenMode Changed: "+sm); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java index 55d3371c9..b6c3cc7fe 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestRegionRendererNEWT01.java @@ -32,11 +32,6 @@ public class TestRegionRendererNEWT01 extends UITestCase { org.junit.runner.JUnitCore.main(tstname);
}
- @BeforeClass
- public static void initClass() {
- GLProfile.initSingleton(true);
- }
-
static void destroyWindow(GLWindow window) {
if(null!=window) {
window.destroy();
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java index 9fd0c05e7..8f03af7c9 100755 --- a/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestTextRendererNEWT01.java @@ -35,11 +35,6 @@ public class TestTextRendererNEWT01 extends UITestCase { org.junit.runner.JUnitCore.main(tstname);
}
- @BeforeClass
- public static void initClass() {
- GLProfile.initSingleton(true);
- }
-
static void destroyWindow(GLWindow window) {
if(null!=window) {
window.destroy();
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java index 5e0c266e6..160dc0ffe 100755 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo01.java @@ -55,7 +55,6 @@ public class GPURegionNewtDemo01 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java index f1db1ccdd..e7b5c73c5 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPURegionNewtDemo02.java @@ -52,7 +52,6 @@ public class GPURegionNewtDemo02 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java index bcd60d441..d257f78fc 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java @@ -49,7 +49,6 @@ public class GPUTextNewtDemo01 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java index 5981e7971..1b71cd781 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo02.java @@ -57,7 +57,6 @@ public class GPUTextNewtDemo02 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java index 91f66875b..0563ab2cf 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo01.java @@ -16,7 +16,6 @@ public class GPUUISceneNewtDemo01 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java index a6cd770d1..4c8da139e 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneNewtDemo02.java @@ -17,7 +17,6 @@ public class GPUUISceneNewtDemo02 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java index 27b7ecc13..0577c5ff0 100644 --- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/UINewtDemo01.java @@ -54,7 +54,6 @@ public class UINewtDemo01 { static final boolean TRACE = false; public static void main(String[] args) { - GLProfile.initSingleton(true); GLProfile glp = GLProfile.getGL2ES2(); GLCapabilities caps = new GLCapabilities(glp); caps.setAlphaBits(4); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug00NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug00NEWT.java index a42247b12..62e74466f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug00NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug00NEWT.java @@ -55,11 +55,6 @@ public class TestGLDebug00NEWT extends UITestCase { static String dbgTstMsg0 = "Hello World"; static int dbgTstId0 = 42; - @BeforeClass - public static void initClass() { - // GLProfile.initSingleton(true); - } - public class WindowContext { public final Window window; public final GLContext context; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java index 6ab6714dc..f9b566c25 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLDebug01NEWT.java @@ -41,7 +41,6 @@ import javax.media.opengl.GLRunnable; import org.junit.Assert; import org.junit.Test; -import org.junit.BeforeClass; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.util.UITestCase; @@ -51,11 +50,6 @@ public class TestGLDebug01NEWT extends UITestCase { static String dbgTstMsg0 = "Hello World"; static int dbgTstId0 = 42; - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - } - GLWindow createWindow(GLProfile glp, boolean debugGL) { GLCapabilities caps = new GLCapabilities(glp); // diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLExtensionQueryOffscreen.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLExtensionQueryOffscreen.java index 5af526364..e4245ef11 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLExtensionQueryOffscreen.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLExtensionQueryOffscreen.java @@ -42,6 +42,8 @@ import javax.media.opengl.GLContext; import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLProfile; +import jogamp.opengl.GLDrawableFactoryImpl; + import org.junit.Test; public class TestGLExtensionQueryOffscreen { @@ -52,9 +54,12 @@ public class TestGLExtensionQueryOffscreen { instance.testJogl2ExtensionCheck2(); } + /** + * @deprecated This test uses a non public API in jogamp.opengl.* and hence is not recommended + */ @Test public void testJogl2ExtensionCheck1() { - GLDrawableFactory factory = GLDrawableFactory.getDesktopFactory(); + GLDrawableFactoryImpl factory = (GLDrawableFactoryImpl) GLDrawableFactory.getDesktopFactory(); GLContext sharedContext = factory.getOrCreateSharedContext(null); sharedContext.makeCurrent(); String extensions; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java index 7813482e1..6a5f76ff9 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java @@ -137,17 +137,6 @@ public class TestGLProfile01NEWT extends UITestCase { dumpVersion(glp); } - @Test - public void test06GLProfileShutdownRecreate() throws InterruptedException { - GLProfile.shutdown(); - GLProfile.initSingleton(true); - System.out.println("GLProfile.getDefault(): "+GLProfile.getDefault()); - System.out.println("GLProfile.getDefaultDesktopDevice(): "+GLProfile.getDefaultDesktopDevice()); - System.out.println("GLProfile.getDefaultEGLDevice(): "+GLProfile.getDefaultEGLDevice()); - System.out.println("GLProfile.getDefaultDevice(): "+GLProfile.getDefaultDevice()); - } - - protected void dumpVersion(GLProfile glp) throws InterruptedException { GLCapabilities caps = new GLCapabilities(glp); GLWindow glWindow = GLWindow.create(caps); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java new file mode 100644 index 000000000..fc025d023 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestInitConcurrentNEWT.java @@ -0,0 +1,230 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.io.IOException; + +import javax.media.nativewindow.Capabilities; +import javax.media.nativewindow.util.InsetsImmutable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Window; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +public class TestInitConcurrentNEWT extends UITestCase { + + static final int demoSize = 128; + + static long duration = 300; // ms + + static InsetsImmutable insets = null; + static int scrnHeight, scrnWidth; + static int num_x, num_y; + + @BeforeClass + public static void initClass() { + Window dummyWindow = NewtFactory.createWindow(new Capabilities()); + dummyWindow.setSize(demoSize, demoSize); + dummyWindow.setVisible(true); + Assert.assertEquals(true, dummyWindow.isVisible()); + Assert.assertEquals(true, dummyWindow.isNativeValid()); + insets = dummyWindow.getInsets(); + scrnHeight = dummyWindow.getScreen().getHeight(); + scrnWidth = dummyWindow.getScreen().getWidth(); + num_x = scrnWidth / ( demoSize + insets.getTotalWidth() ) - 2; + num_y = scrnHeight / ( demoSize + insets.getTotalHeight() ) - 2; + dummyWindow.destroy(); + } + + public class JOGLTask implements Runnable { + private int id; + private Object postSync; + private boolean done = false; + + public JOGLTask(Object postSync, int id) { + this.postSync = postSync; + this.id = id; + } + public void run() { + int x = ( id % num_x ) * ( demoSize + insets.getTotalHeight() ); + int y = ( (id / num_x) % num_y ) * ( demoSize + insets.getTotalHeight() ); + + System.err.println("JOGLTask "+id+": START: "+x+"/"+y+" - "+Thread.currentThread().getName()); + GLWindow glWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault())); + Assert.assertNotNull(glWindow); + glWindow.setTitle("Task "+id); + glWindow.setPosition(x + insets.getLeftWidth(), y + insets.getTopHeight() ); + + glWindow.addGLEventListener(new GearsES2(0)); + + Animator animator = new Animator(glWindow); + + glWindow.setSize(demoSize, demoSize); + glWindow.setVisible(true); + animator.setUpdateFPSFrames(60, null); + animator.start(); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(true, glWindow.isVisible()); + Assert.assertEquals(true, glWindow.isNativeValid()); + Assert.assertEquals(true, glWindow.isRealized()); + System.err.println("JOGLTask "+id+": RUNNING: "+Thread.currentThread().getName()); + + while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + animator.stop(); + glWindow.destroy(); + + System.err.println("JOGLTask "+id+": DONE/SYNC: "+Thread.currentThread().getName()); + synchronized (postSync) { + done = true; + System.err.println("JOGLTask "+id+": END: "+Thread.currentThread().getName()); + postSync.notifyAll(); + } + } + + public boolean done() { return done; } + } + + protected static boolean done(JOGLTask[] tasks) { + for(int i=tasks.length-1; i>=0; i--) { + if(!tasks[i].done()) { + return false; + } + } + return true; + } + protected static String doneDump(JOGLTask[] tasks) { + StringBuffer sb = new StringBuffer(); + sb.append("["); + for(int i=0; i<tasks.length; i++) { + if(i>0) { + sb.append(", "); + } + sb.append(i).append(": ").append(tasks[i].done()); + } + sb.append("]"); + return sb.toString(); + } + + protected static boolean isDead(Thread[] threads) { + for(int i=threads.length-1; i>=0; i--) { + if(threads[i].isAlive()) { + return false; + } + } + return true; + } + protected static String isAliveDump(Thread[] threads) { + StringBuffer sb = new StringBuffer(); + sb.append("["); + for(int i=0; i<threads.length; i++) { + if(i>0) { + sb.append(", "); + } + sb.append(i).append(": ").append(threads[i].isAlive()); + } + sb.append("]"); + return sb.toString(); + } + + protected void runJOGLTasks(int num) throws InterruptedException { + final String currentThreadName = Thread.currentThread().getName(); + final Object sync = new Object(); + final JOGLTask[] tasks = new JOGLTask[num]; + final Thread[] threads = new Thread[num]; + int i; + for(i=0; i<num; i++) { + tasks[i] = new JOGLTask(sync, i); + threads[i] = new Thread(tasks[i], currentThreadName+"-jt"+i); + } + for(i=0; i<num; i++) { + threads[i].start(); + } + synchronized (sync) { + while(!done(tasks)) { + try { + sync.wait(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + Assert.assertTrue("Tasks are incomplete. Complete: "+doneDump(tasks), done(tasks)); + i=0; + while(i<30 && !isDead(threads)) { + Thread.sleep(100); + i++; + } + Assert.assertTrue("Threads are still alive after 3s. Alive: "+isAliveDump(threads), isDead(threads)); + } + + @Test + public void test01OneThread() throws InterruptedException { + runJOGLTasks(1); + } + + @Test + public void test02TwoThreads() throws InterruptedException { + runJOGLTasks(2); + } + + @Test + public void test16SixteenThreads() throws InterruptedException { + runJOGLTasks(16); + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + String tstname = TestInitConcurrentNEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMainVersionGLCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMainVersionGLCanvasAWT.java new file mode 100644 index 000000000..5523ce5ce --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMainVersionGLCanvasAWT.java @@ -0,0 +1,52 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.io.IOException; + +import javax.media.opengl.awt.GLCanvas; + +import org.junit.Test; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +public class TestMainVersionGLCanvasAWT extends UITestCase { + + @Test + public void testMain() throws InterruptedException { + GLCanvas.main(null); + } + + + public static void main(String args[]) throws IOException { + String tstname = TestMainVersionGLCanvasAWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMainVersionGLWindowNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMainVersionGLWindowNEWT.java new file mode 100644 index 000000000..d178e34f4 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestMainVersionGLWindowNEWT.java @@ -0,0 +1,50 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.io.IOException; +import org.junit.Test; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.UITestCase; + +public class TestMainVersionGLWindowNEWT extends UITestCase { + + @Test + public void testMain() throws InterruptedException { + GLWindow.main(null); + } + + + public static void main(String args[]) throws IOException { + String tstname = TestMainVersionGLWindowNEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestNVSwapGroupNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestNVSwapGroupNEWT.java index 0f64738de..05f122bb4 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestNVSwapGroupNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestNVSwapGroupNEWT.java @@ -52,7 +52,6 @@ public class TestNVSwapGroupNEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); glp = GLProfile.getDefault(); Assert.assertNotNull(glp); caps = new GLCapabilities(glp); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPBufferDeadlockAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPBufferDeadlockAWT.java new file mode 100644 index 000000000..5f04ed616 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestPBufferDeadlockAWT.java @@ -0,0 +1,127 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.awt.EventQueue; +import java.lang.reflect.InvocationTargetException; + +import javax.media.opengl.DefaultGLCapabilitiesChooser; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLPbuffer; +import javax.media.opengl.GLProfile; + +import jogamp.nativewindow.jawt.JAWTUtil; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.common.util.RunnableTask; +import com.jogamp.opengl.test.junit.util.UITestCase; + +public class TestPBufferDeadlockAWT extends UITestCase { + static GLProfile glp; + static int width, height; + + @BeforeClass + public static void initClass() { + glp = GLProfile.getDefault(); + Assert.assertNotNull( glp ); + width = 512; + height = 512; + } + + protected void runTestGL( GLCapabilities caps ) throws InterruptedException, InvocationTargetException { + final GLPbuffer pbuffer = GLDrawableFactory.getFactory( GLProfile.get( "GL2" ) ).createGLPbuffer( + null, + caps, new DefaultGLCapabilitiesChooser(), + 512, 512, + null + ); + + final boolean[] done = {false}; + final Runnable pbufferCreationAction = new Runnable() { + public void run() { + System.err.println("AA.1"); + pbuffer.display(); + done[ 0 ] = true; + System.err.println("AA.X"); + } + }; + + EventQueue.invokeAndWait(new Runnable() { + public void run() { + Assert.assertTrue(EventQueue.isDispatchThread()); + JAWTUtil.lockToolkit(); + try { + final RunnableTask rTask = new RunnableTask(pbufferCreationAction, new Object(), false); + System.err.println("BB.0: "+rTask.getSyncObject()); + synchronized (rTask.getSyncObject()) { + System.err.println("BB.1: "+rTask.getSyncObject()); + new Thread(rTask, Thread.currentThread().getName()+"-Pbuffer_Creation").start(); + try { + System.err.println("BB.2"); + rTask.getSyncObject().wait(); + System.err.println("BB.3"); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + System.err.println("BB.X"); + } + } finally { + JAWTUtil.unlockToolkit(); + } + } + }); + Assert.assertTrue(done[0]); + } + + @Test(timeout = 2000) // 2s timeout + public void testDeadlock() throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities( glp ); + runTestGL( caps ); + } + + static long duration = 500; // ms + + public static void main( String args[] ) { + for ( int i = 0; i < args.length; i++ ) { + if ( args[ i ].equals( "-time" ) ) { + i++; + try { + duration = Integer.parseInt( args[ i ] ); + } + catch ( Exception ex ) { + ex.printStackTrace(); + } + } + } + org.junit.runner.JUnitCore.main( TestPBufferDeadlockAWT.class.getName() ); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java index f8f835c3b..308094720 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT.java @@ -56,7 +56,6 @@ public class TestSharedContextListNEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); glp = GLProfile.getDefault(); Assert.assertNotNull(glp); caps = new GLCapabilities(glp); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT2.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT2.java new file mode 100644 index 000000000..4281572d7 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextListNEWT2.java @@ -0,0 +1,156 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.io.IOException; + +import com.jogamp.newt.opengl.GLWindow; + +import javax.media.nativewindow.util.InsetsImmutable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears; +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.UITestCase; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestSharedContextListNEWT2 extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + static int width, height; + GLWindow sharedDrawable; + Gears sharedGears; + + @BeforeClass + public static void initClass() { + glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + width = 256; + height = 256; + } + + private void initShared() { + sharedDrawable = GLWindow.create(caps); + Assert.assertNotNull(sharedDrawable); + sharedGears = new Gears(0); + Assert.assertNotNull(sharedGears); + sharedDrawable.addGLEventListener(sharedGears); + sharedDrawable.setSize(width, height); + sharedDrawable.setVisible(true); + // init and render one frame, which will setup the Gears display lists + sharedDrawable.display(); + } + + private void releaseShared() { + Assert.assertNotNull(sharedDrawable); + sharedDrawable.destroy(); + sharedDrawable = null; + } + + protected GLWindow runTestGL(Animator animator, int x, int y, boolean useShared, boolean vsync) throws InterruptedException { + GLWindow glWindow = GLWindow.create(caps); + + Assert.assertNotNull(glWindow); + glWindow.setTitle("Shared Gears NEWT Test: "+x+"/"+y+" shared "+useShared); + if(useShared) { + glWindow.setSharedContext(sharedDrawable.getContext()); + } + + glWindow.setSize(width, height); + + Gears gears = new Gears(vsync ? 1 : 0); + if(useShared) { + gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3()); + } + glWindow.addGLEventListener(gears); + + animator.add(glWindow); + animator.start(); + glWindow.setVisible(true); + + Assert.assertTrue(AWTRobotUtil.waitForRealized(glWindow, true)); + Assert.assertTrue(AWTRobotUtil.waitForVisible(glWindow, true)); + glWindow.setPosition(x, y); + + return glWindow; + } + + @Test + public void test01() throws InterruptedException { + initShared(); + GLWindow f1 = runTestGL(new Animator(), 0, 0, true, false); + InsetsImmutable insets = f1.getInsets(); + GLWindow f2 = runTestGL(new Animator(), f1.getX()+width+insets.getTotalWidth(), + f1.getY()+0, true, false); + GLWindow f3 = runTestGL(new Animator(), f1.getX()+0, + f1.getY()+height+insets.getTotalHeight(), true, false); + + try { + Thread.sleep(duration); + } catch(Exception e) { + e.printStackTrace(); + } + + // here we go again: On AMD/X11 the create/destroy sequence must be the same + // even though this is against the chicken/egg logic here .. + releaseShared(); + + f1.destroy(); + f2.destroy(); + f3.destroy(); + + // see above .. + // releaseShared(); + } + + static long duration = 2000; // ms + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + /** + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + System.err.println("Press enter to continue"); + System.err.println(stdin.readLine()); */ + org.junit.runner.JUnitCore.main(TestSharedContextListNEWT2.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java new file mode 100644 index 000000000..60f46fe9e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java @@ -0,0 +1,778 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; + +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLContext; +import javax.media.opengl.GLDrawableFactory; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLPbuffer; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; +import javax.media.opengl.glu.GLU; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JSlider; +import javax.swing.SwingUtilities; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.common.nio.Buffers; +import com.jogamp.newt.awt.NewtCanvasAWT; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLBuffers; + + +/** + * TestSharedContextNewtAWTBug523 + * + * Opens a single JFrame with two OpenGL windows and sliders to adjust the view orientation. + * + * Each window renders a red triangle and a blue triangle. + * The red triangle is rendered using glBegin / glVertex / glEnd. + * The blue triangle is rendered using vertex buffer objects bound to a vertex array object. + * + * If static useNewt is true, then those windows are GLWindow objects in a NewtCanvasAWT. + * If static useNewt is false, then those windows are GLCanvas objects. + * + * If shareContext is true, then the two OpenGL windows are initialized with a shared context, + * so that they share the vertex buffer and array objects and display lists. + * If shareContext is false, then the two OpenGL windows each have their own context, and the blue + * triangle fails to render in one of the windows. + * + * The four test cases run through the four combinations of useNewt and shareContext. + * + * Similar test cases are {@link TestSharedContextListNEWT}, {@link TestSharedContextListAWT}, + * {@link TestSharedContextVBOES2NEWT} and {@link TestSharedContextVBOES1NEWT}. + * + */ +public class TestSharedContextNewtAWTBug523 extends UITestCase { + + static long durationPerTest = 1000; + + // counters for instances of event listener TwoTriangles + // private static int instanceCounter; + private static int initializationCounter; + + // This semaphore is released once each time a GLEventListener destroy method is called. + // The main thread waits twice on this semaphore to ensure both canvases have finished cleaning up. + private static Semaphore disposalCompleteSemaphore = new Semaphore(0); + + // Buffer objects can be shared across shared OpenGL context. + // If we run with sharedContext, then the tests will use these shared buffer objects, + // otherwise each event listener allocates its own buffer objects. + private static int [] sharedVertexBufferObjects = {0}; + private static int [] sharedIndexBufferObjects = {0}; + private static FloatBuffer sharedVertexBuffer; + private static IntBuffer sharedIndexBuffer; + + static private GLPbuffer initShared(GLCapabilities caps) { + GLPbuffer sharedDrawable = GLDrawableFactory.getFactory(caps.getGLProfile()).createGLPbuffer(null, caps, null, 64, 64, null); + Assert.assertNotNull(sharedDrawable); + // init and render one frame, which will setup the Gears display lists + sharedDrawable.display(); + return sharedDrawable; + } + + static private void releaseShared(GLPbuffer sharedDrawable) { + if(null != sharedDrawable) { + sharedDrawable.destroy(); + } + } + + // inner class that implements the event listener + static class TwoTriangles implements GLEventListener { + + boolean useShared; + int canvasWidth; + int canvasHeight; + private float boundsRadius = 2f; + private float viewDistance; + private float viewDistanceFactor = 1.0f; + private float xAxisRotation; + private float yAxisRotation; + private float viewFovDegrees = 15f; + + // vertex array objects cannot be shared across open gl canvases; + // + // However, display lists can be shared across GLCanvas instances (if those canvases are initialized with the same GLContext), + // including a display list created in one context that uses a VAO. + private int [] vertexArrayObjects = {0}; + + // Buffer objects can be shared across canvas instances, if those canvases are initialized with the same GLContext. + // If we run with sharedBufferObjects true, then the tests will use these shared buffer objects. + // If we run with sharedBufferObjects false, then each event listener allocates its own buffer objects. + private int [] privateVertexBufferObjects = {0}; + private int [] privateIndexBufferObjects = {0}; + private FloatBuffer privateVertexBuffer; + private IntBuffer privateIndexBuffer; + + TwoTriangles (int canvasWidth, int canvasHeight, boolean useShared) { + // instanceNum = instanceCounter++; + this.canvasWidth = canvasWidth; + this.canvasHeight = canvasHeight; + this.useShared = useShared; + } + + public void setXAxisRotation(float xRot) { + xAxisRotation = xRot; + } + + public void setYAxisRotation(float yRot) { + yAxisRotation = yRot; + } + + public void setViewDistanceFactor(float factor) { + viewDistanceFactor = factor; + } + + + public void init(GLAutoDrawable drawable) { + GL2 gl2 = drawable.getGL().getGL2(); + + System.err.println("INIT GL IS: " + gl2.getClass().getName()); + + // Disable VSync + gl2.setSwapInterval(0); + + // Setup the drawing area and shading mode + gl2.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + + // the first instance of TwoTriangles initializes the shared buffer objects; + // synchronizing to deal with potential liveness issues if the data is intialized from one thread and used on another + synchronized (this) { + gl2.glGenVertexArrays(1, vertexArrayObjects, 0); + + gl2.glBindVertexArray(vertexArrayObjects[0]); + + // use either the shared or private vertex buffers, as + int [] vertexBufferObjects; + int [] indexBufferObjects; + FloatBuffer vertexBuffer; + IntBuffer indexBuffer; + // + if (useShared) { + vertexBufferObjects = sharedVertexBufferObjects; + indexBufferObjects = sharedIndexBufferObjects; + vertexBuffer = sharedVertexBuffer; + indexBuffer = sharedIndexBuffer; + } else { + vertexBufferObjects = privateVertexBufferObjects; + indexBufferObjects = privateIndexBufferObjects; + vertexBuffer = privateVertexBuffer; + indexBuffer = privateIndexBuffer; + } + + // if buffer sharing is enabled, then the first of the two event listeners to be + // initialized will allocate the buffers, and the other will re-use the allocated one + if (vertexBufferObjects[0] == 0) { + vertexBuffer = GLBuffers.newDirectFloatBuffer(18); + vertexBuffer.put(new float[]{ + 1.0f, -0.5f, 0f, // vertex 1 + 0f, 0f, 1f, // normal 1 + 1.5f, -0.5f, 0f, // vertex 2 + 0f, 0f, 1f, // normal 2 + 1.0f, 0.5f, 0f, // vertex 3 + 0f, 0f, 1f // normal 3 + }); + vertexBuffer.position(0); + + gl2.glGenBuffers(1, vertexBufferObjects, 0); + gl2.glBindBuffer(GL2.GL_ARRAY_BUFFER, vertexBufferObjects[0]); + gl2.glBufferData(GL2.GL_ARRAY_BUFFER, vertexBuffer.capacity() * Buffers.SIZEOF_FLOAT, vertexBuffer, GL2.GL_STATIC_DRAW); + } + + // A check in the case that buffer sharing is enabled but context sharing is not enabled -- in that + // case, the buffer objects are not shareable, and the blue triangle cannot be rendereds. + // Furthermore, although the calls to bind and draw elements do not cause an error from glGetError + // when this check is removed, true blue triangle is not rendered anyways, and more importantly, + // I found that with my system glDrawElements causes a runtime exception 50% of the time. Executing the binds + // to unshareable buffers sets up glDrawElements for unpredictable crashes -- sometimes it does, sometimes not. + if (gl2.glIsBuffer(vertexBufferObjects[0])) { + gl2.glBindBuffer(GL2.GL_ARRAY_BUFFER, vertexBufferObjects[0]); + // + gl2.glEnableClientState(GL2.GL_VERTEX_ARRAY); + gl2.glVertexPointer(3, GL2.GL_FLOAT, 6 * GLBuffers.SIZEOF_FLOAT, 0); + // + gl2.glEnableClientState(GL2.GL_NORMAL_ARRAY); + gl2.glNormalPointer(GL2.GL_FLOAT, 6 * GLBuffers.SIZEOF_FLOAT, 3 * GLBuffers.SIZEOF_FLOAT); + } + + if (indexBufferObjects[0] == 0) { + indexBuffer = GLBuffers.newDirectIntBuffer(3); + indexBuffer.put(new int[]{0, 1, 2}); + indexBuffer.position(0); + + gl2.glGenBuffers(1, indexBufferObjects, 0); + gl2.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, indexBufferObjects[0]); + gl2.glBufferData(GL2.GL_ELEMENT_ARRAY_BUFFER, indexBuffer.capacity() * Buffers.SIZEOF_INT, indexBuffer, GL2.GL_STATIC_DRAW); + } + + // again, a check in the case that buffer sharing is enabled but context sharing is not enabled + if (gl2.glIsBuffer(indexBufferObjects[0])) { + gl2.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, indexBufferObjects[0]); + } + + gl2.glBindVertexArray(0); + gl2.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, 0); + gl2.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0); + gl2.glDisableClientState(GL2.GL_VERTEX_ARRAY); + gl2.glDisableClientState(GL2.GL_NORMAL_ARRAY); + + initializationCounter++; + } // synchronized (this) + + + viewDistance = setupViewFrustum(gl2, canvasWidth, canvasHeight, boundsRadius, 1.0f, viewFovDegrees); + + } + + public void dispose(GLAutoDrawable drawable) { + + synchronized (this) { + initializationCounter--; + + GL2 gl2 = drawable.getGL().getGL2(); + + gl2.glDeleteVertexArrays(1, vertexArrayObjects, 0); + vertexArrayObjects[0] = 0; + logAnyErrorCodes(gl2, "display"); + + // release shared resources + if (initializationCounter == 0 || !useShared) { + // use either the shared or private vertex buffers, as + int [] vertexBufferObjects; + int [] indexBufferObjects; + if (useShared) { + vertexBufferObjects = sharedVertexBufferObjects; + indexBufferObjects = sharedIndexBufferObjects; + } else { + vertexBufferObjects = privateVertexBufferObjects; + indexBufferObjects = privateIndexBufferObjects; + } + + gl2.glDeleteBuffers(1, vertexBufferObjects, 0); + gl2.glDeleteBuffers(1, indexBufferObjects, 0); + vertexBufferObjects[0] = 0; + indexBufferObjects[0] = 0; + logAnyErrorCodes(gl2, "display"); + } + + // release the main thread once for each disposal + disposalCompleteSemaphore.release(); + } // synchronized (this) + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + + public void display(GLAutoDrawable drawable) { + + // wait until all instances are initialized before attempting to draw using the + // vertex array object, because the buffers are allocated in init and when the + // buffers are shared, we need to ensure that they are allocated before trying to use thems + synchronized (this) { + if (initializationCounter != 2) { + return; + } + } + + GL2 gl2 = drawable.getGL().getGL2(); + GLU glu = new GLU(); + + // Clear the drawing area + gl2.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); + + gl2.glViewport(0, 0, canvasWidth, canvasHeight); + gl2.glMatrixMode(GL2.GL_PROJECTION); + gl2.glLoadIdentity(); + glu.gluPerspective(viewFovDegrees, (float)canvasWidth/(float)canvasHeight, + viewDistance*viewDistanceFactor-boundsRadius, viewDistance*viewDistanceFactor+boundsRadius); + + // Reset the current matrix to the "identity" + gl2.glMatrixMode(GL2.GL_MODELVIEW); + gl2.glLoadIdentity(); + + // draw the scene + gl2.glPushAttrib(GL2.GL_ALL_ATTRIB_BITS); + gl2.glPushMatrix(); + + glu.gluLookAt(0, 0, 0 + viewDistance*viewDistanceFactor, 0, 0, 0, 0, 1, 0); + gl2.glRotatef(xAxisRotation, 1, 0, 0); + gl2.glRotatef(yAxisRotation, 0, 1, 0); + + gl2.glDisable(GL2.GL_CULL_FACE); + gl2.glEnable(GL2.GL_DEPTH_TEST); + + // draw the triangles + drawTwoTriangles(gl2); + + gl2.glPopMatrix(); + gl2.glPopAttrib(); + + // Flush all drawing operations to the graphics card + gl2.glFlush(); + + logAnyErrorCodes(gl2, "display"); + } + + public void drawTwoTriangles(GL2 gl2) { + + // draw a red triangle the old fashioned way + gl2.glColor3f(1f, 0f, 0f); + gl2.glBegin(GL2.GL_TRIANGLES); + gl2.glVertex3d(-1.5, -0.5, 0); + gl2.glNormal3d(0, 0, 1); + gl2.glVertex3d(-0.5, -0.5, 0); + gl2.glNormal3d(0, 0, 1); + gl2.glVertex3d(-0.75, 0.5, 0); + gl2.glNormal3d(0, 0, 1); + gl2.glEnd(); + + // draw the blue triangle using a vertex array object, sharing the vertex and index buffer objects across + // contexts; if context sharing is not initialized, then one window will simply have to live without a blue triangle + // + // synchronizing to deal with potential liveness issues if the data is intialized from one + // thread and used on another + boolean vaoBound = false; + // use either the shared or private vertex buffers, as + int [] vertexBufferObjects; + int [] indexBufferObjects; + synchronized (this) { + if (useShared) { + vertexBufferObjects = sharedVertexBufferObjects; + indexBufferObjects = sharedIndexBufferObjects; + } else { + vertexBufferObjects = privateVertexBufferObjects; + indexBufferObjects = privateIndexBufferObjects; + } + } // synchronized (this) + + // A check in the case that buffer sharing is enabled but context sharing is not enabled -- in that + // case, the buffer objects are not shareable, and the blue triangle cannot be rendereds. + // Furthermore, although the calls to bind and draw elements do not cause an error from glGetError + // when this check is removed, true blue triangle is not rendered anyways, and more importantly, + // I found that with my system glDrawElements causes a runtime exception 50% of the time. Executing the binds + // to unshareable buffers sets up glDrawElements for unpredictable crashes -- sometimes it does, sometimes not. + if (gl2.glIsVertexArray(vertexArrayObjects[0]) && + gl2.glIsBuffer(indexBufferObjects[0]) && gl2.glIsBuffer(vertexBufferObjects[0])) { + gl2.glBindVertexArray(vertexArrayObjects[0]); + gl2.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, indexBufferObjects[0]); + vaoBound = true; + } + + logAnyErrorCodes(gl2, "drawTwoTriangles"); + + if (vaoBound) { + gl2.glColor3f(0f, 0f, 1f); + gl2.glDrawElements(GL2.GL_TRIANGLES, 3, GL2.GL_UNSIGNED_INT, 0); + gl2.glBindVertexArray(0); + gl2.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, 0); + } + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } + + } // inner class TwoTriangles + + public static void logAnyErrorCodes(GL2 gl2, String prefix) { + int glError = gl2.glGetError(); + while (glError != GL2.GL_NO_ERROR) { + System.err.println(prefix + ", OpenGL error: 0x" + Integer.toHexString(glError)); + glError = gl2.glGetError(); + } + int status = gl2.glCheckFramebufferStatus(GL2.GL_FRAMEBUFFER); + if (status != GL2.GL_FRAMEBUFFER_COMPLETE) { + System.err.println(prefix + ", glCheckFramebufferStatus: 0x" + Integer.toHexString(status)); + } + } + + /** + * Sets the OpenGL projection matrix and front and back clipping planes for + * a viewport and returns the distance the camera should be placed from + * the center of the scene's bounding sphere such that the geometry is + * centered in the view frustum. + * + * @param gl2 current OpenGL context + * @param width width of GLDrawable + * @param height height of GLDrawable + * @param boundsRadius radius of a minimal bounding sphere of objects to be + * rendered in the viewport + * @param zoomFactor affects how far away the camera is placed from the scene; changing the + * zoom from 1.0 to 0.5 would make the scene appear half the size + * @param viewFovDegrees the desired field of vision for the viewport, + * higher is more fish-eye + * @return the distance the camera should be from the center of the scenes + * bounding sphere + */ + public static float setupViewFrustum(GL2 gl2, int width, int height, float boundsRadius, float zoomFactor, float viewFovDegrees) { + assert boundsRadius > 0.0f; + assert zoomFactor > 0.0f; + assert viewFovDegrees > 0.0f; + + GLU glu = new GLU(); + + final float aspectRatio = (float) width / (float) height; + final float boundRadiusAdjusted = boundsRadius / zoomFactor; + final float lowestFov = aspectRatio > 1.0f ? viewFovDegrees : aspectRatio * viewFovDegrees; + final float viewDist = (float) (boundRadiusAdjusted / Math.sin( (lowestFov / 2.0) * (Math.PI / 180.0) )); + + gl2.glMatrixMode(GL2.GL_PROJECTION); + gl2.glLoadIdentity(); + glu.gluPerspective(viewFovDegrees, aspectRatio, 0.1*viewDist, viewDist + boundRadiusAdjusted); + + return viewDist; + } + + @Test + public void testContextSharingCreateVisibleDestroy1() throws InterruptedException, InvocationTargetException { + testContextSharingCreateVisibleDestroy(false, false); + } + + @Test + public void testContextSharingCreateVisibleDestroy2() throws InterruptedException, InvocationTargetException { + testContextSharingCreateVisibleDestroy(false, true); + } + + @Test + public void testContextSharingCreateVisibleDestroy3() throws InterruptedException, InvocationTargetException { + testContextSharingCreateVisibleDestroy(true, false); + } + + @Test + public void testContextSharingCreateVisibleDestroy4() throws InterruptedException, InvocationTargetException { + testContextSharingCreateVisibleDestroy(true, true); + } + + /** + * Assemble the user interface and start the animator. + * It waits until the window is closed an then attempts orderly shutdown and resource deallocation. + */ + public void testContextSharingCreateVisibleDestroy(final boolean useNewt, final boolean shareContext) throws InterruptedException, InvocationTargetException { + final JFrame frame = new JFrame("Simple JOGL App for testing context sharing"); + // + // GLDrawableFactory factory = GLDrawableFactory.getFactory(GLProfile.get(GLProfile.GL2)); + // GLContext sharedContext = factory.getOrCreateSharedContext(factory.getDefaultDevice()); + // + GLCapabilities glCapabilities = new GLCapabilities(GLProfile.get(GLProfile.GL2)); + glCapabilities.setSampleBuffers(true); + glCapabilities.setNumSamples(4); + + final GLPbuffer sharedDrawable; + final GLContext sharedContext; + if(shareContext) { + sharedDrawable = initShared(glCapabilities); + sharedContext = sharedDrawable.getContext(); + } else { + sharedDrawable = null; + sharedContext = null; + } + + final TwoTriangles eventListener1 = new TwoTriangles(640, 480, shareContext); + final TwoTriangles eventListener2 = new TwoTriangles(320, 480, shareContext); + + final Component openGLComponent1; + final Component openGLComponent2; + final GLAutoDrawable openGLAutoDrawable1; + final GLAutoDrawable openGLAutoDrawable2; + + if (useNewt) { + GLWindow glWindow1 = GLWindow.create(glCapabilities); + glWindow1.setSharedContext(sharedContext); + NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1); + newtCanvasAWT1.setPreferredSize(new Dimension(eventListener1.canvasWidth, eventListener1.canvasHeight)); + glWindow1.addGLEventListener(eventListener1); + // + GLWindow glWindow2 = GLWindow.create(glCapabilities); + NewtCanvasAWT newtCanvasAWT2 = new NewtCanvasAWT(glWindow2); + newtCanvasAWT2.setPreferredSize(new Dimension(eventListener2.canvasWidth, eventListener2.canvasHeight)); + glWindow2.addGLEventListener(eventListener2); + + openGLComponent1 = newtCanvasAWT1; + openGLComponent2 = newtCanvasAWT2; + openGLAutoDrawable1 = glWindow1; + openGLAutoDrawable2 = glWindow2; + } else { + // Implementation using two GLCanvas instances; for GLCanvas context sharing to work, you must pass it in + // through the constructor; if you set it after it has no effect -- it does no harm if you initialized the ctor + // with the shared context, but if you didn't, it also doesn't trigger sharing + final GLCanvas canvas1; + final GLCanvas canvas2; + + if (shareContext) { + canvas1 = new GLCanvas(glCapabilities, sharedContext); + canvas2 = new GLCanvas(glCapabilities, sharedContext); + } else { + canvas1 = new GLCanvas(glCapabilities); + canvas2 = new GLCanvas(glCapabilities); + } + + canvas1.setSize(eventListener1.canvasWidth, eventListener1.canvasHeight); + canvas1.addGLEventListener(eventListener1); + // + canvas2.setSize(eventListener2.canvasWidth, eventListener2.canvasHeight); + canvas2.addGLEventListener(eventListener2); + + openGLComponent1 = canvas1; + openGLComponent2 = canvas2; + openGLAutoDrawable1 = canvas1; + openGLAutoDrawable2 = canvas2; + } + + // Create slider for x rotation. + // The vertically oriented slider rotates around the x axis + final JSlider xAxisRotationSlider = new JSlider(JSlider.VERTICAL, -180, 180, 1); + xAxisRotationSlider.setPaintTicks(false); + xAxisRotationSlider.setPaintLabels(false); + xAxisRotationSlider.setSnapToTicks(false); + xAxisRotationSlider.addChangeListener(new ChangeListener() { + + public void stateChanged(ChangeEvent e) { + eventListener1.setXAxisRotation(xAxisRotationSlider.getValue()); + eventListener2.setXAxisRotation(xAxisRotationSlider.getValue()); + } + }); + JLabel xAxisRotationLabel = new JLabel("X-Axis Rotation"); + + // Create slider for y rotation. + // The horizontally oriented slider rotates around the y axis + final JSlider yAxisRotationSlider = new JSlider(JSlider.HORIZONTAL, -180, 180, 1); + yAxisRotationSlider.setPaintTicks(false); + yAxisRotationSlider.setPaintLabels(false); + yAxisRotationSlider.setSnapToTicks(false); + yAxisRotationSlider.addChangeListener(new ChangeListener() { + + public void stateChanged(ChangeEvent e) { + eventListener1.setYAxisRotation(yAxisRotationSlider.getValue()); + eventListener2.setYAxisRotation(yAxisRotationSlider.getValue()); + } + }); + JLabel yAxisRotationLabel = new JLabel("Y-Axis Rotation"); + + // Create slider for view distance factor. + // We want a range of 0.0 to 10.0 with 0.1 increments (so we can scale down using 0.0 to 1.0). + // So, set JSlider to 0 to 100 and divide by 10.0 in stateChanged + final JSlider viewDistanceFactorSlider = new JSlider(JSlider.HORIZONTAL, 0, 100, 10); + viewDistanceFactorSlider.setPaintTicks(false); + viewDistanceFactorSlider.setPaintLabels(false); + viewDistanceFactorSlider.setSnapToTicks(false); + viewDistanceFactorSlider.addChangeListener(new ChangeListener() { + + public void stateChanged(ChangeEvent e) { + eventListener1.setViewDistanceFactor((float) viewDistanceFactorSlider.getValue() / 10.0f); + eventListener2.setViewDistanceFactor((float) viewDistanceFactorSlider.getValue() / 10.0f); + } + }); + JLabel viewDistanceFactorLabel = new JLabel("View Distance Factor"); + + // group the view distance and label into a vertical panel + JPanel viewDistancePanel = new JPanel(); + viewDistancePanel.setLayout(new BoxLayout(viewDistancePanel, BoxLayout.PAGE_AXIS)); + viewDistancePanel.add(Box.createVerticalGlue()); + viewDistancePanel.add(viewDistanceFactorSlider); + viewDistancePanel.add(viewDistanceFactorLabel); + viewDistancePanel.add(Box.createVerticalGlue()); + + // group both OpenGL canvases / windows into a horizontal panel + JPanel openGLPanel = new JPanel(); + openGLPanel.setLayout(new BoxLayout(openGLPanel, BoxLayout.LINE_AXIS)); + openGLPanel.add(openGLComponent1); + openGLPanel.add(Box.createHorizontalStrut(5)); + openGLPanel.add(openGLComponent2); + + // group the open GL panel and the y-axis rotation slider into a vertical panel. + JPanel canvasAndYAxisPanel = new JPanel(); + canvasAndYAxisPanel.setLayout(new BoxLayout(canvasAndYAxisPanel, BoxLayout.PAGE_AXIS)); + canvasAndYAxisPanel.add(openGLPanel); + canvasAndYAxisPanel.add(Box.createVerticalGlue()); + canvasAndYAxisPanel.add(yAxisRotationSlider); + canvasAndYAxisPanel.add(yAxisRotationLabel); + + // group the X-axis rotation slider and label into a horizontal panel. + JPanel xAxisPanel = new JPanel(); + xAxisPanel.setLayout(new BoxLayout(xAxisPanel, BoxLayout.LINE_AXIS)); + xAxisPanel.add(xAxisRotationSlider); + xAxisPanel.add(xAxisRotationLabel); + + JPanel mainPanel = (JPanel) frame.getContentPane(); + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.LINE_AXIS)); + mainPanel.add(viewDistancePanel); + mainPanel.add(Box.createHorizontalGlue()); + mainPanel.add(canvasAndYAxisPanel); + mainPanel.add(Box.createHorizontalGlue()); + mainPanel.add(xAxisPanel); + + final Animator animator = new Animator(Thread.currentThread().getThreadGroup()); + animator.setUpdateFPSFrames(1, null); + animator.add(openGLAutoDrawable1); + animator.add(openGLAutoDrawable2); + + final Semaphore windowOpenSemaphore = new Semaphore(0); + final Semaphore closingSemaphore = new Semaphore(0); + + // signal the main thread when the frame is closed + frame.addWindowListener(new WindowAdapter() { + + @Override + public void windowClosing(WindowEvent e) { + closingSemaphore.release(); + } + }); + + // make the window visible using the EDT + SwingUtilities.invokeLater( new Runnable() { + public void run() { + frame.pack(); + frame.setVisible(true); + windowOpenSemaphore.release(); + } + }); + + // wait for the window to be visible and start the animation + try { + boolean windowOpened = windowOpenSemaphore.tryAcquire(5000, TimeUnit.MILLISECONDS); + Assert.assertEquals(true, windowOpened); + } catch (InterruptedException e) { + System.err.println("Closing wait interrupted: " + e.getMessage()); + } + animator.start(); + + // sleep for test duration, then request the window to close, wait for the window to close,s and stop the animation + try { + while(animator.isAnimating() && animator.getTotalFPSDuration() < durationPerTest) { + Thread.sleep(100); + } + AWTRobotUtil.closeWindow(frame, true); + boolean windowClosed = closingSemaphore.tryAcquire(5000, TimeUnit.MILLISECONDS); + Assert.assertEquals(true, windowClosed); + } catch (InterruptedException e) { + System.err.println("Closing wait interrupted: " + e.getMessage()); + } + animator.stop(); + + // ask the EDT to dispose of the frame; + // if using newt, explicitly dispose of the canvases because otherwise it seems our destroy methods are not called + SwingUtilities.invokeLater( new Runnable() { + public void run() { + frame.setVisible(false); + frame.dispose(); + if (useNewt) { + ((NewtCanvasAWT)openGLComponent1).destroy(); + ((NewtCanvasAWT)openGLComponent2).destroy(); + } + closingSemaphore.release(); + } + }); + + // wait for orderly destruction; it seems that if we share a GLContext across newt windows, bad things happen; + // I must be doing something wrong but I haven't figured it out yet + try { + boolean windowsDisposed = closingSemaphore.tryAcquire(5000, TimeUnit.MILLISECONDS); + Assert.assertEquals(true, windowsDisposed); + } catch (InterruptedException e) { + System.err.println("Closing wait interrupted: " + e.getMessage()); + } + + // ensure that the two OpenGL canvas' destroy methods completed successfully and released resources before we move on + int disposalSuccesses = 0; + try { + boolean acquired; + acquired = disposalCompleteSemaphore.tryAcquire(5000, TimeUnit.MILLISECONDS); + if (acquired){ + disposalSuccesses++; + } + acquired = disposalCompleteSemaphore.tryAcquire(5000, TimeUnit.MILLISECONDS); + if (acquired){ + disposalSuccesses++; + } + } catch (InterruptedException e) { + System.err.println("Clean exit interrupted: " + e.getMessage()); + } + + Assert.assertEquals(true, disposalSuccesses == 2); + + releaseShared(sharedDrawable); + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String[] args) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + if (++i < args.length) { + durationPerTest = atoi(args[i]); + } + } + } + + String testname = TestSharedContextNewtAWTBug523.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + testname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+testname+".xml" } ); + } + +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java index 5d76702ea..6e48e44fe 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES1NEWT.java @@ -54,7 +54,6 @@ public class TestSharedContextVBOES1NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); glp = GLProfile.getDefault(); Assert.assertNotNull(glp); caps = new GLCapabilities(glp); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT.java index dd3e1f347..022ef2142 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT.java @@ -54,7 +54,6 @@ public class TestSharedContextVBOES2NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); glp = GLProfile.getDefault(); Assert.assertNotNull(glp); caps = new GLCapabilities(glp); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java new file mode 100644 index 000000000..5b2cb25b3 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextVBOES2NEWT2.java @@ -0,0 +1,157 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.io.IOException; + +import com.jogamp.newt.opengl.GLWindow; + +import javax.media.nativewindow.util.InsetsImmutable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestSharedContextVBOES2NEWT2 extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + static int width, height; + GLWindow sharedDrawable; + GearsES2 sharedGears; + + @BeforeClass + public static void initClass() { + glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + width = 256; + height = 256; + } + + private void initShared() { + sharedDrawable = GLWindow.create(caps); + Assert.assertNotNull(sharedDrawable); + // sharedGears = new Gears(0); + sharedGears = new GearsES2(0); + Assert.assertNotNull(sharedGears); + sharedDrawable.addGLEventListener(sharedGears); + sharedDrawable.setSize(width, height); + sharedDrawable.setVisible(true); + // init and render one frame, which will setup the Gears display lists + sharedDrawable.display(); + } + + private void releaseShared() { + Assert.assertNotNull(sharedDrawable); + sharedDrawable.destroy(); + sharedDrawable = null; + } + + protected GLWindow runTestGL(Animator animator, int x, int y, boolean useShared, boolean vsync) throws InterruptedException { + GLWindow glWindow = GLWindow.create(caps); + + Assert.assertNotNull(glWindow); + glWindow.setTitle("Shared Gears NEWT Test: "+x+"/"+y+" shared "+useShared); + if(useShared) { + glWindow.setSharedContext(sharedDrawable.getContext()); + } + + glWindow.setSize(width, height); + + GearsES2 gears = new GearsES2(vsync ? 1 : 0); + if(useShared) { + gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3()); + } + glWindow.addGLEventListener(gears); + + animator.add(glWindow); + animator.start(); + glWindow.setVisible(true); + + Assert.assertTrue(AWTRobotUtil.waitForRealized(glWindow, true)); + Assert.assertTrue(AWTRobotUtil.waitForVisible(glWindow, true)); + glWindow.setPosition(x, y); + + return glWindow; + } + + @Test + public void test01() throws InterruptedException { + initShared(); + GLWindow f1 = runTestGL(new Animator(), 0, 0, true, false); + InsetsImmutable insets = f1.getInsets(); + GLWindow f2 = runTestGL(new Animator(), f1.getX()+width+insets.getTotalWidth(), + f1.getY()+0, true, false); + GLWindow f3 = runTestGL(new Animator(), f1.getX()+0, + f1.getY()+height+insets.getTotalHeight(), true, false); + + try { + Thread.sleep(duration); + } catch(Exception e) { + e.printStackTrace(); + } + + // here we go again: On AMD/X11 the create/destroy sequence must be the same + // even though this is against the chicken/egg logic here .. + releaseShared(); + + f1.destroy(); + f2.destroy(); + f3.destroy(); + + // see above .. + // releaseShared(); + } + + static long duration = 2000; // ms + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + /** + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + System.err.println("Press enter to continue"); + System.err.println(stdin.readLine()); */ + org.junit.runner.JUnitCore.main(TestSharedContextVBOES2NEWT2.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteAWT.java new file mode 100644 index 000000000..322ce36c4 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteAWT.java @@ -0,0 +1,125 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.awt.Frame; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +public class TestShutdownCompleteAWT extends UITestCase { + + static long duration = 300; // ms + + protected void runTestGL() throws InterruptedException, InvocationTargetException { + final Frame frame = new Frame("Gears AWT Test"); + Assert.assertNotNull(frame); + + final GLCanvas glCanvas = new GLCanvas(new GLCapabilities(GLProfile.getDefault())); + Assert.assertNotNull(glCanvas); + frame.add(glCanvas); + frame.setSize(256, 256); + + glCanvas.addGLEventListener(new Gears(1)); + + Animator animator = new Animator(glCanvas); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(true); + }}); + + animator.setUpdateFPSFrames(60, System.err); + animator.start(); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(true, glCanvas.isVisible()); + Assert.assertEquals(true, glCanvas.isDisplayable()); + + while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) { + Thread.sleep(100); + } + Assert.assertEquals(true, glCanvas.isRealized()); + + animator.stop(); + Assert.assertEquals(false, animator.isAnimating()); + frame.setVisible(false); + Assert.assertEquals(false, frame.isVisible()); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.remove(glCanvas); + frame.dispose(); + }}); + } + + protected void oneLife() throws InterruptedException, InvocationTargetException { + long t0 = System.nanoTime(); + GLProfile.initSingleton(); + long t1 = System.nanoTime(); + runTestGL(); + long t2 = System.nanoTime(); + GLProfile.shutdown(GLProfile.ShutdownType.COMPLETE); + long t3 = System.nanoTime(); + System.err.println("Total: "+ (t3-t0)/1e6 +"ms"); + System.err.println(" GLProfile.initSingleton(): "+ (t1-t0)/1e6 +"ms"); + System.err.println(" Demo Code: "+ (t2-t1)/1e6 +"ms"); + System.err.println(" GLProfile.shutdown(COMPLETE): "+ (t3-t2)/1e6 +"ms"); + } + + @Test + public void test01OneLife() throws InterruptedException, InvocationTargetException { + oneLife(); + } + + @Test + public void test01AnotherLife() throws InterruptedException, InvocationTargetException { + oneLife(); + } + + @Test + public void test01TwoLifes() throws InterruptedException, InvocationTargetException { + oneLife(); + oneLife(); + } + + public static void main(String args[]) throws IOException { + String tstname = TestShutdownCompleteAWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteNEWT.java new file mode 100644 index 000000000..1abac1094 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteNEWT.java @@ -0,0 +1,144 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +public class TestShutdownCompleteNEWT extends UITestCase { + + static long duration = 300; // ms + + protected void runTestGL() throws InterruptedException { + GLWindow glWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault())); + Assert.assertNotNull(glWindow); + glWindow.setTitle("Gears NEWT Test"); + + glWindow.addGLEventListener(new Gears()); + + Animator animator = new Animator(glWindow); + + glWindow.setSize(256, 256); + glWindow.setVisible(true); + animator.setUpdateFPSFrames(60, System.err); + animator.start(); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(true, glWindow.isVisible()); + Assert.assertEquals(true, glWindow.isNativeValid()); + Assert.assertEquals(true, glWindow.isRealized()); + + while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) { + Thread.sleep(100); + } + + animator.stop(); + glWindow.destroy(); + } + + protected void oneLife() throws InterruptedException { + if(waitForEach) { + waitForEnter(); + } + long t0 = System.nanoTime(); + GLProfile.initSingleton(); + long t1 = System.nanoTime(); + if(!initOnly) { + runTestGL(); + } + long t2 = System.nanoTime(); + GLProfile.shutdown(GLProfile.ShutdownType.COMPLETE); + long t3 = System.nanoTime(); + System.err.println("Total: "+ (t3-t0)/1e6 +"ms"); + System.err.println(" GLProfile.initSingleton(): "+ (t1-t0)/1e6 +"ms"); + System.err.println(" Demo Code: "+ (t2-t1)/1e6 +"ms"); + System.err.println(" GLProfile.shutdown(COMPLETE): "+ (t3-t2)/1e6 +"ms"); + } + + @Test + public void test01OneLife() throws InterruptedException { + oneLife(); + } + + @Test + public void test01AnotherLife() throws InterruptedException { + oneLife(); + } + + @Test + public void test01TwoLifes() throws InterruptedException { + oneLife(); + oneLife(); + } + + static boolean initOnly = false; + static boolean waitForEach = false; + + static void waitForEnter() { + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + System.err.println("Press enter to continue"); + try { + System.err.println(stdin.readLine()); + } catch (IOException e) { } + } + + public static void main(String args[]) throws IOException { + boolean waitForKey = false; + + for(int i=0; i<args.length; i++) { + if(args[i].equals("-wait")) { + waitForKey = true; + } else if(args[i].equals("-waitForEach")) { + waitForEach = true; + waitForKey = true; + } else if(args[i].equals("-initOnly")) { + initOnly = true; + } + } + + if(waitForKey) { + waitForEnter(); + } + + String tstname = TestShutdownCompleteNEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownSharedAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownSharedAWT.java new file mode 100644 index 000000000..a12ef2327 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownSharedAWT.java @@ -0,0 +1,124 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.awt.Frame; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +public class TestShutdownSharedAWT extends UITestCase { + + static long duration = 300; // ms + + protected void runTestGL() throws InterruptedException, InvocationTargetException { + final Frame frame = new Frame("Gears AWT Test"); + Assert.assertNotNull(frame); + + final GLCanvas glCanvas = new GLCanvas(new GLCapabilities(GLProfile.getDefault())); + Assert.assertNotNull(glCanvas); + frame.add(glCanvas); + frame.setSize(256, 256); + + glCanvas.addGLEventListener(new Gears(1)); + + Animator animator = new Animator(glCanvas); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(true); + }}); + animator.setUpdateFPSFrames(60, System.err); + animator.start(); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(true, glCanvas.isVisible()); + Assert.assertEquals(true, glCanvas.isDisplayable()); + + while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) { + Thread.sleep(100); + } + Assert.assertEquals(true, glCanvas.isRealized()); + + animator.stop(); + Assert.assertEquals(false, animator.isAnimating()); + frame.setVisible(false); + Assert.assertEquals(false, frame.isVisible()); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.remove(glCanvas); + frame.dispose(); + }}); + } + + protected void oneLife() throws InterruptedException, InvocationTargetException { + long t0 = System.nanoTime(); + GLProfile.initSingleton(); + long t1 = System.nanoTime(); + runTestGL(); + long t2 = System.nanoTime(); + GLProfile.shutdown(GLProfile.ShutdownType.SHARED_ONLY); + long t3 = System.nanoTime(); + System.err.println("Total: "+ (t3-t0)/1e6 +"ms"); + System.err.println(" GLProfile.initSingleton(): "+ (t1-t0)/1e6 +"ms"); + System.err.println(" Demo Code: "+ (t2-t1)/1e6 +"ms"); + System.err.println(" GLProfile.shutdown(SHARED): "+ (t3-t2)/1e6 +"ms"); + } + + @Test + public void test01OneLife() throws InterruptedException, InvocationTargetException { + oneLife(); + } + + @Test + public void test01AnotherLife() throws InterruptedException, InvocationTargetException { + oneLife(); + } + + @Test + public void test01TwoLifes() throws InterruptedException, InvocationTargetException { + oneLife(); + oneLife(); + } + + public static void main(String args[]) throws IOException { + String tstname = TestShutdownSharedAWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownSharedNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownSharedNEWT.java new file mode 100644 index 000000000..99b5a6c48 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownSharedNEWT.java @@ -0,0 +1,127 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.acore; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +public class TestShutdownSharedNEWT extends UITestCase { + + static long duration = 300; // ms + + protected void runTestGL() throws InterruptedException { + GLWindow glWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault())); + Assert.assertNotNull(glWindow); + glWindow.setTitle("Gears NEWT Test"); + + glWindow.addGLEventListener(new Gears()); + + Animator animator = new Animator(glWindow); + + glWindow.setSize(256, 256); + glWindow.setVisible(true); + animator.setUpdateFPSFrames(60, System.err); + animator.start(); + Assert.assertEquals(true, animator.isAnimating()); + Assert.assertEquals(true, glWindow.isVisible()); + Assert.assertEquals(true, glWindow.isNativeValid()); + Assert.assertEquals(true, glWindow.isRealized()); + + while(animator.isAnimating() && animator.getTotalFPSDuration()<duration) { + Thread.sleep(100); + } + + animator.stop(); + glWindow.destroy(); + } + + protected void oneLife() throws InterruptedException { + long t0 = System.nanoTime(); + GLProfile.initSingleton(); + long t1 = System.nanoTime(); + runTestGL(); + long t2 = System.nanoTime(); + GLProfile.shutdown(GLProfile.ShutdownType.SHARED_ONLY); + long t3 = System.nanoTime(); + System.err.println("Total: "+ (t3-t0)/1e6 +"ms"); + System.err.println(" GLProfile.initSingleton(): "+ (t1-t0)/1e6 +"ms"); + System.err.println(" Demo Code: "+ (t2-t1)/1e6 +"ms"); + System.err.println(" GLProfile.shutdown(SHARED): "+ (t3-t2)/1e6 +"ms"); + } + + @Test + public void test01OneLife() throws InterruptedException { + oneLife(); + } + + @Test + public void test01AnotherLife() throws InterruptedException { + oneLife(); + } + + @Test + public void test01TwoLifes() throws InterruptedException { + oneLife(); + oneLife(); + } + + public static void main(String args[]) throws IOException { + boolean waitForKey = false; + + for(int i=0; i<args.length; i++) { + if(args[i].equals("-wait")) { + waitForKey = true; + } + } + + if(waitForKey) { + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + System.err.println("Press enter to continue"); + try { + System.err.println(stdin.readLine()); + } catch (IOException e) { } + } + + String tstname = TestShutdownSharedNEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWTCardLayoutAnimatorStartStopBug532.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWTCardLayoutAnimatorStartStopBug532.java new file mode 100644 index 000000000..5415ad159 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWTCardLayoutAnimatorStartStopBug532.java @@ -0,0 +1,229 @@ +package com.jogamp.opengl.test.junit.jogl.awt; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Dimension; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.lang.reflect.InvocationTargetException; + +import javax.media.nativewindow.NativeWindow; +import javax.media.opengl.GLAnimatorControl; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import jogamp.nativewindow.windows.GDI; + +import org.junit.Test; + +import com.jogamp.common.os.Platform; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.FPSAnimator; + +public class TestAWTCardLayoutAnimatorStartStopBug532 extends UITestCase { + static final String LABEL = "Label"; + static final String CANVAS = "GLCanvas"; + + public enum AnimatorControlBehavior { + StartStop, PauseResume, Continue; + } + + static long durationPerTest = 200*4; // ms + static boolean manual = false; + static volatile boolean shouldStop = false; + + private String selected = LABEL; + + @Test + public void testFPSAnimatorStartStop() throws InterruptedException, InvocationTargetException { + testImpl(AnimatorControlBehavior.StartStop, true); + } + + @Test + public void testFPSAnimatorResumePause() throws InterruptedException, InvocationTargetException { + testImpl(AnimatorControlBehavior.PauseResume, true); + } + + @Test + public void testFPSAnimatorContinue() throws InterruptedException, InvocationTargetException { + testImpl(AnimatorControlBehavior.Continue, true); + } + + @Test + public void testAnimatorStartStop() throws InterruptedException, InvocationTargetException { + testImpl(AnimatorControlBehavior.StartStop, false); + } + + @Test + public void testAnimatorResumePause() throws InterruptedException, InvocationTargetException { + testImpl(AnimatorControlBehavior.PauseResume, false); + } + + @Test + public void testAnimatorContinue() throws InterruptedException, InvocationTargetException { + testImpl(AnimatorControlBehavior.Continue, false); + } + + void testImpl(final AnimatorControlBehavior animCtrl, boolean useFPSAnimator) throws InterruptedException, InvocationTargetException { + final GLProfile glp = GLProfile.get(GLProfile.GL2); + final GLCapabilities caps = new GLCapabilities(glp); + final GLCanvas canvas = new GLCanvas(caps); + canvas.setPreferredSize(new Dimension(640, 480)); + + final GLAnimatorControl animatorCtrl = useFPSAnimator ? new FPSAnimator(canvas, 60) : new Animator(canvas); + animatorCtrl.setUpdateFPSFrames(60, System.err); + switch (animCtrl) { + case PauseResume: + animatorCtrl.start(); + animatorCtrl.pause(); + break; + case Continue: + animatorCtrl.start(); + break; + } + + canvas.addGLEventListener(new GearsES2(1)); + /* if(Platform.OS_TYPE == Platform.OSType.WINDOWS) { + canvas.addGLEventListener(new GLEventListener() { + public void init(GLAutoDrawable drawable) { } + public void dispose(GLAutoDrawable drawable) { } + public void display(GLAutoDrawable drawable) { + final NativeWindow win = (NativeWindow) drawable.getNativeSurface(); + long hdc = win.getSurfaceHandle(); + long hdw = win.getWindowHandle(); + long hdw_hdc = GDI.WindowFromDC(hdc); + System.err.println("*** hdc 0x"+Long.toHexString(hdc)+", hdw(hdc) 0x"+Long.toHexString(hdw_hdc)+", hdw 0x"+Long.toHexString(hdw) + " - " + Thread.currentThread().getName() + ", " + animatorCtrl); + // System.err.println(drawable.getNativeSurface().toString()); + } + public void reshape(GLAutoDrawable drawable, int x, int y, int width, + int height) { } + }); + } */ + + final JFrame frame = new JFrame(); + frame.setTitle(getSimpleTestName()); + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + animatorCtrl.stop(); + shouldStop = true; + } + }); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + final JPanel cards = new JPanel(new CardLayout()); + final JPanel comboBoxPanel = new JPanel(); // nicer look .. + final JComboBox comboBox = new JComboBox(new String[] { LABEL, CANVAS }); + comboBox.setEditable(false); + comboBox.addItemListener(new ItemListener() { + public void itemStateChanged(final ItemEvent evt) { + final CardLayout cl = (CardLayout)(cards.getLayout()); + final String newSelection = (String)evt.getItem(); + if(!newSelection.equals(selected)) { + final String oldSelected = selected; + if(newSelection.equals(CANVAS)) { + cl.show(cards, CANVAS); + switch (animCtrl) { + case StartStop: + animatorCtrl.start(); + break; + case PauseResume: + animatorCtrl.resume(); + break; + } + selected = CANVAS; + } else if(newSelection.equals(LABEL)) { + switch (animCtrl) { + case StartStop: + animatorCtrl.stop(); + break; + case PauseResume: + animatorCtrl.pause(); + break; + } + cl.show(cards, LABEL); + selected = LABEL; + } else { + throw new RuntimeException("oops .. unexpected item: "+evt); + } + System.err.println("Item Change: "+oldSelected+" -> "+selected+", "+animatorCtrl); + } else { + System.err.println("Item Stays: "+selected+", "+animatorCtrl); + } + } + }); + comboBoxPanel.add(comboBox); + + cards.add(new JLabel("A label to cover the canvas"), LABEL); + cards.add(canvas, CANVAS); + + frame.add(comboBoxPanel, BorderLayout.PAGE_START); + frame.add(cards, BorderLayout.CENTER); + + frame.pack(); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(true); + }}); + + if(manual) { + for(long w=durationPerTest; !shouldStop && w>0; w-=100) { + Thread.sleep(100); + } + } else { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + comboBox.setSelectedItem(LABEL); + }}); + Thread.sleep(durationPerTest/4); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + comboBox.setSelectedItem(CANVAS); + }}); + Thread.sleep(durationPerTest/4); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + comboBox.setSelectedItem(LABEL); + }}); + Thread.sleep(durationPerTest/4); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + comboBox.setSelectedItem(CANVAS); + }}); + Thread.sleep(durationPerTest/4); + } + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(false); + frame.dispose(); + }}); + + } + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest); + } else if(args[i].equals("-manual")) { + manual = true; + } + } + org.junit.runner.JUnitCore.main(TestAWTCardLayoutAnimatorStartStopBug532.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug461OffscreenSupersamplingSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug461OffscreenSupersamplingSwingAWT.java index 55c9c6812..284122be3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug461OffscreenSupersamplingSwingAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug461OffscreenSupersamplingSwingAWT.java @@ -30,35 +30,9 @@ package com.jogamp.opengl.test.junit.jogl.awt; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -/** - * Copyright 2011 JogAmp Community. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of JogAmp Community. - */ import java.awt.image.BufferedImage; +import java.lang.reflect.InvocationTargetException; import javax.media.opengl.GL; import javax.media.opengl.GL2; @@ -123,12 +97,19 @@ public class TestBug461OffscreenSupersamplingSwingAWT extends UITestCase impleme /* @Override */ public void dispose(GLAutoDrawable drawable) { - jframe.setVisible(false); - jframe.dispose(); + try { + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + jframe.setVisible(false); + jframe.dispose(); + }}); + } catch (Exception e) { + e.printStackTrace(); + } } @Test - public void testOffscreenSupersampling() { + public void testOffscreenSupersampling() throws InterruptedException, InvocationTargetException { jframe = new JFrame("Offscreen Supersampling"); Assert.assertNotNull(jframe); jframe.setSize( 300, 300); @@ -163,7 +144,10 @@ public class TestBug461OffscreenSupersamplingSwingAWT extends UITestCase impleme Assert.assertNotNull(offScreenBuffer); offScreenBuffer.addGLEventListener(this); offScreenBuffer.display(); - jframe.setVisible( true ); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + jframe.setVisible(true); + }}); } public static void main(String args[]) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleDemo01.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleDemo01.java index b41501a9b..ab0171cb8 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleDemo01.java @@ -63,7 +63,7 @@ class MultisampleDemo01 implements GLEventListener { } public void init(GLAutoDrawable drawable) { - AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); + AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration(); System.err.println(); System.err.println("Info: " + config); System.err.println(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestTranslucencyAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestTranslucencyAWT.java index e22163847..8e720965c 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestTranslucencyAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestTranslucencyAWT.java @@ -51,6 +51,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import com.jogamp.common.util.ReflectionUtil; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.util.Animator; @@ -80,8 +81,15 @@ public class TestTranslucencyAWT extends UITestCase { boolean capable1 = ( null != tcm ) ? tcm.getTransparency() == Transparency.TRANSLUCENT : false; boolean capable2 = false; try { - capable2 = com.sun.awt.AWTUtilities.isTranslucencyCapable(config); - } catch (Exception e) {} + capable2 = ((Boolean)ReflectionUtil.callStaticMethod( + "com.sun.awt.AWTUtilities", "isTranslucencyCapable", + new Class<?>[] { GraphicsConfiguration.class }, + new Object[] { config } , + GraphicsConfiguration.class.getClassLoader())).booleanValue(); + System.err.println("com.sun.awt.AWTUtilities.isTranslucencyCapable(config) passed: "+capable2); + } catch (RuntimeException re) { + System.err.println("com.sun.awt.AWTUtilities.isTranslucencyCapable(config) failed: "+re.getMessage()); + } System.err.println(i+":"+j+" "+config+", "+tcm+", capable "+capable1+"/"+capable2); if(capable1&&capable2) { gc=configs[j]; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestTranslucencyNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestTranslucencyNEWT.java index a01cb593b..67e8524a3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestTranslucencyNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestTranslucencyNEWT.java @@ -52,7 +52,6 @@ public class TestTranslucencyNEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); /*if(GLProfile.isAvailable(GLProfile.getDefaultEGLDevice(), GLProfile.GLES2)) { // exact match glp = GLProfile.get(GLProfile.getDefaultEGLDevice(), GLProfile.GLES2); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java index 8d579ce5d..b5a729e02 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java @@ -21,6 +21,7 @@ package com.jogamp.opengl.test.junit.jogl.demos.es1; +import javax.media.nativewindow.NativeWindow; import javax.media.opengl.GL; import javax.media.opengl.GL2ES1; import javax.media.opengl.GLAutoDrawable; @@ -181,8 +182,18 @@ public class GearsES1 implements GLEventListener { // Get the GL corresponding to the drawable we are animating GL2ES1 gl = drawable.getGL().getGL2ES1(); - gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - + final boolean hasFocus; + if(drawable.getNativeSurface() instanceof NativeWindow) { + hasFocus = ((NativeWindow)drawable.getNativeSurface()).hasFocus(); + } else { + hasFocus = true; + } + if(hasFocus) { + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + } else { + gl.glClearColor(0.2f, 0.2f, 0.2f, 0.0f); + } + // Special handling for the case where the GLJPanel is translucent // and wants to be composited with other Java 2D content if (GLProfile.isAWTAvailable() && diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/newt/TestGearsES1NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/newt/TestGearsES1NEWT.java index 86f63cb2d..8b41141f1 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/newt/TestGearsES1NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/newt/TestGearsES1NEWT.java @@ -52,7 +52,6 @@ public class TestGearsES1NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); /* if(GLProfile.isAvailable(GLProfile.getDefaultEGLDevice(), GLProfile.GLES1)) { // exact match glp = GLProfile.get(GLProfile.getDefaultEGLDevice(), GLProfile.GLES1); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/newt/TestRedSquareES1NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/newt/TestRedSquareES1NEWT.java index e73be50d6..13aafe48f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/newt/TestRedSquareES1NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/newt/TestRedSquareES1NEWT.java @@ -52,7 +52,6 @@ public class TestRedSquareES1NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); /* if(GLProfile.isAvailable(GLProfile.getDefaultEGLDevice(), GLProfile.GLES1)) { // exact match glp = GLProfile.get(GLProfile.getDefaultEGLDevice(), GLProfile.GLES1); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java index 3fa61bf1d..51bc7d137 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java @@ -34,6 +34,8 @@ import com.jogamp.opengl.util.glsl.ShaderCode; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.glsl.ShaderState; import java.nio.FloatBuffer; + +import javax.media.nativewindow.NativeWindow; import javax.media.opengl.GL; import javax.media.opengl.GL2ES2; import javax.media.opengl.GLAutoDrawable; @@ -244,8 +246,18 @@ public class GearsES2 implements GLEventListener { // Get the GL corresponding to the drawable we are animating GL2ES2 gl = drawable.getGL().getGL2ES2(); - gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - + final boolean hasFocus; + if(drawable.getNativeSurface() instanceof NativeWindow) { + hasFocus = ((NativeWindow)drawable.getNativeSurface()).hasFocus(); + } else { + hasFocus = true; + } + if(hasFocus) { + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + } else { + gl.glClearColor(0.2f, 0.2f, 0.2f, 0.0f); + } + // Special handling for the case where the GLJPanel is translucent // and wants to be composited with other Java 2D content if (GLProfile.isAWTAvailable() && diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java index 01790de10..d645fb9f8 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java @@ -205,7 +205,7 @@ public class RedSquareES2 implements GLEventListener { class MyMouseAdapter extends MouseAdapter { public void mouseClicked(MouseEvent e) { System.err.println(e); - if(null != glWindow && e.getSource() == glWindow.getWindow()) { + if(null != glWindow && e.getSource() == glWindow.getDelegatedWindow()) { if(e.getX() < glWindow.getWidth()/2) { glWindow.setFullscreen(!glWindow.isFullscreen()); System.err.println("setFullscreen: "+glWindow.isFullscreen()); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestElektronenMultipliziererNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestElektronenMultipliziererNEWT.java index d9cee4fdf..fb6359093 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestElektronenMultipliziererNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestElektronenMultipliziererNEWT.java @@ -65,11 +65,6 @@ public class TestElektronenMultipliziererNEWT extends UITestCase { static int startFrame = 1700; static long duration = 5000; // ms - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - } - @AfterClass public static void releaseClass() { } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java index 18a5a5d31..faa7eb311 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java @@ -32,8 +32,13 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import com.jogamp.newt.Display; +import com.jogamp.newt.NewtFactory; +import com.jogamp.newt.Screen; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; +import com.jogamp.newt.event.WindowEvent; +import com.jogamp.newt.event.WindowAdapter; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.test.junit.util.QuitAdapter; @@ -42,6 +47,11 @@ import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.Point; +import javax.media.nativewindow.util.PointImmutable; +import javax.media.nativewindow.util.DimensionImmutable; + import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; @@ -55,11 +65,25 @@ import org.junit.Test; public class TestGearsES2NEWT extends UITestCase { static GLProfile glp; - static int width, height; + + static int screenIdx = 0; + static PointImmutable wpos; + static DimensionImmutable wsize; + static long duration = 500; // ms + static boolean opaque = true; + static boolean undecorated = false; + static boolean alwaysOnTop = false; + static boolean fullscreen = false; + static boolean pmvUseBackingArray = true; + static boolean vsync = false; + static boolean waitForKey = false; + static boolean mouseVisible = true; + static boolean mouseConfined = false; + static boolean showFPS = false; + @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); /*if(GLProfile.isAvailable(GLProfile.getDefaultEGLDevice(), GLProfile.GLES2)) { // exact match glp = GLProfile.get(GLProfile.getDefaultEGLDevice(), GLProfile.GLES2); @@ -68,10 +92,9 @@ public class TestGearsES2NEWT extends UITestCase { glp = GLProfile.getGL2ES2(); } Assert.assertNotNull(glp); - // width = 512; - // height = 512; - width = 200; - height = 200; + if(null == wsize) { + wsize = new Dimension(200, 200); + } } @AfterClass @@ -80,11 +103,15 @@ public class TestGearsES2NEWT extends UITestCase { protected void runTestGL(GLCapabilities caps, boolean undecorated) throws InterruptedException { System.err.println("requested: "+caps); - final GLWindow glWindow = GLWindow.create(caps); + Display dpy = NewtFactory.createDisplay(null); + Screen screen = NewtFactory.createScreen(dpy, screenIdx); + final GLWindow glWindow = GLWindow.create(screen, caps); Assert.assertNotNull(glWindow); - glWindow.setTitle("Gears NEWT Test (translucent "+!caps.isBackgroundOpaque()+")"); - glWindow.setSize(width, height); - glWindow.setPosition(100, 100); + glWindow.setTitle("Gears NEWT Test (translucent "+!caps.isBackgroundOpaque()+"), size "+wsize+", pos "+wpos); + glWindow.setSize(wsize.getWidth(), wsize.getHeight()); + if(null != wpos) { + glWindow.setPosition(wpos.getX(), wpos.getY()); + } glWindow.setUndecorated(undecorated); glWindow.setAlwaysOnTop(alwaysOnTop); glWindow.setFullscreen(fullscreen); @@ -123,6 +150,15 @@ public class TestGearsES2NEWT extends UITestCase { glWindow.addKeyListener(quitAdapter); glWindow.addWindowListener(quitAdapter); + glWindow.addWindowListener(new WindowAdapter() { + public void windowResized(WindowEvent e) { + System.err.println("window resized: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()); + } + public void windowMoved(WindowEvent e) { + System.err.println("window moved: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()); + } + }); + glWindow.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { if(e.getKeyChar()=='f') { @@ -189,14 +225,14 @@ public class TestGearsES2NEWT extends UITestCase { } }); - animator.setUpdateFPSFrames(60, System.err); + animator.setUpdateFPSFrames(60, showFPS ? System.err : null); animator.start(); // glWindow.setSkipContextReleaseThread(animator.getThread()); glWindow.setVisible(true); - System.err.println("size/pos: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", "+glWindow.getInsets()); System.err.println("chosen: "+glWindow.getChosenCapabilities()); + System.err.println("window pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getWidth()+"x"+glWindow.getHeight()+", "+glWindow.getInsets()); while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) { Thread.sleep(100); @@ -213,25 +249,22 @@ public class TestGearsES2NEWT extends UITestCase { runTestGL(caps, undecorated); } - static long duration = 500; // ms - static boolean opaque = true; - static boolean undecorated = false; - static boolean alwaysOnTop = false; - static boolean fullscreen = false; - static boolean pmvUseBackingArray = true; - static boolean vsync = false; - static boolean waitForKey = false; - static boolean mouseVisible = true; - static boolean mouseConfined = false; - + static int atoi(String a) { + try { + return Integer.parseInt(a); + } catch (Exception ex) { throw new RuntimeException(ex); } + } + public static void main(String args[]) throws IOException { + int x=0, y=0, w=200, h=200; + boolean useSize = false; + boolean usePos = false; + for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { i++; - try { - duration = Integer.parseInt(args[i]); - } catch (Exception ex) { ex.printStackTrace(); } + duration = atoi(args[i]); } else if(args[i].equals("-translucent")) { opaque = false; } else if(args[i].equals("-undecorated")) { @@ -250,8 +283,38 @@ public class TestGearsES2NEWT extends UITestCase { mouseVisible = false; } else if(args[i].equals("-mouseConfine")) { mouseConfined = true; + } else if(args[i].equals("-showFPS")) { + showFPS = true; + } else if(args[i].equals("-width")) { + i++; + w = atoi(args[i]); + useSize = true; + } else if(args[i].equals("-height")) { + i++; + h = atoi(args[i]); + useSize = true; + } else if(args[i].equals("-x")) { + i++; + x = atoi(args[i]); + usePos = true; + } else if(args[i].equals("-y")) { + i++; + y = atoi(args[i]); + usePos = true; + } else if(args[i].equals("-screen")) { + i++; + screenIdx = atoi(args[i]); } } + if(useSize) { + wsize = new Dimension(w, h); + } + if(usePos) { + wpos = new Point(x, y); + } + System.err.println("position "+wpos); + System.err.println("size "+wsize); + System.err.println("screen "+screenIdx); System.err.println("translucent "+(!opaque)); System.err.println("undecorated "+undecorated); System.err.println("atop "+alwaysOnTop); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java index 63ec215fc..f3bad286b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestRedSquareES2NEWT.java @@ -52,7 +52,6 @@ public class TestRedSquareES2NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); /* if(GLProfile.isAvailable(GLProfile.getDefaultEGLDevice(), GLProfile.GLES1)) { // exact match glp = GLProfile.get(GLProfile.getDefaultEGLDevice(), GLProfile.GLES1); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/TestGearsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/TestGearsAWT.java index 8ab641267..f03269614 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/TestGearsAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/TestGearsAWT.java @@ -41,6 +41,7 @@ import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.test.junit.util.QuitAdapter; import java.awt.Frame; +import java.lang.reflect.InvocationTargetException; import org.junit.Assert; import org.junit.BeforeClass; @@ -50,6 +51,7 @@ import org.junit.Test; public class TestGearsAWT extends UITestCase { static GLProfile glp; static int width, height; + static boolean firstUIActionOnProcess = false; @BeforeClass public static void initClass() { @@ -63,16 +65,16 @@ public class TestGearsAWT extends UITestCase { public static void releaseClass() { } - protected void runTestGL(GLCapabilities caps) throws InterruptedException { - Frame frame = new Frame("Gears AWT Test"); + protected void runTestGL(GLCapabilities caps) throws InterruptedException, InvocationTargetException { + final Frame frame = new Frame("Gears AWT Test"); Assert.assertNotNull(frame); - GLCanvas glCanvas = new GLCanvas(caps); + final GLCanvas glCanvas = new GLCanvas(caps); Assert.assertNotNull(glCanvas); frame.add(glCanvas); frame.setSize(512, 512); - glCanvas.addGLEventListener(new Gears()); + glCanvas.addGLEventListener(new Gears(1)); Animator animator = new Animator(glCanvas); QuitAdapter quitAdapter = new QuitAdapter(); @@ -80,8 +82,11 @@ public class TestGearsAWT extends UITestCase { new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glCanvas); new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); - frame.setVisible(true); - animator.setUpdateFPSFrames(1, null); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(true); + }}); + animator.setUpdateFPSFrames(60, System.err); animator.start(); while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) { @@ -96,14 +101,15 @@ public class TestGearsAWT extends UITestCase { Assert.assertEquals(false, animator.isAnimating()); frame.setVisible(false); Assert.assertEquals(false, frame.isVisible()); - frame.remove(glCanvas); - frame.dispose(); - frame=null; - glCanvas=null; + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.remove(glCanvas); + frame.dispose(); + }}); } @Test - public void test01() throws InterruptedException { + public void test01() throws InterruptedException, InvocationTargetException { GLCapabilities caps = new GLCapabilities(glp); runTestGL(caps); } @@ -117,6 +123,8 @@ public class TestGearsAWT extends UITestCase { try { duration = Integer.parseInt(args[i]); } catch (Exception ex) { ex.printStackTrace(); } + } else if(args[i].equals("-firstUIAction")) { + firstUIActionOnProcess = true; } } org.junit.runner.JUnitCore.main(TestGearsAWT.class.getName()); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/TestGearsAWTAnalyzeBug455.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/TestGearsAWTAnalyzeBug455.java new file mode 100644 index 000000000..4b670f0e1 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/TestGearsAWTAnalyzeBug455.java @@ -0,0 +1,171 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.demos.gl2.awt; + +import javax.media.opengl.*; + +import com.jogamp.opengl.util.Animator; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.newt.event.awt.AWTKeyAdapter; +import com.jogamp.newt.event.awt.AWTWindowAdapter; +import com.jogamp.newt.event.TraceKeyAdapter; +import com.jogamp.newt.event.TraceWindowAdapter; + +import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.QuitAdapter; +import java.awt.Frame; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +public class TestGearsAWTAnalyzeBug455 extends UITestCase { + static long duration = 500; // ms + static boolean waitForKey = false; // for manual profiling + static boolean altSwap = true; // using alternate GL swap method (copy pixel) no [auto-]swap + + static GLProfile glp; + static int width, height; + + @BeforeClass + public static void initClass() { + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + width = 512; + height = 512; + } + + @AfterClass + public static void releaseClass() { + } + + static class Swapper implements GLEventListener { + public void init(GLAutoDrawable drawable) { + System.err.println("auto-swap: "+drawable.getAutoSwapBufferMode()); + } + public void dispose(GLAutoDrawable drawable) { + } + public void display(GLAutoDrawable drawable) { + if(!drawable.getAutoSwapBufferMode()) { + GL2 gl = drawable.getGL().getGL2(); + // copy the colored content of the back buffer into the front buffer + // gl.glPushAttrib(GL.GL_COLOR_BUFFER_BIT); + gl.glReadBuffer(GL.GL_BACK); // def. in dbl buff mode: GL_BACK + gl.glDrawBuffer(GL.GL_FRONT); // def. in dbl buff mode: GL_BACK + gl.glCopyPixels(0, 0, drawable.getWidth(), drawable.getHeight(), GL2.GL_COLOR); + // gl.glPopAttrib(); + gl.glDrawBuffer(GL.GL_BACK); // def. in dbl buff mode: GL_BACK + } + } + public void reshape(GLAutoDrawable drawable, int x, int y, int width, + int height) { + } + } + protected void runTestGL(GLCapabilities caps) throws InterruptedException, InvocationTargetException { + final Frame frame = new Frame("Gears AWT Test"); + Assert.assertNotNull(frame); + + final GLCanvas glCanvas = new GLCanvas(caps); + Assert.assertNotNull(glCanvas); + glCanvas.setAutoSwapBufferMode(!altSwap); + frame.add(glCanvas); + frame.setSize(512, 512); + + glCanvas.addGLEventListener(new Gears(0)); + glCanvas.addGLEventListener(new Swapper()); + + Animator animator = new Animator(glCanvas); + QuitAdapter quitAdapter = new QuitAdapter(); + + new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter)).addTo(glCanvas); + new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(true); + }}); + animator.setUpdateFPSFrames(60, System.err); + animator.start(); + + while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) { + Thread.sleep(100); + } + + Assert.assertNotNull(frame); + Assert.assertNotNull(glCanvas); + Assert.assertNotNull(animator); + + animator.stop(); + Assert.assertEquals(false, animator.isAnimating()); + frame.setVisible(false); + Assert.assertEquals(false, frame.isVisible()); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.remove(glCanvas); + frame.dispose(); + }}); + } + + @Test + public void test01() throws InterruptedException, InvocationTargetException { + GLCapabilities caps = new GLCapabilities(glp); + caps.setDoubleBuffered(true); // code assumes dbl buffer setup + runTestGL(caps); + } + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } else if(args[i].equals("-wait")) { + waitForKey = true; + } else if(args[i].equals("-autoswap")) { + altSwap = false; + } + } + System.err.println("altSwap "+altSwap); + if(waitForKey) { + BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); + System.err.println("Press enter to continue"); + try { + System.err.println(stdin.readLine()); + } catch (IOException e) { } + } + org.junit.runner.JUnitCore.main(TestGearsAWTAnalyzeBug455.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNEWT.java index 4b6f7999a..f410baf9d 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/newt/TestGearsNEWT.java @@ -55,7 +55,6 @@ public class TestGearsNEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); glp = GLProfile.getDefault(); Assert.assertNotNull(glp); width = 512; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java index 5568b42f7..731f7c867 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/drawable/TestDrawable01NEWT.java @@ -52,7 +52,6 @@ public class TestDrawable01NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); glp = GLProfile.getDefault(); Assert.assertNotNull(glp); factory = GLDrawableFactory.getFactory(glp); @@ -99,7 +98,7 @@ public class TestDrawable01NEWT extends UITestCase { // Create native OpenGL resources .. XGL/WGL/CGL .. // equivalent to GLAutoDrawable methods: setVisible(true) // - GLCapabilities glCaps = (GLCapabilities) window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + GLCapabilities glCaps = (GLCapabilities) window.getGraphicsConfiguration().getChosenCapabilities(); Assert.assertNotNull(glCaps); Assert.assertTrue(glCaps.getGreenBits()>5); Assert.assertTrue(glCaps.getBlueBits()>5); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/GLSLMiscHelper.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/GLSLMiscHelper.java index ae08b640c..297cbbb90 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/GLSLMiscHelper.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/GLSLMiscHelper.java @@ -37,8 +37,8 @@ import javax.media.opengl.GLDrawable; import org.junit.Assert; public class GLSLMiscHelper { - public static final int frames_perftest = 10000; // frames - public static final int frames_warmup = 500; // frames + public static final int frames_perftest = 600; // frames + public static final int frames_warmup = 100; // frames public static void validateGLArrayDataServerState(GL2ES2 gl, GLArrayDataServer data) { final ShaderState st = ShaderState.getShaderState(gl); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java index 50d65e985..aca1e6607 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestFBOMRTNEWT01.java @@ -56,11 +56,6 @@ import org.junit.BeforeClass; public class TestFBOMRTNEWT01 extends UITestCase { static long durationPerTest = 10; // ms - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - } - @Test public void test01() throws InterruptedException { // preset .. diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java index 672938310..ea290693c 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java @@ -54,15 +54,11 @@ import org.junit.BeforeClass; */ public class TestGLSLShaderState01NEWT extends UITestCase { static long durationPerTest = 10; // ms + static boolean firstUIActionOnProcess = false; static final int vertices0_loc = 0; // FIXME: AMD needs this to be location 0 ? hu ? static final int colors0_loc = 1; - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - } - @Test public void testShaderState01Validation() throws InterruptedException { // preset .. @@ -181,11 +177,11 @@ public class TestGLSLShaderState01NEWT extends UITestCase { NEWTGLContext.destroyWindow(winctx); } - @Test(timeout=120000) + @Test(timeout=240000) public void testShaderState00PerformanceSingleKeepEnabled() throws InterruptedException { testShaderState00PerformanceSingle(false); } - @Test(timeout=120000) + @Test(timeout=240000) public void testShaderState00PerformanceSingleToggleEnable() throws InterruptedException { testShaderState00PerformanceSingle(true); } @@ -278,7 +274,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { NEWTGLContext.destroyWindow(winctx); } - @Test(timeout=120000) + @Test(timeout=240000) public void testShaderState01PerformanceDouble() throws InterruptedException { // preset .. final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(GLProfile.getGL2ES2(), 480, 480, false); @@ -386,9 +382,10 @@ public class TestGLSLShaderState01NEWT extends UITestCase { for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest); - } - if(args[i].equals("-wait")) { + } else if(args[i].equals("-wait")) { wait = true; + } else if(args[i].equals("-firstUIAction")) { + firstUIActionOnProcess = true; } } if(wait) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java index 2bb825649..fb52ff04b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java @@ -58,11 +58,6 @@ public class TestGLSLShaderState02NEWT extends UITestCase { static final int vertices0_loc = 0; // FIXME: AMD needs this to be location 0 ? hu ? static final int colors0_loc = 5; - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - } - @Test public void testShaderState01ValidationSP1Linked() throws InterruptedException { testShaderState01Validation(true); @@ -236,7 +231,7 @@ public class TestGLSLShaderState02NEWT extends UITestCase { NEWTGLContext.destroyWindow(winctx); } - @Test(timeout=120000) + @Test(timeout=240000) public void testShaderState01PerformanceDouble() throws InterruptedException { // preset .. final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(GLProfile.getGL2ES2(), 480, 480, false); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java index b683cb2e7..672193946 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLSimple01NEWT.java @@ -54,19 +54,6 @@ import org.junit.AfterClass; public class TestGLSLSimple01NEWT extends UITestCase { static long durationPerTest = 100; // ms - @BeforeClass - public static void initClass() { - System.err.println("class init"); - GLProfile.initSingleton(true); - } - - @AfterClass - public static void tearDownClass() { - System.err.println("class tear down .."); - GLProfile.shutdown(); - System.err.println("class tear down end"); - } - @Test(timeout=60000) public void testGLSLCompilation01() { GLProfile glp = GLProfile.get(GLProfile.GL2ES2); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java index fe1149f86..13780a7e5 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestRulerNEWT01.java @@ -57,13 +57,11 @@ import org.junit.BeforeClass; public class TestRulerNEWT01 extends UITestCase { static long durationPerTest = 10; // ms - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - } - @Test public void test01() throws InterruptedException { + long t0 = System.nanoTime(); + GLProfile.initSingleton(); + long t1 = System.nanoTime(); // preset .. final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow(GLProfile.getGL2ES2(), 640, 480, true); final GLDrawable drawable = winctx.context.getGLDrawable(); @@ -161,7 +159,15 @@ public class TestRulerNEWT01 extends UITestCase { Thread.sleep(durationPerTest/10); } + long t2 = System.nanoTime(); + NEWTGLContext.destroyWindow(winctx); + + long t3 = System.nanoTime(); + + System.err.println("t1-t0: "+ (t1-t0)/1e6 +"ms"); + System.err.println("t3-t0: "+ (t3-t0)/1e6 +"ms"); + System.err.println("t3-t2: "+ (t3-t2)/1e6 +"ms"); } public static void main(String args[]) throws IOException { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java index a6d04cf24..a3059baae 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestTransformFeedbackVaryingsBug407NEWT.java @@ -29,16 +29,6 @@ public class TestTransformFeedbackVaryingsBug407NEWT extends UITestCase { private String VERTEX_SHADER_TEXT; - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - } - - @AfterClass - public static void tearDownClass() { - GLProfile.shutdown(); - } - class MyShader { int shaderProgram; int vertShader; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java b/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java index 2809a138c..213d3ad05 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/newt/TestSwingAWTRobotUsageBeforeJOGLInitBug411.java @@ -112,9 +112,6 @@ public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase { public static void setup() throws InterruptedException, InvocationTargetException, AWTException { System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): Start Pre-JOGL-Swing"); - // GLProfile.initSingleton(false); - // GLProfile.initSingleton(true); - // simulate AWT usage before JOGL's initialization of X11 threading windowClosing=false; border = BorderFactory.createLineBorder (Color.yellow, 2); @@ -166,8 +163,7 @@ public class TestSwingAWTRobotUsageBeforeJOGLInitBug411 extends UITestCase { System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): Before JOGL init"); // just to trigger JOGL initialization at a well defined point .. - // ofc it's not the first UI command - GLProfile.initSingleton(false); + GLProfile.initSingleton(); System.err.println("TestSwingAWTRobotUsageBeforeJOGLInitBug411.setup(): End Pre-JOGL-Swing"); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01GLPBufferNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01GLPBufferNEWT.java index 561819485..3f1fd144f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01GLPBufferNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen01GLPBufferNEWT.java @@ -56,7 +56,6 @@ public class TestOffscreen01GLPBufferNEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); glpDefault = GLProfile.getDefault(); Assert.assertNotNull(glpDefault); glDrawableFactory = GLDrawableFactory.getFactory(glpDefault); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen02BitmapNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen02BitmapNEWT.java index 1b43940cd..e2ce78b9b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen02BitmapNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/TestOffscreen02BitmapNEWT.java @@ -61,7 +61,6 @@ public class TestOffscreen02BitmapNEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); glpDefault = GLProfile.getDefault(); Assert.assertNotNull(glpDefault); glDrawableFactory = GLDrawableFactory.getFactory(glpDefault); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java index 199b094f2..1d1ee1e0c 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/offscreen/WindowUtilNEWT.java @@ -103,7 +103,7 @@ public class WindowUtilNEWT { while ( windowOffScreen.getTotalFPSFrames() < frames) { windowOffScreen.display(); } - windowOffScreen.removeAllSurfaceUpdatedListener(); + windowOffScreen.removeSurfaceUpdatedListener(ul); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java index e6d937d0c..d302c3903 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java @@ -73,7 +73,6 @@ public class TestSWT01GLn extends UITestCase { @BeforeClass
public static void startup() {
- GLProfile.initSingleton(true);
System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() );
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT02GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT02GLn.java index 3e153214b..b8e45dfe1 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT02GLn.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT02GLn.java @@ -38,7 +38,6 @@ import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.opengl.GLCanvas; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; @@ -78,7 +77,6 @@ public class TestSWT02GLn extends UITestCase { @BeforeClass public static void startup() { - GLProfile.initSingleton( true ); System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() ); } @@ -156,7 +154,7 @@ public class TestSWT02GLn extends UITestCase { ProxySurface proxySurface = factory.createProxySurface(device, nativeWindowHandle, caps, null); Assert.assertNotNull( proxySurface ); - proxySurface.setSize( 640, 480 ); + proxySurface.surfaceSizeChanged( 640, 480 ); System.err.println("*** ProxySurface: " + proxySurface); final GLDrawable drawable = factory.createGLDrawable(proxySurface); Assert.assertNotNull( drawable ); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java index 595e6fb31..6139d816a 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java @@ -29,6 +29,7 @@ package com.jogamp.opengl.test.junit.jogl.swt;
import java.awt.Frame;
+import java.lang.reflect.InvocationTargetException;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
@@ -37,6 +38,8 @@ import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
+import jogamp.nativewindow.swt.SWTAccessor;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.graphics.Rectangle;
@@ -76,46 +79,47 @@ public class TestSWTAWT01GLn extends UITestCase { }
@Before
- public void init() {
- display = new Display();
- Assert.assertNotNull( display );
- shell = new Shell( display );
- Assert.assertNotNull( shell );
- shell.setLayout( new FillLayout() );
- composite = new Composite( shell, SWT.EMBEDDED | SWT.NO_BACKGROUND );
- composite.setLayout( new FillLayout() );
- Assert.assertNotNull( composite );
- frame = SWT_AWT.new_Frame( composite );
- Assert.assertNotNull( frame );
+ public void init() throws InterruptedException, InvocationTargetException {
+ SWTAccessor.invoke(true, new Runnable() {
+ public void run() {
+ display = new Display();
+ Assert.assertNotNull( display );
+ shell = new Shell( display );
+ Assert.assertNotNull( shell );
+ shell.setLayout( new FillLayout() );
+ composite = new Composite( shell, SWT.EMBEDDED | SWT.NO_BACKGROUND );
+ composite.setLayout( new FillLayout() );
+ Assert.assertNotNull( composite );
+ frame = SWT_AWT.new_Frame( composite );
+ Assert.assertNotNull( frame );
+ }});
}
@After
- public void release() {
+ public void release() throws InterruptedException, InvocationTargetException {
Assert.assertNotNull( display );
Assert.assertNotNull( shell );
Assert.assertNotNull( composite );
Assert.assertNotNull( glcanvas );
- try {
- javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- frame.setVisible(false);
- frame.remove(glcanvas);
- frame.dispose();
- }});
- composite.dispose();
- shell.close();
- shell.dispose();
- display.dispose();
- }
- catch( Throwable throwable ) {
- throwable.printStackTrace();
- Assume.assumeNoException( throwable );
- }
- display = null;
- shell = null;
- composite = null;
- frame = null;
- glcanvas = null;
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setVisible(false);
+ frame.remove(glcanvas);
+ frame.dispose();
+ frame = null;
+ glcanvas = null;
+ }});
+
+ SWTAccessor.invoke(true, new Runnable() {
+ public void run() {
+ composite.dispose();
+ shell.close();
+ shell.dispose();
+ display.dispose();
+ display = null;
+ shell = null;
+ composite = null;
+ }});
}
protected void runTestGL( GLProfile glprofile ) throws InterruptedException {
@@ -148,18 +152,26 @@ public class TestSWTAWT01GLn extends UITestCase { }
});
- shell.setText( getClass().getName() );
- shell.setSize( 640, 480 );
- shell.open();
+ SWTAccessor.invoke(true, new Runnable() {
+ public void run() {
+ shell.setText( getClass().getName() );
+ shell.setSize( 640, 480 );
+ shell.open();
+ }});
long lStartTime = System.currentTimeMillis();
long lEndTime = lStartTime + duration;
try {
while( (System.currentTimeMillis() < lEndTime) && !composite.isDisposed() ) {
- if( !display.readAndDispatch() ) {
- // blocks on linux .. display.sleep();
- Thread.sleep(10);
- }
+ SWTAccessor.invoke(true, new Runnable() {
+ public void run() {
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) { }
+ }
+ }});
}
}
catch( Throwable throwable ) {
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java index adc885191..4ebb7dddd 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestCloseNewtAWT.java @@ -39,10 +39,9 @@ import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.util.Point; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; + import com.jogamp.newt.Window; import com.jogamp.newt.awt.NewtCanvasAWT; -import com.jogamp.newt.event.WindowAdapter; -import com.jogamp.newt.event.WindowEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.util.AWTRobotUtil; import com.jogamp.opengl.test.junit.util.UITestCase; @@ -53,6 +52,7 @@ public class TestCloseNewtAWT extends UITestCase { NewtCanvasAWT newtCanvas = null; JFrame frame = null; + @SuppressWarnings("serial") class MyCanvas extends NewtCanvasAWT { public MyCanvas(Window window) { super(window); @@ -78,7 +78,7 @@ public class TestCloseNewtAWT extends UITestCase { NativeWindow nw = MyCanvas.this.getNativeWindow(); if(null != nw) { Point p = nw.getLocationOnScreen(null); - System.err.println("MyCanvas On NEWT-EDT: position: "+p); + System.err.println("MyCanvas On NEWT-EDT: position: "+p); } else { System.err.println("MyCanvas On NEWT-EDT: position n/a, null NativeWindow"); } @@ -110,8 +110,6 @@ public class TestCloseNewtAWT extends UITestCase { Thread.sleep(500); Assert.assertEquals(true, AWTRobotUtil.closeWindow(frame, true)); - - GLProfile.shutdown(); } public static void main(String[] args) { diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java index d027460db..c9450c2d6 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle01NEWT.java @@ -51,7 +51,6 @@ public class TestDisplayLifecycle01NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); width = 640; height = 480; glp = GLProfile.getDefault(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java index 4b3c5d506..bf509124b 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestDisplayLifecycle02NEWT.java @@ -51,7 +51,6 @@ public class TestDisplayLifecycle02NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); width = 640; height = 480; glp = GLProfile.getDefault(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java index 13653b907..fe7fef09f 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus01SwingAWTRobot.java @@ -35,6 +35,7 @@ import org.junit.Assume; import java.awt.AWTException; import java.awt.BorderLayout; import java.awt.Button; +import java.awt.Color; import java.awt.Robot; import java.lang.reflect.InvocationTargetException; @@ -119,7 +120,7 @@ public class TestFocus01SwingAWTRobot extends UITestCase { AWTFocusAdapter frame1FA = new AWTFocusAdapter("frame1"); frame1.addFocusListener(frame1FA); frame1.getContentPane().add(newtCanvasAWT, BorderLayout.CENTER); - Button button = new Button("Click me .."); + final Button button = new Button("Click me .."); AWTFocusAdapter buttonFA = new AWTFocusAdapter("Button"); button.addFocusListener(buttonFA); AWTKeyAdapter buttonKA = new AWTKeyAdapter("Button"); @@ -127,7 +128,10 @@ public class TestFocus01SwingAWTRobot extends UITestCase { eventCountAdapters.add(buttonKA); frame1.getContentPane().add(button, BorderLayout.NORTH); frame1.setSize(width, height); - frame1.setVisible(true); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame1.setVisible(true); + } } ); Assert.assertTrue(AWTRobotUtil.toFront(robot, frame1)); Thread.sleep(durationPerTest); // manual testing @@ -162,7 +166,6 @@ public class TestFocus01SwingAWTRobot extends UITestCase { System.err.println("FOCUS NEWT Canvas/GLWindow request"); EventCountAdapterUtil.reset(eventCountAdapters); AWTRobotUtil.assertRequestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonFA); - Assert.assertTrue(AWTRobotUtil.waitForFocusCount(false, newtCanvasAWTFA)); Assert.assertEquals(true, glWindow1FA.focusGained()); Assert.assertEquals(false, buttonFA.focusGained()); Assert.assertEquals(true, buttonFA.focusLost()); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java index 56b08b52a..b9eb748b7 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestFocus02SwingAWTRobot.java @@ -145,14 +145,17 @@ public class TestFocus02SwingAWTRobot extends UITestCase { jPanel1.add(new Button("west"), BorderLayout.WEST); jPanel1.add(container1, BorderLayout.CENTER); - JFrame jFrame1 = new JFrame("Swing Parent JFrame"); + final JFrame jFrame1 = new JFrame("Swing Parent JFrame"); AWTFocusAdapter jFrame1FA = new AWTFocusAdapter("JFrame1"); jFrame1.addFocusListener(jFrame1FA); // jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event! jFrame1.setContentPane(jPanel1); jFrame1.setSize(width, height); - jFrame1.setVisible(true); // from here on, we need to run modifications on EDT + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + jFrame1.setVisible(true); + } } ); Assert.assertTrue(AWTRobotUtil.toFront(robot, jFrame1)); int wait=0; @@ -192,7 +195,6 @@ public class TestFocus02SwingAWTRobot extends UITestCase { System.err.println("FOCUS NEWT Canvas/GLWindow request"); EventCountAdapterUtil.reset(eventCountAdapters); AWTRobotUtil.assertRequestFocusAndWait(robot, newtCanvasAWT, newtCanvasAWT.getNEWTChild(), glWindow1FA, buttonNorthOuterFA); - Assert.assertTrue(AWTRobotUtil.waitForFocusCount(false, newtCanvasAWTFA)); Assert.assertEquals(true, glWindow1FA.focusGained()); Assert.assertEquals(false, buttonNorthOuterFA.focusGained()); Assert.assertEquals(true, buttonNorthOuterFA.focusLost()); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows00NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows00NEWT.java index 5c42f2b16..309d7c7cb 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows00NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows00NEWT.java @@ -50,8 +50,6 @@ public class TestGLWindows00NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); - // GLProfile.initSingleton(false); width = 640; height = 480; glp = GLProfile.getDefault(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows01NEWT.java index 45a0b0b13..0c6f60b5f 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows01NEWT.java @@ -50,8 +50,6 @@ public class TestGLWindows01NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); - // GLProfile.initSingleton(false); width = 640; height = 480; glp = GLProfile.getDefault(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java index 3176d59e5..6f4ced53c 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindows02NEWTAnimated.java @@ -52,7 +52,6 @@ public class TestGLWindows02NEWTAnimated extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); width = 640; height = 480; glp = GLProfile.getDefault(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestListenerCom01AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestListenerCom01AWT.java index 15151fa2c..fa7f0f915 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestListenerCom01AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestListenerCom01AWT.java @@ -42,6 +42,7 @@ import com.jogamp.newt.opengl.*; import com.jogamp.newt.awt.NewtCanvasAWT; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import com.jogamp.opengl.test.junit.util.*; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; @@ -58,7 +59,7 @@ public class TestListenerCom01AWT extends UITestCase { } @Test - public void testListenerStringPassingAndOrder() throws InterruptedException { + public void testListenerStringPassingAndOrder() throws InterruptedException, InvocationTargetException { // setup NEWT GLWindow .. GLWindow glWindow = GLWindow.create(new GLCapabilities(null)); Assert.assertNotNull(glWindow); @@ -88,10 +89,13 @@ public class TestListenerCom01AWT extends UITestCase { // attach NEWT GLWindow to AWT Canvas NewtCanvasAWT newtCanvasAWT = new NewtCanvasAWT(glWindow); - Frame frame = new Frame("AWT Parent Frame"); + final Frame frame = new Frame("AWT Parent Frame"); frame.add(newtCanvasAWT); frame.setSize(width, height); - frame.setVisible(true); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.setVisible(true); + }}); Animator animator1 = new Animator(glWindow); animator1.setUpdateFPSFrames(1, null); @@ -104,14 +108,17 @@ public class TestListenerCom01AWT extends UITestCase { animator1.stop(); Assert.assertEquals(false, animator1.isAnimating()); - frame.dispose(); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.dispose(); + }}); glWindow.destroy(); } public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); Assert.assertNotNull(glWindow); - Window window = glWindow.getWindow(); + Window window = glWindow.getDelegatedWindow(); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java index ee21a8ded..35e24403f 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteGLWindows01NEWT.java @@ -48,17 +48,9 @@ import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.NativeWindowException; public class TestRemoteGLWindows01NEWT extends UITestCase { - static int width, height; + static int width = 640, height = 480; static long durationPerTest = 100; // ms - static String remoteDisplay = "nowhere:0.0"; - - @BeforeClass - public static void initClass() { - GLProfile.initSingleton(true); - // GLProfile.initSingleton(false); - width = 640; - height = 480; - } + static String remoteDisplay = "localhost:0.0"; static GLWindow createWindow(Screen screen, GLCapabilities caps, GLEventListener demo) throws InterruptedException diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java index 9c44545f2..eb652584c 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestRemoteWindow01NEWT.java @@ -43,7 +43,7 @@ import com.jogamp.opengl.test.junit.util.UITestCase; public class TestRemoteWindow01NEWT extends UITestCase { static int width, height; - static String remoteDisplay = "nowhere:0.0"; + static String remoteDisplay = "localhost:0.0"; @BeforeClass public static void initClass() { @@ -77,7 +77,7 @@ public class TestRemoteWindow01NEWT extends UITestCase { // Create native OpenGL resources .. XGL/WGL/CGL .. // equivalent to GLAutoDrawable methods: setVisible(true) // - CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getChosenCapabilities(); Assert.assertNotNull(chosenCapabilities); Assert.assertTrue(chosenCapabilities.getGreenBits()>5); Assert.assertTrue(chosenCapabilities.getBlueBits()>5); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java index 985affa92..a5b7a76e7 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java @@ -35,21 +35,21 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import com.jogamp.newt.Display; import com.jogamp.newt.NewtFactory; import com.jogamp.newt.Screen; -import com.jogamp.newt.Window; import com.jogamp.newt.ScreenMode; import com.jogamp.newt.util.MonitorMode; import com.jogamp.newt.util.ScreenModeUtil; import com.jogamp.opengl.test.junit.util.UITestCase; import java.util.Iterator; import java.util.List; -import javax.media.nativewindow.Capabilities; import javax.media.nativewindow.util.Dimension; import javax.media.nativewindow.util.DimensionImmutable; import javax.media.nativewindow.util.SurfaceSize; public class TestScreenMode00NEWT extends UITestCase { + static int screenIdx = 0; static int width, height; static int waitTimeShort = 4; //1 sec @@ -95,12 +95,12 @@ public class TestScreenMode00NEWT extends UITestCase { @Test public void testScreenModeInfo01() throws InterruptedException { - Capabilities caps = new Capabilities(); - Window window = NewtFactory.createWindow(caps); - window.setSize(width, height); - window.setVisible(true); - - Screen screen = window.getScreen(); + Display dpy = NewtFactory.createDisplay(null); + Screen screen = NewtFactory.createScreen(dpy, screenIdx); + screen.addReference(); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,screen.getDisplay().isNativeValid()); + System.err.println("Screen: "+screen.toString()); List<ScreenMode> screenModes = screen.getScreenModes(); Assert.assertTrue(screenModes.size()>0); @@ -116,18 +116,26 @@ public class TestScreenMode00NEWT extends UITestCase { System.err.println("curr SM: "+sm_c); System.err.println("curr sz: "+screen.getWidth()+"x"+screen.getHeight()); Assert.assertEquals(sm_o, sm_c); - Assert.assertEquals(sm_c.getRotatedWidth(), screen.getWidth()); - Assert.assertEquals(sm_c.getRotatedHeight(), screen.getHeight()); - window.destroy(); + screen.removeReference(); - Assert.assertEquals(false,window.isVisible()); - Assert.assertEquals(false,window.isNativeValid()); Assert.assertEquals(false,screen.isNativeValid()); Assert.assertEquals(false,screen.getDisplay().isNativeValid()); } + static int atoi(String a) { + try { + return Integer.parseInt(a); + } catch (Exception ex) { throw new RuntimeException(ex); } + } + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-screen")) { + i++; + screenIdx = atoi(args[i]); + } + } String tstname = TestScreenMode00NEWT.class.getName(); org.junit.runner.JUnitCore.main(tstname); } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java index 41bdfdfd7..e9e66da2c 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java @@ -95,10 +95,10 @@ public class TestScreenMode00bNEWT extends UITestCase { System.err.println("orig: "+sm_o); System.err.println("curr: "+sm_c); - for(i=0; i<100; i++) { + for(i=0; i<50; i++) { sm_c = screen.getCurrentScreenMode(); Assert.assertNotNull(sm_c); - System.err.print("."); + System.err.print("."+i); } System.err.println("!"); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java index 5f14fc466..c3c68e46c 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java @@ -68,7 +68,6 @@ public class TestScreenMode01NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); width = 640; height = 480; glp = GLProfile.getDefault(); @@ -112,8 +111,8 @@ public class TestScreenMode01NEWT extends UITestCase { */ @After public void cleanupGL() throws InterruptedException { - GLProfile.shutdown(); - GLProfile.initSingleton(true); + GLProfile.shutdown(GLProfile.ShutdownType.COMPLETE); + GLProfile.initSingleton(); } static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) { @@ -201,8 +200,6 @@ public class TestScreenMode01NEWT extends UITestCase { Assert.assertNotNull(smOrig); Assert.assertEquals(smCurrent, smOrig); System.err.println("[0] current/orig: "+smCurrent); - Assert.assertEquals(smCurrent.getRotatedWidth(), screen.getWidth()); - Assert.assertEquals(smCurrent.getRotatedHeight(), screen.getHeight()); screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate()); Assert.assertNotNull(screenModes); @@ -223,8 +220,6 @@ public class TestScreenMode01NEWT extends UITestCase { screen.setCurrentScreenMode(sm); Assert.assertEquals(sm, screen.getCurrentScreenMode()); Assert.assertNotSame(smOrig, screen.getCurrentScreenMode()); - Assert.assertEquals(sm.getRotatedWidth(), screen.getWidth()); - Assert.assertEquals(sm.getRotatedHeight(), screen.getHeight()); Thread.sleep(waitTimeLong); @@ -254,8 +249,6 @@ public class TestScreenMode01NEWT extends UITestCase { Assert.assertNotNull(smCurrent); Assert.assertEquals(smCurrent, smOrig); - Assert.assertEquals(smCurrent.getRotatedWidth(), screen.getWidth()); - Assert.assertEquals(smCurrent.getRotatedHeight(), screen.getHeight()); screen.destroy(); @@ -289,8 +282,6 @@ public class TestScreenMode01NEWT extends UITestCase { Assert.assertNotNull(smOrig); Assert.assertEquals(smCurrent, smOrig); System.err.println("[0] current/orig: "+smCurrent); - Assert.assertEquals(smCurrent.getRotatedWidth(), screen.getWidth()); - Assert.assertEquals(smCurrent.getRotatedHeight(), screen.getHeight()); List<ScreenMode> screenModes = screen.getScreenModes(); if(screenModes.size()==1) { @@ -317,8 +308,6 @@ public class TestScreenMode01NEWT extends UITestCase { System.err.println("[0] set current: "+screenMode); screen.setCurrentScreenMode(screenMode); - Assert.assertEquals(screenMode.getRotatedWidth(), screen.getWidth()); - Assert.assertEquals(screenMode.getRotatedHeight(), screen.getHeight()); if(!preFS) { System.err.println("[0] set FS post 0: "+window.isFullscreen()); @@ -355,8 +344,6 @@ public class TestScreenMode01NEWT extends UITestCase { Assert.assertNotNull(smCurrent); Assert.assertEquals(smCurrent, smOrig); - Assert.assertEquals(smCurrent.getRotatedWidth(), screen.getWidth()); - Assert.assertEquals(smCurrent.getRotatedHeight(), screen.getHeight()); screen.destroy(); } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java index 4d7769669..38612faa8 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java @@ -65,7 +65,6 @@ public class TestScreenMode01bNEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); width = 100; height = 100; glp = GLProfile.getDefault(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java index 8c7f75e2b..1c9cb91f3 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java @@ -60,7 +60,6 @@ public class TestScreenMode02NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); width = 640; height = 480; glp = GLProfile.getDefault(); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java index 827dd09fb..a99edfadb 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestWindows01NEWT.java @@ -90,7 +90,7 @@ public class TestWindows01NEWT extends UITestCase { Assert.assertEquals(y, window.getY()); } */ - CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getChosenCapabilities(); Assert.assertNotNull(chosenCapabilities); Assert.assertTrue(chosenCapabilities.getGreenBits()>=5); Assert.assertTrue(chosenCapabilities.getBlueBits()>=5); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java index 46748cb52..473f2f584 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java @@ -51,7 +51,11 @@ class NewtAWTReparentingKeyAdapter extends KeyAdapter { if(e.getKeyChar()=='d') { glWindow.setUndecorated(!glWindow.isUndecorated()); } else if(e.getKeyChar()=='f') { - glWindow.setFullscreen(!glWindow.isFullscreen()); + glWindow.setFullscreen(!glWindow.isFullscreen()); + } else if(e.getKeyChar()=='l') { + javax.media.nativewindow.util.Point p0 = newtCanvasAWT.getNativeWindow().getLocationOnScreen(null); + javax.media.nativewindow.util.Point p1 = glWindow.getLocationOnScreen(null); + System.err.println("NewtCanvasAWT position: "+p0+", "+p1); } else if(e.getKeyChar()=='p') { new Thread() { public void run() { diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java index 7f97be649..256868c6c 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01NEWT.java @@ -53,7 +53,6 @@ public class TestParenting01NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); width = 640; height = 480; glCaps = new GLCapabilities(null); @@ -654,7 +653,7 @@ public class TestParenting01NEWT extends UITestCase { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); } - if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getWindow())) { + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getDelegatedWindow())) { MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); } } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java index 674cf4a06..2040fb9b6 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01aAWT.java @@ -467,7 +467,7 @@ public class TestParenting01aAWT extends UITestCase { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); } - if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getWindow())) { + if(!MiscUtils.setFieldIfExists(demo, "window", glWindow.getDelegatedWindow())) { MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); } } diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java index 8571609a8..d98a540ec 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01bAWT.java @@ -173,7 +173,7 @@ public class TestParenting01bAWT extends UITestCase { public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); Assert.assertNotNull(glWindow); - Window window = glWindow.getWindow(); + Window window = glWindow.getDelegatedWindow(); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java index 3b40554d2..dfd0787e7 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cAWT.java @@ -228,7 +228,7 @@ public class TestParenting01cAWT extends UITestCase { public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); Assert.assertNotNull(glWindow); - Window window = glWindow.getWindow(); + Window window = glWindow.getDelegatedWindow(); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java index f505547d4..22ed7c6fd 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java @@ -319,7 +319,7 @@ public class TestParenting01cSwingAWT extends UITestCase { public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); Assert.assertNotNull(glWindow); - Window window = glWindow.getWindow(); + Window window = glWindow.getDelegatedWindow(); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java index f01468c2a..da689cea6 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02AWT.java @@ -118,7 +118,8 @@ public class TestParenting02AWT extends UITestCase { } } - frame.setSize(width, height); + // frame.setSize(width, height); + frame.setBounds(100, 100, width, height); javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { @@ -233,7 +234,7 @@ public class TestParenting02AWT extends UITestCase { public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); Assert.assertNotNull(glWindow); - Window window = glWindow.getWindow(); + Window window = glWindow.getDelegatedWindow(); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java index 13aad0c25..bc3988338 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting02NEWT.java @@ -54,7 +54,6 @@ public class TestParenting02NEWT extends UITestCase { @BeforeClass public static void initClass() { - GLProfile.initSingleton(true); width = 640; height = 480; } @@ -120,7 +119,7 @@ public class TestParenting02NEWT extends UITestCase { // glWindow1.addGLEventListener(demo1); glWindow1.setVisible(true); - CapabilitiesImmutable capsChosen = glWindow1.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + CapabilitiesImmutable capsChosen = glWindow1.getGraphicsConfiguration().getChosenCapabilities(); Assert.assertNotNull(capsChosen); Assert.assertTrue(capsChosen.isOnscreen()==true); @@ -142,7 +141,7 @@ public class TestParenting02NEWT extends UITestCase { // glWindow2.addGLEventListener(demo2); glWindow2.setVisible(true); - capsChosen = glWindow2.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + capsChosen = glWindow2.getGraphicsConfiguration().getChosenCapabilities(); Assert.assertNotNull(capsChosen); Assert.assertTrue(capsChosen.isOnscreen()==true); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java index aded8f163..b33a40fae 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting03AWT.java @@ -35,10 +35,10 @@ import org.junit.BeforeClass; import org.junit.Test; import java.awt.BorderLayout; +import java.awt.Button; import java.awt.Container; import java.awt.Dimension; import java.awt.Frame; -import java.awt.Label; import javax.media.opengl.*; @@ -53,28 +53,34 @@ import com.jogamp.opengl.test.junit.util.*; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; public class TestParenting03AWT extends UITestCase { - static Dimension size; - static long durationPerTest = 800; + static Dimension glSize, fSize; + static long durationPerTest = 1100; static long waitAdd2nd = 500; static GLCapabilities glCaps; @BeforeClass public static void initClass() { - size = new Dimension(400,200); + glSize = new Dimension(400,200); + fSize = new Dimension(3*400,2*200); glCaps = new GLCapabilities(null); } @Test - public void testWindowParenting1AWTTwoNewtChilds01() throws InterruptedException, InvocationTargetException { - testWindowParenting1AWTTwoNewtChilds(); + public void testWindowParenting1AWTOneNewtChilds01() throws InterruptedException, InvocationTargetException { + testWindowParenting1AWT(false); } - public void testWindowParenting1AWTTwoNewtChilds() throws InterruptedException, InvocationTargetException { + @Test + public void testWindowParenting1AWTTwoNewtChilds01() throws InterruptedException, InvocationTargetException { + testWindowParenting1AWT(true); + } + + public void testWindowParenting1AWT(boolean use2nd) throws InterruptedException, InvocationTargetException { final Frame frame1 = new Frame("AWT Parent Frame"); GLWindow glWindow1 = GLWindow.create(glCaps); glWindow1.setUpdateFPSFrames(1, null); final NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1); - newtCanvasAWT1.setPreferredSize(size); + newtCanvasAWT1.setPreferredSize(glSize); GLEventListener demo1 = new GearsES2(1); setDemoFields(demo1, glWindow1, false); @@ -83,7 +89,6 @@ public class TestParenting03AWT extends UITestCase { GLAnimatorControl animator1 = new Animator(glWindow1); animator1.start(); - final boolean use2nd = true; GLWindow glWindow2 = null; NewtCanvasAWT newtCanvasAWT2 = null; GLAnimatorControl animator2 = null; @@ -91,7 +96,7 @@ public class TestParenting03AWT extends UITestCase { glWindow2 = GLWindow.create(glCaps); glWindow2.setUpdateFPSFrames(1, null); newtCanvasAWT2 = new NewtCanvasAWT(glWindow2); - newtCanvasAWT2.setPreferredSize(size); + newtCanvasAWT2.setPreferredSize(glSize); GLEventListener demo2 = new GearsES2(1); setDemoFields(demo2, glWindow2, false); @@ -103,10 +108,10 @@ public class TestParenting03AWT extends UITestCase { final Container cont1 = new Container(); cont1.setLayout(new BorderLayout()); - cont1.add(new Label("iNORTH"), BorderLayout.NORTH); - cont1.add(new Label("iSOUTH"), BorderLayout.SOUTH); - cont1.add(new Label("iEAST"), BorderLayout.EAST); - cont1.add(new Label("iWEST"), BorderLayout.WEST); + cont1.add(new Button("NORTH"), BorderLayout.NORTH); + cont1.add(new Button("SOUTH"), BorderLayout.SOUTH); + cont1.add(new Button("EAST"), BorderLayout.EAST); + cont1.add(new Button("WEST"), BorderLayout.WEST); cont1.add(newtCanvasAWT1, BorderLayout.CENTER); System.err.println("******* Cont1 setVisible"); cont1.setVisible(true); @@ -114,34 +119,31 @@ public class TestParenting03AWT extends UITestCase { final Container cont2 = new Container(); cont2.setLayout(new BorderLayout()); if(use2nd) { - cont2.add(new Label("iNORTH"), BorderLayout.NORTH); - cont2.add(new Label("iSOUTH"), BorderLayout.SOUTH); - cont2.add(new Label("iEAST"), BorderLayout.EAST); - cont2.add(new Label("iWEST"), BorderLayout.WEST); + cont2.add(new Button("north"), BorderLayout.NORTH); + cont2.add(new Button("sourth"), BorderLayout.SOUTH); + cont2.add(new Button("east"), BorderLayout.EAST); + cont2.add(new Button("west"), BorderLayout.WEST); cont2.add(newtCanvasAWT2, BorderLayout.CENTER); } System.err.println("******* Cont2 setVisible"); cont2.setVisible(true); frame1.setLayout(new BorderLayout()); - frame1.add(new Label("NORTH"), BorderLayout.NORTH); - frame1.add(new Label("CENTER"), BorderLayout.CENTER); - frame1.add(new Label("SOUTH"), BorderLayout.SOUTH); + frame1.add(new Button("NORTH"), BorderLayout.NORTH); + frame1.add(new Button("CENTER"), BorderLayout.CENTER); + frame1.add(new Button("SOUTH"), BorderLayout.SOUTH); frame1.add(cont1, BorderLayout.EAST); frame1.setLocation(0, 0); - frame1.setSize((int)size.getWidth()*3, (int)size.getHeight()*2); + frame1.setSize(fSize); javax.swing.SwingUtilities.invokeAndWait(new Runnable() { public void run() { System.err.println("******* Frame setVisible"); + frame1.validate(); frame1.setVisible(true); }}); Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent()); - if(use2nd) { - Assert.assertEquals(newtCanvasAWT2.getNativeWindow(),glWindow2.getParent()); - } - Assert.assertEquals(true, animator1.isAnimating()); Assert.assertEquals(false, animator1.isPaused()); Assert.assertNotNull(animator1.getThread()); @@ -150,15 +152,17 @@ public class TestParenting03AWT extends UITestCase { Assert.assertEquals(true, animator2.isAnimating()); Assert.assertEquals(false, animator2.isPaused()); Assert.assertNotNull(animator2.getThread()); - } - Thread.sleep(waitAdd2nd); + Thread.sleep(waitAdd2nd); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame1.add(cont2, BorderLayout.WEST); + frame1.validate(); + }}); + Assert.assertEquals(newtCanvasAWT2.getNativeWindow(),glWindow2.getParent()); + } - javax.swing.SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - frame1.add(cont2, BorderLayout.WEST); - frame1.validate(); - }}); Thread.sleep(durationPerTest); @@ -187,7 +191,7 @@ public class TestParenting03AWT extends UITestCase { public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); Assert.assertNotNull(glWindow); - Window window = glWindow.getWindow(); + Window window = glWindow.getDelegatedWindow(); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java new file mode 100644 index 000000000..b23c17022 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingFocusTraversal01AWT.java @@ -0,0 +1,334 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.newt.parenting; + +import java.lang.reflect.*; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.AWTException; +import java.awt.AWTKeyStroke; +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.KeyboardFocusManager; +import java.awt.Robot; + +import javax.media.opengl.*; + +import com.jogamp.opengl.util.Animator; +import com.jogamp.newt.*; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.awt.NewtCanvasAWT; +import com.jogamp.newt.event.KeyAdapter; +import com.jogamp.newt.event.KeyEvent; + +import java.io.IOException; + +import jogamp.newt.driver.DriverClearFocus; + +import com.jogamp.opengl.test.junit.util.*; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; + +public class TestParentingFocusTraversal01AWT extends UITestCase { + static Dimension glSize, fSize; + static int numFocus = 8; + static long durationPerTest = numFocus * 100; + static GLCapabilities glCaps; + static boolean manual = false; + + @BeforeClass + public static void initClass() { + glSize = new Dimension(200,200); + fSize = new Dimension(300,300); + glCaps = new GLCapabilities(null); + } + + @Test + public void testWindowParentingAWTFocusTraversal01Onscreen() throws InterruptedException, InvocationTargetException, AWTException { + testWindowParentingAWTFocusTraversal(true); + } + + @Test + public void testWindowParentingAWTFocusTraversal02Offscreen() throws InterruptedException, InvocationTargetException, AWTException { + testWindowParentingAWTFocusTraversal(false); + } + + public void testWindowParentingAWTFocusTraversal(boolean onscreen) throws InterruptedException, InvocationTargetException, AWTException { + Robot robot = new Robot(); + + // Bug 4908075 - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4908075 + // Bug 6463168 - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6463168 + { + final KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + final Set<AWTKeyStroke> bwdKeys = kfm.getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); + final AWTKeyStroke newBack = AWTKeyStroke.getAWTKeyStroke(java.awt.event.KeyEvent.VK_BACK_SPACE, 0, false); + Assert.assertNotNull(newBack); + final Set<AWTKeyStroke> bwdKeys2 = new HashSet<AWTKeyStroke>(bwdKeys); + bwdKeys2.add(newBack); + kfm.setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, bwdKeys2); + } + { + final KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + final Set<AWTKeyStroke> fwdKeys = kfm.getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); + final Set<AWTKeyStroke> bwdKeys = kfm.getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); + Iterator<AWTKeyStroke> iter; + for(iter = fwdKeys.iterator(); iter.hasNext(); ) { + System.err.println("FTKL.fwd-keys: "+iter.next()); + } + for(iter = bwdKeys.iterator(); iter.hasNext(); ) { + System.err.println("FTKL.bwd-keys: "+iter.next()); + } + } + + final Frame frame1 = new Frame("AWT Parent Frame"); + final Button cWest = new Button("WEST"); + final Button cEast = new Button("EAST"); + final GLWindow glWindow1 = GLWindow.create(glCaps); + glWindow1.setUpdateFPSFrames(1, null); + final NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1); + newtCanvasAWT1.setPreferredSize(glSize); + newtCanvasAWT1.setShallUseOffscreenLayer(!onscreen); + newtCanvasAWT1.setFocusable(true); + + // Test FocusAdapter + NEWTFocusAdapter glWindow1FA = new NEWTFocusAdapter("GLWindow1"); + glWindow1.addWindowListener(glWindow1FA); + AWTFocusAdapter bWestFA = new AWTFocusAdapter("WEST"); + cWest.addFocusListener(bWestFA); + AWTFocusAdapter bEastFA = new AWTFocusAdapter("EAST"); + cEast.addFocusListener(bEastFA); + + // Test KeyAdapter + NEWTKeyAdapter glWindow1KA = new NEWTKeyAdapter("GLWindow1"); + glWindow1.addKeyListener(glWindow1KA); + AWTKeyAdapter bWestKA = new AWTKeyAdapter("West"); + cWest.addKeyListener(bWestKA); + AWTKeyAdapter bEastKA = new AWTKeyAdapter("East"); + cEast.addKeyListener(bEastKA); + + // demo .. + GLEventListener demo1 = new GearsES2(1); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1)); + glWindow1.addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent e) { + if(e.getKeyChar()=='c') { + System.err.println("Focus Clear"); + if(glWindow1.getDelegatedWindow() instanceof DriverClearFocus) { + ((DriverClearFocus)glWindow1.getDelegatedWindow()).clearFocus(); + } + } else if(e.getKeyChar()=='e') { + System.err.println("Focus East"); + try { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + cEast.requestFocusInWindow(); + } + }); + } catch (Exception ex) { ex.printStackTrace(); } + } else if(e.getKeyChar()=='w') { + System.err.println("Focus West"); + try { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + cWest.requestFocusInWindow(); + } + }); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + }); + GLAnimatorControl animator1 = new Animator(glWindow1); + animator1.start(); + + // make frame + frame1.setLayout(new BorderLayout()); + frame1.setLayout(new BorderLayout()); + frame1.add(cWest, BorderLayout.WEST); + frame1.add(newtCanvasAWT1, BorderLayout.CENTER); + frame1.add(cEast, BorderLayout.EAST); + + frame1.setLocation(0, 0); + frame1.setSize(fSize); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame1.validate(); + frame1.setVisible(true); + }}); + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(glWindow1, true)); + Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent()); + + Assert.assertEquals(true, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertNotNull(animator1.getThread()); + + if(manual) { + Thread.sleep(durationPerTest); + } else { + // + // initial focus on bWest + // + AWTRobotUtil.assertRequestFocusAndWait(robot, cWest, cWest, bWestFA, null); + Assert.assertEquals(true, bWestFA.focusGained()); + Thread.sleep(durationPerTest/numFocus); + + // + // forth + // + + // bWest -> glWin + AWTRobotUtil.keyType(0, robot, java.awt.event.KeyEvent.VK_TAB, cWest, null); + Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(glWindow1, glWindow1FA, bWestFA)); + Assert.assertEquals(true, glWindow1FA.focusGained()); + Assert.assertEquals(true, bWestFA.focusLost()); + Thread.sleep(durationPerTest/numFocus); + + // glWin -> bEast + AWTRobotUtil.keyType(0, robot, java.awt.event.KeyEvent.VK_TAB, glWindow1, null); + Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(cEast, bEastFA, glWindow1FA)); + Assert.assertEquals(true, bEastFA.focusGained()); + Assert.assertEquals(true, glWindow1FA.focusLost()); + Thread.sleep(durationPerTest/numFocus); + + // + // back (using custom back traversal key 'backspace') + // + // bEast -> glWin + AWTRobotUtil.keyType(0, robot, java.awt.event.KeyEvent.VK_BACK_SPACE, cEast, null); + Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(glWindow1, glWindow1FA, bEastFA)); + Assert.assertEquals(true, glWindow1FA.focusGained()); + Assert.assertEquals(true, bEastFA.focusLost()); + Thread.sleep(durationPerTest/numFocus); + + AWTRobotUtil.keyType(0, robot, java.awt.event.KeyEvent.VK_BACK_SPACE, glWindow1, null); + Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(cWest, bWestFA, glWindow1FA)); + Assert.assertEquals(true, bWestFA.focusGained()); + Assert.assertEquals(true, glWindow1FA.focusLost()); + Thread.sleep(durationPerTest/numFocus); + + // direct AWT request focus + try { + java.awt.EventQueue.invokeAndWait(new Runnable() { + public void run() { + newtCanvasAWT1.requestFocus(); + } + }); + } catch (Exception ex) { ex.printStackTrace(); } + Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(glWindow1, glWindow1FA, bWestFA)); + Assert.assertEquals(true, glWindow1FA.focusGained()); + Assert.assertEquals(true, bWestFA.focusLost()); + Thread.sleep(durationPerTest/numFocus); + + // direct AWT request focus + try { + java.awt.EventQueue.invokeAndWait(new Runnable() { + public void run() { + cWest.requestFocus(); + } + }); + } catch (Exception ex) { ex.printStackTrace(); } + Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(cWest, bWestFA, glWindow1FA)); + Assert.assertEquals(true, bWestFA.focusGained()); + Assert.assertEquals(true, glWindow1FA.focusLost()); + Thread.sleep(durationPerTest/numFocus); + + // direct NEWT request focus + glWindow1.requestFocus(); + Assert.assertTrue("Did not gain focus", AWTRobotUtil.waitForFocus(glWindow1, glWindow1FA, bWestFA)); + Assert.assertEquals(true, glWindow1FA.focusGained()); + Assert.assertEquals(true, bWestFA.focusLost()); + Thread.sleep(durationPerTest/numFocus); + } + + animator1.stop(); + Assert.assertEquals(false, animator1.isAnimating()); + Assert.assertEquals(false, animator1.isPaused()); + Assert.assertEquals(null, animator1.getThread()); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame1.dispose(); + } } ); + glWindow1.destroy(); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getDelegatedWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } else if(args[i].equals("-manual")) { + manual = true; + } + } + String tstname = TestParentingFocusTraversal01AWT.class.getName(); + /* + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */ + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01GLCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01GLCanvasAWT.java new file mode 100644 index 000000000..1367a27dd --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01GLCanvasAWT.java @@ -0,0 +1,205 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.newt.parenting; + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Frame; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +import javax.media.opengl.GLAnimatorControl; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.awt.GLCanvas; + +import jogamp.nativewindow.jawt.JAWTUtil; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.Window; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +public class TestParentingOffscreenLayer01GLCanvasAWT extends UITestCase { + static Dimension frameSize0; + static Dimension frameSize1; + static Dimension preferredGLSize; + static Dimension minGLSize; + static long durationPerTest = 1000; + + @BeforeClass + public static void initClass() { + frameSize0 = new Dimension(500,300); + frameSize1 = new Dimension(800,600); + preferredGLSize = new Dimension(400,200); + minGLSize = new Dimension(200,100); + } + + private void setupFrameAndShow(final Frame f, java.awt.Component comp) throws InterruptedException, InvocationTargetException { + + Container c = new Container(); + c.setLayout(new BorderLayout()); + c.add(new Button("north"), BorderLayout.NORTH); + c.add(new Button("south"), BorderLayout.SOUTH); + c.add(new Button("east"), BorderLayout.EAST); + c.add(new Button("west"), BorderLayout.WEST); + c.add(comp, BorderLayout.CENTER); + + f.setLayout(new BorderLayout()); + f.add(new Button("NORTH"), BorderLayout.NORTH); + f.add(new Button("SOUTH"), BorderLayout.SOUTH); + f.add(new Button("EAST"), BorderLayout.EAST); + f.add(new Button("WEST"), BorderLayout.WEST); + f.add(c, BorderLayout.CENTER); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + f.validate(); + f.setVisible(true); + }}); + } + private void end(GLAnimatorControl actrl, final Frame f, Window w) throws InterruptedException, InvocationTargetException { + actrl.stop(); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + f.dispose(); + } } ); + if(null != w) { + w.destroy(); + } + } + + @Test + public void testOnscreenLayerGLCanvas_Onscreen() throws InterruptedException, InvocationTargetException { + testOffscreenLayerGLCanvas_Impl(false, false); + } + + /** We have no GLCanvas OffscreenWindow as we have for NEWT .. test disabled. + @Test + public void testOffscreenLayerGLCanvas_OffscreenLayerWithOffscreenClass() throws InterruptedException, InvocationTargetException { + testOffscreenLayerGLCanvas_Impl(true, true); + } */ + + @Test + public void testOffscreenLayerGLCanvas_OffscreenLayerWithOnscreenClass() throws InterruptedException, InvocationTargetException { + testOffscreenLayerGLCanvas_Impl(true, false); + } + + private void testOffscreenLayerGLCanvas_Impl(boolean offscreenLayer, boolean offscreenClass) throws InterruptedException, InvocationTargetException { + final Frame frame1 = new Frame("AWT Parent Frame"); + + GLCapabilities glCaps = new GLCapabilities(null); + if(offscreenClass) { + glCaps.setOnscreen(false); + glCaps.setPBuffer(true); + } + + final GLCanvas glc = new GLCanvas(glCaps); + glc.setShallUseOffscreenLayer(offscreenLayer); // trigger offscreen layer - if supported + glc.setPreferredSize(preferredGLSize); + glc.setMinimumSize(minGLSize); + + GLEventListener demo1 = new GearsES2(1); + glc.addGLEventListener(demo1); + + frame1.setSize(frameSize0); + setupFrameAndShow(frame1, glc); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glc, true)); + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(glc, true)); + Assert.assertEquals(JAWTUtil.isOffscreenLayerSupported() && offscreenLayer, + glc.isOffscreenLayerSurfaceEnabled()); + + GLAnimatorControl animator1 = new Animator(glc); + animator1.start(); + + Thread.sleep(durationPerTest/2); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame1.setSize(frameSize1); + frame1.validate(); + }}); + + Thread.sleep(durationPerTest/2); + + end(animator1, frame1, null); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getDelegatedWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + String tstname = TestParentingOffscreenLayer01GLCanvasAWT.class.getName(); + /* + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */ + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer02NewtCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer02NewtCanvasAWT.java new file mode 100644 index 000000000..bc59c7378 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer02NewtCanvasAWT.java @@ -0,0 +1,209 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.newt.parenting; + +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.Frame; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + +import javax.media.opengl.GLAnimatorControl; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; + +import jogamp.nativewindow.jawt.JAWTUtil; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.Window; +import com.jogamp.newt.awt.NewtCanvasAWT; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.AWTRobotUtil; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +public class TestParentingOffscreenLayer02NewtCanvasAWT extends UITestCase { + static Dimension frameSize0; + static Dimension frameSize1; + static Dimension preferredGLSize; + static Dimension minGLSize; + static long durationPerTest = 1000; + + @BeforeClass + public static void initClass() { + frameSize0 = new Dimension(500,300); + frameSize1 = new Dimension(800,600); + preferredGLSize = new Dimension(400,200); + minGLSize = new Dimension(200,100); + } + + private void setupFrameAndShow(final Frame f, java.awt.Component comp) throws InterruptedException, InvocationTargetException { + + Container c = new Container(); + c.setLayout(new BorderLayout()); + c.add(new Button("north"), BorderLayout.NORTH); + c.add(new Button("south"), BorderLayout.SOUTH); + c.add(new Button("east"), BorderLayout.EAST); + c.add(new Button("west"), BorderLayout.WEST); + c.add(comp, BorderLayout.CENTER); + + f.setLayout(new BorderLayout()); + f.add(new Button("NORTH"), BorderLayout.NORTH); + f.add(new Button("SOUTH"), BorderLayout.SOUTH); + f.add(new Button("EAST"), BorderLayout.EAST); + f.add(new Button("WEST"), BorderLayout.WEST); + f.add(c, BorderLayout.CENTER); + + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + f.validate(); + f.setVisible(true); + }}); + } + private void end(GLAnimatorControl actrl, final Frame f, Window w) throws InterruptedException, InvocationTargetException { + actrl.stop(); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + f.dispose(); + } } ); + if(null != w) { + w.destroy(); + } + } + + @Test + public void testOnscreenLayerNewtCanvas_Onscreen() throws InterruptedException, InvocationTargetException { + testOffscreenLayerNewtCanvas_Impl(false, false); + } + + @Test + public void testOffscreenLayerNewtCanvas_OffscreenLayerWithOffscreenClass() throws InterruptedException, InvocationTargetException { + testOffscreenLayerNewtCanvas_Impl(true, true); + } + + @Test + public void testOffscreenLayerNewtCanvas_OffscreenLayerWithOnscreenClass() throws InterruptedException, InvocationTargetException { + testOffscreenLayerNewtCanvas_Impl(true, false); + } + + private void testOffscreenLayerNewtCanvas_Impl(boolean offscreenLayer, boolean offscreenClass) throws InterruptedException, InvocationTargetException { + final Frame frame1 = new Frame("AWT Parent Frame"); + + GLCapabilities glCaps = new GLCapabilities(null); + if(offscreenClass) { + glCaps.setOnscreen(false); + glCaps.setPBuffer(true); + } + + GLWindow glWindow1 = GLWindow.create(glCaps); + + final NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1); + newtCanvasAWT1.setShallUseOffscreenLayer(offscreenLayer); // trigger offscreen layer - if supported + newtCanvasAWT1.setPreferredSize(preferredGLSize); + newtCanvasAWT1.setMinimumSize(minGLSize); + + GLEventListener demo1 = new GearsES2(1); + setDemoFields(demo1, glWindow1, false); + glWindow1.addGLEventListener(demo1); + glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1)); + + frame1.setSize(frameSize0); + setupFrameAndShow(frame1, newtCanvasAWT1); + Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, true)); + Assert.assertEquals(true, AWTRobotUtil.waitForVisible(glWindow1, true)); + Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent()); + Assert.assertEquals(JAWTUtil.isOffscreenLayerSupported() && offscreenLayer, + newtCanvasAWT1.isOffscreenLayerSurfaceEnabled()); + + GLAnimatorControl animator1 = new Animator(glWindow1); + animator1.start(); + + Thread.sleep(durationPerTest/2); + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame1.setSize(frameSize1); + frame1.validate(); + }}); + + Thread.sleep(durationPerTest/2); + + end(animator1, frame1, glWindow1); + } + + public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { + Assert.assertNotNull(demo); + Assert.assertNotNull(glWindow); + Window window = glWindow.getDelegatedWindow(); + if(debug) { + MiscUtils.setFieldIfExists(demo, "glDebug", true); + MiscUtils.setFieldIfExists(demo, "glTrace", true); + } + if(!MiscUtils.setFieldIfExists(demo, "window", window)) { + MiscUtils.setFieldIfExists(demo, "glWindow", glWindow); + } + } + + static int atoi(String a) { + int i=0; + try { + i = Integer.parseInt(a); + } catch (Exception ex) { ex.printStackTrace(); } + return i; + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = atoi(args[++i]); + } + } + String tstname = TestParentingOffscreenLayer02NewtCanvasAWT.class.getName(); + /* + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */ + org.junit.runner.JUnitCore.main(tstname); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestTranslucentParentingAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestTranslucentParentingAWT.java index be812e6aa..57b8517a6 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestTranslucentParentingAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestTranslucentParentingAWT.java @@ -50,6 +50,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import com.jogamp.common.util.ReflectionUtil; import com.jogamp.newt.Window; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.opengl.GLWindow; @@ -89,8 +90,15 @@ public class TestTranslucentParentingAWT extends UITestCase { boolean capable1 = ( null != tcm ) ? tcm.getTransparency() == Transparency.TRANSLUCENT : false; boolean capable2 = false; try { - capable2 = com.sun.awt.AWTUtilities.isTranslucencyCapable(config); - } catch (Exception e) {} + capable2 = ((Boolean)ReflectionUtil.callStaticMethod( + "com.sun.awt.AWTUtilities", "isTranslucencyCapable", + new Class<?>[] { GraphicsConfiguration.class }, + new Object[] { config } , + GraphicsConfiguration.class.getClassLoader())).booleanValue(); + System.err.println("com.sun.awt.AWTUtilities.isTranslucencyCapable(config) passed: "+capable2); + } catch (RuntimeException re) { + System.err.println("com.sun.awt.AWTUtilities.isTranslucencyCapable(config) failed: "+re.getMessage()); + } System.err.println(i+":"+j+" "+config+", "+tcm+", capable "+capable1+"/"+capable2); if(capable1&&capable2) { gc=configs[j]; @@ -157,7 +165,7 @@ public class TestTranslucentParentingAWT extends UITestCase { public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) { Assert.assertNotNull(demo); Assert.assertNotNull(glWindow); - Window window = glWindow.getWindow(); + Window window = glWindow.getDelegatedWindow(); if(debug) { MiscUtils.setFieldIfExists(demo, "glDebug", true); MiscUtils.setFieldIfExists(demo, "glTrace", true); diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java index 7df8645de..a27bdd7a2 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java @@ -67,7 +67,7 @@ public class AWTRobotUtil { int x0, y0; if(null!=comp) { - java.awt.Point p0 = comp.getLocationOnScreen(); + java.awt.Point p0 = comp.getLocationOnScreen(); java.awt.Rectangle r0 = comp.getBounds(); if( onTitleBarIfWindow && comp instanceof java.awt.Window) { java.awt.Window window = (java.awt.Window) comp; @@ -78,7 +78,7 @@ public class AWTRobotUtil { } x0 = (int) ( p0.getX() + r0.getWidth() / 2.0 + .5 ) ; } else { - javax.media.nativewindow.util.Point p0 = win.getLocationOnScreen(null); + javax.media.nativewindow.util.Point p0 = win.getLocationOnScreen(null); if( onTitleBarIfWindow ) { javax.media.nativewindow.util.InsetsImmutable insets = win.getInsets(); p0.translate(win.getWidth()/2, insets.getTopHeight()/2); @@ -102,6 +102,9 @@ public class AWTRobotUtil { public static boolean toFront(Robot robot, final java.awt.Window window) throws AWTException, InterruptedException, InvocationTargetException { + AWTWindowFocusAdapter winFA = new AWTWindowFocusAdapter("window"); + window.addWindowFocusListener(winFA); + if(null == robot) { robot = new Robot(); robot.setAutoWaitForIdle(true); @@ -119,11 +122,11 @@ public class AWTRobotUtil { }}); robot.delay(ROBOT_DELAY); - KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); int wait; - for (wait=0; wait<POLL_DIVIDER && window != kfm.getFocusedWindow(); wait++) { + for (wait=0; wait<POLL_DIVIDER && !winFA.focusGained(); wait++) { Thread.sleep(TIME_SLICE); } + window.removeWindowFocusListener(winFA); return wait<POLL_DIVIDER; } @@ -280,8 +283,8 @@ public class AWTRobotUtil { Assert.assertTrue("Did not gain focus", hasFocus); } - static int keyType(int i, Robot robot, int keyCode, - Object obj, InputEventCountAdapter counter) throws InterruptedException, AWTException, InvocationTargetException + public static int keyType(int i, Robot robot, int keyCode, + Object obj, InputEventCountAdapter counter) throws InterruptedException, AWTException, InvocationTargetException { int tc = 0; int j; @@ -293,13 +296,13 @@ public class AWTRobotUtil { if(DEBUG) { System.err.println(i+":"+j+" KC1.0: "+counter+" - regain focus"); } requestFocus(null, obj); } - final int c0 = counter.getCount(); + final int c0 = null!=counter ? counter.getCount() : 0; if(DEBUG) { System.err.println(i+":"+j+" KC1.1: "+counter); } robot.waitForIdle(); robot.keyPress(keyCode); robot.keyRelease(keyCode); if(DEBUG) { System.err.println(i+":"+j+" KC1.2: "+counter); } - tc = counter.getCount() - c0; + tc = ( null!=counter ? counter.getCount() : 1 ) - c0; for (int wait=0; wait<POLL_DIVIDER && 1 > tc; wait++) { robot.delay(TIME_SLICE); tc = counter.getCount() - c0; @@ -355,13 +358,13 @@ public class AWTRobotUtil { if(DEBUG) { System.err.println(i+":"+j+" MC1.0: "+counter+" - regain focus"); } requestFocus(null, obj); } - final int c0 = counter.getCount(); + final int c0 = null != counter ? counter.getCount() : 0; if(DEBUG) { System.err.println(i+":"+j+" MC1.1: "+counter); } robot.waitForIdle(); robot.mousePress(mouseButton); robot.mouseRelease(mouseButton); if(DEBUG) { System.err.println(i+":"+j+" MC1.2: "+counter); } - tc = counter.getCount() - c0; + tc = ( null != counter ? counter.getCount() : 1 ) - c0; for (int wait=0; wait<POLL_DIVIDER && 1 > tc; wait++) { robot.delay(TIME_SLICE); tc = counter.getCount() - c0; diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTWindowFocusAdapter.java b/src/test/com/jogamp/opengl/test/junit/util/AWTWindowFocusAdapter.java new file mode 100644 index 000000000..16aacd2fd --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/util/AWTWindowFocusAdapter.java @@ -0,0 +1,71 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.util; + +import java.awt.event.WindowEvent; +import java.awt.event.WindowFocusListener; + +public class AWTWindowFocusAdapter implements FocusEventCountAdapter, WindowFocusListener { + + String prefix; + int focusCount; + + public AWTWindowFocusAdapter(String prefix) { + this.prefix = prefix; + reset(); + } + + public boolean focusLost() { + return focusCount<0; + } + + public boolean focusGained() { + return focusCount>0; + } + + public void reset() { + focusCount = 0; + } + + /* @Override */ + public void windowGainedFocus(WindowEvent e) { + if(focusCount<0) { focusCount=0; } + focusCount++; + System.err.println("FOCUS AWT GAINED (Window) [fc "+focusCount+"]: "+prefix+", "+e); + } + + /* @Override */ + public void windowLostFocus(WindowEvent e) { + if(focusCount>0) { focusCount=0; } + focusCount--; + System.err.println("FOCUS AWT LOST (Window) [fc "+focusCount+"]: "+prefix+", "+e); + } + + public String toString() { return prefix+"[focusCount "+focusCount +"]"; } +} diff --git a/src/test/com/jogamp/opengl/test/junit/util/NEWTGLContext.java b/src/test/com/jogamp/opengl/test/junit/util/NEWTGLContext.java index 6a6cf390f..c74d2eaa7 100644 --- a/src/test/com/jogamp/opengl/test/junit/util/NEWTGLContext.java +++ b/src/test/com/jogamp/opengl/test/junit/util/NEWTGLContext.java @@ -78,6 +78,7 @@ public class NEWTGLContext { Assert.assertNotNull(drawable); drawable.setRealized(true); + Assert.assertTrue(drawable.isRealized()); GLContext context = drawable.createContext(null); Assert.assertNotNull(context); diff --git a/src/test/jogamp/newt/WindowImplAccess.java b/src/test/jogamp/newt/WindowImplAccess.java index 76d0dc050..e8be5f68a 100644 --- a/src/test/jogamp/newt/WindowImplAccess.java +++ b/src/test/jogamp/newt/WindowImplAccess.java @@ -29,26 +29,16 @@ package jogamp.newt; import com.jogamp.newt.Window; -import com.jogamp.newt.opengl.GLWindow; /** * Allows access to protected methods of WindowImpl */ public class WindowImplAccess { public static final void windowDestroyNotify(Window win) { - WindowImpl winImpl = null; - if(win instanceof GLWindow) { - GLWindow glwin = (GLWindow) win; - winImpl = (WindowImpl) glwin.getWindow(); - } else if(win instanceof WindowImpl) { - winImpl = (WindowImpl) win; - } else { - throw new RuntimeException("Given Window not a GLWindow, not WindowImpl, but "+win.getClass()); - } - final WindowImpl winImplF = winImpl; - winImplF.runOnEDTIfAvail(true, new Runnable() { + final WindowImpl winImpl = (WindowImpl) win.getDelegatedWindow(); + winImpl.runOnEDTIfAvail(true, new Runnable() { public void run() { - winImplF.windowDestroyNotify(); + winImpl.windowDestroyNotify(); } }); } diff --git a/src/test/native/displayMultiple02.c b/src/test/native/displayMultiple02.c index 1bfe95b95..df6666aff 100644 --- a/src/test/native/displayMultiple02.c +++ b/src/test/native/displayMultiple02.c @@ -11,7 +11,21 @@ static void testOrder(int reverseDestroyOrder, const char * msg); +static int useXLockDisplay = 0; + int main(int nargs, char **vargs) { + int arg=1; + while(arg<nargs) { + if(0 == strcmp(vargs[arg], "-xlock")) { + useXLockDisplay = 1; + } + arg++; + } + fprintf(stderr, "-xlock (XLockDisplay): %d\n", useXLockDisplay); + + if( useXLockDisplay ) { + XInitThreads(); + } testOrder(0, "Normal order"); testOrder(1, "Reverse order"); return 0; @@ -20,6 +34,17 @@ int main(int nargs, char **vargs) { static void createGLWin(Display *dpy, int width, int height, Window *rWin, GLXContext *rCtx); static void useGL(Display *dpy, Window win, GLXContext ctx, int width, int height); +static void XLOCKDISPLAY(Display *dpy) { + if( useXLockDisplay ) { + XLockDisplay(dpy); + } +} +static void XUNLOCKDISPLAY(Display *dpy) { + if( useXLockDisplay ) { + XUnlockDisplay(dpy); + } +} + void testOrder(int reverseDestroyOrder, const char * msg) { int major, minor; Display *disp1; @@ -32,35 +57,58 @@ void testOrder(int reverseDestroyOrder, const char * msg) { fprintf(stderr, "%s: Create #1\n", msg); disp1 = XOpenDisplay(NULL); - createGLWin(disp1, 200, 200, &win1, &ctx1); - useGL(disp1, win1, ctx1, 200, 200); + XLOCKDISPLAY(disp1); + createGLWin(disp1, 200, 200, &win1, &ctx1); + useGL(disp1, win1, ctx1, 200, 200); + XUNLOCKDISPLAY(disp1); fprintf(stderr, "%s: Create #2\n", msg); disp2 = XOpenDisplay(NULL); - createGLWin(disp2, 300, 300, &win2, &ctx2); - useGL(disp2, win2, ctx2, 300, 300); + XLOCKDISPLAY(disp2); + createGLWin(disp2, 300, 300, &win2, &ctx2); + useGL(disp2, win2, ctx2, 300, 300); + XUNLOCKDISPLAY(disp2); if(reverseDestroyOrder) { - fprintf(stderr, "%s: Destroy #2\n", msg); - glXMakeCurrent(disp2, 0, 0); - glXDestroyContext(disp2, ctx2); + fprintf(stderr, "%s: Destroy #2.0\n", msg); + XLOCKDISPLAY(disp2); + glXMakeCurrent(disp2, 0, 0); + glXDestroyContext(disp2, ctx2); + XUNLOCKDISPLAY(disp2); XCloseDisplay(disp2); - - fprintf(stderr, "%s: Destroy #1\n", msg); - glXMakeCurrent(disp1, 0, 0); - glXDestroyContext(disp1, ctx1); + fprintf(stderr, "%s: Destroy #2.X\n", msg); + + fprintf(stderr, "%s: Destroy #1.0\n", msg); + XLOCKDISPLAY(disp1); + fprintf(stderr, "%s: Destroy #1.1\n", msg); + glXMakeCurrent(disp1, 0, 0); + fprintf(stderr, "%s: Destroy #1.2\n", msg); + glXDestroyContext(disp1, ctx1); + fprintf(stderr, "%s: Destroy #1.3\n", msg); + XUNLOCKDISPLAY(disp1); + fprintf(stderr, "%s: Destroy #1.4\n", msg); XCloseDisplay(disp1); + fprintf(stderr, "%s: Destroy #1.X\n", msg); } else { - fprintf(stderr, "%s: Destroy #1\n", msg); - glXMakeCurrent(disp1, 0, 0); - glXDestroyContext(disp1, ctx1); + fprintf(stderr, "%s: Destroy #1.0\n", msg); + XLOCKDISPLAY(disp1); + glXMakeCurrent(disp1, 0, 0); + glXDestroyContext(disp1, ctx1); + XUNLOCKDISPLAY(disp1); XCloseDisplay(disp1); - - fprintf(stderr, "%s: Destroy #2\n", msg); - glXMakeCurrent(disp2, 0, 0); - glXDestroyContext(disp2, ctx2); + fprintf(stderr, "%s: Destroy #1.X\n", msg); + + fprintf(stderr, "%s: Destroy #2.0\n", msg); + XLOCKDISPLAY(disp2); + fprintf(stderr, "%s: Destroy #2.1\n", msg); + glXMakeCurrent(disp2, 0, 0); + fprintf(stderr, "%s: Destroy #2.2\n", msg); + glXDestroyContext(disp2, ctx2); + fprintf(stderr, "%s: Destroy #2.3\n", msg); + XUNLOCKDISPLAY(disp2); + fprintf(stderr, "%s: Destroy #2.4\n", msg); XCloseDisplay(disp2); - + fprintf(stderr, "%s: Destroy #2.X\n", msg); } fprintf(stderr, "%s: Success - no bug\n", msg); |