diff options
Diffstat (limited to 'src/newt/classes/com/jogamp')
5 files changed, 34 insertions, 117 deletions
diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java index df4d5b4f8..951b8b172 100755 --- a/src/newt/classes/com/jogamp/newt/Display.java +++ b/src/newt/classes/com/jogamp/newt/Display.java @@ -148,7 +148,9 @@ public abstract class Display { "Display_"+display.getName()+"-"+current.getName(), new Runnable() { public void run() { - f_dpy.pumpMessagesImpl(); + if(null!=f_dpy.getGraphicsDevice()) { + f_dpy.pumpMessagesImpl(); + } } } ); display.edt = display.edtUtil.start(); display.edtUtil.invokeAndWait(new Runnable() { diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index db1b694b9..1802cab8e 100755 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -39,6 +39,7 @@ import com.jogamp.newt.util.EDTUtil; import com.jogamp.common.util.*; import javax.media.nativewindow.*; +import com.jogamp.nativewindow.impl.RecursiveToolkitLock; import java.util.ArrayList; import java.util.Iterator; @@ -283,7 +284,6 @@ public abstract class Window implements NativeWindow /** Recursive and unblocking unlockSurface() implementation */ public synchronized void unlockSurface() throws NativeWindowException { surfaceLock.unlock( new Runnable() { - final Screen f_screen = screen; public void run() { screen.getDisplay().unlockDisplay(); } @@ -956,78 +956,7 @@ public abstract class Window implements NativeWindow return sb.toString(); } - // - // Reentrance locking toolkit - // - public static class WindowToolkitLock implements ToolkitLock { - private Thread owner; - private int recursionCount; - private Exception lockedStack = null; - - public Exception getLockedStack() { - return lockedStack; - } - - public Thread getOwner() { - return owner; - } - - public boolean isOwner() { - return isOwner(Thread.currentThread()); - } - - public synchronized boolean isOwner(Thread thread) { - return owner == thread ; - } - - public synchronized boolean isLocked() { - return null != owner; - } - - /** Recursive and blocking lockSurface() implementation */ - public synchronized void lock() { - Thread cur = Thread.currentThread(); - if (owner == cur) { - ++recursionCount; - return; - } - while (owner != null) { - try { - wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - owner = cur; - lockedStack = new Exception("Previously locked by "+owner); - } - - - /** Recursive and unblocking unlockSurface() implementation */ - public synchronized void unlock() { - unlock(null); - } - - /** Recursive and unblocking unlockSurface() implementation */ - public synchronized void unlock(Runnable releaseAfterUnlockBeforeNotify) { - Thread cur = Thread.currentThread(); - if (owner != cur) { - lockedStack.printStackTrace(); - throw new RuntimeException(cur+": Not owner, owner is "+owner); - } - if (recursionCount > 0) { - --recursionCount; - return; - } - owner = null; - lockedStack = null; - if(null!=releaseAfterUnlockBeforeNotify) { - releaseAfterUnlockBeforeNotify.run(); - } - notifyAll(); - } - } - private WindowToolkitLock destructionLock = new WindowToolkitLock(); - private WindowToolkitLock surfaceLock = new WindowToolkitLock(); + private RecursiveToolkitLock destructionLock = new RecursiveToolkitLock(); + private RecursiveToolkitLock surfaceLock = new RecursiveToolkitLock(); } diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java index 8fb095661..963c0c0a7 100755 --- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java @@ -34,6 +34,7 @@ package com.jogamp.newt.impl.macosx; import javax.media.nativewindow.*; +import com.jogamp.nativewindow.impl.RecursiveToolkitLock; import com.jogamp.newt.util.MainThread; import com.jogamp.newt.*; @@ -213,7 +214,7 @@ public class MacWindow extends Window { } } - private WindowToolkitLock nsViewLock = new WindowToolkitLock(); + private RecursiveToolkitLock nsViewLock = new RecursiveToolkitLock(); public synchronized int lockSurface() throws NativeWindowException { nsViewLock.lock(); diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java index 94d568f55..c2de0fe18 100755 --- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java +++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java @@ -79,16 +79,19 @@ public class X11Display extends Display { } protected void dispatchMessagesNative() { + if(0==getHandle()) { + throw new RuntimeException("display handle null"); + } DispatchMessages(getHandle(), javaObjectAtom, windowDeleteAtom); } protected void lockDisplay() { super.lockDisplay(); - LockDisplay(getHandle()); + X11Util.XLockDisplay(getHandle()); } protected void unlockDisplay() { - UnlockDisplay(getHandle()); + X11Util.XUnlockDisplay(getHandle()); super.unlockDisplay(); } @@ -100,9 +103,6 @@ public class X11Display extends Display { // private static native boolean initIDs(); - private native void LockDisplay(long handle); - private native void UnlockDisplay(long handle); - private native void CompleteDisplay(long handle); private native void DispatchMessages(long display, long javaObjectAtom, long windowDeleteAtom); diff --git a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java index f852bcf5c..2550eef82 100644 --- a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java +++ b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java @@ -62,27 +62,17 @@ public class EDTUtil { public ThreadGroup getThreadGroup() { return threadGroup; } - public Thread start() { - return start(false); - } - /** - * @param externalStimuli true indicates that another thread stimulates, - * ie. calls this TaskManager's run() loop method. - * Hence no own thread is started in this case. - * * @return The started Runnable, which handles the run-loop. - * Usefull in combination with externalStimuli=true, - * so an external stimuli can call it. */ - public Thread start(boolean externalStimuli) { + public Thread start() { synchronized(edtLock) { if(null==edt) { edt = new EventDispatchThread(threadGroup, name); } if(!edt.isRunning()) { shouldStop = false; - edt.start(externalStimuli); + edt.start(); } edtLock.notifyAll(); } @@ -166,7 +156,6 @@ public class EDTUtil { class EventDispatchThread extends Thread { boolean isRunning = false; - boolean externalStimuli = false; public EventDispatchThread(ThreadGroup tg, String name) { super(tg, name); @@ -176,14 +165,11 @@ public class EDTUtil { return isRunning; } - public void start(boolean externalStimuli) throws IllegalThreadStateException { + public void start() throws IllegalThreadStateException { synchronized(this) { - this.externalStimuli = externalStimuli; isRunning = true; } - if(!externalStimuli) { - super.start(); - } + super.start(); } /** @@ -194,8 +180,8 @@ public class EDTUtil { if(DEBUG) { System.out.println(Thread.currentThread()+": EDT run() START"); } - while(!shouldStop) { - try { + try { + while(!shouldStop) { // wait for something todo while(!shouldStop && tasks.size()==0) { synchronized(edtLock) { @@ -219,24 +205,23 @@ public class EDTUtil { } pumpMessages.run(); // event dispatch } - } catch (Throwable t) { - // handle errors .. - t.printStackTrace(); - } finally { - // epilog - unlock locked stuff } - if(externalStimuli) break; // no loop if called by external stimuli - } - synchronized(this) { - isRunning = !shouldStop; - } - if(!isRunning) { - synchronized(edtLock) { - edtLock.notifyAll(); + } catch (Throwable t) { + // handle errors .. + shouldStop = true; + throw new RuntimeException(t); + } finally { + synchronized(this) { + isRunning = !shouldStop; + } + if(!isRunning) { + synchronized(edtLock) { + edtLock.notifyAll(); + } + } + if(DEBUG) { + System.out.println(Thread.currentThread()+": EDT run() EXIT"); } - } - if(DEBUG) { - System.out.println(Thread.currentThread()+": EDT run() EXIT"); } } } |