Jogamp
Bug 741 HiDPI: Simplify ScalableSurface (2): Add request pixelScale API entry, fixed...
[jogl.git] / src / test / com / jogamp / opengl / test / junit / jogl / demos / es2 / newt / TestGearsES2NEWT.java
CommitLineData
d09063b4
SG
1/**
2 * Copyright 2011 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:
dc2deb07 6 *
d09063b4
SG
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
dc2deb07 9 *
d09063b4
SG
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.
dc2deb07 13 *
d09063b4
SG
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.
dc2deb07 23 *
d09063b4
SG
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 */
dc2deb07 28
d09063b4
SG
29package com.jogamp.opengl.test.junit.jogl.demos.es2.newt;
30
f5a2da16 31import java.io.IOException;
2571ed0b 32import java.lang.reflect.InvocationTargetException;
bd98b927 33import java.net.URLConnection;
f5a2da16 34
e7ffa68b 35import com.jogamp.common.util.IOUtil;
f3f794fe 36import com.jogamp.newt.Display;
e7ffa68b 37import com.jogamp.newt.Display.PointerIcon;
f3f794fe
SG
38import com.jogamp.newt.NewtFactory;
39import com.jogamp.newt.Screen;
45160297 40import com.jogamp.newt.Window;
d09063b4
SG
41import com.jogamp.newt.event.KeyAdapter;
42import com.jogamp.newt.event.KeyEvent;
06b6a74f
SG
43import com.jogamp.newt.event.MouseAdapter;
44import com.jogamp.newt.event.MouseEvent;
f3f794fe
SG
45import com.jogamp.newt.event.WindowEvent;
46import com.jogamp.newt.event.WindowAdapter;
d09063b4 47import com.jogamp.newt.opengl.GLWindow;
45160297 48import com.jogamp.newt.util.EDTUtil;
c8c49283 49import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
90c46b1e 50import com.jogamp.opengl.test.junit.util.MiscUtils;
d09063b4
SG
51import com.jogamp.opengl.test.junit.util.UITestCase;
52import com.jogamp.opengl.test.junit.util.QuitAdapter;
d09063b4 53import com.jogamp.opengl.util.Animator;
bd98b927 54import com.jogamp.opengl.util.PNGPixelRect;
d09063b4
SG
55import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
56
590d78dc 57import javax.media.nativewindow.NativeWindowFactory;
2571ed0b 58import javax.media.nativewindow.ScalableSurface;
f3f794fe
SG
59import javax.media.nativewindow.util.Dimension;
60import javax.media.nativewindow.util.Point;
61import javax.media.nativewindow.util.PointImmutable;
62import javax.media.nativewindow.util.DimensionImmutable;
f5a2da16
SG
63import javax.media.opengl.GLAnimatorControl;
64import javax.media.opengl.GLAutoDrawable;
d09063b4 65import javax.media.opengl.GLCapabilities;
90c46b1e 66import javax.media.opengl.GLCapabilitiesImmutable;
f5a2da16 67import javax.media.opengl.GLEventListener;
d09063b4
SG
68import javax.media.opengl.GLProfile;
69
45160297
SG
70import jogamp.newt.DefaultEDTUtil;
71
d09063b4
SG
72import org.junit.Assert;
73import org.junit.BeforeClass;
74import org.junit.AfterClass;
75import org.junit.Test;
43cc2ea7
SG
76import org.junit.FixMethodOrder;
77import org.junit.runners.MethodSorters;
d09063b4 78
43cc2ea7 79@FixMethodOrder(MethodSorters.NAME_ASCENDING)
dc2deb07 80public class TestGearsES2NEWT extends UITestCase {
f3f794fe
SG
81 static int screenIdx = 0;
82 static PointImmutable wpos;
14b27853 83 static DimensionImmutable wsize, rwsize=null;
2571ed0b 84 static int[] reqSurfacePixelScale = new int[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE };
d09063b4 85
f3f794fe
SG
86 static long duration = 500; // ms
87 static boolean opaque = true;
416c7fc1 88 static int forceAlpha = -1;
f3f794fe
SG
89 static boolean undecorated = false;
90 static boolean alwaysOnTop = false;
91 static boolean fullscreen = false;
92 static boolean pmvUseBackingArray = true;
9d522e77 93 static int swapInterval = 1;
f3f794fe
SG
94 static boolean waitForKey = false;
95 static boolean mouseVisible = true;
96 static boolean mouseConfined = false;
fcc0e739 97 static boolean setPointerIcon = false;
f3f794fe 98 static boolean showFPS = false;
90c46b1e 99 static int loops = 1;
f2cfb611 100 static boolean loop_shutdown = false;
90c46b1e 101 static boolean forceES2 = false;
3a0d7703 102 static boolean forceES3 = false;
4f05d5ad 103 static boolean forceGL3 = false;
dc2deb07 104 static boolean forceGL2 = false;
3fb76fce 105 static boolean manualTest = false;
224fab1b 106 static boolean exclusiveContext = false;
30b2490e 107 static boolean useAnimator = true;
343deff4 108 static boolean useMappedBuffers = false;
45160297 109 static enum SysExit { none, testExit, testError, testEDTError, displayExit, displayError, displayEDTError };
2d32b056 110 static SysExit sysExit = SysExit.none;
dc2deb07 111
d09063b4
SG
112 @BeforeClass
113 public static void initClass() {
f3f794fe 114 if(null == wsize) {
08e3f9bf 115 wsize = new Dimension(640, 480);
f3f794fe 116 }
d09063b4
SG
117 }
118
119 @AfterClass
120 public static void releaseClass() {
121 }
122
56d60b36
SG
123 private void setTitle(final Window win, final GLCapabilitiesImmutable caps) {
124 final String capsA = caps.isBackgroundOpaque() ? "opaque" : "transl";
2571ed0b 125 win.setTitle("GLWindow["+capsA+"], swapI "+swapInterval+", win: "+win.getBounds()+", pix: "+win.getSurfaceWidth()+"x"+win.getSurfaceHeight());
56d60b36
SG
126 }
127 protected void runTestGL(final GLCapabilitiesImmutable caps, boolean undecorated) throws InterruptedException {
9d522e77 128 System.err.println("requested: vsync "+swapInterval+", "+caps);
f3f794fe
SG
129 Display dpy = NewtFactory.createDisplay(null);
130 Screen screen = NewtFactory.createScreen(dpy, screenIdx);
131 final GLWindow glWindow = GLWindow.create(screen, caps);
d09063b4 132 Assert.assertNotNull(glWindow);
58153310
SG
133 glWindow.setSurfaceScale(reqSurfacePixelScale);
134 final int[] valReqSurfacePixelScale = glWindow.getRequestedSurfaceScale(new int[2]);
f3f794fe
SG
135 glWindow.setSize(wsize.getWidth(), wsize.getHeight());
136 if(null != wpos) {
137 glWindow.setPosition(wpos.getX(), wpos.getY());
138 }
bbdd6f95 139 glWindow.setUndecorated(undecorated);
fa5fdc4c
SG
140 glWindow.setAlwaysOnTop(alwaysOnTop);
141 glWindow.setFullscreen(fullscreen);
24e0591b
SG
142 glWindow.setPointerVisible(mouseVisible);
143 glWindow.confinePointer(mouseConfined);
56d60b36 144 setTitle(glWindow, caps);
24e0591b 145
9d522e77 146 final GearsES2 demo = new GearsES2(swapInterval);
f5a2da16 147 demo.setPMVUseBackingArray(pmvUseBackingArray);
343deff4
SG
148 demo.setUseMappedBuffers(useMappedBuffers);
149 demo.setValidateBuffers(true);
f5a2da16 150 glWindow.addGLEventListener(demo);
dc2deb07 151
1af63934
SG
152 final SnapshotGLEventListener snap = new SnapshotGLEventListener();
153 glWindow.addGLEventListener(snap);
f5a2da16
SG
154 if(waitForKey) {
155 glWindow.addGLEventListener(new GLEventListener() {
156 public void init(GLAutoDrawable drawable) { }
157 public void dispose(GLAutoDrawable drawable) { }
158 public void display(GLAutoDrawable drawable) {
159 GLAnimatorControl actrl = drawable.getAnimator();
160 if(waitForKey && actrl.getTotalFPSFrames() == 60*3) {
28c64723 161 UITestCase.waitForKey("3s mark");
f5a2da16
SG
162 actrl.resetFPSCounter();
163 waitForKey = false;
164 }
165 }
166 public void reshape(GLAutoDrawable drawable, int x, int y,
167 int width, int height) { }
168 });
169 }
d09063b4 170
30b2490e
SG
171 final Animator animator = useAnimator ? new Animator() : null;
172 if( useAnimator ) {
173 animator.setModeBits(false, Animator.MODE_EXPECT_AWT_RENDERING_THREAD);
174 animator.setExclusiveContext(exclusiveContext);
175 }
dc2deb07 176
45160297 177 final QuitAdapter quitAdapter = new QuitAdapter();
d09063b4
SG
178 //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
179 //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
180 glWindow.addKeyListener(quitAdapter);
181 glWindow.addWindowListener(quitAdapter);
182
f3f794fe
SG
183 glWindow.addWindowListener(new WindowAdapter() {
184 public void windowResized(WindowEvent e) {
f9a00b91 185 System.err.println("window resized: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight());
56d60b36 186 setTitle(glWindow, caps);
f3f794fe
SG
187 }
188 public void windowMoved(WindowEvent e) {
f9a00b91 189 System.err.println("window moved: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight());
56d60b36 190 setTitle(glWindow, caps);
dc2deb07 191 }
f3f794fe 192 });
dc2deb07 193
bd98b927 194 final PointerIcon[] pointerIcons = { null, null, null };
e7ffa68b 195 {
e7ffa68b
SG
196 final Display disp = glWindow.getScreen().getDisplay();
197 disp.createNative();
bd98b927
SG
198 {
199 PointerIcon _pointerIcon = null;
1a0b3287 200 final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/cross-grey-alpha-16x16.png" } );
bd98b927 201 try {
1a0b3287 202 _pointerIcon = disp.createPointerIcon(res, 8, 8);
bd98b927
SG
203 System.err.println("Create PointerIcon #01: "+_pointerIcon);
204 } catch (Exception e) {
205 e.printStackTrace();
206 }
207 pointerIcons[0] = _pointerIcon;
208 }
209 {
210 PointerIcon _pointerIcon = null;
1a0b3287 211 final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/pointer-grey-alpha-16x24.png" } );
bd98b927 212 try {
1a0b3287 213 _pointerIcon = disp.createPointerIcon(res, 0, 0);
bd98b927
SG
214 System.err.println("Create PointerIcon #02: "+_pointerIcon);
215 } catch (Exception e) {
216 e.printStackTrace();
217 }
218 pointerIcons[1] = _pointerIcon;
219 }
220 {
221 PointerIcon _pointerIcon = null;
1a0b3287 222 final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "jogamp-pointer-64x64.png" } );
bd98b927
SG
223 try {
224 final URLConnection urlConn = res.resolve(0);
225 final PNGPixelRect image = PNGPixelRect.read(urlConn.getInputStream(), null, false /* directBuffer */, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */);
226 System.err.println("Create PointerIcon #03: "+image);
1a0b3287 227 _pointerIcon = disp.createPointerIcon(image, 32, 0);
bd98b927
SG
228 System.err.println("Create PointerIcon #03: "+_pointerIcon);
229 } catch (Exception e) {
230 e.printStackTrace();
231 }
232 pointerIcons[2] = _pointerIcon;
e7ffa68b 233 }
e7ffa68b 234 }
fcc0e739 235 if( setPointerIcon ) {
bd98b927 236 glWindow.setPointerIcon(pointerIcons[0]);
fcc0e739
SG
237 System.err.println("Set PointerIcon: "+glWindow.getPointerIcon());
238 }
e7ffa68b 239
d09063b4 240 glWindow.addKeyListener(new KeyAdapter() {
bd98b927
SG
241 int pointerIconIdx = 0;
242
6ebf649d
SG
243 @Override
244 public void keyPressed(final KeyEvent e) {
245 if( e.isAutoRepeat() ) {
246 return;
247 }
d09063b4
SG
248 if(e.getKeyChar()=='f') {
249 new Thread() {
250 public void run() {
224fab1b 251 final Thread t = glWindow.setExclusiveContextThread(null);
f9a00b91 252 System.err.println("[set fullscreen pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
6ebf649d
SG
253 if( glWindow.isFullscreen() ) {
254 glWindow.setFullscreen( false );
255 } else {
256 if( e.isAltDown() ) {
257 glWindow.setFullscreen( null );
258 } else {
259 glWindow.setFullscreen( true );
260 }
261 }
f9a00b91 262 System.err.println("[set fullscreen post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
224fab1b 263 glWindow.setExclusiveContextThread(t);
d09063b4 264 } }.start();
a245d530
SG
265 } else if(e.getKeyChar()=='a') {
266 new Thread() {
267 public void run() {
224fab1b 268 final Thread t = glWindow.setExclusiveContextThread(null);
f9a00b91 269 System.err.println("[set alwaysontop pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
24e0591b 270 glWindow.setAlwaysOnTop(!glWindow.isAlwaysOnTop());
f9a00b91 271 System.err.println("[set alwaysontop post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
224fab1b 272 glWindow.setExclusiveContextThread(t);
a245d530 273 } }.start();
d09063b4
SG
274 } else if(e.getKeyChar()=='d') {
275 new Thread() {
276 public void run() {
224fab1b
SG
277 final Thread t = glWindow.setExclusiveContextThread(null);
278 // while( null != glWindow.getExclusiveContextThread() ) ;
f9a00b91 279 System.err.println("[set undecorated pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", d "+glWindow.isUndecorated()+", "+glWindow.getInsets());
24e0591b 280 glWindow.setUndecorated(!glWindow.isUndecorated());
f9a00b91 281 System.err.println("[set undecorated post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", d "+glWindow.isUndecorated()+", "+glWindow.getInsets());
224fab1b 282 glWindow.setExclusiveContextThread(t);
4faa65ee
SG
283 } }.start();
284 } else if(e.getKeyChar()=='s') {
285 new Thread() {
286 public void run() {
224fab1b 287 final Thread t = glWindow.setExclusiveContextThread(null);
f9a00b91 288 System.err.println("[set position pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
24e0591b 289 glWindow.setPosition(100, 100);
f9a00b91 290 System.err.println("[set position post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
224fab1b 291 glWindow.setExclusiveContextThread(t);
24e0591b 292 } }.start();
fcc0e739
SG
293 } else if(e.getKeyChar()=='c') {
294 new Thread() {
295 public void run() {
296 final Thread t = glWindow.setExclusiveContextThread(null);
297 System.err.println("[set pointer-icon pre]");
298 final PointerIcon currentPI = glWindow.getPointerIcon();
bd98b927
SG
299 final PointerIcon newPI;
300 if( pointerIconIdx >= pointerIcons.length ) {
301 newPI=null;
302 pointerIconIdx=0;
303 } else {
304 newPI=pointerIcons[pointerIconIdx++];
305 }
306 glWindow.setPointerIcon( newPI );
fcc0e739
SG
307 System.err.println("[set pointer-icon post] "+currentPI+" -> "+glWindow.getPointerIcon());
308 glWindow.setExclusiveContextThread(t);
309 } }.start();
24e0591b
SG
310 } else if(e.getKeyChar()=='i') {
311 new Thread() {
312 public void run() {
224fab1b 313 final Thread t = glWindow.setExclusiveContextThread(null);
24e0591b
SG
314 System.err.println("[set mouse visible pre]: "+glWindow.isPointerVisible());
315 glWindow.setPointerVisible(!glWindow.isPointerVisible());
316 System.err.println("[set mouse visible post]: "+glWindow.isPointerVisible());
224fab1b 317 glWindow.setExclusiveContextThread(t);
24e0591b
SG
318 } }.start();
319 } else if(e.getKeyChar()=='j') {
320 new Thread() {
321 public void run() {
224fab1b 322 final Thread t = glWindow.setExclusiveContextThread(null);
24e0591b
SG
323 System.err.println("[set mouse confined pre]: "+glWindow.isPointerConfined());
324 glWindow.confinePointer(!glWindow.isPointerConfined());
325 System.err.println("[set mouse confined post]: "+glWindow.isPointerConfined());
5b30ac32
SG
326 if(!glWindow.isPointerConfined()) {
327 demo.setConfinedFixedCenter(false);
328 }
224fab1b 329 glWindow.setExclusiveContextThread(t);
5b30ac32
SG
330 } }.start();
331 } else if(e.getKeyChar()=='J') {
332 new Thread() {
333 public void run() {
224fab1b 334 final Thread t = glWindow.setExclusiveContextThread(null);
5b30ac32
SG
335 System.err.println("[set mouse confined pre]: "+glWindow.isPointerConfined());
336 glWindow.confinePointer(!glWindow.isPointerConfined());
337 System.err.println("[set mouse confined post]: "+glWindow.isPointerConfined());
338 demo.setConfinedFixedCenter(glWindow.isPointerConfined());
224fab1b 339 glWindow.setExclusiveContextThread(t);
24e0591b
SG
340 } }.start();
341 } else if(e.getKeyChar()=='w') {
342 new Thread() {
343 public void run() {
224fab1b 344 final Thread t = glWindow.setExclusiveContextThread(null);
24e0591b 345 System.err.println("[set mouse pos pre]");
f9a00b91 346 glWindow.warpPointer(glWindow.getSurfaceWidth()/2, glWindow.getSurfaceHeight()/2);
24e0591b 347 System.err.println("[set mouse pos post]");
224fab1b 348 glWindow.setExclusiveContextThread(t);
d09063b4 349 } }.start();
2571ed0b 350 } else if(e.getKeyChar()=='x') {
58153310 351 final int[] hadSurfacePixelScale = glWindow.getCurrentSurfaceScale(new int[2]);
2571ed0b
SG
352 final int[] reqSurfacePixelScale;
353 if( hadSurfacePixelScale[0] == ScalableSurface.IDENTITY_PIXELSCALE ) {
354 reqSurfacePixelScale = new int[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE };
355 } else {
356 reqSurfacePixelScale = new int[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
357 }
358 System.err.println("[set PixelScale pre]: had "+hadSurfacePixelScale[0]+"x"+hadSurfacePixelScale[1]+" -> req "+reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]);
58153310
SG
359 glWindow.setSurfaceScale(reqSurfacePixelScale);
360 final int[] valReqSurfacePixelScale = glWindow.getRequestedSurfaceScale(new int[2]);
2571ed0b 361 final int[] hasSurfacePixelScale0 = glWindow.convertToPixelUnits(new int[] { 1, 1 });
58153310 362 final int[] hasSurfacePixelScale1 = glWindow.getCurrentSurfaceScale(new int[2]);
2571ed0b
SG
363 System.err.println("[set PixelScale post]: "+hadSurfacePixelScale[0]+"x"+hadSurfacePixelScale[1]+" (had) -> "+
364 reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" (req) -> "+
3fb76fce 365 valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+
2571ed0b
SG
366 hasSurfacePixelScale1[0]+"x"+hasSurfacePixelScale1[1]+" (has)");
367 setTitle(glWindow, caps);
368 Assert.assertArrayEquals(hasSurfacePixelScale0, hasSurfacePixelScale1);
d09063b4
SG
369 }
370 }
371 });
06b6a74f
SG
372 glWindow.addMouseListener(new MouseAdapter() {
373 public void mouseClicked(MouseEvent e) {
bc72e232
SG
374 if(e.getClickCount() == 2 && e.getPointerCount() == 1) {
375 glWindow.setFullscreen(!glWindow.isFullscreen());
376 System.err.println("setFullscreen: "+glWindow.isFullscreen());
377 }
06b6a74f
SG
378 }
379 });
d09063b4 380
30b2490e
SG
381 if( useAnimator ) {
382 animator.add(glWindow);
383 animator.start();
384 Assert.assertTrue(animator.isStarted());
385 Assert.assertTrue(animator.isAnimating());
386 Assert.assertEquals(exclusiveContext ? animator.getThread() : null, glWindow.getExclusiveContextThread());
387 }
1ac5f46b 388
45160297 389 if( SysExit.displayError == sysExit || SysExit.displayExit == sysExit || SysExit.displayEDTError == sysExit ) {
2d32b056 390 glWindow.addGLEventListener(new GLEventListener() {
2d32b056
SG
391 @Override
392 public void init(GLAutoDrawable drawable) {}
2d32b056
SG
393 @Override
394 public void dispose(GLAutoDrawable drawable) { }
2d32b056
SG
395 @Override
396 public void display(GLAutoDrawable drawable) {
397 final GLAnimatorControl anim = drawable.getAnimator();
398 if( null != anim && anim.isAnimating() ) {
45160297
SG
399 final long ms = anim.getTotalFPSDuration();
400 if( ms >= duration/2 || ms >= 3000 ) { // max 3s wait until provoking error
2d32b056 401 if( SysExit.displayError == sysExit ) {
45160297 402 throw new Error("test error send from GLEventListener.display - "+Thread.currentThread());
2d32b056
SG
403 } else if ( SysExit.displayExit == sysExit ) {
404 System.err.println("exit(0) send from GLEventListener");
dc2deb07 405 System.exit(0);
45160297
SG
406 } else if ( SysExit.displayEDTError == sysExit ) {
407 final Object upstream = drawable.getUpstreamWidget();
408 System.err.println("EDT invokeAndWaitError: upstream type "+upstream.getClass().getName());
409 if( upstream instanceof Window ) {
410 final EDTUtil edt = ((Window)upstream).getScreen().getDisplay().getEDTUtil();
411 System.err.println("EDT invokeAndWaitError: edt type "+edt.getClass().getName());
412 if( edt instanceof DefaultEDTUtil ) {
413 quitAdapter.doQuit();
414 ((DefaultEDTUtil)edt).invokeAndWaitError(new Runnable() {
415 public void run() {
416 throw new RuntimeException("XXX Should never ever be seen! - "+Thread.currentThread());
417 }
418 });
419 }
420 }
2d32b056
SG
421 }
422 }
423 } else {
424 System.exit(0);
425 }
426 }
427 @Override
dc2deb07 428 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
2d32b056
SG
429 });
430 }
dc2deb07 431
d09063b4 432 glWindow.setVisible(true);
30b2490e
SG
433 if( useAnimator ) {
434 animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
435 }
dc2deb07 436
90c46b1e
SG
437 System.err.println("NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
438 System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
f9a00b91 439 System.err.println("window pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
dc2deb07 440
2571ed0b 441 final int[] hasSurfacePixelScale0 = glWindow.convertToPixelUnits(new int[] { 1, 1 });
58153310 442 final int[] hasSurfacePixelScale1 = glWindow.getCurrentSurfaceScale(new int[2]);
2571ed0b 443 System.err.println("HiDPI PixelScale: "+reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" (req) -> "+
3fb76fce 444 valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+
2571ed0b
SG
445 hasSurfacePixelScale1[0]+"x"+hasSurfacePixelScale1[1]+" (has)");
446 setTitle(glWindow, caps);
447 Assert.assertArrayEquals(hasSurfacePixelScale0, hasSurfacePixelScale1);
448
1af63934
SG
449 snap.setMakeSnapshot();
450
c6224657 451 if( null != rwsize ) {
dc2deb07 452 Thread.sleep(500); // 500ms delay
c6224657 453 glWindow.setSize(rwsize.getWidth(), rwsize.getHeight());
f9a00b91 454 System.err.println("window resize pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
c6224657 455 }
dc2deb07 456
1af63934 457 snap.setMakeSnapshot();
dc2deb07 458
30b2490e
SG
459 final long t0 = System.currentTimeMillis();
460 long t1 = t0;
461 while(!quitAdapter.shouldQuit() && t1-t0<duration) {
d09063b4 462 Thread.sleep(100);
30b2490e 463 t1 = System.currentTimeMillis();
45160297
SG
464 if( SysExit.testError == sysExit || SysExit.testExit == sysExit || SysExit.testEDTError == sysExit) {
465 final long ms = t1-t0;
466 if( ms >= duration/2 || ms >= 3000 ) { // max 3s wait until provoking error
2d32b056
SG
467 if( SysExit.testError == sysExit ) {
468 throw new Error("test error send from test thread");
469 } else if ( SysExit.testExit == sysExit ) {
470 System.err.println("exit(0) send from test thread");
dc2deb07 471 System.exit(0);
45160297
SG
472 } else if ( SysExit.testEDTError == sysExit ) {
473 final EDTUtil edt = glWindow.getScreen().getDisplay().getEDTUtil();
474 System.err.println("EDT invokeAndWaitError: edt type "+edt.getClass().getName());
475 if( edt instanceof DefaultEDTUtil ) {
476 quitAdapter.doQuit();
477 ((DefaultEDTUtil)edt).invokeAndWaitError(new Runnable() {
478 public void run() {
479 throw new RuntimeException("XXX Should never ever be seen!");
480 }
481 });
482 }
2d32b056
SG
483 }
484 }
485 }
d09063b4
SG
486 }
487
30b2490e
SG
488 if( useAnimator ) {
489 Assert.assertEquals(exclusiveContext ? animator.getThread() : null, glWindow.getExclusiveContextThread());
490 animator.stop();
491 Assert.assertFalse(animator.isAnimating());
492 Assert.assertFalse(animator.isStarted());
493 }
224fab1b 494 Assert.assertEquals(null, glWindow.getExclusiveContextThread());
d09063b4 495 glWindow.destroy();
590d78dc
SG
496 if( NativeWindowFactory.isAWTAvailable() ) {
497 Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow, false));
498 }
d09063b4
SG
499 }
500
501 @Test
33abeb80 502 public void test01_GL2ES2() throws InterruptedException {
90c46b1e
SG
503 for(int i=1; i<=loops; i++) {
504 System.err.println("Loop "+i+"/"+loops);
4f05d5ad
SG
505 final GLProfile glp;
506 if(forceGL3) {
507 glp = GLProfile.get(GLProfile.GL3);
3a0d7703
SG
508 } else if(forceES3) {
509 glp = GLProfile.get(GLProfile.GLES3);
4f05d5ad
SG
510 } else if(forceES2) {
511 glp = GLProfile.get(GLProfile.GLES2);
dc2deb07
SG
512 } else if(forceGL2) {
513 glp = GLProfile.get(GLProfile.GL2);
4f05d5ad
SG
514 } else {
515 glp = GLProfile.getGL2ES2();
516 }
b9612255 517 final GLCapabilities caps = new GLCapabilities( glp );
c8c49283 518 caps.setBackgroundOpaque(opaque);
416c7fc1 519 if(-1 < forceAlpha) {
dc2deb07 520 caps.setAlphaBits(forceAlpha);
416c7fc1 521 }
90c46b1e 522 runTestGL(caps, undecorated);
f2cfb611
SG
523 if(loop_shutdown) {
524 GLProfile.shutdown();
c8c49283 525 }
90c46b1e 526 }
4011e70e
SG
527 }
528
b9612255 529 @Test
33abeb80 530 public void test02_GLES2() throws InterruptedException {
3fb76fce 531 if(manualTest) return;
dc2deb07 532
33abeb80
SG
533 if( !GLProfile.isAvailable(GLProfile.GLES2) ) {
534 System.err.println("GLES2 n/a");
6e08b6f0 535 return;
33abeb80
SG
536 }
537 final GLProfile glp = GLProfile.get(GLProfile.GLES2);
538 final GLCapabilities caps = new GLCapabilities( glp );
539 runTestGL(caps, undecorated);
540 }
dc2deb07 541
33abeb80
SG
542 @Test
543 public void test03_GL3() throws InterruptedException {
3fb76fce 544 if(manualTest) return;
dc2deb07 545
b9612255
SG
546 if( !GLProfile.isAvailable(GLProfile.GL3) ) {
547 System.err.println("GL3 n/a");
6e08b6f0 548 return;
b9612255
SG
549 }
550 final GLProfile glp = GLProfile.get(GLProfile.GL3);
551 final GLCapabilities caps = new GLCapabilities( glp );
552 runTestGL(caps, undecorated);
553 }
dc2deb07 554
2571ed0b
SG
555 @Test
556 public void test99_PixelScale1_DefaultNorm() throws InterruptedException, InvocationTargetException {
3fb76fce 557 if( manualTest ) return;
2571ed0b
SG
558
559 reqSurfacePixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
560 reqSurfacePixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;
561
562 GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2());
563 runTestGL(caps, undecorated);
564 }
565
b9612255 566 public static void main(String args[]) throws IOException {
c6224657 567 int x=0, y=0, w=640, h=480, rw=-1, rh=-1;
f3f794fe 568 boolean usePos = false;
dc2deb07 569
d09063b4
SG
570 for(int i=0; i<args.length; i++) {
571 if(args[i].equals("-time")) {
572 i++;
90c46b1e 573 duration = MiscUtils.atol(args[i], duration);
bbdd6f95
SG
574 } else if(args[i].equals("-translucent")) {
575 opaque = false;
416c7fc1
SG
576 } else if(args[i].equals("-forceAlpha")) {
577 i++;
578 forceAlpha = MiscUtils.atoi(args[i], 0);
bbdd6f95
SG
579 } else if(args[i].equals("-undecorated")) {
580 undecorated = true;
fa5fdc4c
SG
581 } else if(args[i].equals("-atop")) {
582 alwaysOnTop = true;
583 } else if(args[i].equals("-fullscreen")) {
584 fullscreen = true;
f5a2da16
SG
585 } else if(args[i].equals("-pmvDirect")) {
586 pmvUseBackingArray = false;
587 } else if(args[i].equals("-vsync")) {
9d522e77
SG
588 i++;
589 swapInterval = MiscUtils.atoi(args[i], swapInterval);
224fab1b
SG
590 } else if(args[i].equals("-exclctx")) {
591 exclusiveContext = true;
30b2490e
SG
592 } else if(args[i].equals("-noanim")) {
593 useAnimator = false;
90c46b1e
SG
594 } else if(args[i].equals("-es2")) {
595 forceES2 = true;
3a0d7703
SG
596 } else if(args[i].equals("-es3")) {
597 forceES3 = true;
4f05d5ad
SG
598 } else if(args[i].equals("-gl3")) {
599 forceGL3 = true;
dc2deb07
SG
600 } else if(args[i].equals("-gl2")) {
601 forceGL2 = true;
343deff4
SG
602 } else if(args[i].equals("-mappedBuffers")) {
603 useMappedBuffers = true;
f5a2da16
SG
604 } else if(args[i].equals("-wait")) {
605 waitForKey = true;
24e0591b
SG
606 } else if(args[i].equals("-mouseInvisible")) {
607 mouseVisible = false;
608 } else if(args[i].equals("-mouseConfine")) {
609 mouseConfined = true;
fcc0e739
SG
610 } else if(args[i].equals("-pointerIcon")) {
611 setPointerIcon = true;
f3f794fe
SG
612 } else if(args[i].equals("-showFPS")) {
613 showFPS = true;
614 } else if(args[i].equals("-width")) {
615 i++;
90c46b1e 616 w = MiscUtils.atoi(args[i], w);
f3f794fe
SG
617 } else if(args[i].equals("-height")) {
618 i++;
90c46b1e 619 h = MiscUtils.atoi(args[i], h);
f3f794fe
SG
620 } else if(args[i].equals("-x")) {
621 i++;
90c46b1e 622 x = MiscUtils.atoi(args[i], x);
f3f794fe
SG
623 usePos = true;
624 } else if(args[i].equals("-y")) {
625 i++;
90c46b1e 626 y = MiscUtils.atoi(args[i], y);
f3f794fe 627 usePos = true;
2571ed0b
SG
628 } else if(args[i].equals("-pixelScale")) {
629 i++;
630 final int pS = MiscUtils.atoi(args[i], reqSurfacePixelScale[0]);
631 reqSurfacePixelScale[0] = pS;
632 reqSurfacePixelScale[1] = pS;
c6224657
SG
633 } else if(args[i].equals("-rwidth")) {
634 i++;
635 rw = MiscUtils.atoi(args[i], rw);
636 } else if(args[i].equals("-rheight")) {
637 i++;
638 rh = MiscUtils.atoi(args[i], rh);
f3f794fe
SG
639 } else if(args[i].equals("-screen")) {
640 i++;
90c46b1e
SG
641 screenIdx = MiscUtils.atoi(args[i], 0);
642 } else if(args[i].equals("-loops")) {
643 i++;
644 loops = MiscUtils.atoi(args[i], 1);
c8c49283 645 } else if(args[i].equals("-loop-shutdown")) {
f2cfb611 646 loop_shutdown = true;
2d32b056
SG
647 } else if(args[i].equals("-sysExit")) {
648 i++;
649 sysExit = SysExit.valueOf(args[i]);
3fb76fce
SG
650 } else if(args[i].equals("-manual")) {
651 manualTest = true;
d09063b4
SG
652 }
653 }
08e3f9bf 654 wsize = new Dimension(w, h);
c6224657
SG
655 if( 0 < rw && 0 < rh ) {
656 rwsize = new Dimension(rw, rh);
657 }
dc2deb07 658
f3f794fe
SG
659 if(usePos) {
660 wpos = new Point(x, y);
661 }
662 System.err.println("position "+wpos);
663 System.err.println("size "+wsize);
c6224657 664 System.err.println("resize "+rwsize);
f3f794fe 665 System.err.println("screen "+screenIdx);
f5a2da16 666 System.err.println("translucent "+(!opaque));
dc2deb07 667 System.err.println("forceAlpha "+forceAlpha);
f5a2da16
SG
668 System.err.println("undecorated "+undecorated);
669 System.err.println("atop "+alwaysOnTop);
670 System.err.println("fullscreen "+fullscreen);
dc2deb07 671 System.err.println("pmvDirect "+(!pmvUseBackingArray));
24e0591b
SG
672 System.err.println("mouseVisible "+mouseVisible);
673 System.err.println("mouseConfined "+mouseConfined);
fcc0e739 674 System.err.println("pointerIcon "+setPointerIcon);
90c46b1e 675 System.err.println("loops "+loops);
c8c49283 676 System.err.println("loop shutdown "+loop_shutdown);
90c46b1e 677 System.err.println("forceES2 "+forceES2);
3a0d7703 678 System.err.println("forceES3 "+forceES3);
c2b328ea 679 System.err.println("forceGL3 "+forceGL3);
dc2deb07 680 System.err.println("forceGL2 "+forceGL2);
224fab1b
SG
681 System.err.println("swapInterval "+swapInterval);
682 System.err.println("exclusiveContext "+exclusiveContext);
30b2490e 683 System.err.println("useAnimator "+useAnimator);
dc2deb07 684 System.err.println("sysExitWithin "+sysExit);
343deff4 685 System.err.println("mappedBuffers "+useMappedBuffers);
f5a2da16
SG
686
687 if(waitForKey) {
28c64723 688 UITestCase.waitForKey("Start");
f5a2da16 689 }
d09063b4
SG
690 org.junit.runner.JUnitCore.main(TestGearsES2NEWT.class.getName());
691 }
692}
http://JogAmp.org git info: FAQ, tutorial and man pages.