JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestScreenMode02aNEWT.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 com.jogamp.opengl.util.Animator;
36
37import org.junit.Assert;
38import org.junit.BeforeClass;
39import org.junit.Test;
40import org.junit.FixMethodOrder;
41import org.junit.runners.MethodSorters;
42
43import com.jogamp.common.os.Platform;
44import com.jogamp.newt.Display;
45import com.jogamp.newt.MonitorDevice;
46import com.jogamp.newt.NewtFactory;
47import com.jogamp.newt.Screen;
48import com.jogamp.newt.Window;
49import com.jogamp.newt.MonitorMode;
50import com.jogamp.newt.opengl.GLWindow;
51import com.jogamp.newt.util.MonitorModeUtil;
52import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
53import com.jogamp.opengl.test.junit.util.NewtTestUtil;
54import com.jogamp.opengl.test.junit.util.UITestCase;
55import java.util.List;
56import com.jogamp.nativewindow.util.Dimension;
57
58/**
59 * Tests MonitorMode change w/ changed rotation,
60 * w/ and w/o fullscreen, pre and post MonitorMode change.
61 * <p>
62 * MonitorMode change does not use highest resolution.
63 * </p>
64 */
65@FixMethodOrder(MethodSorters.NAME_ASCENDING)
66public class TestScreenMode02aNEWT extends UITestCase {
67 static GLProfile glp;
68 static int width, height;
69
70 static int waitTimeShort = 4000; // 4 sec
71 static int waitTimeLong = 8000; // 8 sec
72
73 @BeforeClass
74 public static void initClass() {
75 setResetXRandRIfX11AfterClass();
76 width = 640;
77 height = 480;
78 glp = GLProfile.getDefault();
79 }
80
81 static GLWindow createWindow(final Screen screen, final GLCapabilities caps, final int width, final int height, final boolean onscreen, final boolean undecorated) {
82 Assert.assertNotNull(caps);
83 caps.setOnscreen(onscreen);
84
85 final GLWindow window = GLWindow.create(screen, caps);
86 window.setSize(width, height);
87 window.addGLEventListener(new GearsES2(1));
88 Assert.assertNotNull(window);
89 return window;
90 }
91
92 static void destroyWindow(final Window window) throws InterruptedException {
93 if(null!=window) {
94 window.destroy();
95 Assert.assertTrue(NewtTestUtil.waitForRealized(window, false, null));
96 }
97 }
98
99 @Test
100 public void testScreenRotationChange01_PreWin() throws InterruptedException {
101 testScreenRotationChangeImpl(true, true, false);
102 }
103
104 @Test
105 public void testScreenRotationChange02_PreFull() throws InterruptedException {
106 testScreenRotationChangeImpl(true, true, true);
107 }
108
109 @Test
110 public void testScreenRotationChange11_PostWin() throws InterruptedException {
111 testScreenRotationChangeImpl(true, false, false);
112 }
113
114 @Test
115 public void testScreenRotationChange12_PostFull() throws InterruptedException {
116 testScreenRotationChangeImpl(true, false, true);
117 }
118
119 void testScreenRotationChangeImpl(final boolean changeMode, final boolean preVis, final boolean fullscreen) throws InterruptedException {
120 final GLCapabilities caps = new GLCapabilities(glp);
121 Assert.assertNotNull(caps);
122 final Display display = NewtFactory.createDisplay(null); // local display
123 Assert.assertNotNull(display);
124 final Screen screen = NewtFactory.createScreen(display, 0); // screen 0
125 Assert.assertNotNull(screen);
126 final GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
127 Assert.assertNotNull(window);
128 if( preVis ) {
129 window.setVisible(true);
130 if( fullscreen ) {
131 window.setFullscreen(true);
132 }
133 } else {
134 screen.createNative();
135 Assert.assertEquals(true,display.isNativeValid());
136 Assert.assertEquals(true,screen.isNativeValid());
137 }
138
139 final Animator animator = new Animator(window);
140 animator.start();
141
142 final MonitorDevice monitor = window.getMainMonitor();
143 final MonitorMode mmOrig = monitor.getOriginalMode();
144 Assert.assertNotNull(mmOrig);
145 if(changeMode) {
146 Thread.sleep(waitTimeShort);
147
148 List<MonitorMode> monitorModes = monitor.getSupportedModes();
149 if(monitorModes.size()==1) {
150 // no support ..
151 System.err.println("Your platform has no ScreenMode change support, sorry");
152 animator.stop();
153 destroyWindow(window);
154 return;
155 }
156 Assert.assertTrue(monitorModes.size()>0);
157
158 MonitorMode mmCurrent = monitor.getCurrentMode();
159 Assert.assertNotNull(mmCurrent);
160 System.err.println("[0] orig : "+mmOrig);
161 System.err.println("[0] current: "+mmCurrent);
162 Assert.assertEquals(mmCurrent, mmOrig);
163
164 monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc
165 Assert.assertNotNull(monitorModes);
166 Assert.assertTrue(monitorModes.size()>0);
167 monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 90);
168 if(null==monitorModes || Platform.getOSType() == Platform.OSType.MACOS ) {
169 // no rotation support ..
170 System.err.println("Your platform has no rotation support, sorry");
171 animator.stop();
172 destroyWindow(window);
173 return;
174 }
175 monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(801, 601));
176 Assert.assertNotNull(monitorModes);
177 Assert.assertTrue(monitorModes.size()>0);
178 monitorModes = MonitorModeUtil.filterByRate(monitorModes, mmOrig.getRefreshRate());
179 Assert.assertNotNull(monitorModes);
180 Assert.assertTrue(monitorModes.size()>0);
181 monitorModes = MonitorModeUtil.getHighestAvailableBpp(monitorModes);
182 Assert.assertNotNull(monitorModes);
183 Assert.assertTrue(monitorModes.size()>0);
184
185 // set mode
186 {
187 final MonitorMode mm = monitorModes.get(0);
188 System.err.println("[0] set current: "+mm);
189 final boolean smOk = monitor.setCurrentMode(mm);
190 mmCurrent = monitor.getCurrentMode();
191 System.err.println("[0] has current: "+mmCurrent+", changeOK "+smOk);
192 Assert.assertTrue(monitor.isModeChangedByUs());
193 Assert.assertEquals(mm, mmCurrent);
194 Assert.assertNotSame(mmOrig, mmCurrent);
195 Assert.assertEquals(mmCurrent, monitor.queryCurrentMode());
196 Assert.assertTrue(smOk);
197 }
198 }
199
200 if( !preVis ) {
201 if( fullscreen ) {
202 window.setFullscreen(true);
203 }
204 window.setVisible(true);
205 }
206
207 Thread.sleep(waitTimeLong);
208
209 if( !preVis && fullscreen ) {
210 window.setFullscreen(false);
211 }
212
213 if(changeMode) {
214 Thread.sleep(waitTimeShort);
215
216 // manual restore!
217 {
218 System.err.println("[1] set orig: "+mmOrig);
219 final boolean smOk = monitor.setCurrentMode(mmOrig);
220 final MonitorMode mmCurrent = monitor.getCurrentMode();
221 System.err.println("[1] has orig?: "+mmCurrent+", changeOK "+smOk);
222 Assert.assertFalse(monitor.isModeChangedByUs());
223 Assert.assertEquals(mmOrig, mmCurrent);
224 Assert.assertTrue(smOk);
225 }
226 Thread.sleep(waitTimeShort);
227 }
228
229 if( preVis && fullscreen ) {
230 window.setFullscreen(false);
231 }
232
233 Assert.assertEquals(true,display.isNativeValid());
234 Assert.assertEquals(true,screen.isNativeValid());
235 Assert.assertEquals(true,window.isNativeValid());
236 Assert.assertEquals(true,window.isVisible());
237
238 animator.stop();
239 destroyWindow(window);
240
241 Assert.assertEquals(false,window.isVisible());
242 Assert.assertEquals(false,window.isNativeValid());
243 Assert.assertTrue(NewtTestUtil.waitForRealized(screen, false, null));
244 Assert.assertEquals(false,screen.isNativeValid());
245 Assert.assertEquals(false,display.isNativeValid());
246 }
247
248 public static void main(final String args[]) throws IOException {
249 final String tstname = TestScreenMode02aNEWT.class.getName();
250 org.junit.runner.JUnitCore.main(tstname);
251 }
252
253}
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
abstract boolean isNativeValid()
final MonitorMode getOriginalMode()
Returns the immutable original com.jogamp.newt.MonitorMode, as used at NEWT initialization.
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 boolean isNativeValid()
abstract void createNative()
Manual trigger the native creation, if not done yet.. This is useful to be able to request the com....
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
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 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, w/ and w/o fullscreen, pre and post MonitorMode change.
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.