aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-12-02 04:14:30 +0100
committerSven Gothel <[email protected]>2012-12-02 04:14:30 +0100
commit571c21df9310d043b08a4a72064617cbe6eee0fa (patch)
treef3dadac35a175cf63d4dd7862881366a58349d33
parentaa4b8c9abbf9529fdbb3c4982895c01f2698451f (diff)
SWT GLCanvas/NewtCanvasSWT: Check isVisible() @ validation; NewtCanvasSWT remove just introduced setVisible(false) and adapt to setEDTUtil() changes. ; Enhance Bug 643 unit test: Also test NEWT EDT and pre-visible GLWindow.
- SWT GLCanvas/NewtCanvasSWT: Check isVisible() @ validation - NewtCanvasSWT remove just introduced setVisible(false) and adapt to setEDTUtil() changes - Enhance Bug 643 unit test: Also test NEWT EDT and pre-visible GLWindow.
-rwxr-xr-xmake/scripts/java-win64-dbg.bat1
-rw-r--r--src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java2
-rw-r--r--src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java15
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlock.java6
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java150
5 files changed, 114 insertions, 60 deletions
diff --git a/make/scripts/java-win64-dbg.bat b/make/scripts/java-win64-dbg.bat
index c7e8ea599..7ececa5e4 100755
--- a/make/scripts/java-win64-dbg.bat
+++ b/make/scripts/java-win64-dbg.bat
@@ -46,6 +46,7 @@ REM set D_ARGS="-Djogl.debug.DebugGL" "-Djogl.debug.GLDebugMessageHandler" "-Djo
REM set D_ARGS="-Djogl.debug.GLContext" "-Dnewt.debug=all"
REM set D_ARGS="-Dnewt.debug.Window" "-Dnativewindow.debug.TraceLock"
REM set D_ARGS="-Dnativewindow.debug.TraceLock"
+REM set D_ARGS="-Dnewt.debug.Display" "-Dnewt.debug.EDT" "-Dnewt.debug.Window"
REM set D_ARGS="-Dnewt.debug.Window" "-Dnewt.debug.Display" "-Dnewt.debug.EDT" "-Djogl.debug.GLContext"
REM set D_ARGS="-Dnewt.debug.Screen" "-Dnewt.debug.EDT" "-Dnativewindow.debug=all"
REM set D_ARGS="-Dnewt.debug.Window" "-Dnewt.debug.Display" "-Dnewt.test.Window.reparent.incompatible=true"
diff --git a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java
index 38dd71f5e..a080a7045 100644
--- a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java
+++ b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java
@@ -423,7 +423,7 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
/** assumes drawable == null ! */
protected final boolean validateDrawableAndContext() {
- if( GLCanvas.this.isDisposed() ) {
+ if( isDisposed() || !isVisible() ) {
return false;
}
final Rectangle nClientArea = clientArea;
diff --git a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
index 18036b68b..5af7afeb3 100644
--- a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
+++ b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
@@ -171,7 +171,7 @@ public class NewtCanvasSWT extends Canvas implements WindowClosingProtocol {
/** assumes nativeWindow == null ! */
protected final boolean validateNative() {
- if( isDisposed() ) {
+ if( isDisposed() || !isVisible() ) {
return false;
}
updateSizeCheck();
@@ -347,22 +347,19 @@ public class NewtCanvasSWT extends Canvas implements WindowClosingProtocol {
updateSizeCheck();
final int w = clientArea.width;
final int h = clientArea.height;
-
+
// set SWT EDT and start it
{
final Display newtDisplay = newtChild.getScreen().getDisplay();
- final EDTUtil edt = new SWTEDTUtil(newtDisplay, getDisplay());
- newtDisplay.setEDTUtil(edt);
- edt.invoke(true, null); // start EDT
+ newtDisplay.setEDTUtil( new SWTEDTUtil(newtDisplay, getDisplay()) );
}
- newtChild.setVisible(false); // set invisible to force defineSize(w,h) in WindowImpl since event dispatching might be postponed
- newtChild.setSize(w, h);
+ newtChild.setSize(w, h);
newtChild.reparentWindow(nativeWindow);
newtChild.setVisible(true);
- configureNewtChild(true);
+ configureNewtChild(true);
newtChild.sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener
-
+
// force this SWT Canvas to be focus-able,
// since it is completely covered by the newtChild (z-order).
setEnabled(true);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlock.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlock.java
index 834261d22..a0874e609 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlock.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlock.java
@@ -341,7 +341,7 @@ public class TestNewtCanvasSWTBug628ResizeDeadlock extends UITestCase {
}
{
- new Thread(new Runnable() {
+ final Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
@@ -359,7 +359,9 @@ public class TestNewtCanvasSWTBug628ResizeDeadlock extends UITestCase {
} catch( InterruptedException e ) { }
shallStop = true;
dsc.display.wake();
- } } ).start();
+ } } );
+ t.setDaemon(true);
+ t.start();
}
try {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java
index ccea76c02..0a47b96eb 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java
@@ -50,10 +50,13 @@ import junit.framework.Assert;
import com.jogamp.nativewindow.swt.SWTAccessor;
import com.jogamp.newt.opengl.GLWindow ;
import com.jogamp.newt.swt.NewtCanvasSWT ;
+import com.jogamp.newt.swt.SWTEDTUtil;
import com.jogamp.opengl.swt.GLCanvas;
import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
import com.jogamp.opengl.test.junit.util.MiscUtils;
import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.Animator;
////////////////////////////////////////////////////////////////////////////////
@@ -61,69 +64,93 @@ import com.jogamp.opengl.test.junit.util.UITestCase;
public class TestSWTBug643AsyncExec extends UITestCase {
static int duration = 500;
+ static boolean useAnimator = false;
////////////////////////////////////////////////////////////////////////////////
- static void resetAsyncExecCount() {
- synchronized(asyncExecCountSync) {
- asyncExecCount=0;
+ static void resetSWTAndNEWTEDTCounter() {
+ synchronized(swtCountSync) {
+ swtCount=0;
+ }
+ synchronized(edtCountSync) {
+ edtCount=0;
+ }
+ }
+ static int incrSWTCount() {
+ synchronized(swtCountSync) {
+ swtCount++;
+ return swtCount;
+ }
+ }
+ static int getSWTCount() {
+ synchronized(swtCountSync) {
+ return swtCount;
}
}
- static int incrAsyncExecCount() {
- synchronized(asyncExecCountSync) {
- asyncExecCount++;
- return asyncExecCount;
+ static int incrNEWTCount() {
+ synchronized(edtCountSync) {
+ edtCount++;
+ return edtCount;
}
}
- static int getAsyncExecCount() {
- synchronized(asyncExecCountSync) {
- return asyncExecCount;
+ static int getNEWTCount() {
+ synchronized(edtCountSync) {
+ return edtCount;
}
}
- static Object asyncExecCountSync = new Object();
- static int asyncExecCount = 0;
+ static Object swtCountSync = new Object();
+ static int swtCount = 0;
+ static Object edtCountSync = new Object();
+ static int edtCount = 0;
////////////////////////////////////////////////////////////////////////////////
- static class AsyncExecFeederThread extends Thread {
+ static class AsyncExecEDTFeederThread extends Thread {
volatile boolean shallStop = false;
- private Display display ;
- private int n ;
+ private Display swtDisplay ;
+ private jogamp.newt.DisplayImpl newtDisplay;
+ private int swtN, newtN ;
- public AsyncExecFeederThread( Display display )
+ public AsyncExecEDTFeederThread( Display swtDisplay, com.jogamp.newt.Display newtDisplay )
{
super();
- this.display = display ;
+ this.swtDisplay = swtDisplay ;
+ this.newtDisplay = (jogamp.newt.DisplayImpl)newtDisplay;
}
- final Runnable asyncAction = new Runnable() {
+ final Runnable swtAsyncAction = new Runnable() {
public void run()
{
- ++n ;
- System.err.println("[A-i shallStop "+shallStop+", disposed "+display.isDisposed()+"]: Counter[loc "+n+", glob: "+incrAsyncExecCount()+"]");
+ ++swtN ;
+ System.err.println("[SWT A-i shallStop "+shallStop+"]: Counter[loc "+swtN+", glob: "+incrSWTCount()+"]");
+ } };
+
+ final Runnable newtAsyncAction = new Runnable() {
+ public void run()
+ {
+ ++newtN ;
+ System.err.println("[NEWT A-i shallStop "+shallStop+"]: Counter[loc "+newtN+", glob: "+incrNEWTCount()+"]");
} };
public void run()
{
- System.err.println("[A-0 shallStop "+shallStop+", disposed "+display.isDisposed()+"]");
-
- // final Display d = Display.getDefault();
- final Display d = this.display;
+ System.err.println("[A-0 shallStop "+shallStop+"]");
- while( !shallStop && !d.isDisposed() )
+ while( !shallStop && !swtDisplay.isDisposed() )
{
try
{
- System.err.println("[A-n shallStop "+shallStop+", disposed "+d.isDisposed()+"]");
- d.asyncExec( asyncAction );
- d.wake();
-
+ swtDisplay.asyncExec( swtAsyncAction );
+ if(null != newtDisplay && newtDisplay.isNativeValid() && newtDisplay.getEDTUtil().isRunning()) {
+ // only perform async exec on valid and already running NEWT EDT!
+ newtDisplay.runOnEDTIfAvail(false, newtAsyncAction);
+ }
Thread.sleep( 50L ) ;
} catch( InterruptedException e ) {
break ;
}
}
- System.err.println("*R-Exit* shallStop "+shallStop+", disposed "+d.isDisposed());
+ System.err.println("*R-Exit* shallStop "+shallStop);
}
}
@@ -179,12 +206,13 @@ public class TestSWTBug643AsyncExec extends UITestCase {
}
}
- private void testImpl(boolean useJOGLGLCanvas, boolean useNewtCanvasSWT) throws InterruptedException, AWTException, InvocationTargetException {
- resetAsyncExecCount();
+ private void testImpl(boolean useJOGLGLCanvas, boolean useNewtCanvasSWT, boolean glWindowPreVisible) throws InterruptedException, AWTException, InvocationTargetException {
+ resetSWTAndNEWTEDTCounter();
final SWT_DSC dsc = new SWT_DSC();
dsc.init();
+ final com.jogamp.newt.Display newtDisplay;
{
final GLProfile gl2Profile = GLProfile.get( GLProfile.GL2 ) ;
final GLCapabilities caps = new GLCapabilities( gl2Profile ) ;
@@ -192,42 +220,58 @@ public class TestSWTBug643AsyncExec extends UITestCase {
final GLAutoDrawable glad;
if( useJOGLGLCanvas ) {
glad = GLCanvas.create(dsc.composite, 0, caps, null, null);
+ glad.addGLEventListener( new GearsES2() ) ;
+ newtDisplay = null;
} else if( useNewtCanvasSWT ) {
final GLWindow glWindow = GLWindow.create( caps ) ;
+ glWindow.addGLEventListener( new GearsES2() ) ;
+ newtDisplay = glWindow.getScreen().getDisplay();
+ if( glWindowPreVisible ) {
+ newtDisplay.setEDTUtil(new SWTEDTUtil(newtDisplay, dsc.display)); // Especially Windows requires creation access via same thread!
+ glWindow.setVisible(true);
+ AWTRobotUtil.waitForRealized(glWindow, true);
+ Thread.sleep(120); // let it render a bit, before consumed by SWT
+ }
glad = glWindow;
NewtCanvasSWT.create( dsc.composite, 0, glWindow ) ;
} else {
throw new InternalError("XXX");
}
- glad.addGLEventListener( new GearsES2() ) ;
+ if(useAnimator) {
+ Animator animator = new Animator(glad);
+ animator.start();
+ }
}
+ System.err.println("**** Pre Shell Open");
dsc.display.syncExec( new Runnable() {
public void run() {
dsc.shell.setText( "NewtCanvasSWT Resize Bug Demo" ) ;
dsc.shell.setSize( 400, 450 ) ;
dsc.shell.open() ;
} } );
+ System.err.println("**** Post Shell Open");
shallStop = false;
+
+ final int[] counterBeforeExit = new int[] { 0 /* SWT */, 0 /* NEWT */ };
- final int[] ayncExecCountBeforeExit = new int[] { 0 };
-
- final AsyncExecFeederThread asyncExecFeeder;
+ final AsyncExecEDTFeederThread asyncExecFeeder;
{
- asyncExecFeeder = new AsyncExecFeederThread( dsc.display) ;
+ asyncExecFeeder = new AsyncExecEDTFeederThread(dsc.display, newtDisplay) ;
asyncExecFeeder.start() ;
}
{
- new Thread(new Runnable() {
+ final Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(duration);
} catch (InterruptedException e) {}
- ayncExecCountBeforeExit[0] = getAsyncExecCount();
+ counterBeforeExit[0] = getSWTCount();
+ counterBeforeExit[1] = getNEWTCount();
asyncExecFeeder.shallStop = true;
try
{
@@ -235,15 +279,15 @@ public class TestSWTBug643AsyncExec extends UITestCase {
} catch( InterruptedException e ) { }
shallStop = true;
dsc.display.wake();
- } } ).start();
+ } } );
+ t.setDaemon(true);
+ t.start();
}
try {
final Display d = dsc.display;
while( !shallStop && !d.isDisposed() ) {
- final boolean r = d.readAndDispatch();
- System.err.print(",");
- if( !r ) {
+ if( !d.readAndDispatch() ) {
dsc.display.sleep();
}
}
@@ -256,24 +300,34 @@ public class TestSWTBug643AsyncExec extends UITestCase {
dsc.dispose();
- System.err.println("AsyncExecCount before exit: " + ayncExecCountBeforeExit[0]);
- Assert.assertTrue("AsyncExecCount not greater zero before dispose!", 0 < ayncExecCountBeforeExit[0]);
+ System.err.println("EDT Counter before exit: SWT " + counterBeforeExit[0] + ", NEWT "+counterBeforeExit[1]);
+ Assert.assertTrue("SWT EDT Counter not greater zero before dispose!", 0 < counterBeforeExit[0]);
+ if( null != newtDisplay ) {
+ Assert.assertTrue("NEWT EDT Counter not greater zero before dispose!", 0 < counterBeforeExit[1]);
+ }
}
@Test
public void test01JOGLGLCanvas() throws InterruptedException, AWTException, InvocationTargetException {
- testImpl(true /* useJOGLGLCanvas */, false /* useNewtCanvasSWT */);
+ testImpl(true /* useJOGLGLCanvas */, false /* useNewtCanvasSWT */, false /* glWindowPreVisible */);
+ }
+
+ @Test
+ public void test02NewtCanvasSWTSimple() throws InterruptedException, AWTException, InvocationTargetException {
+ testImpl(false /* useJOGLGLCanvas */, true /* useNewtCanvasSWT */, false /* glWindowPreVisible */);
}
@Test
- public void test02NewtCanvasSWT() throws InterruptedException, AWTException, InvocationTargetException {
- testImpl(false /* useJOGLGLCanvas */, true /* useNewtCanvasSWT */);
+ public void test02NewtCanvasSWTPreVisible() throws InterruptedException, AWTException, InvocationTargetException {
+ testImpl(false /* useJOGLGLCanvas */, true /* useNewtCanvasSWT */, true /* glWindowPreVisible */);
}
public static void main( String[] args ) {
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
duration = MiscUtils.atoi(args[++i], duration);
+ } else if(args[i].equals("-anim")) {
+ useAnimator = true;
}
}
System.out.println("durationPerTest: "+duration);