JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLCanvasSWTNewtCanvasSWTPosInTabs.java
Go to the documentation of this file.
1/**
2 * Copyright 2020 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.swt;
30
31import com.jogamp.opengl.GLAutoDrawable;
32import com.jogamp.opengl.GLCapabilities;
33import com.jogamp.opengl.GLCapabilitiesImmutable;
34import com.jogamp.opengl.GLProfile;
35import com.jogamp.opengl.swt.GLCanvas;
36import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
37import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
38import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
39import com.jogamp.opengl.test.junit.util.GLTestUtil;
40import com.jogamp.opengl.test.junit.util.MiscUtils;
41import com.jogamp.opengl.test.junit.util.NewtTestUtil;
42import com.jogamp.opengl.test.junit.util.QuitAdapter;
43import com.jogamp.opengl.test.junit.util.SWTTestUtil;
44import com.jogamp.opengl.test.junit.util.TestUtil;
45import com.jogamp.opengl.test.junit.util.UITestCase;
46
47import java.io.IOException;
48
49import org.eclipse.swt.SWT;
50import org.eclipse.swt.custom.CTabFolder;
51import org.eclipse.swt.custom.CTabItem;
52import org.eclipse.swt.custom.SashForm;
53import org.eclipse.swt.layout.FillLayout;
54import org.eclipse.swt.widgets.Canvas;
55import org.eclipse.swt.widgets.Composite;
56import org.eclipse.swt.widgets.Control;
57import org.eclipse.swt.widgets.Display;
58import org.eclipse.swt.widgets.Event;
59import org.eclipse.swt.widgets.Listener;
60import org.eclipse.swt.widgets.Shell;
61import org.eclipse.swt.widgets.Text;
62import org.junit.After;
63import org.junit.Assert;
64import org.junit.Assume;
65import org.junit.BeforeClass;
66import org.junit.FixMethodOrder;
67import org.junit.Test;
68import org.junit.runners.MethodSorters;
69
70import com.jogamp.nativewindow.swt.SWTAccessor;
71import com.jogamp.nativewindow.util.Dimension;
72import com.jogamp.nativewindow.util.DimensionImmutable;
73import com.jogamp.nativewindow.util.Point;
74import com.jogamp.nativewindow.util.PointImmutable;
75import com.jogamp.newt.event.KeyAdapter;
76import com.jogamp.newt.event.KeyEvent;
77import com.jogamp.newt.event.KeyListener;
78import com.jogamp.newt.event.WindowAdapter;
79import com.jogamp.newt.event.WindowEvent;
80import com.jogamp.newt.event.WindowListener;
81import com.jogamp.newt.opengl.GLWindow;
82import com.jogamp.newt.opengl.util.NEWTDemoListener;
83import com.jogamp.newt.swt.NewtCanvasSWT;
84import com.jogamp.opengl.util.Animator;
85import com.jogamp.opengl.util.AnimatorBase;
86
87/**
88 * Test for Bug 1421, Bug 1358, Bug 969 and Bug 672.
89 * <p>
90 * High-DPI scaling impact on MacOS and
91 * SWT child window positioning on MacOS.
92 * </p>
93 * <p>
94 * Testing the TabFolder and a SashForm in the 2nd tab
95 * covering both SWT layout use cases on
96 * both our SWT support classes SWT GLCanvas and NewtCanvasSWT.
97 * </p>
98 * <p>
99 * Bug 1421 {@link #test01_tabFolderParent()} shows that the
100 * inner child NEWT GLWindow is position wrongly.
101 * It's position is shifted down abo0ut the height of the
102 * parent TabFolder and right about the width of the same.
103 * </p>
104 */
105@FixMethodOrder(MethodSorters.NAME_ASCENDING)
107
108 static int duration = 250;
109
110 Display display = null;
111 Shell shell = null;
112 Composite composite = null;
113 CTabFolder tabFolder = null;
114 CTabItem tabItem1 = null;
115 CTabItem tabItem2 = null;
116 Composite tab1Comp = null;
117 SashForm sash = null;
118 Composite sashRight = null;
119
120 static PointImmutable wpos = null;
121 static DimensionImmutable wsize = new Dimension(640, 480), rwsize = null;
122
123 @BeforeClass
124 public static void startup() {
126 }
127
128 @After
129 public void release() {
130 try {
131 if( null != display ) {
132 display.syncExec(new Runnable() {
133 @Override
134 public void run() {
135 if( null != sash ) {
136 sash.dispose();
137 }
138 if( null != tab1Comp ) {
139 tab1Comp.dispose();
140 }
141 if( null != tabFolder ) {
142 tabFolder.dispose();
143 }
144 if( null != composite ) {
145 composite.dispose();
146 }
147 if( null != shell ) {
148 shell.dispose();
149 }
150 }});
151 }
152 SWTAccessor.invokeOnOSTKThread(true, new Runnable() {
153 @Override
154 public void run() {
155 if( null != display ) {
156 display.dispose();
157 }
158 }});
159 }
160 catch( final Throwable throwable ) {
161 throwable.printStackTrace();
162 Assume.assumeNoException( throwable );
163 }
164 display = null;
165 shell = null;
166 composite = null;
167 tabFolder = null;
168 tabItem1 = null;
169 tabItem2 = null;
170 tab1Comp = null;
171 sash = null;
172 sashRight = null;
173 }
174
175 protected void runTestInLayout(final boolean focusOnTab1, final boolean useNewtCanvasSWT, final boolean addComposite, final GLCapabilitiesImmutable caps)
176 throws InterruptedException
177 {
178 SWTAccessor.invokeOnOSTKThread(true, new Runnable() {
179 @Override
180 public void run() {
181 display = new Display();
182 Assert.assertNotNull( display );
183 SWTAccessor.printInfo(System.err, display);
184 }});
185
186 display.syncExec(new Runnable() {
187 @Override
188 public void run() {
189 shell = new Shell( display );
190 Assert.assertNotNull( shell );
191 shell.setText( getSimpleTestName(".") );
192 shell.setLayout( new FillLayout() );
193 shell.setSize( wsize.getWidth(), wsize.getHeight() );
194 if( null != wpos ) {
195 shell.setLocation(wpos.getX(), wpos.getY());
196 }
197 composite = new Composite( shell, SWT.NONE );
198 composite.setLayout( new FillLayout() );
199 Assert.assertNotNull( composite );
200
201 tabFolder = new CTabFolder(composite, SWT.TOP);
202 tabFolder.setBorderVisible(true);
203 tabFolder.setLayoutData(new FillLayout());
204 tabItem1 = new CTabItem(tabFolder, SWT.NONE, 0);
205 tabItem1.setText("PlainGL");
206 tabItem2 = new CTabItem(tabFolder, SWT.NONE, 1);
207 tabItem2.setText("SashGL");
208 if( addComposite ) {
209 tab1Comp = new Composite(tabFolder, SWT.NONE);
210 tab1Comp.setLayout(new FillLayout());
211 tabItem1.setControl(tab1Comp);
212 } else {
213 tab1Comp = null;
214 }
215 }});
216
217 final SWTTestUtil.WaitAction waitAction = new SWTTestUtil.WaitAction(display, true, TestUtil.TIME_SLICE);
218 final SWTTestUtil.WaitAction generalWaitAction = new SWTTestUtil.WaitAction(display, true, 10);
219
220 final GLWindow glWindow1;
221 final NewtCanvasSWT newtCanvasSWT1;
222 final GLCanvas glCanvas1;
223 final Canvas canvas1;
224 final GLAutoDrawable glad1;
225 if( useNewtCanvasSWT ) {
226 glCanvas1 = null;
227 glWindow1 = GLWindow.create(caps);
228 glad1 = glWindow1;
229 Assert.assertNotNull(glWindow1);
230 newtCanvasSWT1 = NewtCanvasSWT.create( addComposite ? tab1Comp : tabFolder, 0, glWindow1 );
231 Assert.assertNotNull( newtCanvasSWT1 );
232 canvas1 = newtCanvasSWT1;
233 } else {
234 glWindow1 = null;
235 newtCanvasSWT1 = null;
236 glCanvas1 = GLCanvas.create( addComposite ? tab1Comp : tabFolder, 0, caps, null);
237 glad1 = glCanvas1;
238 Assert.assertNotNull(glCanvas1);
239 canvas1 = glCanvas1;
240 }
241 Assert.assertNotNull(canvas1);
242 Assert.assertNotNull(glad1);
243 final GearsES2 demo1 = new GearsES2(1);
244 glad1.addGLEventListener(demo1);
245
246 display.syncExec(new Runnable() {
247 @Override
248 public void run() {
249 if( !addComposite ) {
250 tabItem1.setControl(canvas1);
251 }
252
253 sash = new SashForm(tabFolder, SWT.NONE);
254 Assert.assertNotNull( sash );
255 final Text text = new Text (sash, SWT.MULTI | SWT.BORDER);
256 text.setText("Left Sash Cell");
257 text.append(Text.DELIMITER);
258 if( useNewtCanvasSWT ) {
259 text.append("SWT running with JogAmp, JOGL and NEWT using NewtCanvasSWT");
260 } else {
261 text.append("SWT running with JogAmp and JOGL using JOGL's GLCanvas");
262 }
263 text.append(Text.DELIMITER);
264 if( addComposite ) {
265 sashRight = new Composite(sash, SWT.NONE);
266 sashRight.setLayout(new FillLayout());
267 } else {
268 sashRight = null;
269 }
270 tabItem2.setControl(sash);
271 } } );
272
273 final Animator animator = new Animator(0 /* w/o AWT */);
274 animator.add(glad1);
275
276 final GLWindow glWindow2;
277 final GLCanvas glCanvas2;
278 final NewtCanvasSWT newtCanvasSWT2;
279 final Canvas canvas2;
280 final GLAutoDrawable glad2;
281 if( useNewtCanvasSWT ) {
282 glWindow2 = GLWindow.create(caps);
283 glad2 = glWindow2;
284 glCanvas2 = null;
285 Assert.assertNotNull(glWindow2);
286 newtCanvasSWT2 = NewtCanvasSWT.create( addComposite ? sashRight : sash, 0, glWindow2 );
287 Assert.assertNotNull( newtCanvasSWT2 );
288 canvas2 = newtCanvasSWT2;
289 } else {
290 glCanvas2 = GLCanvas.create( addComposite ? sashRight : sash, 0, caps, null);
291 glad2 = glCanvas2;
292 glWindow2 = null;
293 Assert.assertNotNull(glCanvas2);
294 newtCanvasSWT2 = null;
295 canvas2 = glCanvas2;
296 }
297 Assert.assertNotNull(canvas2);
298 Assert.assertNotNull(glad2);
299 final RedSquareES2 demo2 = new RedSquareES2(1);
300 glad2.addGLEventListener(demo2);
301
302 if( useNewtCanvasSWT ) {
303 // We have to forward essential events of interest from CTabItem's Control
304 // to our NewtCanvasSWT/GLWindow, as only the direct CTabItem's Control
305 // receives the event.
306 //
307 // Essential events are at least SWT.Show and SWT.Hide!
308 //
309 // In case we use 'addComposite' or a SashForm' etc,
310 // we need to forward these events of interest!
311 // Index 0 -> newtCanvasSWT1 ( glWindow1 )
312 // Index 1 -> newtCanvasSWT2 ( glWindow2 )
313 display.syncExec(new Runnable() {
314 @Override
315 public void run() {
316 final Listener swtListener0 = new Listener() {
317 @Override
318 public void handleEvent(final Event event) {
319 newtCanvasSWT1.notifyListeners(event.type, event);
320 } };
321 final Control itemControl0 = tabFolder.getItem(0).getControl();
322 if( itemControl0 != newtCanvasSWT1 ) {
323 itemControl0.addListener(SWT.Show, swtListener0);
324 itemControl0.addListener(SWT.Hide, swtListener0);
325 }
326
327 final Listener swtListener1 = new Listener() {
328 @Override
329 public void handleEvent(final Event event) {
330 newtCanvasSWT2.notifyListeners(event.type, event);
331 } };
332 final Control itemControl1 = tabFolder.getItem(1).getControl();
333 if( itemControl1 != newtCanvasSWT2 ) {
334 itemControl1.addListener(SWT.Show, swtListener1);
335 itemControl1.addListener(SWT.Hide, swtListener1);
336 }
337 } } );
338 }
339
340 animator.add(glad2);
341
342 display.syncExec(new Runnable() {
343 @Override
344 public void run() {
345 if( focusOnTab1 ) {
346 canvas1.setFocus();
347 tabFolder.setSelection(0);
348 } else {
349 canvas2.setFocus();
350 tabFolder.setSelection(1);
351 }
352 } } );
353
354 final QuitAdapter quitAdapter = new QuitAdapter();
355 if( useNewtCanvasSWT ) {
356 glWindow1.addKeyListener(quitAdapter);
357 glWindow1.addWindowListener(quitAdapter);
358 glWindow2.addKeyListener(quitAdapter);
359 glWindow2.addWindowListener(quitAdapter);
360
361 final WindowListener wl = new WindowAdapter() {
362 @Override
363 public void windowResized(final WindowEvent e) {
364 final GLWindow glWindow = ( e.getSource() instanceof GLWindow ) ? (GLWindow)e.getSource() : null;
365 if( null != glWindow ) {
366 System.err.println("window resized: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight());
367 }
368 }
369 @Override
370 public void windowMoved(final WindowEvent e) {
371 final GLWindow glWindow = ( e.getSource() instanceof GLWindow ) ? (GLWindow)e.getSource() : null;
372 if( null != glWindow ) {
373 System.err.println("window moved: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight());
374 }
375 }
376 };
377 glWindow1.addWindowListener(wl);
378 glWindow2.addWindowListener(wl);
379
380 final KeyListener kl = new KeyAdapter() {
381 @Override
382 public void keyReleased(final KeyEvent e) {
383 if( !e.isPrintableKey() || e.isAutoRepeat() ) {
384 return;
385 }
386 final GLWindow glWindow = ( e.getSource() instanceof GLWindow ) ? (GLWindow)e.getSource() : null;
387 if( null != glWindow ) {
388 if(e.getKeyChar()=='f') {
389 glWindow.invokeOnNewThread(null, false, new Runnable() {
390 @Override
391 public void run() {
392 final Thread t = glWindow.setExclusiveContextThread(null);
393 System.err.println("[set fullscreen pre]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
394 glWindow.setFullscreen(!glWindow.isFullscreen());
395 System.err.println("[set fullscreen post]: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", f "+glWindow.isFullscreen()+", a "+glWindow.isAlwaysOnTop()+", "+glWindow.getInsets());
396 glWindow.setExclusiveContextThread(t);
397 } } );
398 }
399 }
400 }
401 };
402 glWindow1.addKeyListener(kl);
403 glWindow2.addKeyListener(kl);
404 {
405 final NEWTDemoListener newtDemoListener1 = new NEWTDemoListener(glWindow1);
406 newtDemoListener1.quitAdapterEnable(false);
407 glWindow1.addKeyListener(newtDemoListener1);
408 glWindow1.addMouseListener(newtDemoListener1);
409 glWindow1.addWindowListener(newtDemoListener1);
410 }
411 {
412 final NEWTDemoListener newtDemoListener2 = new NEWTDemoListener(glWindow2);
413 newtDemoListener2.quitAdapterEnable(false);
414 glWindow2.addKeyListener(newtDemoListener2);
415 glWindow2.addMouseListener(newtDemoListener2);
416 glWindow2.addWindowListener(newtDemoListener2);
417 }
418 }
419
420 animator.start();
421 Assert.assertTrue(animator.isStarted());
422 Assert.assertTrue(animator.isAnimating());
423 animator.setUpdateFPSFrames(60, null);
424
425 display.syncExec(new Runnable() {
426 @Override
427 public void run() {
428 shell.open();
429 } } );
430
431 Assert.assertEquals(true, GLTestUtil.waitForRealized( focusOnTab1 ? glad1 : glad2, true, waitAction));
432 display.syncExec(new Runnable() {
433 @Override
434 public void run() {
435 final Canvas canvas = focusOnTab1 ? canvas1 : canvas2;
436 System.err.println("Canvas pixel-units pos/siz.0: pos "+SWTAccessor.getLocationInPixels(canvas)+", size "+SWTAccessor.getSizeInPixels(canvas));
437 System.err.println("Canvas window-units pos/siz.0: pos "+canvas.getLocation()+", size "+canvas.getSize());
438 System.err.println("Canvas LOS.0: "+canvas.toDisplay(0, 0));
439 } } );
440 if( useNewtCanvasSWT ) {
441 final GLWindow glWindow = focusOnTab1 ? glWindow1 : glWindow2;
442 final NewtCanvasSWT newtCanvasSWT = focusOnTab1 ? newtCanvasSWT1 : newtCanvasSWT2;
443 Assert.assertNotNull( newtCanvasSWT.getNativeWindow() );
444 System.err.println("NewtCanvasSWT LOS.0: "+newtCanvasSWT.getNativeWindow().getLocationOnScreen(null));
445 System.err.println("GLWindow LOS.0: "+glWindow.getLocationOnScreen(null));
446 System.err.println("GLWindow pos/siz.0: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
447 System.err.println("NW chosen: "+glWindow.getDelegatedWindow().getChosenCapabilities());
448 System.err.println("GL chosen: "+glWindow.getChosenCapabilities());
449 } else {
450 final GLCanvas glCanvas = focusOnTab1 ? glCanvas1: glCanvas2;
451 System.err.println("GL chosen: "+glCanvas.getChosenGLCapabilities());
452 }
453
454 if( null != rwsize ) {
455 for(int i=0; i<50; i++) { // 500 ms dispatched delay
456 generalWaitAction.run();
457 }
458 display.syncExec( new Runnable() {
459 @Override
460 public void run() {
461 shell.setSize( rwsize.getWidth(), rwsize.getHeight() );
462 final Canvas canvas = focusOnTab1 ? canvas1 : canvas2;
463 System.err.println("Canvas pixel-units pos/siz.1: pos "+SWTAccessor.getLocationInPixels(canvas)+", size "+SWTAccessor.getSizeInPixels(canvas));
464 System.err.println("Canvas window-units pos/siz.1: pos "+canvas.getLocation()+", size "+canvas.getSize());
465 System.err.println("Canvas LOS.1: "+canvas.toDisplay(0, 0));
466 } } );
467 if( useNewtCanvasSWT ) {
468 final GLWindow glWindow = focusOnTab1 ? glWindow1 : glWindow2;
469 final NewtCanvasSWT newtCanvasSWT = focusOnTab1 ? newtCanvasSWT1 : newtCanvasSWT2;
470 System.err.println("NewtCanvasSWT LOS.1: "+newtCanvasSWT.getNativeWindow().getLocationOnScreen(null));
471 System.err.println("GLWindow LOS.1: "+glWindow.getLocationOnScreen(null));
472 System.err.println("window resize pos/siz.1: "+glWindow.getX()+"/"+glWindow.getY()+" "+glWindow.getSurfaceWidth()+"x"+glWindow.getSurfaceHeight()+", "+glWindow.getInsets());
473 }
474 }
475
476 if( !focusOnTab1 ) {
477 final PointImmutable pSashRightClient = new Point(wsize.getWidth(), 0);
478 final PointImmutable[] pGLWinLOS = { null };
479 if( useNewtCanvasSWT ) {
480 final PointImmutable pNatWinLOS = newtCanvasSWT2.getNativeWindow().getLocationOnScreen(null);
481 pGLWinLOS[0] = glWindow2.getLocationOnScreen(null);
482 System.err.println("GLWindow2 LOS: "+pGLWinLOS);
483 System.err.println("NewtCanvasSWT2 LOS: "+pNatWinLOS);
484 Assert.assertTrue( "NewtCanvasAWT2 LOS "+pNatWinLOS+" not >= sash-right "+pSashRightClient, pNatWinLOS.compareTo(pSashRightClient) >= 0 );
485 } else {
486 display.syncExec(new Runnable() {
487 @Override
488 public void run() {
489 final org.eclipse.swt.graphics.Point los = glCanvas2.toDisplay(0, 0);
490 pGLWinLOS[0] = new Point(los.x, los.y);
491 System.err.println("GLCanvas2 LOS: "+pGLWinLOS);
492 } } );
493 }
494 Assert.assertTrue( "GLWindow2 LOS "+pGLWinLOS[0]+" not >= sash-right "+pSashRightClient, pGLWinLOS[0].compareTo(pSashRightClient) >= 0 );
495 }
496
497 while( animator.isAnimating() ) {
498 final boolean keepGoing = !quitAdapter.shouldQuit() &&
499 animator.isAnimating() &&
500 animator.getTotalFPSDuration()<duration;
501 if( !keepGoing ) {
502 new Thread() {
503 @Override
504 public void run() {
505 animator.stop();
506 }
507 }.start();
508 }
509 generalWaitAction.run();
510 }
511
512 Assert.assertFalse(animator.isAnimating());
513 Assert.assertFalse(animator.isStarted());
514
515 try {
516 if( useNewtCanvasSWT ) {
517 display.syncExec( new Runnable() {
518 @Override
519 public void run() {
520 newtCanvasSWT1.dispose();
521 } } );
522 glWindow1.destroy();
523 Assert.assertEquals(true, NewtTestUtil.waitForRealized(glWindow1, false, null));
524 display.syncExec( new Runnable() {
525 @Override
526 public void run() {
527 newtCanvasSWT2.dispose();
528 } } );
529 glWindow2.destroy();
530 Assert.assertEquals(true, NewtTestUtil.waitForRealized(glWindow2, false, null));
531 } else {
532 display.syncExec( new Runnable() {
533 @Override
534 public void run() {
535 glCanvas1.dispose();
536 glCanvas2.dispose();
537 } } );
538 }
539 }
540 catch( final Throwable throwable ) {
541 throwable.printStackTrace();
542 Assume.assumeNoException( throwable );
543 }
544 }
545
546 @Test
547 public void test01_GLCanvasTabPlainGLDirect() throws InterruptedException {
548 if( 0 != manualTest && 1 != manualTest ) {
549 return;
550 }
551 runTestInLayout(true /* focusOnTab1 */, false /* useNewtCanvasSWT */, false /* addComposite */, new GLCapabilities(GLProfile.getGL2ES2()));
552 }
553 @Test
554 public void test02_GLCanvasTabSashGLDirect() throws InterruptedException {
555 if( 0 != manualTest && 2 != manualTest ) {
556 return;
557 }
558 runTestInLayout(false /* focusOnTab1 */, false /* useNewtCanvasSWT */, false /* addComposite */, new GLCapabilities(GLProfile.getGL2ES2()));
559 }
560 @Test
561 public void test11_GLCanvasTabPlainGLWComp() throws InterruptedException {
562 if( 0 != manualTest && 11 != manualTest ) {
563 return;
564 }
565 runTestInLayout(true /* focusOnTab1 */, false /* useNewtCanvasSWT */, true /* addComposite */, new GLCapabilities(GLProfile.getGL2ES2()));
566 }
567 @Test
568 public void test12_GLCanvasTabSashGLWComp() throws InterruptedException {
569 if( 0 != manualTest && 12 != manualTest ) {
570 return;
571 }
572 runTestInLayout(false /* focusOnTab1 */, false /* useNewtCanvasSWT */, true /* addComposite */, new GLCapabilities(GLProfile.getGL2ES2()));
573 }
574
575 @Test
576 public void test21_NewtCanvasSWTTabPlainGLDirect() throws InterruptedException {
577 if( 0 != manualTest && 21 != manualTest ) {
578 return;
579 }
580 runTestInLayout(true /* focusOnTab1 */, true /* useNewtCanvasSWT */, false /* addComposite */, new GLCapabilities(GLProfile.getGL2ES2()));
581 }
582 @Test
583 public void test22_NewtCanvasSWTTabSashGLDirect() throws InterruptedException {
584 if( 0 != manualTest && 22 != manualTest ) {
585 return;
586 }
587 runTestInLayout(false /* focusOnTab1 */, true /* useNewtCanvasSWT */, false /* addComposite */, new GLCapabilities(GLProfile.getGL2ES2()));
588 }
589 @Test
590 public void test31_NewtCanvasSWTTabPlainGLWComp() throws InterruptedException {
591 if( 0 != manualTest && 31 != manualTest ) {
592 return;
593 }
594 runTestInLayout(true /* focusOnTab1 */, true /* useNewtCanvasSWT */, true /* addComposite */, new GLCapabilities(GLProfile.getGL2ES2()));
595 }
596 @Test
597 public void test32_NewtCanvasSWTTabSashGLWComp() throws InterruptedException {
598 if( 0 != manualTest && 32 != manualTest ) {
599 return;
600 }
601 runTestInLayout(false /* focusOnTab1 */, true /* useNewtCanvasSWT */, true /* addComposite */, new GLCapabilities(GLProfile.getGL2ES2()));
602 }
603
604 static int manualTest = 0;
605
606 public static void main(final String args[]) throws IOException {
607 int x=0, y=0, w=640, h=480, rw=-1, rh=-1;
608 boolean usePos = false;
609
610 for(int i=0; i<args.length; i++) {
611 if(args[i].equals("-test")) {
612 i++;
613 manualTest = MiscUtils.atoi(args[i], manualTest);
614 } else if(args[i].equals("-time")) {
615 i++;
616 duration = MiscUtils.atoi(args[i], duration);
617 } else if(args[i].equals("-width")) {
618 i++;
619 w = MiscUtils.atoi(args[i], w);
620 } else if(args[i].equals("-height")) {
621 i++;
622 h = MiscUtils.atoi(args[i], h);
623 } else if(args[i].equals("-x")) {
624 i++;
625 x = MiscUtils.atoi(args[i], x);
626 usePos = true;
627 } else if(args[i].equals("-y")) {
628 i++;
629 y = MiscUtils.atoi(args[i], y);
630 usePos = true;
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 }
638 }
639 wsize = new Dimension(w, h);
640 if( 0 < rw && 0 < rh ) {
641 rwsize = new Dimension(rw, rh);
642 }
643
644 if(usePos) {
645 wpos = new Point(x, y);
646 }
647 System.out.println("manualTest: "+manualTest);
648 System.out.println("durationPerTest: "+duration);
649 System.err.println("position "+wpos);
650 System.err.println("size "+wsize);
651 System.err.println("resize "+rwsize);
652
653 org.junit.runner.JUnitCore.main(TestGLCanvasSWTNewtCanvasSWTPosInTabs.class.getName());
654 }
655}
static void invokeOnOSTKThread(final boolean blocking, final Runnable runnable)
Runs the specified action in an SWT compatible OS toolkit thread, which is:
static Point getLocationInPixels(final Control c)
static Point getSizeInPixels(final Control c)
static void printInfo(final PrintStream out, final Display d)
final boolean isAutoRepeat()
getModifiers() contains AUTOREPEAT_MASK.
final char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
Definition: KeyEvent.java:161
static boolean isPrintableKey(final short uniChar, final boolean isKeyChar)
Returns true if given uniChar represents a printable character, i.e.
Definition: KeyEvent.java:316
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
Point getLocationOnScreen(final Point storage)
Returns the window's top-left client-area position in the screen.
Definition: GLWindow.java:643
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:466
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
Definition: GLWindow.java:927
final int getX()
Returns the current x position of this window, relative to it's parent.
Definition: GLWindow.java:436
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
Definition: GLWindow.java:902
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
Definition: GLWindow.java:441
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:461
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
Definition: GLWindow.java:534
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
Definition: GLWindow.java:266
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
Definition: GLWindow.java:431
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
Definition: GLWindow.java:277
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
SWT Canvas containing a NEWT Window using native parenting.
NativeWindow getNativeWindow()
Returns the associated NativeWindow of this NativeWindowHolder, which is identical to getNativeSurfac...
static NewtCanvasSWT create(final Composite parent, final int style, final Window child)
Creates an instance using NewtCanvasSWT(Composite, int, Window) on the SWT thread.
void dispose()
Destroys this resource:
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
static void initSingleton()
Static initialization of JOGL.
Definition: GLProfile.java:204
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
Definition: GLCanvas.java:1225
void runTestInLayout(final boolean focusOnTab1, final boolean useNewtCanvasSWT, final boolean addComposite, final GLCapabilitiesImmutable caps)
static boolean waitForRealized(final GLAutoDrawable glad, final boolean realized, final Runnable waitAction)
Definition: GLTestUtil.java:91
static int atoi(final String str, final int def)
Definition: MiscUtils.java:57
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
synchronized boolean isStarted()
Indicates whether this animator has been started.
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
Point getLocationOnScreen(Point point)
Returns the window's top-left client-area position in the screen.
Immutable Dimension Interface, consisting of it's read only components:
int compareTo(final PointImmutable d)
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
Listener for KeyEvents.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
Thread setExclusiveContextThread(Thread t)
Dedicates this instance's GLContext to the given thread.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Specifies an immutable set of OpenGL capabilities.