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.AfterClass;
38import org.junit.Assert;
39import org.junit.BeforeClass;
41import org.junit.FixMethodOrder;
42import org.junit.runners.MethodSorters;
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;
57import com.jogamp.nativewindow.util.Dimension;
58import com.jogamp.nativewindow.util.RectangleImmutable;
70@FixMethodOrder(MethodSorters.NAME_ASCENDING)
73 static int width, height;
75 static int waitTimeShort = 2000;
76 static int waitTimeLong = 8000;
80 setResetXRandRIfX11AfterClass();
88 Thread.sleep(waitTimeShort);
122 private void cleanupGL() throws InterruptedException {
123 System.err.println(
"*** cleanupGL.shutdown");
125 System.err.println(
"*** cleanupGL.initSingleton");
127 System.err.println(
"*** cleanupGL.DONE");
130 static GLWindow createWindow(
final Screen screen,
final GLCapabilities caps,
final int width,
final int height,
final boolean onscreen,
final boolean undecorated) {
131 Assert.assertNotNull(caps);
137 Assert.assertNotNull(window);
142 static void destroyWindow(
final Window window)
throws InterruptedException {
145 Assert.assertTrue(NewtTestUtil.waitForRealized(window,
false,
null));
151 Thread.sleep(waitTimeShort);
153 Assert.assertNotNull(caps);
155 Assert.assertNotNull(display);
157 Assert.assertNotNull(screen);
159 final GLWindow window = createWindow(screen, caps, width, height,
true ,
false );
166 Assert.assertEquals(width, window.
getWidth());
167 Assert.assertEquals(height, window.
getHeight());
174 Thread.sleep(waitTimeShort);
178 Assert.assertEquals(width, window.
getWidth());
179 Assert.assertEquals(height, window.
getHeight());
181 Thread.sleep(waitTimeShort);
184 Assert.assertEquals(
false, animator.isAnimating());
185 Assert.assertEquals(
false, animator.
isStarted());
187 destroyWindow(window);
189 Assert.assertEquals(
false,window.
isVisible());
190 Assert.assertEquals(
false,window.
isRealized());
201 Thread.sleep(waitTimeShort);
204 Assert.assertNotNull(caps);
206 Assert.assertNotNull(display);
208 Assert.assertNotNull(screen);
209 final GLWindow window = createWindow(screen, caps, width, height,
true ,
false );
210 Assert.assertNotNull(window);
216 Assert.assertTrue(monitorModes.size()>0);
217 if(monitorModes.size()==1) {
219 System.err.println(
"Your platform has no MonitorMode change support, sorry");
220 destroyWindow(window);
228 Assert.assertNotNull(mmCurrent);
230 Assert.assertNotNull(mmOrig);
231 System.err.println(
"[0] orig : "+mmOrig);
232 System.err.println(
"[0] current: "+mmCurrent);
233 Assert.assertEquals(mmCurrent, mmOrig);
236 Assert.assertNotNull(monitorModes);
237 Assert.assertTrue(monitorModes.size()>0);
239 Assert.assertNotNull(monitorModes);
240 Assert.assertTrue(monitorModes.size()>0);
242 Assert.assertNotNull(monitorModes);
243 Assert.assertTrue(monitorModes.size()>0);
245 Assert.assertNotNull(monitorModes);
246 Assert.assertTrue(monitorModes.size()>0);
249 Assert.assertNotNull(monitorModes);
250 Assert.assertTrue(monitorModes.size()>0);
255 System.err.println(
"[0] set current: "+sm);
258 System.err.println(
"[0] has current: "+mmCurrent+
", changeOK "+smOk);
260 Assert.assertEquals(sm, mmCurrent);
261 Assert.assertNotSame(mmOrig, mmCurrent);
263 Assert.assertTrue(smOk);
266 Thread.sleep(waitTimeLong);
271 Assert.assertEquals(
true,window.
isVisible());
274 Assert.assertEquals(
false, animator.isAnimating());
275 Assert.assertEquals(
false, animator.
isStarted());
277 destroyWindow(window);
279 Assert.assertEquals(
false,window.
isVisible());
280 Assert.assertEquals(
false,window.
isRealized());
286 validateScreenModeReset(mmOrig, winRect);
292 Thread.sleep(waitTimeShort);
293 testScreenModeChangeWithFS01Impl(
false) ;
298 Thread.sleep(waitTimeShort);
299 testScreenModeChangeWithFS01Impl(
true) ;
306 final GLWindow window = createWindow(screen, caps, width, height,
true ,
false );
313 Assert.assertNotNull(mmCurrent);
315 Assert.assertNotNull(mmOrig);
316 System.err.println(
"[0] orig : "+mmOrig);
317 System.err.println(
"[0] current: "+mmCurrent);
318 Assert.assertEquals(mmCurrent, mmOrig);
321 if(monitorModes.size()==1) {
323 destroyWindow(window);
326 Assert.assertTrue(monitorModes.size()>0);
333 final MonitorMode monitorMode = monitorModes.get(0);
334 Assert.assertNotNull(monitorMode);
337 System.err.println(
"[1] set FS pre 0: "+window.
isFullscreen());
339 System.err.println(
"[1] set FS pre 1: "+window.
isFullscreen());
341 System.err.println(
"[1] set FS pre X: "+window.
isFullscreen());
343 Thread.sleep(waitTimeShort);
347 System.err.println(
"[2] set current: "+monitorMode);
350 System.err.println(
"[2] has current: "+mmCurrent+
", changeOK "+smOk);
352 Assert.assertEquals(monitorMode, mmCurrent);
353 Assert.assertNotSame(mmOrig, mmCurrent);
355 Assert.assertTrue(smOk);
359 System.err.println(
"[3] set FS post 0: "+window.
isFullscreen());
362 System.err.println(
"[3] set FS post X: "+window.
isFullscreen());
365 Thread.sleep(waitTimeLong);
368 System.err.println(
"[4] set !FS post 0: "+window.
isFullscreen());
371 System.err.println(
"[4] set !FS post X: "+window.
isFullscreen());
372 Thread.sleep(waitTimeShort);
378 Assert.assertEquals(
true,window.
isVisible());
381 Assert.assertEquals(
false, animator.isAnimating());
382 Assert.assertEquals(
false, animator.
isStarted());
384 destroyWindow(window);
386 Assert.assertEquals(
false,window.
isVisible());
387 Assert.assertEquals(
false,window.
isRealized());
393 validateScreenModeReset(mmOrig, winRect);
404 Assert.assertNotNull(display);
406 Assert.assertNotNull(screen);
421 public static void main(
final String args[])
throws IOException {
423 org.junit.runner.JUnitCore.
main(tstname);
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
abstract boolean isNativeValid()
Visual output device, i.e.
final boolean isModeChangedByUs()
Returns true</true> if the MonitorMode has been changed programmatic via this API only,...
final MonitorMode getCurrentMode()
Returns the cached current MonitorMode w/o native query.
abstract MonitorMode queryCurrentMode()
Returns the current MonitorMode resulting from a native query.
abstract boolean setCurrentMode(MonitorMode mode)
Set the current com.jogamp.newt.MonitorMode.
final List< MonitorMode > getSupportedModes()
Returns a list of immutable MonitorModes supported by this monitor.
final MonitorMode getOriginalMode()
Returns the immutable original com.jogamp.newt.MonitorMode, as used at NEWT initialization.
final RectangleImmutable getViewport()
Returns the current rectangular portion of the rotated virtual Screen size in pixel units represented...
Immutable MonitorMode Class, consisting of it's read only components:
final float getRefreshRate()
Returns the vertical refresh rate.
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 int addReference()
See Display#addReference().
abstract int removeReference()
See Display#removeReference().
final MonitorDevice getMainMonitor(final RectangleImmutable r)
Returns the MonitorDevice with the highest viewport coverage of the given rectangle in window units,...
abstract boolean isNativeValid()
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final boolean isFullscreen()
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final boolean isNativeValid()
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
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 Rectangle getBounds()
Returns a newly created Rectangle containing window origin, getX() & getY(), and size,...
final int getHeight()
Returns the height of the client area excluding insets (window decorations) in window units.
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
final int getWidth()
Returns the width of the client area excluding insets (window decorations) in window units.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Convenient com.jogamp.newt.MonitorMode utility methods, filters etc.
static List< MonitorMode > filterByFlags(final List< MonitorMode > monitorModes, final int flags)
static List< MonitorMode > filterByResolution(final List< MonitorMode > monitorModes, final DimensionImmutable resolution)
static List< MonitorMode > getHighestAvailableBpp(final List< MonitorMode > monitorModes)
static List< MonitorMode > filterByRotation(final List< MonitorMode > monitorModes, final int rotation)
static List< MonitorMode > filterByRate(final List< MonitorMode > monitorModes, final float refreshRate)
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static void shutdown()
Manual shutdown method, may be called after your last JOGL use within the running JVM.
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
static void initSingleton()
Static initialization of JOGL.
Demonstrates fullscreen without MonitorMode change and fullscreen before and after MonitorMode change...
static void releaseClass()
void test01FullscreenChange01()
static void main(final String args[])
void test02ScreenModeChange01()
void test03ScreenModeChangeWithFS01Post()
void testScreenModeChangeWithFS01Impl(final boolean preFS)
void test04ScreenModeChangeWithFS01Pre()
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Immutable Rectangle interface, with its position on the top-left.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
boolean isRealized()
Returns true if this drawable is realized, otherwise false.