29package com.jogamp.opengl.test.junit.jogl.swt;
31import java.awt.AWTException;
33import java.lang.reflect.InvocationTargetException;
35import org.eclipse.swt.SWT ;
36import org.eclipse.swt.layout.FillLayout ;
37import org.eclipse.swt.widgets.Composite ;
38import org.eclipse.swt.widgets.Display ;
39import org.eclipse.swt.widgets.Shell ;
40import org.junit.Assert;
41import org.junit.Assume;
43import org.junit.FixMethodOrder;
44import org.junit.runners.MethodSorters;
51import com.jogamp.opengl.GLProfile;
52import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
53import com.jogamp.common.util.InterruptSource;
54import com.jogamp.common.util.InterruptedRuntimeException;
55import com.jogamp.nativewindow.swt.SWTAccessor;
56import com.jogamp.newt.NewtFactory;
57import com.jogamp.newt.event.KeyAdapter;
58import com.jogamp.newt.event.KeyEvent;
61import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
62import com.jogamp.opengl.test.junit.util.MiscUtils;
63import com.jogamp.opengl.test.junit.util.NewtTestUtil;
64import com.jogamp.opengl.test.junit.util.SWTTestUtil;
65import com.jogamp.opengl.test.junit.util.TestUtil;
66import com.jogamp.opengl.test.junit.util.UITestCase;
71@FixMethodOrder(MethodSorters.NAME_ASCENDING)
74 static int duration = 500;
78 float r = 0f, g = 0f, b = 0f;
93 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height )
102 gl.
glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ) ;
154 static class ResizeThread
extends InterruptSource.Thread {
155 volatile boolean shallStop =
false;
156 private final Shell _shell ;
159 public ResizeThread(
final Shell shell )
164 final Runnable resizeAction =
new Runnable() {
168 System.err.println(
"[R-i shallStop "+shallStop+
", disposed "+_shell.isDisposed()+
"]");
169 if( shallStop || _shell.isDisposed() ) {
174 _shell.setSize( 200, 200 ) ;
176 _shell.setSize( 400, 450 ) ;
178 }
catch (
final Exception e0) {
179 e0.printStackTrace();
180 Assert.assertTrue(
"Deadlock @ setSize: "+e0,
false);
196 System.err.println(
"[R-0 shallStop "+shallStop+
", disposed "+_shell.isDisposed()+
"]");
198 final Display display = _shell.getDisplay();
200 while( !shallStop && !_shell.isDisposed() )
204 System.err.println(
"[R-n shallStop "+shallStop+
", disposed "+_shell.isDisposed()+
"]");
205 display.asyncExec( resizeAction );
208 java.lang.Thread.sleep( 50L ) ;
209 }
catch(
final InterruptedException e ) {
210 throw new InterruptedRuntimeException(e);
213 System.err.println(
"*R-Exit* shallStop "+shallStop+
", disposed "+_shell.isDisposed());
219 static class KeyfireThread
extends InterruptSource.Thread
221 volatile boolean shallStop =
false;
226 public KeyfireThread(
final Robot robot,
final Display display)
236 System.err.println(
"[K-0]");
241 System.err.println(
"[K-"+_n+
"]");
245 java.lang.Thread.sleep( 40L ) ;
247 if(!_display.isDisposed()) {
250 }
catch(
final InterruptedException e ) {
254 System.err.println(
"*K-Exit*");
260 private volatile boolean shallStop =
false;
262 static class SWT_DSC {
263 volatile Display display;
264 volatile Shell shell;
265 volatile Composite composite;
272 display =
new Display();
273 Assert.assertNotNull( display );
276 display.syncExec(
new Runnable() {
279 shell =
new Shell( display );
280 Assert.assertNotNull( shell );
281 shell.setLayout(
new FillLayout() );
282 composite =
new Composite( shell, SWT.NO_BACKGROUND );
283 composite.setLayout(
new FillLayout() );
284 Assert.assertNotNull( composite );
289 public void dispose() {
290 Assert.assertNotNull( display );
291 Assert.assertNotNull( shell );
292 Assert.assertNotNull( composite );
294 display.syncExec(
new Runnable() {
306 catch(
final Throwable throwable ) {
307 throwable.printStackTrace();
308 Assume.assumeNoException( throwable );
310 swtNewtDisplay =
null;
318 public void test() throws InterruptedException, AWTException, InvocationTargetException {
350 final SWT_DSC dsc =
new SWT_DSC();
353 final Robot robot =
new Robot();
364 public void keyReleased(
final com.jogamp.newt.event.KeyEvent e) {
365 if( !e.isPrintableKey() || e.isAutoRepeat() ) {
368 System.err.print(
".");
375 dsc.display.syncExec(
new Runnable() {
378 dsc.shell.setText(
"NewtCanvasSWT Resize Bug Demo" ) ;
379 dsc.shell.setSize( 400, 450 ) ;
393 final ResizeThread resizer;
395 resizer =
new ResizeThread( dsc.shell ) ;
399 final KeyfireThread keyfire;
401 keyfire =
new KeyfireThread( robot, dsc.display ) ;
406 final Thread t =
new InterruptSource.Thread(
null,
new Runnable() {
410 Thread.sleep(duration);
411 }
catch (
final InterruptedException e) {}
412 resizer.shallStop =
true;
413 keyfire.shallStop =
true;
417 }
catch(
final InterruptedException e ) { }
421 }
catch(
final InterruptedException e ) { }
423 if(
null != dsc.display && !dsc.display.isDisposed() ) {
432 while( !shallStop && !dsc.display.isDisposed() ) {
433 generalWaitAction.run();
435 }
catch (
final Exception e0) {
436 e0.printStackTrace();
437 Assert.assertTrue(
"Deadlock @ dispatch: "+e0,
false);
445 public static void main(
final String[] args ) {
446 for(
int i=0; i<args.length; i++) {
447 if(args[i].equals(
"-time")) {
451 System.out.println(
"durationPerTest: "+duration);
static void invokeOnOSTKThread(final boolean blocking, final Runnable runnable)
Runs the specified action in an SWT compatible OS toolkit thread, which is:
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.
static final short VK_0
VK_0 thru VK_9 are the same as UTF16/ASCII '0' thru '9' [0x30 - 0x39].
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
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.
static NewtCanvasSWT create(final Composite parent, final int style, final Window child)
Creates an instance using NewtCanvasSWT(Composite, int, Window) on the SWT thread.
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
static void main(final String[] args)
static void setMouseToClientLocation(Robot robot, final Object obj, final int x, final int y)
static int newtKeyPress(final int i, final Robot robot, final boolean press, final short newtKeyCode, final int msDelay)
No validation is performed .
static void requestFocus(final Robot robot, final Object obj)
FIXME: AWTRobotUtil Cleanup: Use specific type for argument object.
static void waitForIdle(final Robot robot)
Issuing validateAWTEDTIsAlive() before calling Robot#waitForIdle().
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
void glOrtho(double left, double right, double bottom, double top, double near_val, double far_val)
void glBegin(int mode)
Entry point to C language function: void {@native glBegin}(GLenum mode) Part of GL_VERSION_1_0
void glVertex2f(float x, float y)
Entry point to C language function: void {@native glVertex2f}(GLfloat x, GLfloat y) Part of GL_VER...
void glEnd()
Entry point to C language function: void {@native glEnd}() Part of GL_VERSION_1_0
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
GL2 getGL2()
Casts this object to the GL2 interface.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" wit...
static final int GL_LINE_SMOOTH
Common in ES1, GL2 and GL3.
static final int GL_ONE_MINUS_SRC_ALPHA
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_ONE_MINUS_SRC_ALPHA" ...
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
static final int GL_SRC_ALPHA
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_SRC_ALPHA" with expre...
void glEnable(int cap)
Entry point to C language function: void {@native glEnable}(GLenum cap) Part of GL_ES_VERSION_2_0,...
void glBlendFunc(int sfactor, int dfactor)
Entry point to C language function: void {@native glBlendFunc}(GLenum sfactor, GLenum dfactor) Par...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
void glViewport(int x, int y, int width, int height)
Entry point to C language function: void {@native glViewport}(GLint x, GLint y, GLsizei width,...
static final int GL_BLEND
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_BLEND" with expressio...
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" wit...
static final int GL_LINES
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_LINES" with expressio...
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
static final int GL_MODELVIEW
Matrix mode modelview.
void glLoadIdentity()
Load the current matrix with the identity matrix.
void glMatrixMode(int mode)
Sets the current matrix mode.
void glColor4f(float red, float green, float blue, float alpha)