29package com.jogamp.opengl.test.junit.newt.parenting;
31import java.io.IOException;
32import java.lang.reflect.InvocationTargetException;
34import com.jogamp.opengl.GLCapabilities;
35import com.jogamp.opengl.GLEventListener;
37import org.eclipse.swt.SWT;
38import org.eclipse.swt.layout.FillLayout;
39import org.eclipse.swt.widgets.Composite;
40import org.eclipse.swt.widgets.Display;
41import org.eclipse.swt.widgets.Shell;
42import org.junit.After;
43import org.junit.Assert;
44import org.junit.Assume;
45import org.junit.Before;
46import org.junit.BeforeClass;
48import org.junit.FixMethodOrder;
49import org.junit.runners.MethodSorters;
51import com.jogamp.nativewindow.swt.SWTAccessor;
52import com.jogamp.newt.NewtFactory;
53import com.jogamp.newt.Window;
54import com.jogamp.newt.opengl.GLWindow;
55import com.jogamp.newt.swt.NewtCanvasSWT;
56import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
57import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
58import com.jogamp.opengl.test.junit.jogl.demos.es2.swt.TestGearsES2SWT;
59import com.jogamp.opengl.test.junit.util.MiscUtils;
60import com.jogamp.opengl.test.junit.util.SWTTestUtil;
61import com.jogamp.opengl.test.junit.util.UITestCase;
62import com.jogamp.opengl.util.Animator;
67@FixMethodOrder(MethodSorters.NAME_ASCENDING)
69 static int width, height;
70 static long durationPerTest = 800;
73 Display display =
null;
76 Composite composite1 =
null;
77 Composite composite2 =
null;
91 display =
new Display();
92 Assert.assertNotNull( display );
94 shell1 =
new Shell( display );
95 Assert.assertNotNull( shell1 );
96 shell1.setLayout(
new FillLayout() );
97 composite1 =
new Composite( shell1, SWT.NONE );
98 composite1.setLayout(
new FillLayout() );
99 Assert.assertNotNull( composite1 );
101 shell2 =
new Shell( display );
102 Assert.assertNotNull( shell2 );
103 shell2.setLayout(
new FillLayout() );
104 composite2 =
new Composite( shell2, SWT.NONE );
105 composite2.setLayout(
new FillLayout() );
106 Assert.assertNotNull( composite2 );
113 Assert.assertNotNull( display );
114 Assert.assertNotNull( shell1 );
115 Assert.assertNotNull( shell2 );
116 Assert.assertNotNull( composite1 );
117 Assert.assertNotNull( composite2 );
121 composite1.dispose();
122 composite2.dispose();
128 catch(
final Throwable throwable ) {
129 throwable.printStackTrace();
130 Assume.assumeNoException( throwable );
132 swtNewtDisplay =
null;
143 winHopFrame2Frame(
false);
149 winHopFrame2Frame(
true);
152 protected void winHopFrame2Frame(
final boolean detachFirst)
throws InterruptedException, InvocationTargetException {
157 setDemoFields(demo1, glWindow1,
false);
163 setDemoFields(demo2, glWindow2,
false);
172 shell1.setText( getSimpleTestName(
".")+
"-Win1" );
173 shell1.setSize( width, height);
174 shell1.setLocation(0, 0);
176 shell2.setText( getSimpleTestName(
".")+
"-Win2" );
177 shell2.setSize( width, height);
178 shell2.setLocation(width + 50, 0);
190 for(state=0; state<3; state++) {
191 for(
int i=0; i*10<durationPerTest; i++) {
236 Assert.assertNotNull(demo);
237 Assert.assertNotNull(glWindow);
248 static int atoi(
final String a) {
251 i = Integer.parseInt(a);
252 }
catch (
final Exception ex) { ex.printStackTrace(); }
256 public static void main(
final String args[])
throws IOException {
257 for(
int i=0; i<args.length; i++) {
258 if(args[i].equals(
"-time")) {
259 durationPerTest = atoi(args[++i]);
static void invokeOnOSTKThread(final boolean blocking, final Runnable runnable)
Runs the specified action in an SWT compatible OS toolkit thread, which is:
static void invokeOnSWTThread(final org.eclipse.swt.widgets.Display display, final boolean blocking, final Runnable runnable)
Runs the specified action on the SWT UI thread.
static Display createDisplay(final String name)
Create a Display entity.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final NativeWindow getParent()
final boolean isNativeValid()
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...
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:
Window setNEWTChild(final Window newChild)
Sets a new NEWT child, provoking reparenting.
Specifies a set of OpenGL capabilities.
Using NewtCanvasSWT#setNEWTChild(Window) for reparenting, i.e.
static void setDemoFields(final GLEventListener demo, final GLWindow glWindow, final boolean debug)
void test02WinHopFrame2FrameDetachFirst()
static void main(final String args[])
void winHopFrame2Frame(final boolean detachFirst)
void test01WinHopFrame2FrameDirectHop()
static boolean setFieldIfExists(final Object instance, final String fieldName, final Object value)
final synchronized boolean start()
Starts this animator, if not running.
Specifying NEWT's Window functionality:
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.