Jogamp
458536d0fd47ececa2f62ed9dfae2b57c80f2f83
[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 manualTest = 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         final int[] valReqSurfacePixelScale = glWindow.setSurfaceScale(new int[2], 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                     final int[] valReqSurfacePixelScale = glWindow.setSurfaceScale(new int[2], 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                                        valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+
364                                        hasSurfacePixelScale1[0]+"x"+hasSurfacePixelScale1[1]+" (has)");
365                     setTitle(glWindow, caps);
366                     Assert.assertArrayEquals(hasSurfacePixelScale0, hasSurfacePixelScale1);
367                 }
368             }
369         });
370         glWindow.addMouseListener(new MouseAdapter() {
371             public void mouseClicked(MouseEvent e) {
372                 if(e.getClickCount() == 2 && e.getPointerCount() == 1) {
373                     glWindow.setFullscreen(!glWindow.isFullscreen());
374                     System.err.println("setFullscreen: "+glWindow.isFullscreen());
375                 }
376             }
377          });
378
379         if( useAnimator ) {
380             animator.add(glWindow);
381             animator.start();
382             Assert.assertTrue(animator.isStarted());
383             Assert.assertTrue(animator.isAnimating());
384             Assert.assertEquals(exclusiveContext ? animator.getThread() : null, glWindow.getExclusiveContextThread());
385         }
386
387         if( SysExit.displayError == sysExit || SysExit.displayExit == sysExit || SysExit.displayEDTError == sysExit ) {
388             glWindow.addGLEventListener(new GLEventListener() {
389                 @Override
390                 public void init(GLAutoDrawable drawable) {}
391                 @Override
392                 public void dispose(GLAutoDrawable drawable) { }
393                 @Override
394                 public void display(GLAutoDrawable drawable) {
395                     final GLAnimatorControl anim = drawable.getAnimator();
396                     if( null != anim && anim.isAnimating() ) {
397                         final long ms = anim.getTotalFPSDuration();
398                         if( ms >= duration/2 || ms >= 3000 ) { // max 3s wait until provoking error
399                             if( SysExit.displayError == sysExit ) {
400                                 throw new Error("test error send from GLEventListener.display - "+Thread.currentThread());
401                             } else if ( SysExit.displayExit == sysExit ) {
402                                 System.err.println("exit(0) send from GLEventListener");
403                                 System.exit(0);
404                             } else if ( SysExit.displayEDTError == sysExit ) {
405                                 final Object upstream = drawable.getUpstreamWidget();
406                                 System.err.println("EDT invokeAndWaitError: upstream type "+upstream.getClass().getName());
407                                 if( upstream instanceof Window ) {
408                                     final EDTUtil edt = ((Window)upstream).getScreen().getDisplay().getEDTUtil();
409                                     System.err.println("EDT invokeAndWaitError: edt type "+edt.getClass().getName());
410                                     if( edt instanceof DefaultEDTUtil ) {
411                                         quitAdapter.doQuit();
412                                         ((DefaultEDTUtil)edt).invokeAndWaitError(new Runnable() {
413                                             public void run() {
414                                                 throw new RuntimeException("XXX Should never ever be seen! - "+Thread.currentThread());
415                                             }
416                                         });
417                                     }
418                                 }
419                             }
420                         }
421                     } else {
422                         System.exit(0);
423                     }
424                 }
425                 @Override
426                 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
427             });
428         }
429
430         glWindow.setVisible(true);
431         if( useAnimator ) {
432             animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
433         }
434
435         System.err.println("NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
436         System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
437         System.err.println("window pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
438
439         final int[] hasSurfacePixelScale0 = glWindow.convertToPixelUnits(new int[] { 1, 1 });
440         final int[] hasSurfacePixelScale1 = glWindow.getSurfaceScale(new int[2]);
441         System.err.println("HiDPI PixelScale: "+reqSurfacePixelScale[0]+"x"+reqSurfacePixelScale[1]+" (req) -> "+
442                            valReqSurfacePixelScale[0]+"x"+valReqSurfacePixelScale[1]+" (val) -> "+
443                            hasSurfacePixelScale1[0]+"x"+hasSurfacePixelScale1[1]+" (has)");
444         setTitle(glWindow, caps);
445         Assert.assertArrayEquals(hasSurfacePixelScale0, hasSurfacePixelScale1);
446
447         snap.setMakeSnapshot();
448
449         if( null != rwsize ) {
450             Thread.sleep(500); // 500ms delay
451             glWindow.setSize(rwsize.getWidth(), rwsize.getHeight());
452             System.err.println("window resize pos/siz: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
453         }
454
455         snap.setMakeSnapshot();
456
457         final long t0 = System.currentTimeMillis();
458         long t1 = t0;
459         while(!quitAdapter.shouldQuit() && t1-t0<duration) {
460             Thread.sleep(100);
461             t1 = System.currentTimeMillis();
462             if( SysExit.testError == sysExit || SysExit.testExit == sysExit || SysExit.testEDTError == sysExit) {
463                 final long ms = t1-t0;
464                 if( ms >= duration/2 || ms >= 3000 ) { // max 3s wait until provoking error
465                     if( SysExit.testError == sysExit ) {
466                         throw new Error("test error send from test thread");
467                     } else if ( SysExit.testExit == sysExit ) {
468                         System.err.println("exit(0) send from test thread");
469                         System.exit(0);
470                     } else if ( SysExit.testEDTError == sysExit ) {
471                         final EDTUtil edt = glWindow.getScreen().getDisplay().getEDTUtil();
472                         System.err.println("EDT invokeAndWaitError: edt type "+edt.getClass().getName());
473                         if( edt instanceof DefaultEDTUtil ) {
474                             quitAdapter.doQuit();
475                             ((DefaultEDTUtil)edt).invokeAndWaitError(new Runnable() {
476                                 public void run() {
477                                     throw new RuntimeException("XXX Should never ever be seen!");
478                                 }
479                             });
480                         }
481                     }
482                 }
483             }
484         }
485
486         if( useAnimator ) {
487             Assert.assertEquals(exclusiveContext ? animator.getThread() : null, glWindow.getExclusiveContextThread());
488             animator.stop();
489             Assert.assertFalse(animator.isAnimating());
490             Assert.assertFalse(animator.isStarted());
491         }
492         Assert.assertEquals(null, glWindow.getExclusiveContextThread());
493         glWindow.destroy();
494         if( NativeWindowFactory.isAWTAvailable() ) {
495             Assert.assertEquals(true,  AWTRobotUtil.waitForRealized(glWindow, false));
496         }
497     }
498
499     @Test
500     public void test01_GL2ES2() throws InterruptedException {
501         for(int i=1; i<=loops; i++) {
502             System.err.println("Loop "+i+"/"+loops);
503             final GLProfile glp;
504             if(forceGL3) {
505                 glp = GLProfile.get(GLProfile.GL3);
506             } else if(forceES3) {
507                 glp = GLProfile.get(GLProfile.GLES3);
508             } else if(forceES2) {
509                 glp = GLProfile.get(GLProfile.GLES2);
510             } else if(forceGL2) {
511                 glp = GLProfile.get(GLProfile.GL2);
512             } else {
513                 glp = GLProfile.getGL2ES2();
514             }
515             final GLCapabilities caps = new GLCapabilities( glp );
516             caps.setBackgroundOpaque(opaque);
517             if(-1 < forceAlpha) {
518                 caps.setAlphaBits(forceAlpha);
519             }
520             runTestGL(caps, undecorated);
521             if(loop_shutdown) {
522                 GLProfile.shutdown();
523             }
524         }
525     }
526
527     @Test
528     public void test02_GLES2() throws InterruptedException {
529         if(manualTest) return;
530
531         if( !GLProfile.isAvailable(GLProfile.GLES2) ) {
532             System.err.println("GLES2 n/a");
533             return;
534         }
535         final GLProfile glp = GLProfile.get(GLProfile.GLES2);
536         final GLCapabilities caps = new GLCapabilities( glp );
537         runTestGL(caps, undecorated);
538     }
539
540     @Test
541     public void test03_GL3() throws InterruptedException {
542         if(manualTest) return;
543
544         if( !GLProfile.isAvailable(GLProfile.GL3) ) {
545             System.err.println("GL3 n/a");
546             return;
547         }
548         final GLProfile glp = GLProfile.get(GLProfile.GL3);
549         final GLCapabilities caps = new GLCapabilities( glp );
550         runTestGL(caps, undecorated);
551     }
552
553     @Test
554     public void test99_PixelScale1_DefaultNorm() throws InterruptedException, InvocationTargetException {
555         if( manualTest ) return;
556
557         reqSurfacePixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
558         reqSurfacePixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;
559
560         GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2());
561         runTestGL(caps, undecorated);
562     }
563
564     public static void main(String args[]) throws IOException {
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             } else if(args[i].equals("-manual")) {
649                 manualTest = true;
650             }
651         }
652         wsize = new Dimension(w, h);
653         if( 0 < rw && 0 < rh ) {
654             rwsize = new Dimension(rw, rh);
655         }
656
657         if(usePos) {
658             wpos = new Point(x, y);
659         }
660         System.err.println("position "+wpos);
661         System.err.println("size "+wsize);
662         System.err.println("resize "+rwsize);
663         System.err.println("screen "+screenIdx);
664         System.err.println("translucent "+(!opaque));
665         System.err.println("forceAlpha "+forceAlpha);
666         System.err.println("undecorated "+undecorated);
667         System.err.println("atop "+alwaysOnTop);
668         System.err.println("fullscreen "+fullscreen);
669         System.err.println("pmvDirect "+(!pmvUseBackingArray));
670         System.err.println("mouseVisible "+mouseVisible);
671         System.err.println("mouseConfined "+mouseConfined);
672         System.err.println("pointerIcon "+setPointerIcon);
673         System.err.println("loops "+loops);
674         System.err.println("loop shutdown "+loop_shutdown);
675         System.err.println("forceES2 "+forceES2);
676         System.err.println("forceES3 "+forceES3);
677         System.err.println("forceGL3 "+forceGL3);
678         System.err.println("forceGL2 "+forceGL2);
679         System.err.println("swapInterval "+swapInterval);
680         System.err.println("exclusiveContext "+exclusiveContext);
681         System.err.println("useAnimator "+useAnimator);
682         System.err.println("sysExitWithin "+sysExit);
683         System.err.println("mappedBuffers "+useMappedBuffers);
684
685         if(waitForKey) {
686             UITestCase.waitForKey("Start");
687         }
688         org.junit.runner.JUnitCore.main(TestGearsES2NEWT.class.getName());
689     }
690 }
http://JogAmp.org git info: FAQ, tutorial and man pages.