29package com.jogamp.opengl.test.junit.jogl.swt;
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;
47import java.io.IOException;
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;
68import org.junit.runners.MethodSorters;
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;
105@FixMethodOrder(MethodSorters.NAME_ASCENDING)
108 static int duration = 250;
110 Display display =
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;
131 if(
null != display ) {
132 display.syncExec(
new Runnable() {
138 if(
null != tab1Comp ) {
141 if(
null != tabFolder ) {
144 if(
null != composite ) {
147 if(
null != shell ) {
155 if(
null != display ) {
160 catch(
final Throwable throwable ) {
161 throwable.printStackTrace();
162 Assume.assumeNoException( throwable );
176 throws InterruptedException
181 display =
new Display();
182 Assert.assertNotNull( display );
186 display.syncExec(
new Runnable() {
189 shell =
new Shell( display );
190 Assert.assertNotNull( shell );
191 shell.setText( getSimpleTestName(
".") );
192 shell.setLayout(
new FillLayout() );
195 shell.setLocation(wpos.
getX(), wpos.
getY());
197 composite =
new Composite( shell, SWT.NONE );
198 composite.setLayout(
new FillLayout() );
199 Assert.assertNotNull( composite );
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");
209 tab1Comp =
new Composite(tabFolder, SWT.NONE);
210 tab1Comp.setLayout(
new FillLayout());
211 tabItem1.setControl(tab1Comp);
223 final Canvas canvas1;
225 if( useNewtCanvasSWT ) {
229 Assert.assertNotNull(glWindow1);
230 newtCanvasSWT1 =
NewtCanvasSWT.
create( addComposite ? tab1Comp : tabFolder, 0, glWindow1 );
231 Assert.assertNotNull( newtCanvasSWT1 );
232 canvas1 = newtCanvasSWT1;
235 newtCanvasSWT1 =
null;
236 glCanvas1 =
GLCanvas.create( addComposite ? tab1Comp : tabFolder, 0, caps,
null);
238 Assert.assertNotNull(glCanvas1);
241 Assert.assertNotNull(canvas1);
242 Assert.assertNotNull(glad1);
246 display.syncExec(
new Runnable() {
249 if( !addComposite ) {
250 tabItem1.setControl(canvas1);
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");
261 text.append(
"SWT running with JogAmp and JOGL using JOGL's GLCanvas");
263 text.append(Text.DELIMITER);
265 sashRight =
new Composite(sash, SWT.NONE);
266 sashRight.setLayout(
new FillLayout());
270 tabItem2.setControl(sash);
279 final Canvas canvas2;
281 if( useNewtCanvasSWT ) {
285 Assert.assertNotNull(glWindow2);
287 Assert.assertNotNull( newtCanvasSWT2 );
288 canvas2 = newtCanvasSWT2;
290 glCanvas2 =
GLCanvas.create( addComposite ? sashRight : sash, 0, caps,
null);
293 Assert.assertNotNull(glCanvas2);
294 newtCanvasSWT2 =
null;
297 Assert.assertNotNull(canvas2);
298 Assert.assertNotNull(glad2);
302 if( useNewtCanvasSWT ) {
313 display.syncExec(
new Runnable() {
316 final Listener swtListener0 =
new Listener() {
318 public void handleEvent(
final Event event) {
319 newtCanvasSWT1.notifyListeners(event.type, event);
321 final Control itemControl0 = tabFolder.getItem(0).getControl();
322 if( itemControl0 != newtCanvasSWT1 ) {
323 itemControl0.addListener(SWT.Show, swtListener0);
324 itemControl0.addListener(SWT.Hide, swtListener0);
327 final Listener swtListener1 =
new Listener() {
329 public void handleEvent(
final Event event) {
330 newtCanvasSWT2.notifyListeners(event.type, event);
332 final Control itemControl1 = tabFolder.getItem(1).getControl();
333 if( itemControl1 != newtCanvasSWT2 ) {
334 itemControl1.addListener(SWT.Show, swtListener1);
335 itemControl1.addListener(SWT.Hide, swtListener1);
342 display.syncExec(
new Runnable() {
347 tabFolder.setSelection(0);
350 tabFolder.setSelection(1);
355 if( useNewtCanvasSWT ) {
365 if(
null != glWindow ) {
372 if(
null != glWindow ) {
382 public void keyReleased(
final KeyEvent e) {
387 if(
null != glWindow ) {
389 glWindow.invokeOnNewThread(
null,
false,
new Runnable() {
422 Assert.assertTrue(animator.isAnimating());
425 display.syncExec(
new Runnable() {
432 display.syncExec(
new Runnable() {
435 final Canvas canvas = focusOnTab1 ? canvas1 : canvas2;
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));
440 if( useNewtCanvasSWT ) {
441 final GLWindow glWindow = focusOnTab1 ? glWindow1 : glWindow2;
442 final NewtCanvasSWT newtCanvasSWT = focusOnTab1 ? newtCanvasSWT1 : newtCanvasSWT2;
450 final GLCanvas glCanvas = focusOnTab1 ? glCanvas1: glCanvas2;
454 if(
null != rwsize ) {
455 for(
int i=0; i<50; i++) {
456 generalWaitAction.run();
458 display.syncExec(
new Runnable() {
461 shell.setSize( rwsize.getWidth(), rwsize.getHeight() );
462 final Canvas canvas = focusOnTab1 ? canvas1 : canvas2;
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));
467 if( useNewtCanvasSWT ) {
468 final GLWindow glWindow = focusOnTab1 ? glWindow1 : glWindow2;
469 final NewtCanvasSWT newtCanvasSWT = focusOnTab1 ? newtCanvasSWT1 : newtCanvasSWT2;
479 if( useNewtCanvasSWT ) {
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 );
486 display.syncExec(
new Runnable() {
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);
494 Assert.assertTrue(
"GLWindow2 LOS "+pGLWinLOS[0]+
" not >= sash-right "+pSashRightClient, pGLWinLOS[0].compareTo(pSashRightClient) >= 0 );
497 while( animator.isAnimating() ) {
498 final boolean keepGoing = !quitAdapter.shouldQuit() &&
499 animator.isAnimating() &&
509 generalWaitAction.run();
512 Assert.assertFalse(animator.isAnimating());
513 Assert.assertFalse(animator.
isStarted());
516 if( useNewtCanvasSWT ) {
517 display.syncExec(
new Runnable() {
524 display.syncExec(
new Runnable() {
532 display.syncExec(
new Runnable() {
540 catch(
final Throwable throwable ) {
541 throwable.printStackTrace();
542 Assume.assumeNoException( throwable );
548 if( 0 != manualTest && 1 != manualTest ) {
555 if( 0 != manualTest && 2 != manualTest ) {
562 if( 0 != manualTest && 11 != manualTest ) {
569 if( 0 != manualTest && 12 != manualTest ) {
577 if( 0 != manualTest && 21 != manualTest ) {
584 if( 0 != manualTest && 22 != manualTest ) {
591 if( 0 != manualTest && 31 != manualTest ) {
598 if( 0 != manualTest && 32 != manualTest ) {
604 static int manualTest = 0;
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;
610 for(
int i=0; i<args.length; i++) {
611 if(args[i].equals(
"-test")) {
614 }
else if(args[i].equals(
"-time")) {
617 }
else if(args[i].equals(
"-width")) {
620 }
else if(args[i].equals(
"-height")) {
623 }
else if(args[i].equals(
"-x")) {
627 }
else if(args[i].equals(
"-y")) {
631 }
else if(args[i].equals(
"-rwidth")) {
634 }
else if(args[i].equals(
"-rheight")) {
640 if( 0 < rw && 0 < rh ) {
645 wpos =
new Point(x, y);
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);
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 char getKeyChar()
Returns the UTF-16 character reflecting the key symbol incl.
static boolean isPrintableKey(final short uniChar, final boolean isKeyChar)
Returns true if given uniChar represents a printable character, i.e.
NEWT Window events are provided for notification purposes ONLY.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Point getLocationOnScreen(final Point storage)
Returns the window's top-left client-area position in the screen.
final boolean isFullscreen()
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
final int getX()
Returns the current x position of this window, relative to it's parent.
final boolean isAlwaysOnTop()
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
final int getY()
Returns the current y position of the top-left corner of the client area relative to it's parent in w...
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
final CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
final InsetsImmutable getInsets()
Returns the insets defined as the width and height of the window decoration on the left,...
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
NEWT GLWindow Demo functionality.
void quitAdapterEnable(final boolean v)
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.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
static void initSingleton()
Static initialization of JOGL.
A heavyweight AWT component which provides OpenGL rendering support.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
Test for Bug 1421, Bug 1358, Bug 969 and Bug 672.
void test01_GLCanvasTabPlainGLDirect()
void test32_NewtCanvasSWTTabSashGLWComp()
void test02_GLCanvasTabSashGLDirect()
static void main(final String args[])
void test21_NewtCanvasSWTTabPlainGLDirect()
void test22_NewtCanvasSWTTabSashGLDirect()
void test31_NewtCanvasSWTTabPlainGLWComp()
void test12_GLCanvasTabSashGLWComp()
void test11_GLCanvasTabPlainGLWComp()
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)
static int atoi(final String str, final int def)
static boolean waitForRealized(final Screen screen, final boolean realized, final Runnable waitAction)
static final int TIME_SLICE
final long getTotalFPSDuration()
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.
final synchronized boolean stop()
Stops this animator.
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:
Immutable Point interface.
int compareTo(final PointImmutable d)
CapabilitiesImmutable getChosenCapabilities()
Gets an immutable set of chosen capabilities.
NEWT WindowEvent listener.
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.