aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes/com/sun
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2009-10-12 02:07:44 -0700
committerSven Gothel <[email protected]>2009-10-12 02:07:44 -0700
commiteab82899e93c0f72df6c7f4bfba5ad252a36013e (patch)
tree33ab60783b2701f405271c734fd608b15600b4e0 /src/newt/classes/com/sun
parent7a2103506ba9e570737da6af4e156c3bf06fe765 (diff)
X11 Display Lock completed (hope so)
- JOGL GLXUtil - JOGL X11GLXDrawableFactory - JOGL X11GLXGraphicsConfigurationFactory - JOGL X11OffscreenGLXDrawable - NW X11GraphicsConfigurationFactory NEWT Display - Stop EDT immediatly from within EDT when destroying - NEWT Window - Remove obsolete 'disposeSurfaceHandle()' NEWT GLWindow destroy(): - Deep destruction (Window, Screen and Display) if owner, otherwise just the GLWindow/GLDrawable - Add 'sendDisposeEvent' flag, to allow avoiding sending dispose to all GLEventListeners in a critical shutdown, ie from within the browser. NEWT EDT - More fine grained locking - unlocked while event dispatching - double check locking - Fixed cases where we are running on the EDT ..
Diffstat (limited to 'src/newt/classes/com/sun')
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/Display.java5
-rw-r--r--src/newt/classes/com/sun/javafx/newt/OffscreenWindow.java6
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/Window.java7
-rw-r--r--src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java56
-rw-r--r--src/newt/classes/com/sun/javafx/newt/util/EventDispatchThread.java55
-rwxr-xr-xsrc/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java11
6 files changed, 62 insertions, 78 deletions
diff --git a/src/newt/classes/com/sun/javafx/newt/Display.java b/src/newt/classes/com/sun/javafx/newt/Display.java
index 97d5465c9..a4b7a4f51 100755
--- a/src/newt/classes/com/sun/javafx/newt/Display.java
+++ b/src/newt/classes/com/sun/javafx/newt/Display.java
@@ -203,20 +203,21 @@ public abstract class Display {
}
if(null!=eventDispatchThread) {
final Display f_dpy = this;
+ final EventDispatchThread f_edt = eventDispatchThread;
eventDispatchThread.invokeAndWait(new Runnable() {
public void run() {
f_dpy.closeNative();
+ f_edt.stop();
}
} );
} else {
closeNative();
}
- aDevice = null;
if(null!=eventDispatchThread) {
- eventDispatchThread.stop();
eventDispatchThread.waitUntilStopped();
eventDispatchThread=null;
}
+ aDevice = null;
} else {
if(DEBUG) {
System.err.println("Display.destroy("+name+") KEEP: refCount "+refCount+", "+this+" "+Thread.currentThread());
diff --git a/src/newt/classes/com/sun/javafx/newt/OffscreenWindow.java b/src/newt/classes/com/sun/javafx/newt/OffscreenWindow.java
index b5efc03e8..11ce8e6c7 100644
--- a/src/newt/classes/com/sun/javafx/newt/OffscreenWindow.java
+++ b/src/newt/classes/com/sun/javafx/newt/OffscreenWindow.java
@@ -68,15 +68,11 @@ public class OffscreenWindow extends Window implements SurfaceChangeable {
public void invalidate() {
super.invalidate();
- disposeSurfaceHandle();
- }
-
- public void disposeSurfaceHandle() {
surfaceHandle = 0;
}
public synchronized void destroy() {
- disposeSurfaceHandle();
+ surfaceHandle = 0;
}
public void setSurfaceHandle(long handle) {
diff --git a/src/newt/classes/com/sun/javafx/newt/Window.java b/src/newt/classes/com/sun/javafx/newt/Window.java
index 8260b1a16..58bd251d2 100755
--- a/src/newt/classes/com/sun/javafx/newt/Window.java
+++ b/src/newt/classes/com/sun/javafx/newt/Window.java
@@ -411,13 +411,6 @@ public abstract class Window implements NativeWindow
return windowHandle; // default: return window handle
}
- /** Special method to dispose a surface handle,
- in case of a device change _and_ where there
- is a different semantics of window handle and surface handle.
- This is currently only true for Windows. */
- public void disposeSurfaceHandle() {
- }
-
public AbstractGraphicsConfiguration getGraphicsConfiguration() {
return config;
}
diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java b/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java
index aebf8f9dd..e809d2cdc 100644
--- a/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java
@@ -54,14 +54,14 @@ import java.util.*;
public class GLWindow extends Window implements GLAutoDrawable {
private static List/*GLWindow*/ glwindows = new ArrayList();
- private boolean ownerOfDisplayAndScreen;
+ private boolean ownerOfWinScrDpy;
private Window window;
private boolean runPumpMessages;
/** Constructor. Do not call this directly -- use {@link
create()} instead. */
- protected GLWindow(Window window, boolean ownerOfDisplayAndScreen) {
- this.ownerOfDisplayAndScreen = ownerOfDisplayAndScreen;
+ protected GLWindow(Window window, boolean ownerOfWinScrDpy) {
+ this.ownerOfWinScrDpy = ownerOfWinScrDpy;
this.window = window;
this.window.setAutoDrawableClient(true);
this.runPumpMessages = ( null == getScreen().getDisplay().getEDT() ) ;
@@ -118,18 +118,18 @@ public class GLWindow extends Window implements GLAutoDrawable {
GLCapabilities caps,
boolean undecorated) {
Display display;
- boolean ownerOfDisplayAndScreen=false;
+ boolean ownerOfWinScrDpy=false;
if (window == null) {
if (caps == null) {
caps = new GLCapabilities(null); // default ..
}
- ownerOfDisplayAndScreen = true;
+ ownerOfWinScrDpy = true;
display = NewtFactory.createDisplay(null); // local display
Screen screen = NewtFactory.createScreen(display, 0); // screen 0
window = NewtFactory.createWindow(screen, caps, undecorated);
}
- return new GLWindow(window, ownerOfDisplayAndScreen);
+ return new GLWindow(window, ownerOfWinScrDpy);
}
/**
@@ -165,13 +165,15 @@ public class GLWindow extends Window implements GLAutoDrawable {
shouldNotCallThis();
}
- protected void dispose(boolean regenerate) {
+ protected void dispose(boolean regenerate, boolean sendEvent) {
if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) {
- Exception e1 = new Exception("GLWindow.dispose("+regenerate+") "+Thread.currentThread()+", 1: "+this);
+ Exception e1 = new Exception("GLWindow.dispose("+regenerate+") "+Thread.currentThread()+", 1");
e1.printStackTrace();
}
- sendDisposeEvent();
+ if(sendEvent) {
+ sendDisposeEvent();
+ }
if (context != null) {
context.destroy();
@@ -180,10 +182,6 @@ public class GLWindow extends Window implements GLAutoDrawable {
drawable.setRealized(false);
}
- if(null!=window) {
- window.disposeSurfaceHandle();
- }
-
if(regenerate) {
if(null==window) {
throw new GLException("GLWindow.dispose(true): null window");
@@ -208,10 +206,11 @@ public class GLWindow extends Window implements GLAutoDrawable {
}
public synchronized void destroy() {
- destroy(false);
+ destroy(true);
}
- public synchronized void destroy(boolean deep) {
+ /** @param sendDisposeEvent should be false in a [time,reliable] critical shutdown */
+ public synchronized void destroy(boolean sendDisposeEvent) {
if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) {
Exception e1 = new Exception("GLWindow.destroy "+Thread.currentThread()+", 1: "+this);
e1.printStackTrace();
@@ -221,34 +220,21 @@ public class GLWindow extends Window implements GLAutoDrawable {
newglw.remove(this);
glwindows=newglw;
- dispose(false);
+ dispose(false, sendDisposeEvent);
- Screen _screen = null;
- Display _device = null;
if(null!=window) {
- if(!deep && ownerOfDisplayAndScreen) {
- _screen = getScreen();
- if(null != _screen) {
- _device = _screen.getDisplay();
- }
+ if(ownerOfWinScrDpy) {
+ window.destroy(true);
}
- window.destroy(deep);
- }
-
- if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) {
- System.out.println("GLWindow.destroy "+Thread.currentThread()+", fin: "+this);
}
drawable = null;
context = null;
+ window = null;
- if(null != _screen) {
- _screen.destroy();
- }
- if(null != _device) {
- _device.destroy();
+ if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) {
+ System.out.println("GLWindow.destroy "+Thread.currentThread()+", fin: "+this);
}
- window = null;
}
public boolean getPerfLogEnabled() { return perfLog; }
@@ -453,7 +439,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
window.getScreen().getDisplay().pumpMessages();
}
if(window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED) {
- dispose(true);
+ dispose(true, true);
}
if (sendDestroy) {
destroy();
diff --git a/src/newt/classes/com/sun/javafx/newt/util/EventDispatchThread.java b/src/newt/classes/com/sun/javafx/newt/util/EventDispatchThread.java
index e5a98cc55..a98ebab93 100644
--- a/src/newt/classes/com/sun/javafx/newt/util/EventDispatchThread.java
+++ b/src/newt/classes/com/sun/javafx/newt/util/EventDispatchThread.java
@@ -55,7 +55,7 @@ public class EventDispatchThread {
public EventDispatchThread(Display display, ThreadGroup tg, String name) {
this.display = display;
this.threadGroup = tg;
- this.name=new String("EDT-"+name);
+ this.name=new String("EDT-Display_"+display.getName()+"-"+name);
}
public String getName() { return name; }
@@ -101,8 +101,12 @@ public class EventDispatchThread {
}
}
- public boolean isEDTThread(Thread thread) {
- return taskWorker == thread;
+ public boolean isThreadEDT(Thread thread) {
+ return null!=taskWorker && taskWorker == thread;
+ }
+
+ public boolean isCurrentThreadEDT() {
+ return null!=taskWorker && taskWorker == Thread.currentThread();
}
public boolean isRunning() {
@@ -114,8 +118,13 @@ public class EventDispatchThread {
return;
}
synchronized(taskWorkerLock) {
- tasks.add(task);
- taskWorkerLock.notifyAll();
+ if(null!=taskWorker && taskWorker.isRunning() && taskWorker != Thread.currentThread() ) {
+ tasks.add(task);
+ taskWorkerLock.notifyAll();
+ } else {
+ // if !running or isEDTThread, do it right away
+ task.run();
+ }
}
}
@@ -173,29 +182,39 @@ public class EventDispatchThread {
}
}
+ /**
+ * Utilizing taskWorkerLock only for local resources and task execution,
+ * not for event dispatching.
+ */
public void run() {
if(DEBUG) {
System.out.println(Thread.currentThread()+": EDT run() START");
}
while(!shouldStop) {
try {
- // wait for something todo ..
- synchronized(taskWorkerLock) {
- while(!shouldStop && tasks.size()==0) {
- try {
- display.pumpMessages(); // event dispatch
- taskWorkerLock.wait(edtPollGranularity);
- } catch (InterruptedException e) {
- e.printStackTrace();
+ // wait for something todo
+ while(!shouldStop && tasks.size()==0) {
+ synchronized(taskWorkerLock) {
+ if(!shouldStop && tasks.size()==0) {
+ try {
+ taskWorkerLock.wait(edtPollGranularity);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
}
- if(tasks.size()>0) {
- Runnable task = (Runnable) tasks.remove(0);
- task.run();
- taskWorkerLock.notifyAll();
+ display.pumpMessages(); // event dispatch
+ }
+ if(!shouldStop && tasks.size()>0) {
+ synchronized(taskWorkerLock) {
+ if(!shouldStop && tasks.size()>0) {
+ Runnable task = (Runnable) tasks.remove(0);
+ task.run();
+ taskWorkerLock.notifyAll();
+ }
}
+ display.pumpMessages(); // event dispatch
}
- display.pumpMessages(); // event dispatch
} catch (Throwable t) {
// handle errors ..
t.printStackTrace();
diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java
index 5749039aa..1b5bf80cf 100755
--- a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java
+++ b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java
@@ -106,17 +106,6 @@ public class WindowsWindow extends Window {
return false;
}
- public void disposeSurfaceHandle() {
- if (0!=hdc && 0!=windowHandle) {
- ReleaseDC(windowHandle, hdc);
- hdc=0;
- if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
- Exception e = new Exception("!!! Window surface handle disposed "+Thread.currentThread().getName()+", "+Thread.currentThread());
- e.printStackTrace();
- }
- }
- }
-
protected void createNative(long parentWindowHandle, Capabilities caps) {
WindowsScreen screen = (WindowsScreen) getScreen();
WindowsDisplay display = (WindowsDisplay) screen.getDisplay();