From d186f6e945fd157b219231fb3861b3b0ce10ee75 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 13 Oct 2011 17:04:17 +0200 Subject: OSX/SWT: Adding OSXUtil: RunOnMainThread(), IsMainThread() / Utilizing those for SWT access/calls Adding OSXUtil: RunOnMainThread(), IsMainThread() - Issuing a native call where the user Runnable is to be performed on the main thread - Enable query if we are on the main thread. Utilizing those for SWT access/calls - Using the above to call all SWT functions on the main thread if required (incomplete) TODO/Issues: - JOGL OSX CGL Context fails, ie expecting NS, but having CGL --- .../opengl/test/junit/jogl/swt/TestSWT02GLn.java | 51 +++++++++++++++++----- 1 file changed, 39 insertions(+), 12 deletions(-) (limited to 'src/test/com/jogamp/opengl') diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT02GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT02GLn.java index 1ee374895..3e153214b 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT02GLn.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT02GLn.java @@ -38,6 +38,7 @@ import org.eclipse.swt.events.PaintEvent; import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.opengl.GLCanvas; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; @@ -83,14 +84,26 @@ public class TestSWT02GLn extends UITestCase { @Before public void init() { - display = new Display(); - Assert.assertNotNull( display ); - shell = new Shell( display ); + final Display[] r = new Display[1]; + final Shell[] s = new Shell[1]; + SWTAccessor.invoke(true, new Runnable() { + public void run() { + r[0] = new Display(); + s[0] = new Shell(); + } + }); + display = r[0]; + shell = s[0]; + Assert.assertNotNull( display ); Assert.assertNotNull( shell ); - shell.setLayout( new FillLayout() ); - composite = new Composite( shell, SWT.NONE ); - composite.setLayout( new FillLayout() ); - Assert.assertNotNull( composite ); + + SWTAccessor.invoke(true, new Runnable() { + public void run() { + shell.setLayout( new FillLayout() ); + composite = new Composite( shell, SWT.NONE ); + Assert.assertNotNull( composite ); + composite.setLayout( new FillLayout() ); + }}); } @After @@ -99,9 +112,12 @@ public class TestSWT02GLn extends UITestCase { Assert.assertNotNull( shell ); Assert.assertNotNull( composite ); try { - composite.dispose(); - shell.dispose(); - display.dispose(); + SWTAccessor.invoke(true, new Runnable() { + public void run() { + composite.dispose(); + shell.dispose(); + display.dispose(); + }}); } catch( Throwable throwable ) { throwable.printStackTrace(); @@ -111,14 +127,25 @@ public class TestSWT02GLn extends UITestCase { shell = null; composite = null; } - + + class CanvasCStr implements Runnable { + Canvas canvas; + + public void run() { + canvas = new Canvas( composite, SWT.NO_BACKGROUND); + } + } + protected void runTestAGL( GLProfile glprofile ) throws InterruptedException { GLCapabilities caps = new GLCapabilities(glprofile); GLDrawableFactory factory = GLDrawableFactory.getFactory(glprofile); // need SWT.NO_BACKGROUND to prevent SWT from clearing the window // at the wrong times (we use glClear for this instead) - final Canvas canvas = new Canvas( composite, SWT.NO_BACKGROUND); + CanvasCStr canvasCstr = new CanvasCStr(); + + SWTAccessor.invoke(true, canvasCstr); + final Canvas canvas = canvasCstr.canvas; Assert.assertNotNull( canvas ); SWTAccessor.setRealized(canvas, true); -- cgit v1.2.3