JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestScreenMode00aNEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.newt.mm;
30
31import java.io.IOException;
32
33import com.jogamp.nativewindow.NativeWindowFactory;
34
35import org.junit.Assert;
36import org.junit.BeforeClass;
37import org.junit.Test;
38import org.junit.FixMethodOrder;
39import org.junit.runners.MethodSorters;
40
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;
49
50import java.util.Iterator;
51import java.util.List;
52
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;
59
60import jogamp.newt.MonitorDeviceImpl;
61import jogamp.newt.MonitorModeProps;
62
63/**
64 * Validating consistency of MonitorMode data from Screen (all modes)
65 * and from a particular MonitorDevice.
66 * <p>
67 * Also validates the descending order of the given MonitorMode lists.
68 * </p>
69 */
70@FixMethodOrder(MethodSorters.NAME_ASCENDING)
71public class TestScreenMode00aNEWT extends UITestCase {
72 static int screenIdx = 0;
73 static int width, height;
74
75 static int waitTimeShort = 4; //1 sec
76 static int waitTimeLong = 6; //6 sec
77
78
79
80 @BeforeClass
81 public static void initClass() {
82 setResetXRandRIfX11AfterClass();
83 GLProfile.initSingleton(); // hack to initialize GL for BCM_IV (Rasp.Pi)
85 width = 640;
86 height = 480;
87 }
88
89 @Test
90 public void test00ScreenModeStream() throws InterruptedException {
91 final DimensionImmutable res = new Dimension(640, 480);
92 final SurfaceSize surfsz = new SurfaceSize(res, 32);
93 final MonitorMode modeOut = new MonitorMode(surfsz, 60.0f, 0, 0);
94 System.err.println("00 out: "+modeOut);
95 final MonitorModeProps.Cache cache = new MonitorModeProps.Cache();
96 cache.monitorModes.add(modeOut);
97 {
98 final int[] props = MonitorModeProps.streamOutMonitorMode(modeOut);
99 final MonitorMode modeIn = MonitorModeProps.streamInMonitorMode(null, cache, props, 0);
100 System.err.println("00 in : "+modeIn);
101
102 Assert.assertEquals(modeOut.getSurfaceSize().getResolution(), modeIn.getSurfaceSize().getResolution());
103
104 Assert.assertEquals(modeOut.getSurfaceSize(), modeIn.getSurfaceSize());
105
106 Assert.assertEquals(modeOut.hashCode(), modeIn.hashCode());
107
108 Assert.assertEquals(modeOut, modeIn);
109 }
110
111 final long monitor_handle = -1;
112 final int monitor_id = -1;
113 final String monitor_name = "DP-1";
114 final DimensionImmutable sizeMM = new Dimension(50, 50);
115 final Rectangle viewport = new Rectangle(0, 0, 1920, 1080);
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);
121 {
122 final int[] props = MonitorModeProps.streamOutMonitorDevice(monOut);
123 final MonitorDevice monIn = MonitorModeProps.streamInMonitorDevice(cache, null, monitor_handle, monitor_name, null, false /* invscale_wuviewport */, props, 0, null);
124 System.err.println("01 in : "+monIn);
125
126 Assert.assertEquals(monOut.getHandle(), monIn.getHandle());
127 Assert.assertEquals(monOut.getId(), monIn.getId());
128 Assert.assertEquals(monOut.getName(), monIn.getName());
129 Assert.assertEquals(monOut.isClone(), monIn.isClone());
130 Assert.assertEquals(monOut.isPrimary(), monIn.isPrimary());
131 Assert.assertEquals(monOut.getViewport(), monIn.getViewport());
132 Assert.assertEquals(monOut.getViewportInWindowUnits(), monIn.getViewportInWindowUnits());
133 Assert.assertEquals(monOut.getOriginalMode(), monIn.getOriginalMode());
134 Assert.assertEquals(monOut.getCurrentMode(), monIn.getCurrentMode());
135 Assert.assertEquals(monOut.getSupportedModes(), monIn.getSupportedModes());
136 Assert.assertEquals(monOut.getCurrentMode(), monOut.getOriginalMode());
137 Assert.assertEquals(monOut.hashCode(), monIn.hashCode());
138 Assert.assertEquals(monOut, monIn);
139 }
140 }
141
142 static void dumpMonitor(final String pre0, final String pre1, final MonitorDevice monitor) {
143 System.err.println(pre0+" "+monitor);
144 final float[] pixelPerMM = monitor.getPixelsPerMM(new float[2]);
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+"]");
147 final MonitorMode sm_o = monitor.getOriginalMode();
148 Assert.assertNotNull(sm_o);
149 final MonitorMode sm_c = monitor.queryCurrentMode();
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);
154 }
155
156 @Test
157 public void test01ScreenAllMonitor() throws InterruptedException {
158 final Display dpy = NewtFactory.createDisplay(null);
159 final Screen screen = NewtFactory.createScreen(dpy, screenIdx);
160 screen.addReference();
161 Assert.assertEquals(true,screen.isNativeValid());
162 Assert.assertEquals(true,screen.getDisplay().isNativeValid());
163 final List<MonitorDevice> monitors = screen.getMonitorDevices();
164 Assert.assertTrue(monitors.size()>0);
165
166 final MonitorDevice primMonitor = screen.getPrimaryMonitor();
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());
170
171 // Dump all Monitor's and its DPI and current/original mode
172 int j=0;
173 for(final Iterator<MonitorDevice> iMonitor=monitors.iterator(); iMonitor.hasNext(); j++) {
174 final MonitorDevice monitor = iMonitor.next();
175 dumpMonitor("Monitor Index "+j, " ", monitor);
176 if( monitor.getId() == primMonitor.getId() ) {
177 Assert.assertTrue("Primary monitor not flagged as primary", monitor.isPrimary());
178 } else {
179 Assert.assertFalse("Non primary monitor flagged as primary", monitor.isPrimary());
180 }
181 }
182 final RectangleImmutable zero = new Rectangle();
183
184 final Rectangle monitorViewPU = new Rectangle();
185 final Rectangle monitorViewWU = new Rectangle();
186 MonitorDevice.unionOfViewports(monitorViewPU, monitorViewWU, monitors);
187 System.err.println("Test.0: Monitor union viewport: "+monitorViewPU+" [pu] / "+monitorViewWU+" [wu]");
188 Assert.assertNotEquals(zero, monitorViewPU);
189 Assert.assertNotEquals(zero, monitorViewWU);
190
191 final RectangleImmutable screenViewPU = screen.getViewport();
192 final RectangleImmutable screenViewWU = screen.getViewportInWindowUnits();
193 System.err.println("Test.1: Screen viewport: "+screenViewPU+" [pu] / "+screenViewWU+" [wu]");
194 Assert.assertNotEquals(zero, screenViewPU);
195 Assert.assertNotEquals(zero, screenViewWU);
196
197 screen.removeReference();
198
199 Assert.assertEquals(false,screen.isNativeValid());
200 Assert.assertEquals(false,screen.getDisplay().isNativeValid());
201 }
202
203 @Test
204 public void test02ScreenAllModesInfo() throws InterruptedException {
205 final Display dpy = NewtFactory.createDisplay(null);
206 final Screen screen = NewtFactory.createScreen(dpy, screenIdx);
207 screen.addReference();
208 Assert.assertEquals(true,screen.isNativeValid());
209 Assert.assertEquals(true,screen.getDisplay().isNativeValid());
210 System.err.println("Screen: "+screen.toString());
211 final List<MonitorMode> allMonitorModes = screen.getMonitorModes();
212 Assert.assertTrue(allMonitorModes.size()>0);
213 {
214 int i=0;
215 MonitorMode mmPre = null;
216 for(final Iterator<MonitorMode> iMode=allMonitorModes.iterator(); iMode.hasNext(); i++) {
217 final MonitorMode mm = iMode.next();
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);
221 }
222 mmPre = mm;
223 }
224 }
225 MonitorModeUtil.sort(allMonitorModes, true /* ascendingOrder*/);
226 {
227 int i=0;
228 MonitorMode mmPre = null;
229 for(final Iterator<MonitorMode> iMode=allMonitorModes.iterator(); iMode.hasNext(); i++) {
230 final MonitorMode mm = iMode.next();
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);
234 }
235 mmPre = mm;
236 }
237 }
238
239 final List<MonitorDevice> monitors = screen.getMonitorDevices();
240 Assert.assertTrue(monitors.size()>0);
241
242 // Dump all Monitor's and its modes
243 int j=0;
244 for(final Iterator<MonitorDevice> iMonitor=monitors.iterator(); iMonitor.hasNext(); j++) {
245 final MonitorDevice monitor = iMonitor.next();
246 System.err.println(j+": "+monitor);
247 final List<MonitorMode> modes = monitor.getSupportedModes();
248 Assert.assertTrue(modes.size()>0);
249 int i=0;
250 MonitorMode mmPre = null;
251 for(final Iterator<MonitorMode> iMode=modes.iterator(); iMode.hasNext(); i++) {
252 final MonitorMode mm = iMode.next();
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);
256 }
257 mmPre = mm;
258 }
259 Assert.assertTrue(allMonitorModes.containsAll(modes));
260 }
261 screen.removeReference();
262
263 Assert.assertEquals(false,screen.isNativeValid());
264 Assert.assertEquals(false,screen.getDisplay().isNativeValid());
265 }
266
267 static int atoi(final String a) {
268 try {
269 return Integer.parseInt(a);
270 } catch (final Exception ex) { throw new RuntimeException(ex); }
271 }
272
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")) {
276 i++;
277 screenIdx = atoi(args[i]);
278 }
279 }
280 final String tstname = TestScreenMode00aNEWT.class.getName();
281 org.junit.runner.JUnitCore.main(tstname);
282 }
283}
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.
Definition: Screen.java:58
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.
Definition: GLProfile.java:77
static void initSingleton()
Static initialization of JOGL.
Definition: GLProfile.java:204
Validating consistency of MonitorMode data from Screen (all modes) and from a particular MonitorDevic...
Immutable Dimension Interface, consisting of it's read only components:
Immutable Rectangle interface, with its position on the top-left.