JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestScreenMode02bNEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.newt.mm;
30
31import java.io.IOException;
32import com.jogamp.opengl.GLCapabilities;
33import com.jogamp.opengl.GLProfile;
34
35import org.junit.AfterClass;
36import org.junit.Assert;
37import org.junit.BeforeClass;
38import org.junit.Test;
39import org.junit.FixMethodOrder;
40import org.junit.runners.MethodSorters;
41
42import com.jogamp.common.os.Platform;
43import com.jogamp.newt.Display;
44import com.jogamp.newt.MonitorDevice;
45import com.jogamp.newt.NewtFactory;
46import com.jogamp.newt.Screen;
47import com.jogamp.newt.Window;
48import com.jogamp.newt.MonitorMode;
49import com.jogamp.newt.opengl.GLWindow;
50import com.jogamp.newt.util.MonitorModeUtil;
51import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
52import com.jogamp.opengl.test.junit.util.NewtTestUtil;
53import com.jogamp.opengl.test.junit.util.UITestCase;
54import com.jogamp.opengl.util.Animator;
55
56import java.util.List;
57import com.jogamp.nativewindow.util.Dimension;
58
59/**
60 * Tests MonitorMode change w/ changed rotation and fullscreen.
61 * <p>
62 * MonitorMode change uses highest resolution.
63 * </p>
64 * <p>
65 * Bug 734 could not be reproduced, however on tests systems
66 * here - AMD fglrx and Intel Mesa, the rotated height
67 * is cut off .. probably due to bug of driver code and rotation.
68 * </p>
69 * <p>
70 * Documents remedy B) for NV RANDR/GL bug
71 * </p>
72 *
73 * @see TestScreenMode01NEWT#cleanupGL()
74 */
75@FixMethodOrder(MethodSorters.NAME_ASCENDING)
76public class TestScreenMode02bNEWT extends UITestCase {
77 static GLProfile glp;
78
79 static int waitTimeShort = 2000; // 2 sec
80 static int waitTimeLong = 8000; // 8 sec
81
82 @BeforeClass
83 public static void initClass() {
84 setResetXRandRIfX11AfterClass();
85 glp = GLProfile.getDefault();
86 }
87
88 @AfterClass
89 public static void releaseClass() throws InterruptedException {
90 Thread.sleep(waitTimeShort);
91 }
92
93 static GLWindow createWindow(final Screen screen, final GLCapabilities caps, final String name, final int x, final int y, final int width, final int height) {
94 Assert.assertNotNull(caps);
95
96 final GLWindow window = GLWindow.create(screen, caps);
97 // Window window = NewtFactory.createWindow(screen, caps);
98 window.setTitle(name);
99 window.setPosition(x, y);
100 window.setSize(width, height);
101 window.addGLEventListener(new GearsES2(1));
102 Assert.assertNotNull(window);
103 return window;
104 }
105
106 static void destroyWindow(final Window window) throws InterruptedException {
107 if(null!=window) {
108 window.destroy();
109 Assert.assertTrue(NewtTestUtil.waitForRealized(window, false, null));
110 }
111 }
112
113 @Test
114 public void testScreenModeChange01_PreFull() throws InterruptedException {
115 testScreenModeChangeImpl(true);
116 }
117
118 @Test
119 public void testScreenModeChange02_PostFull() throws InterruptedException {
120 testScreenModeChangeImpl(false);
121 }
122
123 void testScreenModeChangeImpl(final boolean preVis) throws InterruptedException {
124 final GLCapabilities caps = new GLCapabilities(glp);
125 Assert.assertNotNull(caps);
126 final Display display = NewtFactory.createDisplay(null); // local display
127 Assert.assertNotNull(display);
128 final Screen screen = NewtFactory.createScreen(display, 0); // screen 0
129 Assert.assertNotNull(screen);
130 screen.createNative(); // instantiate for resolution query and keep it alive !
131 final int swidth = screen.getWidth();
132 final int sheight = screen.getHeight();
133
134 final GLWindow window = createWindow(screen, caps, "win0", 0, 0, 640, 480);
135 if( preVis ) {
136 window.setVisible(true);
137 window.setFullscreen(true);
138 }
139 window.setUndecorated(true);
140 Assert.assertNotNull(window);
141
142 final List<MonitorMode> allMonitorModes = screen.getMonitorModes();
143 Assert.assertTrue(allMonitorModes.size()>0);
144 if(allMonitorModes.size()==1) {
145 // no support ..
146 System.err.println("Your platform has no MonitorMode change support (all), sorry");
147 destroyWindow(window);
148 return;
149 }
150
151 final MonitorDevice monitor = window.getMainMonitor();
152 List<MonitorMode> monitorModes = monitor.getSupportedModes();
153 Assert.assertTrue(monitorModes.size()>0);
154 if(monitorModes.size()==1) {
155 // no support ..
156 System.err.println("Your platform has no MonitorMode change support (monitor), sorry");
157 destroyWindow(window);
158 return;
159 }
160 Assert.assertTrue(allMonitorModes.containsAll(monitorModes));
161
162 final Animator animator = new Animator(window);
163 animator.start();
164
165 MonitorMode mmCurrent = monitor.queryCurrentMode();
166 Assert.assertNotNull(mmCurrent);
167 final MonitorMode mmOrig = monitor.getOriginalMode();
168 Assert.assertNotNull(mmOrig);
169 System.err.println("[0] orig : "+mmOrig);
170 System.err.println("[0] current: "+mmCurrent);
171 Assert.assertEquals(mmCurrent, mmOrig);
172
173 monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc
174 Assert.assertNotNull(monitorModes);
175 Assert.assertTrue(monitorModes.size()>0);
176 monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 90);
177 if(null==monitorModes || Platform.getOSType() == Platform.OSType.MACOS ) {
178 // no rotation support ..
179 System.err.println("Your platform has no rotation support, sorry");
180 animator.stop();
181 destroyWindow(window);
182 return;
183 }
184 monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(swidth, sheight));
185 Assert.assertNotNull(monitorModes);
186 Assert.assertTrue(monitorModes.size()>0);
187 monitorModes = MonitorModeUtil.filterByRate(monitorModes, mmOrig.getRefreshRate());
188 Assert.assertNotNull(monitorModes);
189 Assert.assertTrue(monitorModes.size()>0);
190
191 monitorModes = MonitorModeUtil.getHighestAvailableBpp(monitorModes);
192 Assert.assertNotNull(monitorModes);
193 Assert.assertTrue(monitorModes.size()>0);
194
195 // set mode
196 {
197 final MonitorMode mm = monitorModes.get(0); // highest resolution ..
198 System.err.println("[0] set current: "+mm);
199 final boolean smOk = monitor.setCurrentMode(mm);
200 mmCurrent = monitor.getCurrentMode();
201 System.err.println("[0] has current: "+mmCurrent+", changeOK "+smOk);
202 if( !smOk ) {
203 System.err.println("ERROR: Full MonitorMode w/ rotation failure - Expected on some platforms (NV driver) - Tolerated for now.");
204 animator.stop();
205 destroyWindow(window);
206 return;
207 }
208 Assert.assertTrue(monitor.isModeChangedByUs());
209 Assert.assertEquals(mm, mmCurrent);
210 Assert.assertNotSame(mmOrig, mmCurrent);
211 Assert.assertEquals(mmCurrent, monitor.queryCurrentMode());
212 Assert.assertTrue(smOk);
213 }
214
215 if( !preVis ) {
216 window.setFullscreen(true);
217 window.setVisible(true);
218 }
219
220 Thread.sleep(waitTimeLong);
221
222 if( !preVis ) {
223 window.setFullscreen(false);
224 }
225
226 // manual restore!
227 {
228 System.err.println("[1] set orig: "+mmOrig);
229 final boolean smOk = monitor.setCurrentMode(mmOrig);
230 mmCurrent = monitor.getCurrentMode();
231 System.err.println("[1] has orig?: "+mmCurrent+", changeOK "+smOk);
232 Assert.assertFalse(monitor.isModeChangedByUs());
233 Assert.assertEquals(mmOrig, mmCurrent);
234 Assert.assertTrue(smOk);
235 }
236 Thread.sleep(waitTimeShort);
237
238 if( preVis ) {
239 window.setFullscreen(false);
240 }
241
242 Assert.assertEquals(true,display.isNativeValid());
243 Assert.assertEquals(true,screen.isNativeValid());
244 Assert.assertEquals(true,window.isNativeValid());
245 Assert.assertEquals(true,window.isVisible());
246
247 animator.stop();
248 destroyWindow(window);
249
250 Assert.assertEquals(false,window.isVisible());
251 Assert.assertEquals(false,window.isNativeValid());
252 Assert.assertTrue(NewtTestUtil.waitForRealized(screen, false, null));
253 Assert.assertEquals(false,screen.isNativeValid());
254 Assert.assertEquals(false,display.isNativeValid());
255 }
256
257 public static void main(final String args[]) throws IOException {
258 final String tstname = TestScreenMode02bNEWT.class.getName();
259 org.junit.runner.JUnitCore.main(tstname);
260 }
261}
abstract boolean isNativeValid()
final List< MonitorMode > getSupportedModes()
Returns a list of immutable MonitorModes supported by this monitor.
static Display createDisplay(final String name)
Create a Display entity.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
Definition: Screen.java:58
abstract int getHeight()
abstract List< MonitorMode > getMonitorModes()
Return a list of all MonitorModes for all MonitorDevices.
abstract boolean isNativeValid()
abstract void createNative()
Manual trigger the native creation, if not done yet.. This is useful to be able to request the com....
abstract int getWidth()
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
Definition: GLWindow.java:525
final void setTitle(final String title)
Definition: GLWindow.java:297
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final MonitorDevice getMainMonitor()
Returns the MonitorDevice with the highest viewport coverage of this window.
Definition: GLWindow.java:292
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
Definition: GLWindow.java:534
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void setUndecorated(final boolean value)
Definition: GLWindow.java:337
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
Tests MonitorMode change w/ changed rotation and fullscreen.
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
Specifying NEWT's Window functionality:
Definition: Window.java:115
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.