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.opengl.test.junit.jogl.demos.es2.GearsES2;
51import com.jogamp.opengl.test.junit.util.MiscUtils;
52import com.jogamp.opengl.test.junit.util.NewtTestUtil;
53import com.jogamp.opengl.test.junit.util.UITestCase;
54import com.jogamp.opengl.util.Animator;
56import java.util.ArrayList;
59import com.jogamp.nativewindow.util.Dimension;
60import com.jogamp.nativewindow.util.DimensionImmutable;
61import com.jogamp.nativewindow.util.Rectangle;
62import com.jogamp.nativewindow.util.RectangleImmutable;
67@FixMethodOrder(MethodSorters.NAME_ASCENDING)
70 static int width, height;
72 static long waitTimeShort = 2000;
73 static long duration = 4000;
77 setResetXRandRIfX11AfterClass();
85 Thread.sleep(waitTimeShort);
88 static GLWindow createWindow(
final Screen screen,
final GLCapabilities caps,
final String name,
final int screenXPos,
final int screenYPos,
final int width,
final int height)
throws InterruptedException {
89 Assert.assertNotNull(caps);
98 Assert.assertNotNull(window);
99 final long t0 = System.currentTimeMillis();
101 System.err.println(
"Time for visible/pos: "+(System.currentTimeMillis()-t0)+
" ms");
105 static void destroyWindow(
final Window window)
throws InterruptedException {
108 NewtTestUtil.waitForRealized(window,
false,
null);
115 Assert.assertNotNull(display);
117 Assert.assertNotNull(screen);
121 testScreenFullscreenImpl(screen, monitorVp.
getX(), monitorVp.
getY(),
false,
null);
131 Assert.assertNotNull(display);
133 Assert.assertNotNull(screen);
137 System.err.println(
"Test Disabled (1): Monitor count < 2: "+screen);
141 testScreenFullscreenImpl(screen, monitorVp.
getX(), monitorVp.
getY(),
false,
null);
151 Assert.assertNotNull(display);
153 Assert.assertNotNull(screen);
157 System.err.println(
"Test Disabled (2): Spanning monitor count < 2: "+screen);
160 final ArrayList<MonitorDevice> monitors =
new ArrayList<MonitorDevice>();
164 testScreenFullscreenImpl(screen, monitorVp.
getX()+50, monitorVp.
getY()+50,
true, monitors);
174 Assert.assertNotNull(display);
176 Assert.assertNotNull(screen);
180 System.err.println(
"Test Disabled (3): Monitor count < 2: "+screen);
184 testScreenFullscreenImpl(screen, monitorVp.
getX()-50, monitorVp.
getY()+50,
true,
null);
191 void testScreenFullscreenImpl(
final Screen screen,
final int screenXPos,
final int screenYPos,
192 final boolean spanAcrossMonitors,
final List<MonitorDevice> monitors)
throws InterruptedException {
193 Thread.sleep(waitTimeShort);
196 Assert.assertNotNull(caps);
197 final Display display = screen.getDisplay();
199 System.err.println(
"Test.0: Window screen: "+screen);
201 System.err.println(
"Test.0: Window bounds (pre): screenPos "+screenXPos+
"/"+screenYPos+
" [pixels], windowSize "+width+
"x"+height+
" [wu] within "+screen.getViewport()+
" [pixels]");
203 final GLWindow window0 = createWindow(screen, caps,
"win0", screenXPos, screenYPos, width, height);
204 Assert.assertNotNull(window0);
207 System.err.println(
"Test.0: Window bounds : "+window0WindowBounds+
" [wu] within "+screen.getViewportInWindowUnits()+
" [wu]");
208 System.err.println(
"Test.0: Window size : "+window0SurfaceSize+
" [pixels]");
209 System.err.println(
"Test.0: Screen viewport : "+screen.getViewport()+
" [pixels]");
214 final List<MonitorMode> allMonitorModes = screen.getMonitorModes();
215 Assert.assertTrue(allMonitorModes.size()>0);
218 System.err.println(
"Test.0: Window monitor: "+monitor);
219 if( !spanAcrossMonitors ) {
226 window0WindowBounds = window0.
getBounds();
228 System.err.println(
"Test.1: Window bounds : "+window0WindowBounds+
" [wu] within "+screen.getViewportInWindowUnits()+
" [wu]");
229 System.err.println(
"Test.1: Window size : "+window0SurfaceSize+
" [pixels]");
230 System.err.println(
"Test.1: Screen viewport : "+screen.getViewport()+
" [pixels]");
232 if( !spanAcrossMonitors ) {
235 List<MonitorDevice> monitorsUsed = monitors;
236 if(
null == monitorsUsed ) {
239 final Rectangle monitorsUsedViewport =
new Rectangle();
240 MonitorDevice.unionOfViewports(
null, monitorsUsedViewport, monitorsUsed);
241 Assert.assertEquals(monitorsUsedViewport, window0WindowBounds);
244 Thread.sleep(duration);
248 window0WindowBounds = window0.
getBounds();
251 System.err.println(
"Test.2: Window bounds : "+window0WindowBounds+
" [wu] within "+screen.getViewportInWindowUnits()+
" [wu]");
252 System.err.println(
"Test.2: Window size : "+window0SurfaceSize+
" [pixels]");
253 System.err.println(
"Test.2: Screen viewport : "+screen.getViewport()+
" [pixels]");
256 Thread.sleep(duration);
258 destroyWindow(window0);
259 Assert.assertEquals(
false,window0.
isVisible());
262 Assert.assertEquals(
true,screen.isNativeValid());
265 public static void main(
final String args[])
throws IOException {
266 for(
int i=0; i<args.length; i++) {
267 if(args[i].equals(
"-time")) {
273 org.junit.runner.JUnitCore.
main(tstname);
abstract boolean isNativeValid()
Visual output device, i.e.
final RectangleImmutable getViewportInWindowUnits()
Returns the current rectangular portion of the rotated virtual Screen size in window units represente...
final RectangleImmutable getViewport()
Returns the current rectangular portion of the rotated virtual Screen size in pixel units represented...
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 List< MonitorDevice > getMonitorDevices()
Return a list of available MonitorDevices.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final boolean isNativeValid()
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 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 int[] convertToWindowUnits(final int[] pixelUnitsAndResult)
Converts the given pixel units into window units in place.
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 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.
Fullscreen on separate monitors, incl.
void test01ScreenFullscreenSingleQ1()
static void main(final String args[])
void test02ScreenFullscreenSingleQ2()
void test03ScreenFullscreenSpanQ1Q2()
void test04ScreenFullscreenSpanALL()
static void releaseClass()
static long atol(final String str, final long def)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this animator.
Immutable Dimension Interface, consisting of it's read only components:
Immutable Rectangle interface, with its position on the top-left.
int getX()
x-position, left of rectangle.
int getY()
y-position, top of rectangle.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.