summaryrefslogtreecommitdiffstats
path: root/src/junit/com
diff options
context:
space:
mode:
authorRami Santina <[email protected]>2010-10-18 23:06:50 +0300
committerRami Santina <[email protected]>2010-10-18 23:06:50 +0300
commitc74be6eeeb273cd7530ac7e94c3128cb5fa1e420 (patch)
treeac8169f6f4e6a5116ba3dedc67abf66df7a5d24e /src/junit/com
parent735ebb60ead9996106dfcb958ddfbb6b00b407fd (diff)
Added Screen Rotation manipulation API (with X11 impl)
Added screen rotation change capability with impl for X11 (using Xrandr) com.jogamp.newt.Screen: added 2 methods which cover screen roation lifecycle setScreenRotation(int rot): Change the Screen Rotation to one of the rotations defined in ScreenMode, namely: ROTATE_0, ROTATE_90, ROTATE_180, ROTATE_270 int getCurrentScreenRotation(): Get the Current screen rotation returns -1 if not implemented natively. +++++++++++++++++++++++++ Notes: 1- At init the original rotation is called natively and cached, when screen is destroyed the rotation is reverted. 2- On X11 with Nvidia: you need to edit /etc/X11/xorg.conf: Add the following line: Option "RandRRotation" "on" in Section "Device" after BoardName. +++++++++++++++ Added TestScreenMode02NEWT which includes 4 tests 1- Rotate 90 2- Rotate 180 3- Rotate 270 4- Rotate with screen mode change should fail if screen rotation not implemented natively. (4) withh fail if screen mode not impl natively as well.
Diffstat (limited to 'src/junit/com')
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java37
-rw-r--r--src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java272
2 files changed, 288 insertions, 21 deletions
diff --git a/src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java
index acbcc6e17..5dbc56c7d 100644
--- a/src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java
+++ b/src/junit/com/jogamp/test/junit/newt/TestScreenMode01NEWT.java
@@ -28,29 +28,27 @@
package com.jogamp.test.junit.newt;
-import java.lang.reflect.*;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.io.IOException;
+import javax.media.nativewindow.Capabilities;
+import javax.media.nativewindow.NativeWindowFactory;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Test;
-import javax.media.nativewindow.*;
-
-import com.jogamp.newt.*;
+import com.jogamp.newt.Display;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+import com.jogamp.newt.Window;
import com.jogamp.newt.impl.ScreenMode;
-
-import java.io.IOException;
-
import com.jogamp.test.junit.util.UITestCase;
public class TestScreenMode01NEWT extends UITestCase {
static int width, height;
+
+ static int waitTimeShort = 1000; //1 sec
+ static int waitTimeLong = 6000; //6 sec
+
@BeforeClass
public static void initClass() {
@@ -73,9 +71,6 @@ public class TestScreenMode01NEWT extends UITestCase {
window.setVisible(true);
Assert.assertEquals(true,window.isVisible());
Assert.assertEquals(true,window.isNativeValid());
- // Assert.assertEquals(width,window.getWidth());
- // Assert.assertEquals(height,window.getHeight());
- // System.out.println("Created: "+window);
//
// Create native OpenGL resources .. XGL/WGL/CGL ..
@@ -118,7 +113,7 @@ public class TestScreenMode01NEWT extends UITestCase {
Assert.assertEquals(true, window.isFullscreen());
- Thread.sleep(1000); // 1 sec
+ Thread.sleep(waitTimeShort);
window.setFullscreen(false);
Assert.assertEquals(false, window.isFullscreen());
@@ -157,7 +152,7 @@ public class TestScreenMode01NEWT extends UITestCase {
Assert.assertEquals(modeIndex, screen.getDesktopScreenModeIndex());
Assert.assertEquals(modeRate, screen.getCurrentScreenRate());
- Thread.sleep(6000); // 6 sec
+ Thread.sleep(waitTimeLong);
screen.setScreenMode(-1, (short)-1);
Assert.assertEquals(originalScreenMode, screen.getDesktopScreenModeIndex());
@@ -200,7 +195,7 @@ public class TestScreenMode01NEWT extends UITestCase {
window.setFullscreen(true);
Assert.assertEquals(true, window.isFullscreen());
- Thread.sleep(6000); // 6 sec
+ Thread.sleep(waitTimeLong);
window.setFullscreen(false);
Assert.assertEquals(false, window.isFullscreen());
@@ -246,7 +241,7 @@ public class TestScreenMode01NEWT extends UITestCase {
window.setFullscreen(true);
Assert.assertEquals(true, window.isFullscreen());
- Thread.sleep(6000); // 6 sec
+ Thread.sleep(waitTimeLong);
screen.setScreenMode(-1, (short)-1);
Assert.assertEquals(originalScreenMode, screen.getDesktopScreenModeIndex());
@@ -257,7 +252,7 @@ public class TestScreenMode01NEWT extends UITestCase {
destroyWindow(display, screen, window);
}
-
+
public static void main(String args[]) throws IOException {
String tstname = TestScreenMode01NEWT.class.getName();
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
diff --git a/src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java
new file mode 100644
index 000000000..713e1f2ef
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/newt/TestScreenMode02NEWT.java
@@ -0,0 +1,272 @@
+/**
+ * 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.test.junit.newt;
+
+
+import java.io.IOException;
+
+import javax.media.nativewindow.Capabilities;
+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.Window;
+import com.jogamp.newt.impl.ScreenMode;
+import com.jogamp.test.junit.util.UITestCase;
+
+public class TestScreenMode02NEWT extends UITestCase {
+ static int width, height;
+
+ static int waitTimeShort = 1000; //1 sec
+ static int waitTimeLong = 4000; //4 sec
+
+
+ @BeforeClass
+ public static void initClass() {
+ NativeWindowFactory.initSingleton(true);
+ width = 640;
+ height = 480;
+ }
+
+ static Window createWindow(Screen screen, Capabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+ // Create native windowing resources .. X11/Win/OSX
+ //
+ Window window = NewtFactory.createWindow(screen, caps);
+ Assert.assertNotNull(window);
+ window.setUndecorated(onscreen && undecorated);
+ window.setSize(width, height);
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertEquals(false,window.isVisible());
+ window.setVisible(true);
+ Assert.assertEquals(true,window.isVisible());
+ Assert.assertEquals(true,window.isNativeValid());
+
+ //
+ // Create native OpenGL resources .. XGL/WGL/CGL ..
+ // equivalent to GLAutoDrawable methods: setVisible(true)
+ //
+ caps = window.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities();
+ Assert.assertNotNull(caps);
+ Assert.assertTrue(caps.getGreenBits()>5);
+ Assert.assertTrue(caps.getBlueBits()>5);
+ Assert.assertTrue(caps.getRedBits()>5);
+ Assert.assertEquals(caps.isOnscreen(),onscreen);
+
+ return window;
+ }
+
+ static void destroyWindow(Display display, Screen screen, Window window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ if(null!=screen) {
+ screen.destroy();
+ }
+ if(null!=display) {
+ display.destroy();
+ }
+ }
+
+ @Test
+ public void testScreenRotationChange01() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ 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 window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+
+ ScreenMode[] screenModes = screen.getScreenModes();
+ Assert.assertNotNull(screenModes);
+
+ int originalScreenMode = screen.getDesktopScreenModeIndex();
+ short originalScreenRate = screen.getCurrentScreenRate();
+ int originalScreenRotation = screen.getCurrentScreenRotation();
+
+ Assert.assertNotSame(-1, originalScreenMode);
+ Assert.assertNotSame(-1, originalScreenRate);
+ Assert.assertNotSame(-1, originalScreenRotation);
+ System.out.println("Original Rotation: " + originalScreenRotation);
+
+ screen.setScreenRotation(ScreenMode.ROTATE_90);
+ Assert.assertEquals(ScreenMode.ROTATE_90, screen.getCurrentScreenRotation());
+
+ Thread.sleep(waitTimeShort);
+
+ screen.setScreenRotation(originalScreenRotation);
+ Assert.assertEquals(originalScreenRotation, screen.getCurrentScreenRotation());
+
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testScreenRotationChange02() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ 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 window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+
+ ScreenMode[] screenModes = screen.getScreenModes();
+ Assert.assertNotNull(screenModes);
+
+ int originalScreenMode = screen.getDesktopScreenModeIndex();
+ short originalScreenRate = screen.getCurrentScreenRate();
+ int originalScreenRotation = screen.getCurrentScreenRotation();
+
+ Assert.assertNotSame(-1, originalScreenMode);
+ Assert.assertNotSame(-1, originalScreenRate);
+ Assert.assertNotSame(-1, originalScreenRotation);
+ System.out.println("Original Rotation: " + originalScreenRotation);
+
+ screen.setScreenRotation(ScreenMode.ROTATE_180);
+ Assert.assertEquals(ScreenMode.ROTATE_180, screen.getCurrentScreenRotation());
+
+ Thread.sleep(waitTimeShort);
+
+ screen.setScreenRotation(originalScreenRotation);
+ Assert.assertEquals(originalScreenRotation, screen.getCurrentScreenRotation());
+
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testScreenRotationChange03() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ 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 window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+
+ ScreenMode[] screenModes = screen.getScreenModes();
+ Assert.assertNotNull(screenModes);
+
+ int originalScreenMode = screen.getDesktopScreenModeIndex();
+ short originalScreenRate = screen.getCurrentScreenRate();
+ int originalScreenRotation = screen.getCurrentScreenRotation();
+
+ Assert.assertNotSame(-1, originalScreenMode);
+ Assert.assertNotSame(-1, originalScreenRate);
+ Assert.assertNotSame(-1, originalScreenRotation);
+
+ screen.setScreenRotation(ScreenMode.ROTATE_270);
+ Assert.assertEquals(ScreenMode.ROTATE_270, screen.getCurrentScreenRotation());
+
+ Thread.sleep(waitTimeShort);
+
+ screen.setScreenRotation(originalScreenRotation);
+ Assert.assertEquals(originalScreenRotation, screen.getCurrentScreenRotation());
+
+ destroyWindow(display, screen, window);
+ }
+
+ @Test
+ public void testScreenModeChangeWithRotate01() throws InterruptedException {
+ Capabilities caps = new Capabilities();
+ 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 window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+
+ ScreenMode[] screenModes = screen.getScreenModes();
+ Assert.assertNotNull(screenModes);
+
+ int originalScreenMode = screen.getDesktopScreenModeIndex();
+ short originalScreenRate = screen.getCurrentScreenRate();
+ int originalScreenRotation = screen.getCurrentScreenRotation();
+
+ Assert.assertNotSame(-1, originalScreenMode);
+ Assert.assertNotSame(-1, originalScreenRate);
+ Assert.assertNotSame(-1, originalScreenRotation);
+
+ int modeIndex = 1;
+
+ ScreenMode screenMode = screenModes[modeIndex];
+ Assert.assertNotNull(screenMode);
+
+ short modeRate = screenMode.getRates()[0];
+ screen.setScreenMode(modeIndex, modeRate);
+
+ Assert.assertEquals(modeIndex, screen.getDesktopScreenModeIndex());
+ Assert.assertEquals(modeRate, screen.getCurrentScreenRate());
+
+ Thread.sleep(waitTimeLong);
+
+ screen.setScreenRotation(ScreenMode.ROTATE_180);
+ Assert.assertEquals(ScreenMode.ROTATE_180, screen.getCurrentScreenRotation());
+
+ Thread.sleep(waitTimeShort);
+
+ screen.setScreenRotation(originalScreenRotation);
+ Assert.assertEquals(originalScreenRotation, screen.getCurrentScreenRotation());
+
+ Thread.sleep(waitTimeShort);
+
+ screen.setScreenMode(-1, (short)-1);
+ Assert.assertEquals(originalScreenMode, screen.getDesktopScreenModeIndex());
+ Assert.assertEquals(originalScreenRate, screen.getCurrentScreenRate());
+
+ destroyWindow(display, screen, window);
+ }
+
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestScreenMode02NEWT.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" } );
+ }
+
+}