JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestScreenMode00bNEWT.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;
32import com.jogamp.nativewindow.NativeWindowFactory;
33
34import org.junit.Assert;
35import org.junit.BeforeClass;
36import org.junit.Test;
37import org.junit.FixMethodOrder;
38import org.junit.runners.MethodSorters;
39
40import com.jogamp.newt.Display;
41import com.jogamp.newt.MonitorDevice;
42import com.jogamp.newt.NewtFactory;
43import com.jogamp.newt.Screen;
44import com.jogamp.newt.MonitorMode;
45import com.jogamp.newt.opengl.GLWindow;
46import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
47import com.jogamp.opengl.test.junit.util.NewtTestUtil;
48import com.jogamp.opengl.test.junit.util.UITestCase;
49import com.jogamp.opengl.util.Animator;
50
51import java.util.Iterator;
52import java.util.List;
53import com.jogamp.opengl.GLCapabilities;
54import com.jogamp.opengl.GLCapabilitiesImmutable;
55
56/**
57 * Queries the current MonitorMode 50 times,
58 * stressing a possible race condition.
59 */
60@FixMethodOrder(MethodSorters.NAME_ASCENDING)
61public class TestScreenMode00bNEWT extends UITestCase {
62 static int width, height;
63
64 static int waitTimeShort = 4; //1 sec
65 static int waitTimeLong = 6; //6 sec
66
67 @BeforeClass
68 public static void initClass() {
69 setResetXRandRIfX11AfterClass();
71 width = 640;
72 height = 480;
73 }
74
75 @Test
76 public void testScreenModeInfo01() throws InterruptedException {
77 final Display display = NewtFactory.createDisplay(null);
78 final Screen screen = NewtFactory.createScreen(display, 0);
79 // screen.addReference();
80
81 // put some load on the screen/display context ..
82 final GLCapabilitiesImmutable caps = new GLCapabilities(null);
83 final GLWindow window = GLWindow.create(screen, caps);
84 window.addGLEventListener(new GearsES2());
85 window.setSize(256, 256);
86 window.setVisible(true);
87 final Animator anim = new Animator(window);
88 anim.start();
89
90 Assert.assertEquals(true,window.isNativeValid());
91 Assert.assertEquals(true,screen.isNativeValid());
92 Assert.assertEquals(true,display.isNativeValid());
93
94 final List<MonitorMode> screenModes = screen.getMonitorModes();
95 Assert.assertTrue(screenModes.size()>0);
96 int i=0;
97 for(final Iterator<MonitorMode> iter=screenModes.iterator(); iter.hasNext(); i++) {
98 System.err.println(i+": "+iter.next());
99 }
100 final MonitorDevice monitor = window.getMainMonitor();
101 final MonitorMode mm_o = monitor.getOriginalMode();
102
103 Assert.assertNotNull(mm_o);
104 MonitorMode mm_c = monitor.queryCurrentMode();
105 Assert.assertNotNull(mm_c);
106 System.err.println("orig: "+mm_o);
107 System.err.println("curr: "+mm_c);
108
109 for(i=0; i<50; i++) {
110 mm_c = monitor.queryCurrentMode();
111 Assert.assertNotNull(mm_c);
112 System.err.print("."+i);
113 }
114 System.err.println("!");
115
116 // screen.removeReference();
117 anim.stop();
118 window.destroy();
119
120 Assert.assertEquals(false,window.isVisible());
121 Assert.assertEquals(false,window.isNativeValid());
122 Assert.assertTrue(NewtTestUtil.waitForRealized(screen, false, null));
123 Assert.assertEquals(false,screen.isNativeValid());
124 Assert.assertEquals(false,display.isNativeValid());
125 }
126
127 public static void main(final String args[]) throws IOException {
128 final String tstname = TestScreenMode00bNEWT.class.getName();
129 org.junit.runner.JUnitCore.main(tstname);
130 }
131}
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.
abstract boolean isNativeValid()
Visual output device, i.e.
abstract MonitorMode queryCurrentMode()
Returns the current MonitorMode resulting from a native query.
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:
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 List< MonitorMode > getMonitorModes()
Return a list of all MonitorModes for all MonitorDevices.
abstract boolean isNativeValid()
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final MonitorDevice getMainMonitor()
Returns the MonitorDevice with the highest viewport coverage of this window.
Definition: GLWindow.java:292
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
Queries the current MonitorMode 50 times, stressing a possible race condition.
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Specifies an immutable set of OpenGL capabilities.