aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmake/scripts/tests-win.bat3
-rw-r--r--make/scripts/tests.sh5
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java5
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java221
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java30
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/UITestCase.java20
6 files changed, 280 insertions, 4 deletions
diff --git a/make/scripts/tests-win.bat b/make/scripts/tests-win.bat
index da531dd66..872ba3716 100755
--- a/make/scripts/tests-win.bat
+++ b/make/scripts/tests-win.bat
@@ -115,10 +115,11 @@ REM scripts\java-win.bat com.jogamp.opengl.test.junit.nativewindow.TestRecursive
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00aNEWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00bNEWT %*
+scripts\java-win.bat com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00cNEWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01aNEWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01bNEWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01cNEWT %*
-scripts\java-win.bat com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01dNEWT %*
+REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01dNEWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.mm.TestScreenMode02aNEWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.mm.TestScreenMode02bNEWT %*
REM scripts\java-win.bat com.jogamp.opengl.test.junit.newt.mm.ManualScreenMode03sNEWT %*
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index a5ce8d2e9..bc37f2845 100644
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -152,7 +152,7 @@ function jrun() {
#D_ARGS="-Djogl.debug.GLProfile"
#D_ARGS="-Dnativewindow.debug.NativeWindow -Dnewt.debug.Window -Dnewt.debug.Screen -Dnewt.debug.Display"
#D_ARGS="-Djogl.debug.GLCanvas -Dnewt.debug.Window -Dnewt.debug.Display -Dnewt.debug.EDT -Djogl.debug.Animator"
- D_ARGS="-Dnewt.debug.Display -Dnewt.debug.EDT -Dnewt.debug.Window"
+ #D_ARGS="-Dnewt.debug.Display -Dnewt.debug.EDT -Dnewt.debug.Window"
#D_ARGS="-Dnewt.debug.EDT -Dnewt.debug.Window -Djogl.debug.GLContext"
#D_ARGS="-Dnativewindow.debug.X11Util.XErrorStackDump -Dnativewindow.debug.X11Util.TraceDisplayLifecycle -Dnativewindow.debug.X11Util"
#D_ARGS="-Dnativewindow.debug.X11Util -Djogl.debug.GLContext -Djogl.debug.GLDrawable -Dnewt.debug=all"
@@ -405,6 +405,7 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.newt.TestDisplayLifecycle02NEWT
#testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00aNEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00bNEWT $*
+testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode00cNEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01aNEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01bNEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01cNEWT $*
@@ -515,7 +516,7 @@ function testawtswt() {
#
# NEWT Parenting (w/ NEWT, AWT or SWT)
#
-testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01NEWT $*
+#testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting02NEWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocusTraversal01AWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01cSwingAWT $*
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
index bf37b8d0c..07d1008b4 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
@@ -187,7 +187,7 @@ public abstract class NativeWindowFactory {
}
}
- static boolean initialized = false;
+ private static boolean initialized = false;
private static void initSingletonNativeImpl(final ClassLoader cl) {
final String clazzName;
@@ -295,6 +295,9 @@ public abstract class NativeWindowFactory {
}
}
+ /** Returns true if {@link #initSingleton()} has been called w/o subsequent {@link #shutdown(boolean)}. */
+ public static synchronized boolean isInitialized() { return initialized; }
+
/**
* Static one time initialization of this factory.<br>
* This initialization method <b>must be called</b> once by the program or utilizing modules!
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java
new file mode 100644
index 000000000..dc3bf3c97
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00cNEWT.java
@@ -0,0 +1,221 @@
+/**
+ * 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.mm;
+
+import java.io.IOException;
+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.MonitorDevice;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.MonitorMode;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.newt.util.MonitorModeUtil;
+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 java.util.List;
+
+import javax.media.nativewindow.NativeWindowFactory;
+import javax.media.nativewindow.util.Dimension;
+
+/**
+ * Tests X11 XRandR MonitorMode reset via {@link UITestCase#resetXRandRIfX11()}.
+ */
+public class TestScreenMode00cNEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ static final int waitTimeShort = 2000;
+ static long duration = waitTimeShort;
+
+ @BeforeClass
+ public static void initClass() {
+ NativeWindowFactory.initSingleton();
+ if( NativeWindowFactory.TYPE_X11 != NativeWindowFactory.getNativeWindowType(true) ) {
+ setTestSupported(false);
+ return;
+ }
+ 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) throws InterruptedException {
+ if(null!=window) {
+ window.destroy();
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(window, false));
+ }
+ }
+
+ @Test
+ public void testScreenModeChange01() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+
+ final GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ final Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ final Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ final Window window0 = createWindow(screen, caps, "win0", 0, 0, width, height);
+ Assert.assertNotNull(window0);
+
+ final List<MonitorMode> allMonitorModes = screen.getMonitorModes();
+ Assert.assertTrue(allMonitorModes.size()>0);
+ if(allMonitorModes.size()==1) {
+ // no support ..
+ System.err.println("Your platform has no MonitorMode change support (all), sorry");
+ destroyWindow(window0);
+ return;
+ }
+
+ final MonitorDevice monitor = screen.getMonitorDevices().get(0);
+
+ List<MonitorMode> monitorModes = monitor.getSupportedModes();
+ Assert.assertTrue(monitorModes.size()>0);
+ if(monitorModes.size()==1) {
+ // no support ..
+ System.err.println("Your platform has no MonitorMode change support (monitor), sorry");
+ destroyWindow(window0);
+ return;
+ }
+ Assert.assertTrue(allMonitorModes.containsAll(monitorModes));
+
+ final MonitorMode mmSet0 = monitor.queryCurrentMode();
+ Assert.assertNotNull(mmSet0);
+ final MonitorMode mmOrig = monitor.getOriginalMode();
+ Assert.assertNotNull(mmOrig);
+ System.err.println("[0] orig : "+mmOrig);
+ System.err.println("[0] current: "+mmSet0);
+ Assert.assertEquals(mmSet0, mmOrig);
+
+
+ monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc
+ Assert.assertNotNull(monitorModes);
+ Assert.assertTrue(monitorModes.size()>0);
+ monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 0);
+ Assert.assertNotNull(monitorModes);
+ Assert.assertTrue(monitorModes.size()>0);
+ monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(801, 601));
+ Assert.assertNotNull(monitorModes);
+ Assert.assertTrue(monitorModes.size()>0);
+ monitorModes = MonitorModeUtil.filterByRate(monitorModes, mmOrig.getRefreshRate());
+ Assert.assertNotNull(monitorModes);
+ Assert.assertTrue(monitorModes.size()>0);
+
+ monitorModes = MonitorModeUtil.getHighestAvailableBpp(monitorModes);
+ Assert.assertNotNull(monitorModes);
+ Assert.assertTrue(monitorModes.size()>0);
+
+ // set mode
+ {
+ MonitorMode mm = monitorModes.get(0);
+ System.err.println("[0] set current: "+mm);
+ final boolean smOk = monitor.setCurrentMode(mm);
+ MonitorMode mmCurrent = monitor.getCurrentMode();
+ System.err.println("[0] has current: "+mmCurrent+", changeOK "+smOk);
+ Assert.assertTrue(monitor.isModeChangedByUs());
+ Assert.assertEquals(mm, mmCurrent);
+ Assert.assertNotSame(mmOrig, mmCurrent);
+ Assert.assertEquals(mmCurrent, monitor.queryCurrentMode());
+ Assert.assertTrue(smOk);
+ }
+
+ Thread.sleep(duration);
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window0.isNativeValid());
+ Assert.assertEquals(true,window0.isVisible());
+
+ UITestCase.resetXRandRIfX11();
+ System.err.println("XRandR Reset :"+monitor.queryCurrentMode());
+ validateScreenModeReset(mmOrig, 0);
+
+ destroyWindow(window0);
+
+ Thread.sleep(waitTimeShort);
+ }
+
+ void validateScreenModeReset(final MonitorMode mmOrig, int mmIdx) {
+ final Display display = NewtFactory.createDisplay(null); // local display
+ Assert.assertNotNull(display);
+ final Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ Assert.assertNotNull(screen);
+ screen.addReference();
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ final MonitorDevice monitor = screen.getMonitorDevices().get(0);
+ Assert.assertEquals(mmOrig, monitor.queryCurrentMode());
+
+ screen.removeReference();
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ duration = MiscUtils.atol(args[i], duration);
+ }
+ }
+ String tstname = TestScreenMode00cNEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
index d6e9743e0..5717335b7 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
@@ -29,6 +29,10 @@
package com.jogamp.opengl.test.junit.util;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.lang.reflect.*;
import java.nio.FloatBuffer;
@@ -148,6 +152,32 @@ public class MiscUtils {
}
return false;
}
+
+ public static class StreamDump extends Thread {
+ final InputStream is;
+ final String prefix;
+
+ public StreamDump(InputStream is, String prefix) {
+ this.is = is;
+ this.prefix = prefix;
+ }
+
+ @Override
+ public void run() {
+ try {
+ InputStreamReader isr = new InputStreamReader(is);
+ BufferedReader br = new BufferedReader(isr);
+ String line = null;
+ while ((line = br.readLine()) != null) {
+ System.out.println(prefix + "> " + line);
+ }
+ }
+ catch (IOException ioe) {
+ System.err.println("Catched "+ioe.getClass().getName()+": "+ioe.getMessage());
+ ioe.printStackTrace();
+ }
+ }
+ }
}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
index 82a80ff49..90452ebfb 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/UITestCase.java
@@ -35,6 +35,7 @@ import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;
+import javax.media.nativewindow.NativeWindowFactory;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilitiesImmutable;
@@ -90,6 +91,24 @@ public abstract class UITestCase {
testSupported = v;
}
+ public static void resetXRandRIfX11() {
+ if( NativeWindowFactory.isInitialized() && NativeWindowFactory.TYPE_X11 == NativeWindowFactory.getNativeWindowType(true) ) {
+ try {
+ final ProcessBuilder pb = new ProcessBuilder("xrandr", "-s", "0", "-o", "normal");
+ pb.redirectErrorStream(true);
+ System.err.println("XRandR Reset cmd: "+pb.command());
+ final Process p = pb.start();
+ new MiscUtils.StreamDump( p.getInputStream(), "xrandr-reset" ).start();
+ p.waitFor();
+ System.err.println("XRandR Reset result "+p.exitValue());
+ } catch (Exception e) {
+ System.err.println("Catched "+e.getClass().getName()+": "+e.getMessage());
+ e.printStackTrace();
+ }
+ System.err.println("XRandR Reset done");
+ }
+ }
+
public int getMaxTestNameLen() {
if(0 == maxMethodNameLen) {
int ml = 0;
@@ -125,6 +144,7 @@ public abstract class UITestCase {
@AfterClass
public static void oneTimeTearDown() {
// one-time cleanup code
+ resetXRandRIfX11();
System.gc(); // force cleanup
singletonInstance.unlock();
}