29package com.jogamp.opengl.test.junit.newt.mm;
31import java.io.IOException;
33import com.jogamp.nativewindow.NativeWindowFactory;
35import org.junit.Assert;
36import org.junit.BeforeClass;
38import org.junit.FixMethodOrder;
39import org.junit.runners.MethodSorters;
41import com.jogamp.common.util.ArrayHashSet;
42import com.jogamp.newt.Display;
43import com.jogamp.newt.MonitorDevice;
44import com.jogamp.newt.NewtFactory;
45import com.jogamp.newt.MonitorMode;
46import com.jogamp.newt.Screen;
47import com.jogamp.newt.util.MonitorModeUtil;
48import com.jogamp.opengl.test.junit.util.UITestCase;
50import java.util.Iterator;
53import com.jogamp.nativewindow.util.Dimension;
54import com.jogamp.nativewindow.util.DimensionImmutable;
55import com.jogamp.nativewindow.util.Rectangle;
56import com.jogamp.nativewindow.util.RectangleImmutable;
57import com.jogamp.nativewindow.util.SurfaceSize;
58import com.jogamp.opengl.GLProfile;
60import jogamp.newt.MonitorDeviceImpl;
61import jogamp.newt.MonitorModeProps;
70@FixMethodOrder(MethodSorters.NAME_ASCENDING)
72 static int screenIdx = 0;
73 static int width, height;
75 static int waitTimeShort = 4;
76 static int waitTimeLong = 6;
82 setResetXRandRIfX11AfterClass();
94 System.err.println(
"00 out: "+modeOut);
95 final MonitorModeProps.Cache cache =
new MonitorModeProps.Cache();
96 cache.monitorModes.add(modeOut);
98 final int[] props = MonitorModeProps.streamOutMonitorMode(modeOut);
99 final MonitorMode modeIn = MonitorModeProps.streamInMonitorMode(
null, cache, props, 0);
100 System.err.println(
"00 in : "+modeIn);
106 Assert.assertEquals(modeOut.hashCode(), modeIn.hashCode());
108 Assert.assertEquals(modeOut, modeIn);
111 final long monitor_handle = -1;
112 final int monitor_id = -1;
113 final String monitor_name =
"DP-1";
116 final ArrayHashSet<MonitorMode> supportedModes =
new ArrayHashSet<MonitorMode>(
false, ArrayHashSet.DEFAULT_INITIAL_CAPACITY, ArrayHashSet.DEFAULT_LOAD_FACTOR);
117 supportedModes.add(modeOut);
118 final MonitorDevice monOut =
new MonitorDeviceImpl(
null, monitor_handle, monitor_id, monitor_name,
false,
true, sizeMM, modeOut,
null, viewport, viewport, supportedModes);
119 System.err.println(
"01 out : "+monOut);
120 cache.monitorDevices.add(monOut);
122 final int[] props = MonitorModeProps.streamOutMonitorDevice(monOut);
123 final MonitorDevice monIn = MonitorModeProps.streamInMonitorDevice(cache,
null, monitor_handle, monitor_name,
null,
false , props, 0,
null);
124 System.err.println(
"01 in : "+monIn);
127 Assert.assertEquals(monOut.
getId(), monIn.
getId());
138 Assert.assertEquals(monOut, monIn);
142 static void dumpMonitor(
final String pre0,
final String pre1,
final MonitorDevice monitor) {
143 System.err.println(pre0+
" "+monitor);
145 System.err.println(pre1+
" pixel/mm ["+pixelPerMM[0]+
", "+pixelPerMM[1]+
"]");
146 System.err.println(pre1+
" pixel/in ["+pixelPerMM[0]*25.4f+
", "+pixelPerMM[1]*25.4f+
"]");
148 Assert.assertNotNull(sm_o);
150 System.err.println(pre1+
" orig : "+sm_o);
151 System.err.println(pre1+
" current: "+sm_c);
152 Assert.assertNotNull(sm_c);
153 Assert.assertEquals(sm_o, sm_c);
164 Assert.assertTrue(monitors.size()>0);
167 Assert.assertNotNull(
"Could not retrieve primary monitor", primMonitor);
168 dumpMonitor(
"Primary Device ",
" ", primMonitor);
169 Assert.assertTrue(
"Tracked primary monitor not flagged as primary", primMonitor.
isPrimary());
173 for(
final Iterator<MonitorDevice> iMonitor=monitors.iterator(); iMonitor.hasNext(); j++) {
175 dumpMonitor(
"Monitor Index "+j,
" ", monitor);
176 if( monitor.
getId() == primMonitor.
getId() ) {
177 Assert.assertTrue(
"Primary monitor not flagged as primary", monitor.
isPrimary());
179 Assert.assertFalse(
"Non primary monitor flagged as primary", monitor.
isPrimary());
187 System.err.println(
"Test.0: Monitor union viewport: "+monitorViewPU+
" [pu] / "+monitorViewWU+
" [wu]");
188 Assert.assertNotEquals(zero, monitorViewPU);
189 Assert.assertNotEquals(zero, monitorViewWU);
193 System.err.println(
"Test.1: Screen viewport: "+screenViewPU+
" [pu] / "+screenViewWU+
" [wu]");
194 Assert.assertNotEquals(zero, screenViewPU);
195 Assert.assertNotEquals(zero, screenViewWU);
210 System.err.println(
"Screen: "+screen.toString());
212 Assert.assertTrue(allMonitorModes.size()>0);
216 for(
final Iterator<MonitorMode> iMode=allMonitorModes.iterator(); iMode.hasNext(); i++) {
218 System.err.println(String.format(
"All-0[%03d]: %s", i, mm));
219 if(
null != mmPre ) {
220 Assert.assertTrue(
"Wrong order", mmPre.
compareTo(mm) >= 0);
229 for(
final Iterator<MonitorMode> iMode=allMonitorModes.iterator(); iMode.hasNext(); i++) {
231 System.err.println(String.format(
"All-1[%03d]: %s", i, mm));
232 if(
null != mmPre ) {
233 Assert.assertTrue(
"Wrong order", mmPre.
compareTo(mm) <= 0);
240 Assert.assertTrue(monitors.size()>0);
244 for(
final Iterator<MonitorDevice> iMonitor=monitors.iterator(); iMonitor.hasNext(); j++) {
246 System.err.println(j+
": "+monitor);
248 Assert.assertTrue(modes.size()>0);
251 for(
final Iterator<MonitorMode> iMode=modes.iterator(); iMode.hasNext(); i++) {
253 System.err.println(String.format(
"[%02d][%03d]: %s", j, i, mm));
254 if(
null != mmPre ) {
255 Assert.assertTrue(
"Wrong order", mmPre.
compareTo(mm) >= 0);
259 Assert.assertTrue(allMonitorModes.containsAll(modes));
267 static int atoi(
final String a) {
269 return Integer.parseInt(a);
270 }
catch (
final Exception ex) {
throw new RuntimeException(ex); }
273 public static void main(
final String args[])
throws IOException {
274 for(
int i=0; i<args.length; i++) {
275 if(args[i].equals(
"-screen")) {
277 screenIdx = atoi(args[i]);
281 org.junit.runner.JUnitCore.
main(tstname);
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
static synchronized void initSingleton()
Static one time initialization of this factory.
Immutable SurfaceSize Class, consisting of it's read only components:
final DimensionImmutable getResolution()
Returns the resolution in pixel units.
abstract boolean isNativeValid()
Visual output device, i.e.
static void unionOfViewports(final Rectangle viewport, final Rectangle viewportInWindowUnits, final List< MonitorDevice > monitors)
Calculates the union of the given monitor's viewport in pixel- and window units.
final int hashCode()
Returns a combined hash code of it's elements:
final MonitorMode getCurrentMode()
Returns the cached current MonitorMode w/o native query.
abstract MonitorMode queryCurrentMode()
Returns the current MonitorMode resulting from a native query.
final RectangleImmutable getViewportInWindowUnits()
Returns the current rectangular portion of the rotated virtual Screen size in window units represente...
final float[] getPixelsPerMM(final float[] ppmmStore)
Returns the pixels per millimeter value according to the current mode's surface resolution.
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 SurfaceSize getSurfaceSize()
Returns the unrotated SurfaceSize.
int compareTo(final MonitorMode mm)
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 Display getDisplay()
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 MonitorDevice getPrimaryMonitor()
Returns the windowing manager's primary MonitorDevice, which holds the system menu bar,...
abstract boolean isNativeValid()
abstract List< MonitorDevice > getMonitorDevices()
Return a list of available MonitorDevices.
Convenient com.jogamp.newt.MonitorMode utility methods, filters etc.
static void sort(final List< MonitorMode > monitorModes, final boolean ascendingOrder)
Sort the given MonitorMode collection w/ MonitorMode#compareTo(MonitorMode) function.
Specifies the the OpenGL profile.
static void initSingleton()
Static initialization of JOGL.
Validating consistency of MonitorMode data from Screen (all modes) and from a particular MonitorDevic...
void test01ScreenAllMonitor()
void test00ScreenModeStream()
void test02ScreenAllModesInfo()
static void main(final String args[])
Immutable Dimension Interface, consisting of it's read only components:
Immutable Rectangle interface, with its position on the top-left.