29package com.jogamp.opengl.test.junit.jogl.swt;
31import java.lang.reflect.InvocationTargetException;
33import org.eclipse.swt.SWT;
34import org.eclipse.swt.graphics.Color;
35import org.eclipse.swt.graphics.Rectangle;
36import org.eclipse.swt.layout.FillLayout;
37import org.eclipse.swt.layout.GridData;
38import org.eclipse.swt.layout.GridLayout;
39import org.eclipse.swt.widgets.Canvas;
40import org.eclipse.swt.widgets.Composite;
41import org.eclipse.swt.widgets.Display;
42import org.eclipse.swt.widgets.Event;
43import org.eclipse.swt.widgets.Listener;
44import org.eclipse.swt.widgets.Shell;
45import org.eclipse.swt.widgets.Text;
46import org.junit.Assert;
47import org.junit.BeforeClass;
49import org.junit.FixMethodOrder;
50import org.junit.runners.MethodSorters;
52import com.jogamp.common.os.Platform;
53import com.jogamp.junit.util.JunitTracer;
54import com.jogamp.nativewindow.AbstractGraphicsScreen;
55import com.jogamp.nativewindow.NativeWindow;
56import com.jogamp.nativewindow.NativeWindowFactory;
57import com.jogamp.nativewindow.UpstreamWindowHookMutableSizePos;
58import com.jogamp.nativewindow.swt.SWTAccessor;
59import com.jogamp.newt.swt.NewtCanvasSWT;
60import com.jogamp.newt.util.EDTUtil;
61import com.jogamp.newt.opengl.GLWindow;
62import com.jogamp.opengl.GLCapabilities;
63import com.jogamp.opengl.GLProfile;
64import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
65import com.jogamp.opengl.test.junit.util.GLTestUtil;
66import com.jogamp.opengl.test.junit.util.MiscUtils;
67import com.jogamp.opengl.test.junit.util.NewtTestUtil;
68import com.jogamp.opengl.test.junit.util.SWTTestUtil;
69import com.jogamp.opengl.test.junit.util.UITestCase;
71import jogamp.newt.swt.SWTEDTUtil;
86@FixMethodOrder(MethodSorters.NAME_ASCENDING)
89 static int duration = 250;
91 Display display =
null;
93 Composite composite =
null;
95 protected void init() throws InterruptedException, InvocationTargetException {
99 display =
new Display();
100 Assert.assertNotNull( display );
102 shell =
new Shell( display );
103 Assert.assertNotNull( shell );
104 shell.setLayout(
new GridLayout(3,
false) );
105 shell.setBackground(
new Color(display, 0, 0, 255));
106 new Text(shell, SWT.NONE).setText(
"1");
107 new Text(shell, SWT.NONE).setText(
"2");
108 new Text(shell, SWT.NONE).setText(
"3");
109 new Text(shell, SWT.NONE).setText(
"4");
110 composite =
new Composite( shell, SWT.NO_BACKGROUND );
111 composite.setLayout(
new FillLayout() );
112 composite.setBackground(
new Color(display, 0, 255, 0));
113 final GridData gd =
new GridData (GridData.FILL, GridData.FILL,
true ,
true );
114 composite.setLayoutData(gd);
115 new Text(shell, SWT.NONE).setText(
"6");
116 new Text(shell, SWT.NONE).setText(
"7");
117 new Text(shell, SWT.NONE).setText(
"8");
118 new Text(shell, SWT.NONE).setText(
"9");
119 Assert.assertNotNull( composite );
123 protected void release(
final GLWindow glwin)
throws InterruptedException, InvocationTargetException {
124 Assert.assertNotNull( display );
125 Assert.assertNotNull( shell );
126 Assert.assertNotNull( composite );
140 protected void runTest() throws InterruptedException, InvocationTargetException {
152 final EDTUtil edtUtil =
new SWTEDTUtil(newtDisplay, display);
156 final Canvas canvas[] = {
null };
158 display.syncExec(
new Runnable() {
161 canvas[0] =
new Canvas (composite, SWT.NO_BACKGROUND);
164 canvas[0].setBackground(
new Color(display, 255, 255, 255));
165 shell.setText( getClass().getName() );
166 shell.setBounds( 0, 0, 700, 700 );
173 final Listener listener =
new Listener () {
175 public void handleEvent (
final Event event) {
176 switch (event.type) {
182 final Rectangle nClientArea = canvas[0].getClientArea();
183 if(
null != nClientArea ) {
184 upstreamSizePosHook.
setSurfaceSize(nClientArea.width, nClientArea.height);
185 upstreamSizePosHook.
setWinSize(nClientArea.width, nClientArea.height);
186 upstreamSizePosHook.
setWinPos(nClientArea.x, nClientArea.y);
187 if( SWT.Resize == event.type ) {
188 glwin.
setSize(nClientArea.width, nClientArea.height);
199 canvas[0].addListener (SWT.Move, listener);
200 canvas[0].addListener (SWT.Resize, listener);
201 canvas[0].addListener (SWT.Paint, listener);
202 canvas[0].addListener (SWT.Dispose, listener);
204 final Rectangle r = canvas[0].getClientArea();
206 glwin.
setSize(r.width, r.height);
219 final long lStartTime = System.currentTimeMillis();
220 final long lEndTime = lStartTime + duration;
221 while( System.currentTimeMillis() < lEndTime && !composite.isDisposed() ) {
230 public void test() throws InterruptedException, InvocationTargetException {
234 public static void main(
final String args[]) {
235 for(
int i=0; i<args.length; i++) {
236 if(args[i].equals(
"-time")) {
Provides a pluggable mechanism for arbitrary window toolkits to adapt their components to the NativeW...
static AbstractGraphicsDevice createDevice(final String displayConnection, final boolean own)
Creates a native device type, following getNativeWindowType(true).
static NativeWindow createWrappedWindow(final AbstractGraphicsScreen aScreen, final long surfaceHandle, final long windowHandle, final UpstreamWindowHookMutableSizePos hook)
Creates a wrapped NativeWindow with given native handles and AbstractGraphicsScreen.
static AbstractGraphicsScreen createScreen(final AbstractGraphicsDevice device, int screen)
final void setSurfaceSize(final int width, final int height)
Resizes the upstream surface.
final void setWinSize(final int winWidth, final int winHeight)
final void setWinPos(final int winX, final int winY)
static void invokeOnOSTKThread(final boolean blocking, final Runnable runnable)
Runs the specified action in an SWT compatible OS toolkit thread, which is:
static long getWindowHandle(final Control swtControl)
static void printInfo(final PrintStream out, final Display d)
abstract EDTUtil setEDTUtil(EDTUtil usrEDTUtil)
Sets a new EDTUtil and returns the previous one.
abstract Display getDisplay()
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
final ReparentOperation reparentWindow(final NativeWindow newParent, final int x, final int y, final int hints)
Change this window's parent window.
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
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.
Tests utilizing SWTAccessor#getWindowHandle(org.eclipse.swt.widgets.Control) for NEWT native window r...
static void main(final String args[])
void release(final GLWindow glwin)
static boolean waitForRealized(final GLAutoDrawable glad, final boolean realized, final Runnable waitAction)
static int atoi(final String str, final int def)
static boolean waitForVisible(final Window win, final boolean visible, final Runnable waitAction)
A interface describing a graphics screen in a toolkit-independent manner.
Extend the NativeSurface interface with windowing information such as window-handle,...
EDT stands for Event Dispatch Thread.
void start()
Starts the EDT after it's creation or after stopping.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.