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