diff options
author | Sven Gothel <[email protected]> | 2011-09-08 03:53:33 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-09-08 03:53:33 +0200 |
commit | a9289ce0fde4d4d344e4ab895790642383226cb4 (patch) | |
tree | 51f482164527586fdcf56eb6777740ed5a07864a /src/test/com | |
parent | 3812f3400e5156622ae1c11178bacc675941693b (diff) |
NEWT/ScreenMode: X11 fixes ; Ensure Screen's size is set if screenMode changed ; Enhanced tests; Catch NV/XRANDR/GL bug
X11 fixes
- X11Screen properly uses it's display's connection
decorated in lock/unlock (for ScreenMode etc)
Ensure Screen's size is set if screenMode changed
- ScreenImpl's ScreenModeListener updates it's screen size
so 'external' changes will be detected.
Enhanced tests
- Verify more data rel. ScreenMode
Catch NV/XRANDR/GL bug
- Read TestScreenMode01NEWT/TestScreenMode01bNEWT comments
Diffstat (limited to 'src/test/com')
5 files changed, 379 insertions, 7 deletions
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 4abf41f66..cfb8c7715 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00NEWT.java @@ -111,10 +111,14 @@ public class TestScreenMode00NEWT extends UITestCase { } ScreenMode sm_o = screen.getOriginalScreenMode(); Assert.assertNotNull(sm_o); - ScreenMode sm_c = screen.getOriginalScreenMode(); + ScreenMode sm_c = screen.getCurrentScreenMode(); Assert.assertNotNull(sm_c); - System.err.println("orig: "+sm_o); - System.err.println("curr: "+sm_c); + System.err.println("orig SM: "+sm_o); + 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()); } else { // no support .. System.err.println("Your platform has no ScreenMode change support, sorry"); diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java new file mode 100644 index 000000000..a2d7d09bb --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.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.newt; + +import java.io.IOException; +import javax.media.nativewindow.NativeWindowFactory; + +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.ScreenMode; +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; + +import java.util.Iterator; +import java.util.List; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; + +public class TestScreenMode00bNEWT extends UITestCase { + static int width, height; + + static int waitTimeShort = 4; //1 sec + static int waitTimeLong = 6; //6 sec + + @BeforeClass + public static void initClass() { + NativeWindowFactory.initSingleton(true); + width = 640; + height = 480; + } + + @Test + public void testScreenModeInfo01() throws InterruptedException { + Display display = NewtFactory.createDisplay(null); + Screen screen = NewtFactory.createScreen(display, 0); + // screen.addReference(); + + // put some load on the screen/display context .. + GLCapabilitiesImmutable caps = new GLCapabilities(null); + GLWindow window = GLWindow.create(screen, caps); + window.addGLEventListener(new GearsES2()); + window.setSize(256, 256); + window.setVisible(true); + Animator anim = new Animator(window); + anim.start(); + + Assert.assertEquals(true,window.isNativeValid()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,display.isNativeValid()); + + List<ScreenMode> screenModes = screen.getScreenModes(); + if(null != screenModes) { + Assert.assertTrue(screenModes.size()>0); + int i=0; + for(Iterator<ScreenMode> iter=screenModes.iterator(); iter.hasNext(); i++) { + System.err.println(i+": "+iter.next()); + } + ScreenMode sm_o = screen.getOriginalScreenMode(); + + Assert.assertNotNull(sm_o); + ScreenMode sm_c = screen.getCurrentScreenMode(); + Assert.assertNotNull(sm_c); + System.err.println("orig: "+sm_o); + System.err.println("curr: "+sm_c); + + for(i=0; i<1000; i++) { + sm_c = screen.getCurrentScreenMode(); + Assert.assertNotNull(sm_c); + System.err.print("."); + } + System.err.println("!"); + } else { + // no support .. + System.err.println("Your platform has no ScreenMode change support, sorry"); + } + + // screen.removeReference(); + anim.stop(); + window.destroy(); + + Assert.assertEquals(false,window.isVisible()); + Assert.assertEquals(false,window.isNativeValid()); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,display.isNativeValid()); + } + + public static void main(String args[]) throws IOException { + String tstname = TestScreenMode00bNEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} 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 a874d5fe1..c53c9a1de 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01NEWT.java @@ -29,12 +29,12 @@ package com.jogamp.opengl.test.junit.newt; import java.io.IOException; -import javax.media.nativewindow.NativeWindowFactory; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; import com.jogamp.opengl.util.Animator; +import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -53,6 +53,12 @@ import com.jogamp.opengl.test.junit.util.UITestCase; import java.util.List; import javax.media.nativewindow.util.Dimension; +/** + * Demonstrates fullscreen with and without ScreenMode change. + * + * <p> + * Also documents NV RANDR/GL bug, see {@link TestScreenMode01NEWT#cleanupGL()}.</p> + */ public class TestScreenMode01NEWT extends UITestCase { static GLProfile glp; static int width, height; @@ -62,7 +68,7 @@ public class TestScreenMode01NEWT extends UITestCase { @BeforeClass public static void initClass() { - NativeWindowFactory.initSingleton(true); + GLProfile.initSingleton(true); width = 640; height = 480; glp = GLProfile.getDefault(); @@ -73,6 +79,43 @@ public class TestScreenMode01NEWT extends UITestCase { Thread.sleep(waitTimeShort); } + /** + * Following configurations results in a SIGSEGV: + * <pre> + * Ubuntu 11.04 (natty), NV GTX 460, driver [280.10* - 285.03] + * </pre> + * + * Situation: + * <pre> + * 1 - Create Screen, GLWindow (w/ context) + * 2 - ScreenMode change + * 3 - Destroy GLWindow (w/ context), Screen + * 4 - Create Screen, GLWindow (w/ context) (*) + * </pre> + * + * Step 4 causes the exception within 1st 'glXMakeContextCurrent(..)' call + * on the the created GL context. + * + * Remedy: + * <pre> + * A) Releasing all resources before step 4 .. works. + * B) Holding the native Display/Screen in NEWT also works (ie screen.addReference()). + * </pre> + * + * Hence there must be some correlations with the screen randr mode + * and some of the glcontext/gldrawables. + * + * <pre> + * Remedy A) is demonstrated here + * Remedy B) is shown in {@link TestScreenMode01bNEWT} + * </pre> + */ + @After + public void cleanupGL() throws InterruptedException { + GLProfile.shutdown(); + GLProfile.initSingleton(true); + } + static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) { Assert.assertNotNull(caps); caps.setOnscreen(onscreen); @@ -158,6 +201,8 @@ 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); @@ -178,6 +223,8 @@ 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); @@ -207,6 +254,8 @@ 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(); @@ -240,6 +289,8 @@ 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(null==screenModes) { @@ -266,6 +317,8 @@ 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()); @@ -302,6 +355,8 @@ 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 new file mode 100644 index 000000000..6c505d58a --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java @@ -0,0 +1,190 @@ +/** + * 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; + +import java.io.IOException; +import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLProfile; + +import org.junit.AfterClass; +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.opengl.GLWindow; +import com.jogamp.newt.util.ScreenModeUtil; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; +import com.jogamp.opengl.test.junit.util.UITestCase; + +import java.util.List; +import javax.media.nativewindow.util.Dimension; + +/** + * Documents remedy B) for NV RANDR/GL bug + * + * @see TestScreenMode01NEWT#cleanupGL() + */ +public class TestScreenMode01bNEWT extends UITestCase { + static GLProfile glp; + static int width, height; + + static int waitTimeShort = 2000; + static int waitTimeLong = 2000; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + width = 100; + height = 100; + glp = GLProfile.getDefault(); + } + + @AfterClass + public static void releaseClass() throws InterruptedException { + Thread.sleep(waitTimeShort); + } + + static Window createWindow(Screen screen, GLCapabilities caps, String name, int x, int y, int width, int height) { + Assert.assertNotNull(caps); + + GLWindow window = GLWindow.create(screen, caps); + // Window window = NewtFactory.createWindow(screen, caps); + window.setTitle(name); + window.setPosition(x, y); + window.setSize(width, height); + window.addGLEventListener(new GearsES2()); + Assert.assertNotNull(window); + window.setVisible(true); + return window; + } + + static void destroyWindow(Window window) { + if(null!=window) { + window.destroy(); + } + } + + @Test + public void testScreenModeChange01() throws InterruptedException { + Thread.sleep(waitTimeShort); + + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + Display display = NewtFactory.createDisplay(null); // local display + Assert.assertNotNull(display); + Screen screen = NewtFactory.createScreen(display, 0); // screen 0 + Assert.assertNotNull(screen); + Window window0 = createWindow(screen, caps, "win0", 0, 0, width, height); + Assert.assertNotNull(window0); + + List<ScreenMode> screenModes = screen.getScreenModes(); + if(null==screenModes) { + // no support .. + System.err.println("Your platform has no ScreenMode change support, sorry"); + destroyWindow(window0); + return; + } + Assert.assertTrue(screenModes.size()>0); + + ScreenMode smCurrent = screen.getCurrentScreenMode(); + Assert.assertNotNull(smCurrent); + ScreenMode smOrig = screen.getOriginalScreenMode(); + Assert.assertNotNull(smOrig); + Assert.assertEquals(smCurrent, smOrig); + System.err.println("[0] current/orig: "+smCurrent); + + screenModes = ScreenModeUtil.filterByRate(screenModes, smOrig.getMonitorMode().getRefreshRate()); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.filterByRotation(screenModes, 0); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + screenModes = ScreenModeUtil.filterByResolution(screenModes, new Dimension(801, 601)); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + + screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes); + Assert.assertNotNull(screenModes); + Assert.assertTrue(screenModes.size()>0); + + ScreenMode sm = (ScreenMode) screenModes.get(0); + System.err.println("[0] set current: "+sm); + screen.setCurrentScreenMode(sm); + Assert.assertEquals(sm, screen.getCurrentScreenMode()); + Assert.assertNotSame(smOrig, screen.getCurrentScreenMode()); + + Thread.sleep(waitTimeShort); + + // check reset .. + + Assert.assertEquals(true,display.isNativeValid()); + Assert.assertEquals(true,screen.isNativeValid()); + Assert.assertEquals(true,window0.isNativeValid()); + Assert.assertEquals(true,window0.isVisible()); + + screen.addReference(); // keep it alive ! + screen.setCurrentScreenMode(smOrig); + + destroyWindow(window0); + Assert.assertEquals(false,window0.isVisible()); + Assert.assertEquals(false,window0.isNativeValid()); + Assert.assertEquals(true,screen.isNativeValid()); // alive ! + Assert.assertEquals(true,display.isNativeValid()); + + Thread.sleep(waitTimeShort); + + Window window1 = createWindow(screen, caps, "win1", + width+window0.getInsets().getTotalWidth(), 0, + width, height); + Assert.assertNotNull(window1); + Assert.assertEquals(true,window1.isNativeValid()); + Assert.assertEquals(true,window1.isVisible()); + + Thread.sleep(waitTimeShort); + + destroyWindow(window1); + Assert.assertEquals(false,window1.isNativeValid()); + Assert.assertEquals(false,window1.isVisible()); + + screen.removeReference(); + Assert.assertEquals(false,screen.isNativeValid()); + Assert.assertEquals(false,display.isNativeValid()); + } + + public static void main(String args[]) throws IOException { + String tstname = TestScreenMode01bNEWT.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} 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 896b02263..c5c11682c 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02NEWT.java @@ -29,7 +29,6 @@ package com.jogamp.opengl.test.junit.newt; import java.io.IOException; -import javax.media.nativewindow.NativeWindowFactory; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLProfile; @@ -61,7 +60,7 @@ public class TestScreenMode02NEWT extends UITestCase { @BeforeClass public static void initClass() { - NativeWindowFactory.initSingleton(true); + GLProfile.initSingleton(true); width = 640; height = 480; glp = GLProfile.getDefault(); |