29package com.jogamp.opengl.test.junit.newt.mm;
31import java.io.IOException;
33import com.jogamp.opengl.GLCapabilities;
34import com.jogamp.opengl.GLProfile;
36import org.junit.AfterClass;
37import org.junit.Assert;
38import org.junit.BeforeClass;
40import org.junit.FixMethodOrder;
41import org.junit.runners.MethodSorters;
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.MiscUtils;
53import com.jogamp.opengl.test.junit.util.NewtTestUtil;
54import com.jogamp.opengl.test.junit.util.UITestCase;
58import com.jogamp.nativewindow.NativeWindowFactory;
59import com.jogamp.nativewindow.util.Dimension;
60import com.jogamp.nativewindow.util.DimensionImmutable;
61import com.jogamp.nativewindow.util.Rectangle;
66@FixMethodOrder(MethodSorters.NAME_ASCENDING)
68 static boolean manualTest =
false;
70 static int width, height;
72 static final int waitTimeShort = 2000;
73 static long duration = 4000;
75 static int mm_width = 800;
76 static int mm_height = 600;
80 setResetXRandRIfX11AfterClass();
83 setTestSupported(
false);
93 Thread.sleep(waitTimeShort);
96 static Window createWindow(
final Screen screen,
final GLCapabilities caps,
final String name,
final int x,
final int y,
final int width,
final int height) {
97 Assert.assertNotNull(caps);
105 Assert.assertNotNull(window);
110 static void destroyWindow(
final Window window)
throws InterruptedException {
119 Thread.sleep(waitTimeShort);
122 Assert.assertNotNull(caps);
124 Assert.assertNotNull(display);
126 Assert.assertNotNull(screen);
127 final Window window0 = createWindow(screen, caps,
"win0", 0, 0, width, height);
128 Assert.assertNotNull(window0);
132 System.err.println(
"Test.0: Window bounds : "+window0WindowBounds+
" [wu] within "+screen.
getViewportInWindowUnits()+
" [wu]");
133 System.err.println(
"Test.0: Window size : "+window0SurfaceSize+
" [pixels]");
134 System.err.println(
"Test.0: Screen viewport : "+screen.
getViewport()+
" [pixels]");
137 Assert.assertTrue(allMonitorModes.size()>0);
138 if(allMonitorModes.size()==1) {
140 System.err.println(
"Your platform has no MonitorMode change support (all), sorry");
141 destroyWindow(window0);
147 Assert.assertTrue(monitorModes.size()>0);
148 if(monitorModes.size()==1) {
150 System.err.println(
"Your platform has no MonitorMode change support (monitor), sorry");
151 destroyWindow(window0);
154 Assert.assertTrue(allMonitorModes.containsAll(monitorModes));
157 Assert.assertNotNull(mmSet0);
159 Assert.assertNotNull(mmOrig);
160 System.err.println(
"[0] orig : "+mmOrig);
161 System.err.println(
"[0] current: "+mmSet0);
162 Assert.assertEquals(mmSet0, mmOrig);
166 Assert.assertNotNull(monitorModes);
167 Assert.assertTrue(monitorModes.size()>0);
169 Assert.assertNotNull(monitorModes);
170 Assert.assertTrue(monitorModes.size()>0);
172 Assert.assertNotNull(monitorModes);
173 Assert.assertTrue(monitorModes.size()>0);
175 Assert.assertNotNull(monitorModes);
176 Assert.assertTrue(monitorModes.size()>0);
179 Assert.assertNotNull(monitorModes);
180 Assert.assertTrue(monitorModes.size()>0);
185 System.err.println(
"[1] set current: "+mm);
189 final boolean mmCurrentEquals = mmQueriedCurrent.
equals(mmCachedCurrent);
190 System.err.println(
"[1] changeOK : "+smOk);
191 System.err.println(
"[1] has current cached : "+mmCachedCurrent);
192 System.err.println(
"[1] has current queried : "+mmQueriedCurrent+
", equal "+mmCurrentEquals);
193 window0WindowBounds = window0.
getBounds();
195 System.err.println(
"Test.1: Window bounds : "+window0WindowBounds+
" [wu] within "+screen.
getViewportInWindowUnits()+
" [wu]");
196 System.err.println(
"Test.1: Window size : "+window0SurfaceSize+
" [pixels]");
197 System.err.println(
"Test.1: Screen viewport : "+screen.
getViewport()+
" [pixels]");
200 Assert.assertEquals(mm, mmCachedCurrent);
201 Assert.assertNotSame(mmOrig, mmCachedCurrent);
202 Assert.assertEquals(mmCachedCurrent, mmQueriedCurrent);
203 Assert.assertTrue(smOk);
206 Thread.sleep(duration);
211 Assert.assertEquals(
true,window0.
isVisible());
214 final int xrandrErrorCode;
218 System.err.println(
"XRandR Reset : Failed w/ errorCode "+xrandrErrorCode+
", fall back to manual reset");
220 System.err.println(
"[X] changeOK : "+smOk);
222 Thread.sleep(duration);
223 validateScreenModeReset0(mmOrig);
225 destroyWindow(window0);
227 Thread.sleep(waitTimeShort);
228 validateScreenModeReset(mmOrig);
231 void validateScreenModeReset0(
final MonitorMode mmOrig) {
233 Assert.assertNotNull(display);
235 Assert.assertNotNull(screen);
245 void validateScreenModeReset(
final MonitorMode mmOrig) {
246 final Display display = NewtFactory.createDisplay(
null);
247 Assert.assertNotNull(display);
248 final Screen screen = NewtFactory.createScreen(display, 0);
249 Assert.assertNotNull(screen);
257 Assert.assertEquals(mmOrig, monitor.getCurrentMode());
264 public static void main(
final String args[])
throws IOException {
266 for(
int i=0; i<args.length; i++) {
267 if(args[i].equals(
"-time")) {
270 }
else if(args[i].equals(
"-mwidth")) {
273 }
else if(args[i].equals(
"-mheight")) {
278 System.err.println(
"Desired mode w/ resolution "+mm_width+
"x"+mm_height);
280 org.junit.runner.JUnitCore.
main(tstname);
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
static final String TYPE_X11
X11 type, as retrieved with getNativeWindowType(boolean).
static synchronized void initSingleton()
Static one time initialization of this factory.
static String getNativeWindowType(final boolean useCustom)
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.
Immutable MonitorMode Class, consisting of it's read only components:
final boolean equals(final Object obj)
Tests equality of two MonitorMode objects by evaluating equality of it's 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().
abstract RectangleImmutable getViewport()
See Coordinate System.
abstract RectangleImmutable getViewportInWindowUnits()
See Coordinate System.
abstract List< MonitorMode > getMonitorModes()
Return a list of all MonitorModes for all MonitorDevices.
abstract boolean isNativeValid()
abstract List< MonitorDevice > getMonitorDevices()
Return a list of available MonitorDevices.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
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.
final void setTitle(final String title)
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
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...
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 GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Tests X11 XRandR MonitorMode reset via UITestCase#resetXRandRIfX11().
static void main(final String args[])
void testScreenModeChange01()
static void releaseClass()
static int atoi(final String str, final int def)
static long atol(final String str, final long def)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static int resetXRandRIfX11()
Iterates through all outputs and sets the preferred mode and normal rotation using RandR 1....
int getSurfaceWidth()
Returns the width of the client area excluding insets (window decorations) in pixel units.
int getSurfaceHeight()
Returns the height of the client area excluding insets (window decorations) in pixel units.
Rectangle getBounds()
Returns a newly created Rectangle containing window origin, getX() & getY(), and size,...
Immutable Dimension Interface, consisting of it's read only components:
Specifying NEWT's Window functionality:
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.