29package com.jogamp.opengl.test.junit.newt.mm;
31import java.io.IOException;
32import com.jogamp.opengl.GLCapabilities;
33import com.jogamp.opengl.GLProfile;
35import com.jogamp.opengl.util.Animator;
37import org.junit.Assert;
38import org.junit.BeforeClass;
40import org.junit.FixMethodOrder;
41import org.junit.runners.MethodSorters;
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;
56import com.jogamp.nativewindow.util.Dimension;
65@FixMethodOrder(MethodSorters.NAME_ASCENDING)
68 static int width, height;
70 static int waitTimeShort = 4000;
71 static int waitTimeLong = 8000;
75 setResetXRandRIfX11AfterClass();
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);
88 Assert.assertNotNull(window);
92 static void destroyWindow(
final Window window)
throws InterruptedException {
101 testScreenRotationChangeImpl(
true,
true,
false);
106 testScreenRotationChangeImpl(
true,
true,
true);
111 testScreenRotationChangeImpl(
true,
false,
false);
116 testScreenRotationChangeImpl(
true,
false,
true);
119 void testScreenRotationChangeImpl(
final boolean changeMode,
final boolean preVis,
final boolean fullscreen)
throws InterruptedException {
121 Assert.assertNotNull(caps);
123 Assert.assertNotNull(display);
125 Assert.assertNotNull(screen);
126 final GLWindow window = createWindow(screen, caps, width, height,
true ,
false );
127 Assert.assertNotNull(window);
139 final Animator animator =
new Animator(window);
144 Assert.assertNotNull(mmOrig);
146 Thread.sleep(waitTimeShort);
148 List<MonitorMode> monitorModes = monitor.getSupportedModes();
149 if(monitorModes.size()==1) {
151 System.err.println(
"Your platform has no ScreenMode change support, sorry");
153 destroyWindow(window);
156 Assert.assertTrue(monitorModes.size()>0);
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);
164 monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0);
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 ) {
170 System.err.println(
"Your platform has no rotation support, sorry");
172 destroyWindow(window);
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);
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);
207 Thread.sleep(waitTimeLong);
209 if( !preVis && fullscreen ) {
214 Thread.sleep(waitTimeShort);
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);
226 Thread.sleep(waitTimeShort);
229 if( preVis && fullscreen ) {
236 Assert.assertEquals(
true,window.
isVisible());
239 destroyWindow(window);
241 Assert.assertEquals(
false,window.
isVisible());
243 Assert.assertTrue(NewtTestUtil.waitForRealized(screen,
false,
null));
248 public static void main(
final String args[])
throws IOException {
250 org.junit.runner.JUnitCore.
main(tstname);
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.
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,...
final boolean isNativeValid()
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final MonitorDevice getMainMonitor()
Returns the MonitorDevice with the highest viewport coverage of this window.
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
final boolean isVisible()
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Tests MonitorMode change w/ changed rotation, w/ and w/o fullscreen, pre and post MonitorMode change.
void testScreenRotationChange02_PreFull()
void testScreenRotationChange12_PostFull()
static void main(final String args[])
void testScreenRotationChange11_PostWin()
void testScreenRotationChange01_PreWin()
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
Specifying NEWT's Window functionality:
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.