summaryrefslogtreecommitdiffstats
path: root/src/newt/classes
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-10-09 02:10:19 +0200
committerSven Gothel <[email protected]>2013-10-09 02:10:19 +0200
commit56502090ba5c2e0c266666a4ba3ddd501e9ad95f (patch)
tree59ab9e12de5be7b78f83360f0fe7009d433751a6 /src/newt/classes
parent88291cd5e20fc8b172f1d78a683be7d2bdec807a (diff)
NEWT Display: Issue EDTUtil.start() at runOnEDTIfAvail(..) even if on EDT, which is to be stopped.
This case appears on e.g. OSX/CALayer (offscreen) reparenting using recreation (onscreen <-> offscreen), i.e. display destroy/create is performed on EDT. Misc Cleanup: - Rename EDTUtil: restart() -> start() - Rename Display: validateEDT() -> validateEDTStopped() - Simplify Display.setEDTUtil(..): Remove need for redundant 'newEDTUtil' local var. - Simplify Display.runOnEDTIfAvail(..): edtUtil is never null
Diffstat (limited to 'src/newt/classes')
-rw-r--r--src/newt/classes/com/jogamp/newt/Display.java2
-rw-r--r--src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java2
-rw-r--r--src/newt/classes/com/jogamp/newt/util/EDTUtil.java10
-rw-r--r--src/newt/classes/jogamp/newt/DefaultEDTUtil.java6
-rw-r--r--src/newt/classes/jogamp/newt/DisplayImpl.java54
-rw-r--r--src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java2
-rw-r--r--src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java2
7 files changed, 39 insertions, 39 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java
index c618405c2..382a5d583 100644
--- a/src/newt/classes/com/jogamp/newt/Display.java
+++ b/src/newt/classes/com/jogamp/newt/Display.java
@@ -78,7 +78,7 @@ public abstract class Display {
* Stop the running EDT in case this display is destroyed already.<br>
* @return true if EDT has been stopped (destroyed but running), otherwise false.
*/
- public abstract boolean validateEDT();
+ public abstract boolean validateEDTStopped();
/**
* @return true if the native display handle is valid and ready to operate,
diff --git a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
index 47dfca0f3..2fa83e0e2 100644
--- a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
+++ b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java
@@ -346,7 +346,7 @@ public class NewtCanvasSWT extends Canvas implements WindowClosingProtocol {
{
final Display newtDisplay = newtChild.getScreen().getDisplay();
final EDTUtil edtUtil = new SWTEDTUtil(newtDisplay, getDisplay());
- edtUtil.restart();
+ edtUtil.start();
newtDisplay.setEDTUtil( edtUtil );
}
diff --git a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
index e86df2084..52ca95682 100644
--- a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
+++ b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
@@ -65,10 +65,10 @@ public interface EDTUtil {
public void setPollPeriod(long ms);
/**
- * Starts or restarts the EDT.
+ * Starts the EDT after it's creation or after {@link #invokeStop(boolean, Runnable) stopping}.
* <p>
- * If the EDT is running, it must be stopped first via {@link #invokeStop(boolean, Runnable)}
- * and the caller should wait until it's stopped via {@link #waitUntilStopped()}.
+ * If the EDT is running, it must be {@link #invokeStop(boolean, Runnable) stopped} first
+ * and the caller should wait {@link #waitUntilStopped() until it's stopped}.
* </p>
*
* @return true if EDT has been successfully restarted, otherwise false
@@ -77,7 +77,7 @@ public interface EDTUtil {
* @see #invokeStop(boolean, java.lang.Runnable)
* @see #waitUntilStopped()
*/
- public boolean restart() throws IllegalStateException;
+ public boolean start() throws IllegalStateException;
/**
* Returns true if the current thread is the event dispatch thread (EDT).
@@ -130,7 +130,7 @@ public interface EDTUtil {
* <li>All previous queued tasks will be finished.</li>
* <li>No new tasks are allowed, an Exception is thrown.</li>
* <li>Can be issued from within EDT, ie from within an enqueued task.</li>
- * <li>{@link #restart()} may follow immediately, ie creating a new EDT</li>
+ * <li>{@link #start()} may follow immediately, ie creating a new EDT</li>
* </ul>
* </p>
* @return true if <code>task</code> has been executed or queued for later execution, otherwise false
diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
index 5794d4ae9..3d1037ad5 100644
--- a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
+++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java
@@ -77,7 +77,7 @@ public class DefaultEDTUtil implements EDTUtil {
}
@Override
- public final boolean restart() throws IllegalStateException {
+ public final boolean start() throws IllegalStateException {
synchronized(edtLock) {
if( edt.isRunning() ) {
throw new IllegalStateException("EDT still running and not subject to stop. Curr "+Thread.currentThread().getName()+", EDT "+edt.getName()+", isRunning "+edt.isRunning+", shouldStop "+edt.shouldStop);
@@ -135,6 +135,10 @@ public class DefaultEDTUtil implements EDTUtil {
@Override
public final boolean invokeStop(boolean wait, Runnable task) {
+ if(DEBUG) {
+ System.err.println(Thread.currentThread()+": Default-EDT.invokeStop wait "+wait);
+ Thread.dumpStack();
+ }
return invokeImpl(wait, task, true);
}
diff --git a/src/newt/classes/jogamp/newt/DisplayImpl.java b/src/newt/classes/jogamp/newt/DisplayImpl.java
index 8f792b23c..0f47c87a0 100644
--- a/src/newt/classes/jogamp/newt/DisplayImpl.java
+++ b/src/newt/classes/jogamp/newt/DisplayImpl.java
@@ -170,7 +170,7 @@ public abstract class DisplayImpl extends Display {
if(NewtFactory.useEDT()) {
def = new DefaultEDTUtil(Thread.currentThread().getThreadGroup(), "Display-"+getFQName(), dispatchMessagesRunnable);
if(DEBUG) {
- System.err.println("Display.createNative("+getFQName()+") Create EDTUtil: "+def.getClass().getName());
+ System.err.println("Display.createEDTUtil("+getFQName()+"): "+def.getClass().getName());
}
} else {
def = null;
@@ -181,21 +181,18 @@ public abstract class DisplayImpl extends Display {
@Override
public synchronized EDTUtil setEDTUtil(final EDTUtil usrEDTUtil) {
final EDTUtil oldEDTUtil = edtUtil;
- final EDTUtil newEDTUtil;
if( null != usrEDTUtil && usrEDTUtil == oldEDTUtil ) {
if( DEBUG ) {
System.err.println("Display.setEDTUtil: "+usrEDTUtil+" - keep!");
}
- newEDTUtil = oldEDTUtil;
- } else {
- if(DEBUG) {
- final String msg = ( null == usrEDTUtil ) ? "default" : "custom";
- System.err.println("Display.setEDTUtil("+msg+"): "+oldEDTUtil+" -> "+usrEDTUtil);
- }
- stopEDT( oldEDTUtil, null );
- newEDTUtil = ( null == usrEDTUtil ) ? createEDTUtil() : usrEDTUtil;
+ return oldEDTUtil;
+ }
+ if(DEBUG) {
+ final String msg = ( null == usrEDTUtil ) ? "default" : "custom";
+ System.err.println("Display.setEDTUtil("+msg+"): "+oldEDTUtil+" -> "+usrEDTUtil);
}
- edtUtil = newEDTUtil;
+ stopEDT( oldEDTUtil, null );
+ edtUtil = ( null == usrEDTUtil ) ? createEDTUtil() : usrEDTUtil;
return oldEDTUtil;
}
@@ -224,31 +221,30 @@ public abstract class DisplayImpl extends Display {
public void runOnEDTIfAvail(boolean wait, final Runnable task) {
final EDTUtil _edtUtil = edtUtil;
- if( null != _edtUtil && !_edtUtil.isCurrentThreadEDT() ) {
- if( !_edtUtil.isRunning() ) { // start EDT if not running yet
- synchronized( this ) {
- if( !_edtUtil.isRunning() ) { // // volatile dbl-checked-locking OK
- _edtUtil.restart();
- if( DEBUG ) {
- System.err.println("Info: EDT started "+Thread.currentThread().getName()+", "+this);
- Thread.dumpStack();
- }
+ if( !_edtUtil.isRunning() ) { // start EDT if not running yet
+ synchronized( this ) {
+ if( !_edtUtil.isRunning() ) { // // volatile dbl-checked-locking OK
+ if( DEBUG ) {
+ System.err.println("Info: EDT start "+Thread.currentThread().getName()+", "+this);
+ Thread.dumpStack();
}
+ _edtUtil.start();
}
}
- if( !_edtUtil.invoke(wait, task) ) {
- if( DEBUG ) {
- System.err.println("Warning: invoke(wait "+wait+", ..) on EDT failed .. invoke on current thread "+Thread.currentThread().getName());
- Thread.dumpStack();
- }
- task.run();
+ }
+ if( !_edtUtil.isCurrentThreadEDT() ) {
+ if( _edtUtil.invoke(wait, task) ) {
+ return; // done
+ }
+ if( DEBUG ) {
+ System.err.println("Warning: invoke(wait "+wait+", ..) on EDT failed .. invoke on current thread "+Thread.currentThread().getName());
+ Thread.dumpStack();
}
- } else {
- task.run();
}
+ task.run();
}
- public boolean validateEDT() {
+ public boolean validateEDTStopped() {
if( 0==refCount && null == aDevice ) {
final EDTUtil _edtUtil = edtUtil;
if( null != _edtUtil && _edtUtil.isRunning() ) {
diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java
index 80c72c008..02f4be0cd 100644
--- a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java
+++ b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java
@@ -68,7 +68,7 @@ public class AWTEDTUtil implements EDTUtil {
}
@Override
- public final boolean restart() throws IllegalStateException {
+ public final boolean start() throws IllegalStateException {
synchronized(edtLock) {
if( nedt.isRunning() ) {
throw new IllegalStateException("EDT still running and not subject to stop. Curr "+Thread.currentThread().getName()+", NEDT "+nedt.getName()+", isRunning "+nedt.isRunning+", shouldStop "+nedt.shouldStop+", on AWT-EDT "+EventQueue.isDispatchThread());
diff --git a/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java b/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java
index d46562050..6024195e3 100644
--- a/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java
+++ b/src/newt/classes/jogamp/newt/swt/SWTEDTUtil.java
@@ -77,7 +77,7 @@ public class SWTEDTUtil implements EDTUtil {
}
@Override
- public final boolean restart() throws IllegalStateException {
+ public final boolean start() throws IllegalStateException {
final boolean swtDisposed = swtDisplay.isDisposed();
synchronized(edtLock) {
if( nedt.isRunning() ) {