From 1a20ec143a7434ec035a567f73f7b3656edb4c3d Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Sat, 29 Jun 2013 11:42:10 +0200
Subject: Tests: Put monitor/screen mode tests to own subpackage
---
.../test/junit/newt/ManualScreenMode03aNEWT.java | 114 ------
.../test/junit/newt/TestScreenMode00aNEWT.java | 183 ----------
.../test/junit/newt/TestScreenMode00bNEWT.java | 127 -------
.../test/junit/newt/TestScreenMode01aNEWT.java | 218 ------------
.../test/junit/newt/TestScreenMode01bNEWT.java | 249 -------------
.../test/junit/newt/TestScreenMode01cNEWT.java | 249 -------------
.../test/junit/newt/TestScreenMode01dNEWT.java | 392 ---------------------
.../test/junit/newt/TestScreenMode02aNEWT.java | 204 -----------
.../junit/newt/mm/ManualScreenMode03aNEWT.java | 114 ++++++
.../test/junit/newt/mm/TestScreenMode00aNEWT.java | 183 ++++++++++
.../test/junit/newt/mm/TestScreenMode00bNEWT.java | 127 +++++++
.../test/junit/newt/mm/TestScreenMode01aNEWT.java | 218 ++++++++++++
.../test/junit/newt/mm/TestScreenMode01bNEWT.java | 249 +++++++++++++
.../test/junit/newt/mm/TestScreenMode01cNEWT.java | 249 +++++++++++++
.../test/junit/newt/mm/TestScreenMode01dNEWT.java | 392 +++++++++++++++++++++
.../test/junit/newt/mm/TestScreenMode02aNEWT.java | 204 +++++++++++
16 files changed, 1736 insertions(+), 1736 deletions(-)
delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/ManualScreenMode03aNEWT.java
delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00aNEWT.java
delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00bNEWT.java
delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01aNEWT.java
delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java
delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01cNEWT.java
delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01dNEWT.java
delete mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02aNEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/mm/ManualScreenMode03aNEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00aNEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00bNEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01aNEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01bNEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01cNEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01dNEWT.java
create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode02aNEWT.java
(limited to 'src')
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/ManualScreenMode03aNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/ManualScreenMode03aNEWT.java
deleted file mode 100644
index 1b67f1fe5..000000000
--- a/src/test/com/jogamp/opengl/test/junit/newt/ManualScreenMode03aNEWT.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/**
- * 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;
-
-import java.io.IOException;
-import javax.media.opengl.GLCapabilities;
-import javax.media.opengl.GLProfile;
-
-import com.jogamp.opengl.util.Animator;
-
-import com.jogamp.newt.Display;
-import com.jogamp.newt.MonitorDevice;
-import com.jogamp.newt.NewtFactory;
-import com.jogamp.newt.Screen;
-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.UITestCase;
-import java.util.List;
-import javax.media.nativewindow.util.Dimension;
-
-/**
- * Manual testing the ScreenImpl shutdown hook,
- * which shall reset the ScreenMode to it's original state
- * when the application exists (normal or ctrl-c).
- */
-public class ManualScreenMode03aNEWT extends UITestCase {
- static int waitTime = 7000; // 1 sec
-
- static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
- caps.setOnscreen(onscreen);
-
- GLWindow window = GLWindow.create(screen, caps);
- window.setSize(width, height);
- window.addGLEventListener(new GearsES2());
- window.setVisible(true);
- return window;
- }
-
- public void run() {
- int width = 640;
- int height = 480;
- GLProfile glp = GLProfile.getDefault();
- GLCapabilities caps = new GLCapabilities(glp);
- Display display = NewtFactory.createDisplay(null); // local display
- Screen screen = NewtFactory.createScreen(display, 0); // screen 0
- GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
-
- List monitorModes = screen.getMonitorModes();
- if(null==monitorModes) {
- // no support ..
- System.err.println("Your platform has no ScreenMode change support, sorry");
- return;
- }
- Animator animator = new Animator(window);
- animator.start();
-
- MonitorDevice monitor = window.getMainMonitor();
- MonitorMode mmCurrent = monitor.queryCurrentMode();
- MonitorMode mmOrig = monitor.getOriginalMode();
- System.err.println("[0] orig : "+mmOrig);
- System.err.println("[0] current: "+mmCurrent);
-
- monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc
- monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 0);
- monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(801, 601));
- monitorModes = MonitorModeUtil.filterByRate(monitorModes, mmOrig.getRefreshRate());
- monitorModes = MonitorModeUtil.getHighestAvailableBpp(monitorModes);
-
- MonitorMode mm = (MonitorMode) monitorModes.get(0);
- System.err.println("[0] set current: "+mm);
- monitor.setCurrentMode(mm);
-
- System.err.print("[0] post setting .. wait <");
- try {
- Thread.sleep(waitTime);
- } catch (InterruptedException e) {
- }
- System.err.println("done>");
- System.exit(0);
- }
-
- public static void main(String args[]) throws IOException {
- ManualScreenMode03aNEWT t = new ManualScreenMode03aNEWT();
- t.run();
- }
-}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00aNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00aNEWT.java
deleted file mode 100644
index 353377292..000000000
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode00aNEWT.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/**
- * 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.common.util.ArrayHashSet;
-import com.jogamp.newt.Display;
-import com.jogamp.newt.MonitorDevice;
-import com.jogamp.newt.NewtFactory;
-import com.jogamp.newt.MonitorMode;
-import com.jogamp.newt.Screen;
-import com.jogamp.opengl.test.junit.util.UITestCase;
-import java.util.Iterator;
-import java.util.List;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.DimensionImmutable;
-import javax.media.nativewindow.util.Rectangle;
-import javax.media.nativewindow.util.SurfaceSize;
-import javax.media.opengl.GLProfile;
-
-import jogamp.newt.MonitorDeviceImpl;
-import jogamp.newt.MonitorModeProps;
-
-/**
- * Validating consistency of MonitorMode data from Screen (all modes)
- * and from a particular MonitorDevice.
- */
-public class TestScreenMode00aNEWT extends UITestCase {
- static int screenIdx = 0;
- static int width, height;
-
- static int waitTimeShort = 4; //1 sec
- static int waitTimeLong = 6; //6 sec
-
-
-
- @BeforeClass
- public static void initClass() {
- GLProfile.initSingleton(); // hack to initialize GL for BCM_IV (Rasp.Pi)
- NativeWindowFactory.initSingleton();
- width = 640;
- height = 480;
- }
-
- @Test
- public void testScreenModeInfo00() throws InterruptedException {
- final DimensionImmutable res = new Dimension(640, 480);
- final SurfaceSize surfsz = new SurfaceSize(res, 32);
- final MonitorMode modeOut = new MonitorMode(surfsz, 60.0f, 0, 0);
- System.err.println("00 out: "+modeOut);
- final MonitorModeProps.Cache cache = new MonitorModeProps.Cache();
- cache.monitorModes.add(modeOut);
- {
- final int[] props = MonitorModeProps.streamOutMonitorMode(modeOut);
- final MonitorMode modeIn = MonitorModeProps.streamInMonitorMode(null, cache, props, 0);
- System.err.println("00 in : "+modeIn);
-
- Assert.assertEquals(modeOut.getSurfaceSize().getResolution(), modeIn.getSurfaceSize().getResolution());
-
- Assert.assertEquals(modeOut.getSurfaceSize(), modeIn.getSurfaceSize());
-
- Assert.assertEquals(modeOut.hashCode(), modeIn.hashCode());
-
- Assert.assertEquals(modeOut, modeIn);
- }
-
- final DimensionImmutable sizeMM = new Dimension(50, 50);
- final Rectangle viewport = new Rectangle(0, 0, 1920, 1080);
- final ArrayHashSet supportedModes = new ArrayHashSet();
- supportedModes.add(modeOut);
- final MonitorDevice monOut = new MonitorDeviceImpl(null, -1, sizeMM, viewport, modeOut, supportedModes);
- System.err.println("01 out : "+monOut);
- cache.monitorDevices.add(monOut);
- {
- final int[] props = MonitorModeProps.streamOutMonitorDevice(monOut);
- final MonitorDevice monIn = MonitorModeProps.streamInMonitorDevice(null, cache, null, props, 0);
- System.err.println("01 in : "+monIn);
-
- Assert.assertEquals(monOut.getCurrentMode(), monOut.getOriginalMode());
- Assert.assertEquals(monOut.getSupportedModes(), monIn.getSupportedModes());
- Assert.assertEquals(monOut.getViewport(), monIn.getViewport());
- Assert.assertEquals(monOut.getOriginalMode(), monIn.getOriginalMode());
- Assert.assertEquals(monOut.getCurrentMode(), monIn.getCurrentMode());
- Assert.assertEquals(monOut.hashCode(), monIn.hashCode());
- Assert.assertEquals(monOut, monIn);
- }
- }
-
- @Test
- public void testScreenModeInfo01() throws InterruptedException {
- 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 allMonitorModes = screen.getMonitorModes();
- Assert.assertTrue(allMonitorModes.size()>0);
- {
- int i=0;
- for(Iterator iMode=allMonitorModes.iterator(); iMode.hasNext(); i++) {
- System.err.println("All["+i+"]: "+iMode.next());
- }
- }
-
- List monitors = screen.getMonitorDevices();
- Assert.assertTrue(monitors.size()>0);
- int j=0;
- for(Iterator iMonitor=monitors.iterator(); iMonitor.hasNext(); j++) {
- MonitorDevice monitor = iMonitor.next();
- System.err.println(j+": "+monitor);
- List modes = monitor.getSupportedModes();
- Assert.assertTrue(modes.size()>0);
- int i=0;
- for(Iterator iMode=modes.iterator(); iMode.hasNext(); i++) {
- System.err.println("["+j+"]["+i+"]: "+iMode.next());
- }
- Assert.assertTrue(allMonitorModes.containsAll(modes));
-
- MonitorMode sm_o = monitor.getOriginalMode();
- Assert.assertNotNull(sm_o);
- MonitorMode sm_c = monitor.queryCurrentMode();
- System.err.println("[0] orig : "+sm_o);
- System.err.println("[0] current: "+sm_c);
- Assert.assertNotNull(sm_c);
- Assert.assertEquals(sm_o, sm_c);
- }
-
- screen.removeReference();
-
- 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 screenModes = screen.getMonitorModes();
- Assert.assertTrue(screenModes.size()>0);
- int i=0;
- for(Iterator iter=screenModes.iterator(); iter.hasNext(); i++) {
- System.err.println(i+": "+iter.next());
- }
- MonitorDevice monitor = window.getMainMonitor();
- MonitorMode mm_o = monitor.getOriginalMode();
-
- Assert.assertNotNull(mm_o);
- MonitorMode mm_c = monitor.queryCurrentMode();
- Assert.assertNotNull(mm_c);
- System.err.println("orig: "+mm_o);
- System.err.println("curr: "+mm_c);
-
- for(i=0; i<50; i++) {
- mm_c = monitor.queryCurrentMode();
- Assert.assertNotNull(mm_c);
- System.err.print("."+i);
- }
- System.err.println("!");
-
- // screen.removeReference();
- anim.stop();
- window.destroy();
-
- Assert.assertEquals(false,window.isVisible());
- Assert.assertEquals(false,window.isNativeValid());
- Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false));
- 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/TestScreenMode01aNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01aNEWT.java
deleted file mode 100644
index 482a0cf34..000000000
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01aNEWT.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/**
- * 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.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.UITestCase;
-
-import java.util.List;
-import javax.media.nativewindow.util.Dimension;
-
-/**
- *
- * Tests MonitorMode reset, by destroying the last Screen (reference),
- * i.e. the original MonitorMode should get reinstated!
- *
- *
- * Documents remedy B) for NV RANDR/GL bug
- *
- *
- * @see TestScreenMode01dNEWT#cleanupGL()
- */
-public class TestScreenMode01aNEWT extends UITestCase {
- static GLProfile glp;
- static int width, height;
-
- static int waitTimeShort = 2000;
- static int waitTimeLong = 2000;
-
- @BeforeClass
- public static void initClass() {
- 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 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;
- }
-
- MonitorDevice monitor = window0.getMainMonitor();
-
- List 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));
-
- MonitorMode mmCurrent = monitor.queryCurrentMode();
- Assert.assertNotNull(mmCurrent);
- MonitorMode mmOrig = monitor.getOriginalMode();
- Assert.assertNotNull(mmOrig);
- System.err.println("[0] orig : "+mmOrig);
- System.err.println("[0] current: "+mmCurrent);
- Assert.assertEquals(mmCurrent, 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);
-
- MonitorMode mm = monitorModes.get(0);
- System.err.println("[0] set current: "+mm);
- Assert.assertTrue(monitor.setCurrentMode(mm));
- Assert.assertTrue(monitor.isModeChangedByUs());
- Assert.assertEquals(mm, monitor.getCurrentMode());
- Assert.assertNotSame(mmOrig, monitor.getCurrentMode());
- Assert.assertEquals(mm, monitor.queryCurrentMode());
-
- Thread.sleep(waitTimeShort);
-
- // check manual 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 !
- Assert.assertTrue(monitor.setCurrentMode(mmOrig));
- Assert.assertFalse(monitor.isModeChangedByUs());
- Assert.assertEquals(mmOrig, monitor.getCurrentMode());
- Assert.assertNotSame(mm, monitor.getCurrentMode());
- Assert.assertEquals(mmOrig, monitor.queryCurrentMode());
-
- 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 = TestScreenMode01aNEWT.class.getName();
- org.junit.runner.JUnitCore.main(tstname);
- }
-}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java
deleted file mode 100644
index 9108853e5..000000000
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode01bNEWT.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/**
- * Copyright 2013 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.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.MiscUtils;
-import com.jogamp.opengl.test.junit.util.UITestCase;
-import com.jogamp.opengl.util.Animator;
-
-import java.util.List;
-import javax.media.nativewindow.util.Dimension;
-import javax.media.nativewindow.util.RectangleImmutable;
-
-/**
- * Mode change on separate monitors ..
- */
-public class TestScreenMode01bNEWT extends UITestCase {
- static GLProfile glp;
- static int width, height;
-
- static long waitTimeShort = 2000;
- static long duration = 6000;
-
- @BeforeClass
- public static void initClass() {
- width = 200;
- height = 200;
- glp = GLProfile.getDefault();
- }
-
- @AfterClass
- public static void releaseClass() throws InterruptedException {
- Thread.sleep(waitTimeShort);
- }
-
- static GLWindow createWindow(Screen screen, GLCapabilities caps, String name, int x, int y, int width, int height) throws InterruptedException {
- 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);
- final long t0 = System.currentTimeMillis();
- window.setVisible(true);
- System.err.println("Time for visible/pos: "+(System.currentTimeMillis()-t0)+" ms");
- return window;
- }
-
- static void destroyWindow(Window window) {
- if(null!=window) {
- window.destroy();
- }
- }
-
- @Test
- public void testScreenModeChangeSingleQ1() throws InterruptedException {
- 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(); // trigger creation
- try {
- RectangleImmutable monitorVp = screen.getMonitorDevices().get(0).getViewport();
- testScreenModeChangeImpl(screen, monitorVp.getX(), monitorVp.getY());
- } finally {
- screen.removeReference();
- }
- }
-
- @Test
- public void testScreenModeChangeSingleQ2() throws InterruptedException {
- 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(); // trigger creation
- try {
- if( 2 > screen.getMonitorDevices().size() ) {
- System.err.println("Test Disabled (1): Monitor count < 2: "+screen);
- return;
- }
- RectangleImmutable monitorVp = screen.getMonitorDevices().get(1).getViewport();
- testScreenModeChangeImpl(screen, monitorVp.getX(), monitorVp.getY());
- } finally {
- screen.removeReference();
- }
- }
-
- void testScreenModeChangeImpl(final Screen screen, int xpos, int ypos) throws InterruptedException {
- Thread.sleep(waitTimeShort);
-
- final GLCapabilities caps = new GLCapabilities(glp);
- Assert.assertNotNull(caps);
- final Display display = screen.getDisplay();
- System.err.println("Test.0: Window screen: "+screen);
-
- System.err.println("Test.0: Window bounds (pre): "+xpos+"/"+ypos+" "+width+"x"+height+" within "+screen.getViewport());
-
- GLWindow window0 = createWindow(screen, caps, "win0", xpos, ypos, width, height);
- Assert.assertNotNull(window0);
- System.err.println("Test.0: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWidth()+"x"+window0.getHeight()+" within "+screen.getViewport());
-
- final Animator anim = new Animator(window0);
- anim.start();
-
- List 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;
- }
-
- MonitorDevice monitor = window0.getMainMonitor();
- System.err.println("Test.0: Window monitor: "+monitor);
-
- List 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));
-
- MonitorMode mmCurrent = monitor.getCurrentMode();
- Assert.assertNotNull(mmCurrent);
- MonitorMode mmOrig = monitor.getOriginalMode();
- Assert.assertNotNull(mmOrig);
- System.err.println("[0] orig : "+mmOrig);
- System.err.println("[0] current: "+mmCurrent);
- Assert.assertEquals(mmCurrent, 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);
-
- MonitorMode sm = (MonitorMode) monitorModes.get(0);
- System.err.println("[1] set current: "+sm);
- Assert.assertTrue(monitor.setCurrentMode(sm));
- mmCurrent = monitor.getCurrentMode();
- System.err.println("[1] current: "+mmCurrent);
- Assert.assertTrue(monitor.isModeChangedByUs());
- Assert.assertEquals(sm, monitor.getCurrentMode());
- Assert.assertNotSame(mmOrig, monitor.getCurrentMode());
- Assert.assertEquals(sm, monitor.queryCurrentMode());
-
- System.err.println("Test.1: Window screen: "+screen);
- System.err.println("Test.1: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWidth()+"x"+window0.getHeight()+" within "+screen.getViewport());
- System.err.println("Test.1: Window monitor: "+window0.getMainMonitor());
-
- Thread.sleep(duration);
-
- Assert.assertEquals(true,display.isNativeValid());
- Assert.assertEquals(true,screen.isNativeValid());
- Assert.assertEquals(true,window0.isNativeValid());
- Assert.assertEquals(true,window0.isVisible());
-
- Assert.assertTrue(monitor.setCurrentMode(mmOrig));
- Assert.assertFalse(monitor.isModeChangedByUs());
- Assert.assertEquals(mmOrig, monitor.getCurrentMode());
- Assert.assertNotSame(sm, monitor.getCurrentMode());
- Assert.assertEquals(mmOrig, monitor.queryCurrentMode());
-
- System.err.println("Test.2: Window screen: "+screen);
- System.err.println("Test.2: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWidth()+"x"+window0.getHeight()+" within "+screen.getViewport());
- System.err.println("Test.2: Window monitor: "+window0.getMainMonitor());
-
- Thread.sleep(duration);
- anim.stop();
- destroyWindow(window0);
- Assert.assertEquals(false,window0.isVisible());
- Assert.assertEquals(false,window0.isNativeValid());
- Assert.assertEquals(true,display.isNativeValid());
- Assert.assertEquals(true,screen.isNativeValid());
- }
-
- public static void main(String args[]) throws IOException {
- for(int i=0; i screen.getMonitorDevices().size() ) {
- System.err.println("Test Disabled (1): Monitor count < 2: "+screen);
- return;
- }
- RectangleImmutable monitorVp = screen.getMonitorDevices().get(1).getViewport();
- testScreenFullscreenImpl(screen, monitorVp.getX(), monitorVp.getY(), false, null);
- } finally {
- screen.removeReference();
- }
- }
-
- @Test
- public void testScreenFullscreenSpanQ1Q2() throws InterruptedException {
- 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(); // trigger creation
- try {
- final int crtCount = screen.getMonitorDevices().size();
- if( 2 >= crtCount ) {
- System.err.println("Test Disabled (2): Spanning monitor count "+2+" >= screen monitor count: "+screen);
- return;
- }
- final ArrayList monitors = new ArrayList();
- monitors.add(screen.getMonitorDevices().get(0)); // Q1
- monitors.add(screen.getMonitorDevices().get(1)); // Q2
- RectangleImmutable monitorVp = screen.getMonitorDevices().get(0).getViewport();
- testScreenFullscreenImpl(screen, monitorVp.getX()+50, monitorVp.getY()+50, true, monitors);
- } finally {
- screen.removeReference();
- }
- }
-
- @Test
- public void testScreenFullscreenSpanALL() throws InterruptedException {
- 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(); // trigger creation
- try {
- if( 2 > screen.getMonitorDevices().size() ) {
- System.err.println("Test Disabled (3): Monitor count < 2: "+screen);
- return;
- }
- RectangleImmutable monitorVp = screen.getMonitorDevices().get(1).getViewport();
- testScreenFullscreenImpl(screen, monitorVp.getX()-50, monitorVp.getY()+50, true, null);
- } finally {
- screen.removeReference();
- }
- }
-
- void testScreenFullscreenImpl(final Screen screen, int xpos, int ypos, boolean spanAcrossMonitors, List monitors) throws InterruptedException {
- Thread.sleep(waitTimeShort);
-
- final GLCapabilities caps = new GLCapabilities(glp);
- Assert.assertNotNull(caps);
- final Display display = screen.getDisplay();
-
- System.err.println("Test.0: Window screen: "+screen);
-
- System.err.println("Test.0: Window bounds (pre): "+xpos+"/"+ypos+" "+width+"x"+height+" within "+screen.getViewport());
-
- GLWindow window0 = createWindow(screen, caps, "win0", xpos, ypos, width, height);
- Assert.assertNotNull(window0);
- System.err.println("Test.0: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWidth()+"x"+window0.getHeight()+" within "+screen.getViewport());
-
- final Animator anim = new Animator(window0);
- anim.start();
-
- List allMonitorModes = screen.getMonitorModes();
- Assert.assertTrue(allMonitorModes.size()>0);
-
- MonitorDevice monitor = window0.getMainMonitor();
- System.err.println("Test.0: Window monitor: "+monitor);
- if( !spanAcrossMonitors ) {
- window0.setFullscreen(true);
- } else {
- window0.setFullscreen(monitors);
- }
-
- monitor = window0.getMainMonitor();
- System.err.println("Test.1: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWidth()+"x"+window0.getHeight()+" within "+screen.getViewport());
- System.err.println("Test.1: Window monitor: "+monitor.getViewport());
- Rectangle window0Rect = new Rectangle(window0.getX(), window0.getY(), window0.getWidth(), window0.getHeight());
- if( !spanAcrossMonitors ) {
- Assert.assertEquals(monitor.getViewport(), window0Rect);
- } else {
- List monitorsUsed = monitors;
- if( null == monitorsUsed ) {
- monitorsUsed = window0.getScreen().getMonitorDevices();
- }
- Rectangle monitorsUsedViewport = MonitorDevice.unionOfViewports(new Rectangle(), monitorsUsed);
- Assert.assertEquals(monitorsUsedViewport, window0Rect);
- }
-
- Thread.sleep(duration);
-
- window0.setFullscreen(false);
-
- window0Rect = new Rectangle(window0.getX(), window0.getY(), window0.getWidth(), window0.getHeight());
- monitor = window0.getMainMonitor();
- System.err.println("Test.2: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWidth()+"x"+window0.getHeight()+" within "+screen.getViewport());
- System.err.println("Test.2: Window monitor: "+monitor.getViewport());
-
- Thread.sleep(duration);
- anim.stop();
- destroyWindow(window0);
- Assert.assertEquals(false,window0.isVisible());
- Assert.assertEquals(false,window0.isNativeValid());
- Assert.assertEquals(true,display.isNativeValid());
- Assert.assertEquals(true,screen.isNativeValid());
- }
-
- public static void main(String args[]) throws IOException {
- for(int i=0; i
- * Also documents NV RANDR/GL bug, see {@link TestScreenMode01dNEWT#cleanupGL()}.
- */
-public class TestScreenMode01dNEWT extends UITestCase {
- static GLProfile glp;
- static int width, height;
-
- static int waitTimeShort = 2000; // 2 sec
- static int waitTimeLong = 8000; // 8 sec
-
- @BeforeClass
- public static void initClass() {
- width = 640;
- height = 480;
- glp = GLProfile.getDefault();
- }
-
- @AfterClass
- public static void releaseClass() throws InterruptedException {
- Thread.sleep(waitTimeShort);
- }
-
- /**
- * Following configurations results in a SIGSEGV:
- *
- * Ubuntu 11.04 (natty), NV GTX 460, driver [280.10* - 285.03]
- *
- *
- * Situation:
- *
- * 1 - Create Screen, GLWindow (w/ context)
- * 2 - ScreenMode change
- * 3 - Destroy GLWindow (w/ context), Screen
- * 4 - Create Screen, GLWindow (w/ context) (*)
- *
- *
- * Step 4 causes the exception within 1st 'glXMakeContextCurrent(..)' call
- * on the the created GL context.
- *
- * Remedy:
- *
- * A) Releasing all resources before step 4 .. works.
- * B) Holding the native Display/Screen in NEWT also works (ie screen.addReference()).
- *
- *
- * Hence there must be some correlations with the screen randr mode
- * and some of the glcontext/gldrawables.
- *
- *
- * Remedy A) is demonstrated here
- * Remedy B) is shown in {@link TestScreenMode01bNEWT}
- *
- */
- private void cleanupGL() throws InterruptedException {
- System.err.println("*** cleanupGL.shutdown");
- GLProfile.shutdown();
- System.err.println("*** cleanupGL.initSingleton");
- GLProfile.initSingleton();
- System.err.println("*** cleanupGL.DONE");
- }
-
- static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
- Assert.assertNotNull(caps);
- caps.setOnscreen(onscreen);
-
- GLWindow window = GLWindow.create(screen, caps);
- 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 testFullscreenChange01() 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);
-
- GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
- Animator animator = new Animator(window);
- animator.start();
-
- final MonitorDevice monitor = window.getMainMonitor();
-
- Assert.assertEquals(false, window.isFullscreen());
- Assert.assertEquals(width, window.getWidth());
- Assert.assertEquals(height, window.getHeight());
-
- window.setFullscreen(true);
- Assert.assertEquals(true, window.isFullscreen());
- Assert.assertEquals(monitor.getViewport().getWidth(), window.getWidth());
- Assert.assertEquals(monitor.getViewport().getHeight(), window.getHeight());
-
- Thread.sleep(waitTimeShort);
-
- window.setFullscreen(false);
- Assert.assertEquals(false, window.isFullscreen());
- Assert.assertEquals(width, window.getWidth());
- Assert.assertEquals(height, window.getHeight());
-
- Thread.sleep(waitTimeShort);
-
- animator.stop();
- Assert.assertEquals(false, animator.isAnimating());
- Assert.assertEquals(false, animator.isStarted());
-
- destroyWindow(window);
- Assert.assertTrue(AWTRobotUtil.waitForRealized(window, false));
- Assert.assertEquals(false, window.isRealized());
- Assert.assertEquals(false, window.isNativeValid());
-
- cleanupGL();
- }
-
- @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);
- GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
- Assert.assertNotNull(window);
-
- MonitorDevice monitor = window.getMainMonitor();
-
- List monitorModes = monitor.getSupportedModes();
- Assert.assertTrue(monitorModes.size()>0);
- if(monitorModes.size()==1) {
- // no support ..
- System.err.println("Your platform has no MonitorMode change support, sorry");
- destroyWindow(window);
- return;
- }
-
- Animator animator = new Animator(window);
- animator.start();
-
- MonitorMode mmCurrent = monitor.queryCurrentMode();
- Assert.assertNotNull(mmCurrent);
- MonitorMode mmOrig = monitor.getOriginalMode();
- Assert.assertNotNull(mmOrig);
- System.err.println("[0] orig : "+mmOrig);
- System.err.println("[0] current: "+mmCurrent);
- Assert.assertEquals(mmCurrent, 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);
-
- MonitorMode sm = (MonitorMode) monitorModes.get(0);
- System.err.println("[0] set current: "+sm);
- monitor.setCurrentMode(sm);
- Assert.assertTrue(monitor.isModeChangedByUs());
- Assert.assertEquals(sm, monitor.getCurrentMode());
- Assert.assertNotSame(mmOrig, monitor.getCurrentMode());
- Assert.assertEquals(sm, monitor.queryCurrentMode());
-
- Thread.sleep(waitTimeLong);
-
- // check reset ..
-
- Assert.assertEquals(true,display.isNativeValid());
- Assert.assertEquals(true,screen.isNativeValid());
- Assert.assertEquals(true,window.isNativeValid());
- Assert.assertEquals(true,window.isVisible());
-
- animator.stop();
- Assert.assertEquals(false, animator.isAnimating());
- Assert.assertEquals(false, animator.isStarted());
-
- destroyWindow(window);
- Assert.assertTrue(AWTRobotUtil.waitForRealized(window, false));
-
- Assert.assertEquals(false,window.isVisible());
- Assert.assertEquals(false,window.isRealized());
- Assert.assertEquals(false,window.isNativeValid());
- Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false));
- Assert.assertEquals(false,screen.isNativeValid());
- Assert.assertEquals(false,display.isNativeValid());
-
- screen.createNative(); // trigger native re-creation
-
- Assert.assertEquals(true,display.isNativeValid());
- Assert.assertEquals(true,screen.isNativeValid());
-
- mmCurrent = monitor.getCurrentMode();
- System.err.println("[1] current/orig: "+mmCurrent);
- screen.destroy();
- Assert.assertEquals(false,screen.isNativeValid());
- Assert.assertEquals(false,display.isNativeValid());
-
- Assert.assertNotNull(mmCurrent);
- Assert.assertEquals(mmCurrent, mmOrig);
-
- cleanupGL();
- }
-
- @Test
- public void testScreenModeChangeWithFS01Pre() throws InterruptedException {
- Thread.sleep(waitTimeShort);
- testScreenModeChangeWithFS01Impl(true) ;
- }
-
- @Test
- public void testScreenModeChangeWithFS01Post() throws InterruptedException {
- Thread.sleep(waitTimeShort);
- testScreenModeChangeWithFS01Impl(false) ;
- }
-
- protected void testScreenModeChangeWithFS01Impl(boolean preFS) throws InterruptedException {
- GLCapabilities caps = new GLCapabilities(glp);
- Display display = NewtFactory.createDisplay(null); // local display
- Screen screen = NewtFactory.createScreen(display, 0); // screen 0
- GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
- Animator animator = new Animator(window);
- animator.start();
-
- MonitorDevice monitor = window.getMainMonitor();
- MonitorMode mmCurrent = monitor.queryCurrentMode();
- Assert.assertNotNull(mmCurrent);
- MonitorMode mmOrig = monitor.getOriginalMode();
- Assert.assertNotNull(mmOrig);
- System.err.println("[0] orig : "+mmOrig);
- System.err.println("[0] current: "+mmCurrent);
- Assert.assertEquals(mmCurrent, mmOrig);
-
- List monitorModes = monitor.getSupportedModes();
- if(monitorModes.size()==1) {
- // no support ..
- destroyWindow(window);
- return;
- }
- Assert.assertTrue(monitorModes.size()>0);
- monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc
- monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 0);
- monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(801, 601));
- monitorModes = MonitorModeUtil.filterByRate(monitorModes, mmOrig.getRefreshRate());
- monitorModes = MonitorModeUtil.getHighestAvailableBpp(monitorModes);
-
- MonitorMode monitorMode = (MonitorMode) monitorModes.get(0);
- Assert.assertNotNull(monitorMode);
-
- if(preFS) {
- System.err.println("[0] set FS pre 0: "+window.isFullscreen());
- window.setFullscreen(true);
- System.err.println("[0] set FS pre 1: "+window.isFullscreen());
- Assert.assertEquals(true, window.isFullscreen());
- System.err.println("[0] set FS pre X: "+window.isFullscreen());
- }
-
- System.err.println("[0] set current: "+monitorMode);
- monitor.setCurrentMode(monitorMode);
-
- if(!preFS) {
- System.err.println("[0] set FS post 0: "+window.isFullscreen());
- window.setFullscreen(true);
- Assert.assertEquals(true, window.isFullscreen());
- System.err.println("[0] set FS post X: "+window.isFullscreen());
- }
-
- Thread.sleep(waitTimeLong);
-
- // check reset ..
-
- Assert.assertEquals(true,display.isNativeValid());
- Assert.assertEquals(true,screen.isNativeValid());
- Assert.assertEquals(true,window.isNativeValid());
- Assert.assertEquals(true,window.isVisible());
-
- animator.stop();
- Assert.assertEquals(false, animator.isAnimating());
- Assert.assertEquals(false, animator.isStarted());
-
- destroyWindow(window);
- Assert.assertTrue(AWTRobotUtil.waitForRealized(window, false));
-
- Assert.assertEquals(false,window.isVisible());
- Assert.assertEquals(false,window.isRealized());
- Assert.assertEquals(false,window.isNativeValid());
- Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false));
- Assert.assertEquals(false,screen.isNativeValid());
- Assert.assertEquals(false,display.isNativeValid());
-
- screen.createNative(); // trigger native re-creation
-
- Assert.assertEquals(true,display.isNativeValid());
- Assert.assertEquals(true,screen.isNativeValid());
-
- mmCurrent = monitor.getCurrentMode();
- System.err.println("[1] current/orig: "+mmCurrent);
- screen.destroy();
- Assert.assertEquals(false,screen.isNativeValid());
- Assert.assertEquals(false,display.isNativeValid());
-
- Assert.assertNotNull(mmCurrent);
- Assert.assertEquals(mmCurrent, mmOrig);
-
- cleanupGL();
- }
-
- public static void main(String args[]) throws IOException {
- String tstname = TestScreenMode01dNEWT.class.getName();
- org.junit.runner.JUnitCore.main(tstname);
- }
-}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02aNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02aNEWT.java
deleted file mode 100644
index 6b12a6bed..000000000
--- a/src/test/com/jogamp/opengl/test/junit/newt/TestScreenMode02aNEWT.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/**
- * 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.opengl.GLCapabilities;
-import javax.media.opengl.GLProfile;
-
-import com.jogamp.opengl.util.Animator;
-
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.jogamp.common.os.Platform;
-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.UITestCase;
-import java.util.List;
-import javax.media.nativewindow.util.Dimension;
-
-/**
- * Tests MonitorMode change w/ changed rotation.
- *
- * Also tests MonitorMode reset after last Screen is dereferenced,
- * i.e. MonitorMode should be reinstated.
- *
- */
-public class TestScreenMode02aNEWT extends UITestCase {
- static GLProfile glp;
- static int width, height;
-
- static int waitTimeShort = 2000; // 2 sec
- static int waitTimeLong = 8000; // 8 sec
-
- @BeforeClass
- public static void initClass() {
- width = 640;
- height = 480;
- glp = GLProfile.getDefault();
- }
-
- @AfterClass
- public static void releaseClass() throws InterruptedException {
- Thread.sleep(waitTimeShort);
- }
-
- static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
- Assert.assertNotNull(caps);
- caps.setOnscreen(onscreen);
-
- GLWindow window = GLWindow.create(screen, caps);
- window.setSize(width, height);
- window.addGLEventListener(new GearsES2());
- Assert.assertNotNull(window);
- window.setVisible(true);
- Assert.assertTrue(window.isVisible());
- return window;
- }
-
- static void destroyWindow(Window window) {
- if(null!=window) {
- window.destroy();
- }
- }
-
- @Test
- public void testScreenRotationChange01() 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);
- GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
- Assert.assertNotNull(window);
-
- MonitorDevice monitor = window.getMainMonitor();
- List monitorModes = monitor.getSupportedModes();
- if(monitorModes.size()==1) {
- // no support ..
- System.err.println("Your platform has no ScreenMode change support, sorry");
- destroyWindow(window);
- return;
- }
- Assert.assertTrue(monitorModes.size()>0);
-
- Animator animator = new Animator(window);
- animator.start();
-
- MonitorMode mmCurrent = monitor.getCurrentMode();
- Assert.assertNotNull(mmCurrent);
- MonitorMode mmOrig = monitor.getOriginalMode();
- Assert.assertNotNull(mmOrig);
- System.err.println("[0] orig : "+mmOrig);
- System.err.println("[0] current: "+mmCurrent);
- Assert.assertEquals(mmCurrent, mmOrig);
-
- monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc
- Assert.assertNotNull(monitorModes);
- Assert.assertTrue(monitorModes.size()>0);
- monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 90);
- if(null==monitorModes || Platform.getOSType() == Platform.OSType.MACOS ) {
- // no rotation support ..
- System.err.println("Your platform has no rotation support, sorry");
- destroyWindow(window);
- return;
- }
- 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);
-
- MonitorMode sm = (MonitorMode) monitorModes.get(0);
- System.err.println("[0] set current: "+sm);
- monitor.setCurrentMode(sm);
- Assert.assertTrue(monitor.isModeChangedByUs());
- Assert.assertEquals(sm, monitor.getCurrentMode());
- Assert.assertNotSame(mmOrig, monitor.getCurrentMode());
- Assert.assertEquals(sm, monitor.queryCurrentMode());
-
- Thread.sleep(waitTimeLong);
-
- // check reset ..
-
- Assert.assertEquals(true,display.isNativeValid());
- Assert.assertEquals(true,screen.isNativeValid());
- Assert.assertEquals(true,window.isNativeValid());
- Assert.assertEquals(true,window.isVisible());
-
- animator.stop();
- destroyWindow(window);
-
- Assert.assertEquals(false,window.isVisible());
- Assert.assertEquals(false,window.isNativeValid());
- Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false));
- Assert.assertEquals(false,screen.isNativeValid());
- Assert.assertEquals(false,display.isNativeValid());
-
- screen.createNative(); // trigger native re-creation
-
- Assert.assertEquals(true,display.isNativeValid());
- Assert.assertEquals(true,screen.isNativeValid());
-
- mmCurrent = monitor.getCurrentMode();
- System.err.println("[1] current/orig: "+mmCurrent);
-
- Assert.assertNotNull(mmCurrent);
- Assert.assertEquals(mmCurrent, mmOrig);
-
- screen.destroy();
-
- Assert.assertEquals(false,screen.isNativeValid());
- Assert.assertEquals(false,display.isNativeValid());
- }
-
- public static void main(String args[]) throws IOException {
- String tstname = TestScreenMode02aNEWT.class.getName();
- org.junit.runner.JUnitCore.main(tstname);
- }
-
-}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/ManualScreenMode03aNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/ManualScreenMode03aNEWT.java
new file mode 100644
index 000000000..464efa5bb
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/ManualScreenMode03aNEWT.java
@@ -0,0 +1,114 @@
+/**
+ * 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.mm;
+
+import java.io.IOException;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.newt.Display;
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Screen;
+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.UITestCase;
+import java.util.List;
+import javax.media.nativewindow.util.Dimension;
+
+/**
+ * Manual testing the ScreenImpl shutdown hook,
+ * which shall reset the ScreenMode to it's original state
+ * when the application exists (normal or ctrl-c).
+ */
+public class ManualScreenMode03aNEWT extends UITestCase {
+ static int waitTime = 7000; // 1 sec
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ caps.setOnscreen(onscreen);
+
+ GLWindow window = GLWindow.create(screen, caps);
+ window.setSize(width, height);
+ window.addGLEventListener(new GearsES2());
+ window.setVisible(true);
+ return window;
+ }
+
+ public void run() {
+ int width = 640;
+ int height = 480;
+ GLProfile glp = GLProfile.getDefault();
+ GLCapabilities caps = new GLCapabilities(glp);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+
+ List monitorModes = screen.getMonitorModes();
+ if(null==monitorModes) {
+ // no support ..
+ System.err.println("Your platform has no ScreenMode change support, sorry");
+ return;
+ }
+ Animator animator = new Animator(window);
+ animator.start();
+
+ MonitorDevice monitor = window.getMainMonitor();
+ MonitorMode mmCurrent = monitor.queryCurrentMode();
+ MonitorMode mmOrig = monitor.getOriginalMode();
+ System.err.println("[0] orig : "+mmOrig);
+ System.err.println("[0] current: "+mmCurrent);
+
+ monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc
+ monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 0);
+ monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(801, 601));
+ monitorModes = MonitorModeUtil.filterByRate(monitorModes, mmOrig.getRefreshRate());
+ monitorModes = MonitorModeUtil.getHighestAvailableBpp(monitorModes);
+
+ MonitorMode mm = (MonitorMode) monitorModes.get(0);
+ System.err.println("[0] set current: "+mm);
+ monitor.setCurrentMode(mm);
+
+ System.err.print("[0] post setting .. wait <");
+ try {
+ Thread.sleep(waitTime);
+ } catch (InterruptedException e) {
+ }
+ System.err.println("done>");
+ System.exit(0);
+ }
+
+ public static void main(String args[]) throws IOException {
+ ManualScreenMode03aNEWT t = new ManualScreenMode03aNEWT();
+ t.run();
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00aNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00aNEWT.java
new file mode 100644
index 000000000..123199427
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode00aNEWT.java
@@ -0,0 +1,183 @@
+/**
+ * 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.nativewindow.NativeWindowFactory;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.common.util.ArrayHashSet;
+import com.jogamp.newt.Display;
+import com.jogamp.newt.MonitorDevice;
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.MonitorMode;
+import com.jogamp.newt.Screen;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import java.util.Iterator;
+import java.util.List;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.DimensionImmutable;
+import javax.media.nativewindow.util.Rectangle;
+import javax.media.nativewindow.util.SurfaceSize;
+import javax.media.opengl.GLProfile;
+
+import jogamp.newt.MonitorDeviceImpl;
+import jogamp.newt.MonitorModeProps;
+
+/**
+ * Validating consistency of MonitorMode data from Screen (all modes)
+ * and from a particular MonitorDevice.
+ */
+public class TestScreenMode00aNEWT extends UITestCase {
+ static int screenIdx = 0;
+ static int width, height;
+
+ static int waitTimeShort = 4; //1 sec
+ static int waitTimeLong = 6; //6 sec
+
+
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(); // hack to initialize GL for BCM_IV (Rasp.Pi)
+ NativeWindowFactory.initSingleton();
+ width = 640;
+ height = 480;
+ }
+
+ @Test
+ public void testScreenModeInfo00() throws InterruptedException {
+ final DimensionImmutable res = new Dimension(640, 480);
+ final SurfaceSize surfsz = new SurfaceSize(res, 32);
+ final MonitorMode modeOut = new MonitorMode(surfsz, 60.0f, 0, 0);
+ System.err.println("00 out: "+modeOut);
+ final MonitorModeProps.Cache cache = new MonitorModeProps.Cache();
+ cache.monitorModes.add(modeOut);
+ {
+ final int[] props = MonitorModeProps.streamOutMonitorMode(modeOut);
+ final MonitorMode modeIn = MonitorModeProps.streamInMonitorMode(null, cache, props, 0);
+ System.err.println("00 in : "+modeIn);
+
+ Assert.assertEquals(modeOut.getSurfaceSize().getResolution(), modeIn.getSurfaceSize().getResolution());
+
+ Assert.assertEquals(modeOut.getSurfaceSize(), modeIn.getSurfaceSize());
+
+ Assert.assertEquals(modeOut.hashCode(), modeIn.hashCode());
+
+ Assert.assertEquals(modeOut, modeIn);
+ }
+
+ final DimensionImmutable sizeMM = new Dimension(50, 50);
+ final Rectangle viewport = new Rectangle(0, 0, 1920, 1080);
+ final ArrayHashSet supportedModes = new ArrayHashSet();
+ supportedModes.add(modeOut);
+ final MonitorDevice monOut = new MonitorDeviceImpl(null, -1, sizeMM, viewport, modeOut, supportedModes);
+ System.err.println("01 out : "+monOut);
+ cache.monitorDevices.add(monOut);
+ {
+ final int[] props = MonitorModeProps.streamOutMonitorDevice(monOut);
+ final MonitorDevice monIn = MonitorModeProps.streamInMonitorDevice(null, cache, null, props, 0);
+ System.err.println("01 in : "+monIn);
+
+ Assert.assertEquals(monOut.getCurrentMode(), monOut.getOriginalMode());
+ Assert.assertEquals(monOut.getSupportedModes(), monIn.getSupportedModes());
+ Assert.assertEquals(monOut.getViewport(), monIn.getViewport());
+ Assert.assertEquals(monOut.getOriginalMode(), monIn.getOriginalMode());
+ Assert.assertEquals(monOut.getCurrentMode(), monIn.getCurrentMode());
+ Assert.assertEquals(monOut.hashCode(), monIn.hashCode());
+ Assert.assertEquals(monOut, monIn);
+ }
+ }
+
+ @Test
+ public void testScreenModeInfo01() throws InterruptedException {
+ 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 allMonitorModes = screen.getMonitorModes();
+ Assert.assertTrue(allMonitorModes.size()>0);
+ {
+ int i=0;
+ for(Iterator iMode=allMonitorModes.iterator(); iMode.hasNext(); i++) {
+ System.err.println("All["+i+"]: "+iMode.next());
+ }
+ }
+
+ List monitors = screen.getMonitorDevices();
+ Assert.assertTrue(monitors.size()>0);
+ int j=0;
+ for(Iterator iMonitor=monitors.iterator(); iMonitor.hasNext(); j++) {
+ MonitorDevice monitor = iMonitor.next();
+ System.err.println(j+": "+monitor);
+ List modes = monitor.getSupportedModes();
+ Assert.assertTrue(modes.size()>0);
+ int i=0;
+ for(Iterator iMode=modes.iterator(); iMode.hasNext(); i++) {
+ System.err.println("["+j+"]["+i+"]: "+iMode.next());
+ }
+ Assert.assertTrue(allMonitorModes.containsAll(modes));
+
+ MonitorMode sm_o = monitor.getOriginalMode();
+ Assert.assertNotNull(sm_o);
+ MonitorMode sm_c = monitor.queryCurrentMode();
+ System.err.println("[0] orig : "+sm_o);
+ System.err.println("[0] current: "+sm_c);
+ Assert.assertNotNull(sm_c);
+ Assert.assertEquals(sm_o, sm_c);
+ }
+
+ screen.removeReference();
+
+ 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 screenModes = screen.getMonitorModes();
+ Assert.assertTrue(screenModes.size()>0);
+ int i=0;
+ for(Iterator iter=screenModes.iterator(); iter.hasNext(); i++) {
+ System.err.println(i+": "+iter.next());
+ }
+ MonitorDevice monitor = window.getMainMonitor();
+ MonitorMode mm_o = monitor.getOriginalMode();
+
+ Assert.assertNotNull(mm_o);
+ MonitorMode mm_c = monitor.queryCurrentMode();
+ Assert.assertNotNull(mm_c);
+ System.err.println("orig: "+mm_o);
+ System.err.println("curr: "+mm_c);
+
+ for(i=0; i<50; i++) {
+ mm_c = monitor.queryCurrentMode();
+ Assert.assertNotNull(mm_c);
+ System.err.print("."+i);
+ }
+ System.err.println("!");
+
+ // screen.removeReference();
+ anim.stop();
+ window.destroy();
+
+ Assert.assertEquals(false,window.isVisible());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false));
+ 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/mm/TestScreenMode01aNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01aNEWT.java
new file mode 100644
index 000000000..f431e099b
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01aNEWT.java
@@ -0,0 +1,218 @@
+/**
+ * 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.UITestCase;
+
+import java.util.List;
+import javax.media.nativewindow.util.Dimension;
+
+/**
+ *
+ * Tests MonitorMode reset, by destroying the last Screen (reference),
+ * i.e. the original MonitorMode should get reinstated!
+ *
+ *
+ * Documents remedy B) for NV RANDR/GL bug
+ *
+ *
+ * @see TestScreenMode01dNEWT#cleanupGL()
+ */
+public class TestScreenMode01aNEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ static int waitTimeShort = 2000;
+ static int waitTimeLong = 2000;
+
+ @BeforeClass
+ public static void initClass() {
+ 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 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;
+ }
+
+ MonitorDevice monitor = window0.getMainMonitor();
+
+ List 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));
+
+ MonitorMode mmCurrent = monitor.queryCurrentMode();
+ Assert.assertNotNull(mmCurrent);
+ MonitorMode mmOrig = monitor.getOriginalMode();
+ Assert.assertNotNull(mmOrig);
+ System.err.println("[0] orig : "+mmOrig);
+ System.err.println("[0] current: "+mmCurrent);
+ Assert.assertEquals(mmCurrent, 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);
+
+ MonitorMode mm = monitorModes.get(0);
+ System.err.println("[0] set current: "+mm);
+ Assert.assertTrue(monitor.setCurrentMode(mm));
+ Assert.assertTrue(monitor.isModeChangedByUs());
+ Assert.assertEquals(mm, monitor.getCurrentMode());
+ Assert.assertNotSame(mmOrig, monitor.getCurrentMode());
+ Assert.assertEquals(mm, monitor.queryCurrentMode());
+
+ Thread.sleep(waitTimeShort);
+
+ // check manual 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 !
+ Assert.assertTrue(monitor.setCurrentMode(mmOrig));
+ Assert.assertFalse(monitor.isModeChangedByUs());
+ Assert.assertEquals(mmOrig, monitor.getCurrentMode());
+ Assert.assertNotSame(mm, monitor.getCurrentMode());
+ Assert.assertEquals(mmOrig, monitor.queryCurrentMode());
+
+ 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 = TestScreenMode01aNEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01bNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01bNEWT.java
new file mode 100644
index 000000000..c80760c1f
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode01bNEWT.java
@@ -0,0 +1,249 @@
+/**
+ * Copyright 2013 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.MiscUtils;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.Animator;
+
+import java.util.List;
+import javax.media.nativewindow.util.Dimension;
+import javax.media.nativewindow.util.RectangleImmutable;
+
+/**
+ * Mode change on separate monitors ..
+ */
+public class TestScreenMode01bNEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ static long waitTimeShort = 2000;
+ static long duration = 6000;
+
+ @BeforeClass
+ public static void initClass() {
+ width = 200;
+ height = 200;
+ glp = GLProfile.getDefault();
+ }
+
+ @AfterClass
+ public static void releaseClass() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps, String name, int x, int y, int width, int height) throws InterruptedException {
+ 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);
+ final long t0 = System.currentTimeMillis();
+ window.setVisible(true);
+ System.err.println("Time for visible/pos: "+(System.currentTimeMillis()-t0)+" ms");
+ return window;
+ }
+
+ static void destroyWindow(Window window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ }
+
+ @Test
+ public void testScreenModeChangeSingleQ1() throws InterruptedException {
+ 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(); // trigger creation
+ try {
+ RectangleImmutable monitorVp = screen.getMonitorDevices().get(0).getViewport();
+ testScreenModeChangeImpl(screen, monitorVp.getX(), monitorVp.getY());
+ } finally {
+ screen.removeReference();
+ }
+ }
+
+ @Test
+ public void testScreenModeChangeSingleQ2() throws InterruptedException {
+ 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(); // trigger creation
+ try {
+ if( 2 > screen.getMonitorDevices().size() ) {
+ System.err.println("Test Disabled (1): Monitor count < 2: "+screen);
+ return;
+ }
+ RectangleImmutable monitorVp = screen.getMonitorDevices().get(1).getViewport();
+ testScreenModeChangeImpl(screen, monitorVp.getX(), monitorVp.getY());
+ } finally {
+ screen.removeReference();
+ }
+ }
+
+ void testScreenModeChangeImpl(final Screen screen, int xpos, int ypos) throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+
+ final GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ final Display display = screen.getDisplay();
+ System.err.println("Test.0: Window screen: "+screen);
+
+ System.err.println("Test.0: Window bounds (pre): "+xpos+"/"+ypos+" "+width+"x"+height+" within "+screen.getViewport());
+
+ GLWindow window0 = createWindow(screen, caps, "win0", xpos, ypos, width, height);
+ Assert.assertNotNull(window0);
+ System.err.println("Test.0: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWidth()+"x"+window0.getHeight()+" within "+screen.getViewport());
+
+ final Animator anim = new Animator(window0);
+ anim.start();
+
+ List 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;
+ }
+
+ MonitorDevice monitor = window0.getMainMonitor();
+ System.err.println("Test.0: Window monitor: "+monitor);
+
+ List 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));
+
+ MonitorMode mmCurrent = monitor.getCurrentMode();
+ Assert.assertNotNull(mmCurrent);
+ MonitorMode mmOrig = monitor.getOriginalMode();
+ Assert.assertNotNull(mmOrig);
+ System.err.println("[0] orig : "+mmOrig);
+ System.err.println("[0] current: "+mmCurrent);
+ Assert.assertEquals(mmCurrent, 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);
+
+ MonitorMode sm = (MonitorMode) monitorModes.get(0);
+ System.err.println("[1] set current: "+sm);
+ Assert.assertTrue(monitor.setCurrentMode(sm));
+ mmCurrent = monitor.getCurrentMode();
+ System.err.println("[1] current: "+mmCurrent);
+ Assert.assertTrue(monitor.isModeChangedByUs());
+ Assert.assertEquals(sm, monitor.getCurrentMode());
+ Assert.assertNotSame(mmOrig, monitor.getCurrentMode());
+ Assert.assertEquals(sm, monitor.queryCurrentMode());
+
+ System.err.println("Test.1: Window screen: "+screen);
+ System.err.println("Test.1: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWidth()+"x"+window0.getHeight()+" within "+screen.getViewport());
+ System.err.println("Test.1: Window monitor: "+window0.getMainMonitor());
+
+ Thread.sleep(duration);
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window0.isNativeValid());
+ Assert.assertEquals(true,window0.isVisible());
+
+ Assert.assertTrue(monitor.setCurrentMode(mmOrig));
+ Assert.assertFalse(monitor.isModeChangedByUs());
+ Assert.assertEquals(mmOrig, monitor.getCurrentMode());
+ Assert.assertNotSame(sm, monitor.getCurrentMode());
+ Assert.assertEquals(mmOrig, monitor.queryCurrentMode());
+
+ System.err.println("Test.2: Window screen: "+screen);
+ System.err.println("Test.2: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWidth()+"x"+window0.getHeight()+" within "+screen.getViewport());
+ System.err.println("Test.2: Window monitor: "+window0.getMainMonitor());
+
+ Thread.sleep(duration);
+ anim.stop();
+ destroyWindow(window0);
+ Assert.assertEquals(false,window0.isVisible());
+ Assert.assertEquals(false,window0.isNativeValid());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i screen.getMonitorDevices().size() ) {
+ System.err.println("Test Disabled (1): Monitor count < 2: "+screen);
+ return;
+ }
+ RectangleImmutable monitorVp = screen.getMonitorDevices().get(1).getViewport();
+ testScreenFullscreenImpl(screen, monitorVp.getX(), monitorVp.getY(), false, null);
+ } finally {
+ screen.removeReference();
+ }
+ }
+
+ @Test
+ public void testScreenFullscreenSpanQ1Q2() throws InterruptedException {
+ 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(); // trigger creation
+ try {
+ final int crtCount = screen.getMonitorDevices().size();
+ if( 2 >= crtCount ) {
+ System.err.println("Test Disabled (2): Spanning monitor count "+2+" >= screen monitor count: "+screen);
+ return;
+ }
+ final ArrayList monitors = new ArrayList();
+ monitors.add(screen.getMonitorDevices().get(0)); // Q1
+ monitors.add(screen.getMonitorDevices().get(1)); // Q2
+ RectangleImmutable monitorVp = screen.getMonitorDevices().get(0).getViewport();
+ testScreenFullscreenImpl(screen, monitorVp.getX()+50, monitorVp.getY()+50, true, monitors);
+ } finally {
+ screen.removeReference();
+ }
+ }
+
+ @Test
+ public void testScreenFullscreenSpanALL() throws InterruptedException {
+ 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(); // trigger creation
+ try {
+ if( 2 > screen.getMonitorDevices().size() ) {
+ System.err.println("Test Disabled (3): Monitor count < 2: "+screen);
+ return;
+ }
+ RectangleImmutable monitorVp = screen.getMonitorDevices().get(1).getViewport();
+ testScreenFullscreenImpl(screen, monitorVp.getX()-50, monitorVp.getY()+50, true, null);
+ } finally {
+ screen.removeReference();
+ }
+ }
+
+ void testScreenFullscreenImpl(final Screen screen, int xpos, int ypos, boolean spanAcrossMonitors, List monitors) throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+
+ final GLCapabilities caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ final Display display = screen.getDisplay();
+
+ System.err.println("Test.0: Window screen: "+screen);
+
+ System.err.println("Test.0: Window bounds (pre): "+xpos+"/"+ypos+" "+width+"x"+height+" within "+screen.getViewport());
+
+ GLWindow window0 = createWindow(screen, caps, "win0", xpos, ypos, width, height);
+ Assert.assertNotNull(window0);
+ System.err.println("Test.0: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWidth()+"x"+window0.getHeight()+" within "+screen.getViewport());
+
+ final Animator anim = new Animator(window0);
+ anim.start();
+
+ List allMonitorModes = screen.getMonitorModes();
+ Assert.assertTrue(allMonitorModes.size()>0);
+
+ MonitorDevice monitor = window0.getMainMonitor();
+ System.err.println("Test.0: Window monitor: "+monitor);
+ if( !spanAcrossMonitors ) {
+ window0.setFullscreen(true);
+ } else {
+ window0.setFullscreen(monitors);
+ }
+
+ monitor = window0.getMainMonitor();
+ System.err.println("Test.1: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWidth()+"x"+window0.getHeight()+" within "+screen.getViewport());
+ System.err.println("Test.1: Window monitor: "+monitor.getViewport());
+ Rectangle window0Rect = new Rectangle(window0.getX(), window0.getY(), window0.getWidth(), window0.getHeight());
+ if( !spanAcrossMonitors ) {
+ Assert.assertEquals(monitor.getViewport(), window0Rect);
+ } else {
+ List monitorsUsed = monitors;
+ if( null == monitorsUsed ) {
+ monitorsUsed = window0.getScreen().getMonitorDevices();
+ }
+ Rectangle monitorsUsedViewport = MonitorDevice.unionOfViewports(new Rectangle(), monitorsUsed);
+ Assert.assertEquals(monitorsUsedViewport, window0Rect);
+ }
+
+ Thread.sleep(duration);
+
+ window0.setFullscreen(false);
+
+ window0Rect = new Rectangle(window0.getX(), window0.getY(), window0.getWidth(), window0.getHeight());
+ monitor = window0.getMainMonitor();
+ System.err.println("Test.2: Window bounds: "+window0.getX()+"/"+window0.getY()+" "+window0.getWidth()+"x"+window0.getHeight()+" within "+screen.getViewport());
+ System.err.println("Test.2: Window monitor: "+monitor.getViewport());
+
+ Thread.sleep(duration);
+ anim.stop();
+ destroyWindow(window0);
+ Assert.assertEquals(false,window0.isVisible());
+ Assert.assertEquals(false,window0.isNativeValid());
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i
+ * Also documents NV RANDR/GL bug, see {@link TestScreenMode01dNEWT#cleanupGL()}.
+ */
+public class TestScreenMode01dNEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ static int waitTimeShort = 2000; // 2 sec
+ static int waitTimeLong = 8000; // 8 sec
+
+ @BeforeClass
+ public static void initClass() {
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ }
+
+ @AfterClass
+ public static void releaseClass() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+ }
+
+ /**
+ * Following configurations results in a SIGSEGV:
+ *
+ * Ubuntu 11.04 (natty), NV GTX 460, driver [280.10* - 285.03]
+ *
+ *
+ * Situation:
+ *
+ * 1 - Create Screen, GLWindow (w/ context)
+ * 2 - ScreenMode change
+ * 3 - Destroy GLWindow (w/ context), Screen
+ * 4 - Create Screen, GLWindow (w/ context) (*)
+ *
+ *
+ * Step 4 causes the exception within 1st 'glXMakeContextCurrent(..)' call
+ * on the the created GL context.
+ *
+ * Remedy:
+ *
+ * A) Releasing all resources before step 4 .. works.
+ * B) Holding the native Display/Screen in NEWT also works (ie screen.addReference()).
+ *
+ *
+ * Hence there must be some correlations with the screen randr mode
+ * and some of the glcontext/gldrawables.
+ *
+ *
+ * Remedy A) is demonstrated here
+ * Remedy B) is shown in {@link TestScreenMode01bNEWT}
+ *
+ */
+ private void cleanupGL() throws InterruptedException {
+ System.err.println("*** cleanupGL.shutdown");
+ GLProfile.shutdown();
+ System.err.println("*** cleanupGL.initSingleton");
+ GLProfile.initSingleton();
+ System.err.println("*** cleanupGL.DONE");
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+
+ GLWindow window = GLWindow.create(screen, caps);
+ 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 testFullscreenChange01() 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);
+
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Animator animator = new Animator(window);
+ animator.start();
+
+ final MonitorDevice monitor = window.getMainMonitor();
+
+ Assert.assertEquals(false, window.isFullscreen());
+ Assert.assertEquals(width, window.getWidth());
+ Assert.assertEquals(height, window.getHeight());
+
+ window.setFullscreen(true);
+ Assert.assertEquals(true, window.isFullscreen());
+ Assert.assertEquals(monitor.getViewport().getWidth(), window.getWidth());
+ Assert.assertEquals(monitor.getViewport().getHeight(), window.getHeight());
+
+ Thread.sleep(waitTimeShort);
+
+ window.setFullscreen(false);
+ Assert.assertEquals(false, window.isFullscreen());
+ Assert.assertEquals(width, window.getWidth());
+ Assert.assertEquals(height, window.getHeight());
+
+ Thread.sleep(waitTimeShort);
+
+ animator.stop();
+ Assert.assertEquals(false, animator.isAnimating());
+ Assert.assertEquals(false, animator.isStarted());
+
+ destroyWindow(window);
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(window, false));
+ Assert.assertEquals(false, window.isRealized());
+ Assert.assertEquals(false, window.isNativeValid());
+
+ cleanupGL();
+ }
+
+ @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);
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window);
+
+ MonitorDevice monitor = window.getMainMonitor();
+
+ List monitorModes = monitor.getSupportedModes();
+ Assert.assertTrue(monitorModes.size()>0);
+ if(monitorModes.size()==1) {
+ // no support ..
+ System.err.println("Your platform has no MonitorMode change support, sorry");
+ destroyWindow(window);
+ return;
+ }
+
+ Animator animator = new Animator(window);
+ animator.start();
+
+ MonitorMode mmCurrent = monitor.queryCurrentMode();
+ Assert.assertNotNull(mmCurrent);
+ MonitorMode mmOrig = monitor.getOriginalMode();
+ Assert.assertNotNull(mmOrig);
+ System.err.println("[0] orig : "+mmOrig);
+ System.err.println("[0] current: "+mmCurrent);
+ Assert.assertEquals(mmCurrent, 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);
+
+ MonitorMode sm = (MonitorMode) monitorModes.get(0);
+ System.err.println("[0] set current: "+sm);
+ monitor.setCurrentMode(sm);
+ Assert.assertTrue(monitor.isModeChangedByUs());
+ Assert.assertEquals(sm, monitor.getCurrentMode());
+ Assert.assertNotSame(mmOrig, monitor.getCurrentMode());
+ Assert.assertEquals(sm, monitor.queryCurrentMode());
+
+ Thread.sleep(waitTimeLong);
+
+ // check reset ..
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ animator.stop();
+ Assert.assertEquals(false, animator.isAnimating());
+ Assert.assertEquals(false, animator.isStarted());
+
+ destroyWindow(window);
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(window, false));
+
+ Assert.assertEquals(false,window.isVisible());
+ Assert.assertEquals(false,window.isRealized());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false));
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,display.isNativeValid());
+
+ screen.createNative(); // trigger native re-creation
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ mmCurrent = monitor.getCurrentMode();
+ System.err.println("[1] current/orig: "+mmCurrent);
+ screen.destroy();
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,display.isNativeValid());
+
+ Assert.assertNotNull(mmCurrent);
+ Assert.assertEquals(mmCurrent, mmOrig);
+
+ cleanupGL();
+ }
+
+ @Test
+ public void testScreenModeChangeWithFS01Pre() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+ testScreenModeChangeWithFS01Impl(true) ;
+ }
+
+ @Test
+ public void testScreenModeChangeWithFS01Post() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+ testScreenModeChangeWithFS01Impl(false) ;
+ }
+
+ protected void testScreenModeChangeWithFS01Impl(boolean preFS) throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ Display display = NewtFactory.createDisplay(null); // local display
+ Screen screen = NewtFactory.createScreen(display, 0); // screen 0
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Animator animator = new Animator(window);
+ animator.start();
+
+ MonitorDevice monitor = window.getMainMonitor();
+ MonitorMode mmCurrent = monitor.queryCurrentMode();
+ Assert.assertNotNull(mmCurrent);
+ MonitorMode mmOrig = monitor.getOriginalMode();
+ Assert.assertNotNull(mmOrig);
+ System.err.println("[0] orig : "+mmOrig);
+ System.err.println("[0] current: "+mmCurrent);
+ Assert.assertEquals(mmCurrent, mmOrig);
+
+ List monitorModes = monitor.getSupportedModes();
+ if(monitorModes.size()==1) {
+ // no support ..
+ destroyWindow(window);
+ return;
+ }
+ Assert.assertTrue(monitorModes.size()>0);
+ monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc
+ monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 0);
+ monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(801, 601));
+ monitorModes = MonitorModeUtil.filterByRate(monitorModes, mmOrig.getRefreshRate());
+ monitorModes = MonitorModeUtil.getHighestAvailableBpp(monitorModes);
+
+ MonitorMode monitorMode = (MonitorMode) monitorModes.get(0);
+ Assert.assertNotNull(monitorMode);
+
+ if(preFS) {
+ System.err.println("[0] set FS pre 0: "+window.isFullscreen());
+ window.setFullscreen(true);
+ System.err.println("[0] set FS pre 1: "+window.isFullscreen());
+ Assert.assertEquals(true, window.isFullscreen());
+ System.err.println("[0] set FS pre X: "+window.isFullscreen());
+ }
+
+ System.err.println("[0] set current: "+monitorMode);
+ monitor.setCurrentMode(monitorMode);
+
+ if(!preFS) {
+ System.err.println("[0] set FS post 0: "+window.isFullscreen());
+ window.setFullscreen(true);
+ Assert.assertEquals(true, window.isFullscreen());
+ System.err.println("[0] set FS post X: "+window.isFullscreen());
+ }
+
+ Thread.sleep(waitTimeLong);
+
+ // check reset ..
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ animator.stop();
+ Assert.assertEquals(false, animator.isAnimating());
+ Assert.assertEquals(false, animator.isStarted());
+
+ destroyWindow(window);
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(window, false));
+
+ Assert.assertEquals(false,window.isVisible());
+ Assert.assertEquals(false,window.isRealized());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false));
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,display.isNativeValid());
+
+ screen.createNative(); // trigger native re-creation
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ mmCurrent = monitor.getCurrentMode();
+ System.err.println("[1] current/orig: "+mmCurrent);
+ screen.destroy();
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,display.isNativeValid());
+
+ Assert.assertNotNull(mmCurrent);
+ Assert.assertEquals(mmCurrent, mmOrig);
+
+ cleanupGL();
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestScreenMode01dNEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode02aNEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode02aNEWT.java
new file mode 100644
index 000000000..37ea499df
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/mm/TestScreenMode02aNEWT.java
@@ -0,0 +1,204 @@
+/**
+ * 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 com.jogamp.opengl.util.Animator;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.common.os.Platform;
+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.UITestCase;
+import java.util.List;
+import javax.media.nativewindow.util.Dimension;
+
+/**
+ * Tests MonitorMode change w/ changed rotation.
+ *
+ * Also tests MonitorMode reset after last Screen is dereferenced,
+ * i.e. MonitorMode should be reinstated.
+ *
+ */
+public class TestScreenMode02aNEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ static int waitTimeShort = 2000; // 2 sec
+ static int waitTimeLong = 8000; // 8 sec
+
+ @BeforeClass
+ public static void initClass() {
+ width = 640;
+ height = 480;
+ glp = GLProfile.getDefault();
+ }
+
+ @AfterClass
+ public static void releaseClass() throws InterruptedException {
+ Thread.sleep(waitTimeShort);
+ }
+
+ static GLWindow createWindow(Screen screen, GLCapabilities caps, int width, int height, boolean onscreen, boolean undecorated) {
+ Assert.assertNotNull(caps);
+ caps.setOnscreen(onscreen);
+
+ GLWindow window = GLWindow.create(screen, caps);
+ window.setSize(width, height);
+ window.addGLEventListener(new GearsES2());
+ Assert.assertNotNull(window);
+ window.setVisible(true);
+ Assert.assertTrue(window.isVisible());
+ return window;
+ }
+
+ static void destroyWindow(Window window) {
+ if(null!=window) {
+ window.destroy();
+ }
+ }
+
+ @Test
+ public void testScreenRotationChange01() 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);
+ GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
+ Assert.assertNotNull(window);
+
+ MonitorDevice monitor = window.getMainMonitor();
+ List monitorModes = monitor.getSupportedModes();
+ if(monitorModes.size()==1) {
+ // no support ..
+ System.err.println("Your platform has no ScreenMode change support, sorry");
+ destroyWindow(window);
+ return;
+ }
+ Assert.assertTrue(monitorModes.size()>0);
+
+ Animator animator = new Animator(window);
+ animator.start();
+
+ MonitorMode mmCurrent = monitor.getCurrentMode();
+ Assert.assertNotNull(mmCurrent);
+ MonitorMode mmOrig = monitor.getOriginalMode();
+ Assert.assertNotNull(mmOrig);
+ System.err.println("[0] orig : "+mmOrig);
+ System.err.println("[0] current: "+mmCurrent);
+ Assert.assertEquals(mmCurrent, mmOrig);
+
+ monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc
+ Assert.assertNotNull(monitorModes);
+ Assert.assertTrue(monitorModes.size()>0);
+ monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 90);
+ if(null==monitorModes || Platform.getOSType() == Platform.OSType.MACOS ) {
+ // no rotation support ..
+ System.err.println("Your platform has no rotation support, sorry");
+ destroyWindow(window);
+ return;
+ }
+ 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);
+
+ MonitorMode sm = (MonitorMode) monitorModes.get(0);
+ System.err.println("[0] set current: "+sm);
+ monitor.setCurrentMode(sm);
+ Assert.assertTrue(monitor.isModeChangedByUs());
+ Assert.assertEquals(sm, monitor.getCurrentMode());
+ Assert.assertNotSame(mmOrig, monitor.getCurrentMode());
+ Assert.assertEquals(sm, monitor.queryCurrentMode());
+
+ Thread.sleep(waitTimeLong);
+
+ // check reset ..
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+ Assert.assertEquals(true,window.isNativeValid());
+ Assert.assertEquals(true,window.isVisible());
+
+ animator.stop();
+ destroyWindow(window);
+
+ Assert.assertEquals(false,window.isVisible());
+ Assert.assertEquals(false,window.isNativeValid());
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(screen, false));
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,display.isNativeValid());
+
+ screen.createNative(); // trigger native re-creation
+
+ Assert.assertEquals(true,display.isNativeValid());
+ Assert.assertEquals(true,screen.isNativeValid());
+
+ mmCurrent = monitor.getCurrentMode();
+ System.err.println("[1] current/orig: "+mmCurrent);
+
+ Assert.assertNotNull(mmCurrent);
+ Assert.assertEquals(mmCurrent, mmOrig);
+
+ screen.destroy();
+
+ Assert.assertEquals(false,screen.isNativeValid());
+ Assert.assertEquals(false,display.isNativeValid());
+ }
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestScreenMode02aNEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
--
cgit v1.2.3