From 63be4a40aa6ecfe9fbc6585acccbc6f6f6689377 Mon Sep 17 00:00:00 2001
From: Sven Gothel
* all other resources and states are kept intact,
- * ie listeners, parent handles and size, position etc.
setVisible(true)
.
* @see #destroy()
* @see #invalidate(boolean)
+ * @see #setVisible(boolean)
*/
- public void destroy(boolean deep) {
- if(!isDestroyed()) {
- runOnEDTIfAvail(true, new DestroyAction(deep));
+ public void destroy(boolean unrecoverable) {
+ if(isValid()) {
+ runOnEDTIfAvail(true, new DestroyAction(unrecoverable));
}
}
class DestroyAction implements Runnable {
- boolean deep;
- public DestroyAction(boolean deep) {
- this.deep = deep;
+ boolean unrecoverable;
+ public DestroyAction(boolean unrecoverable) {
+ this.unrecoverable = unrecoverable;
}
public void run() {
windowLock();
try {
if(DEBUG_IMPLEMENTATION) {
- System.out.println("Window.destroy(deep: "+deep+") START "+getThreadName()+", "+Window.this);
+ System.out.println("Window.destroy(unrecoverable: "+unrecoverable+") START "+getThreadName()+", "+Window.this);
}
// Childs first ..
synchronized(childWindowsLock) {
for(Iterator i = childWindows.iterator(); i.hasNext(); ) {
NativeWindow nw = (NativeWindow) i.next();
- System.out.println("Window.destroy(deep: "+deep+") CHILD BEGIN");
+ System.out.println("Window.destroy(unrecoverable: "+unrecoverable+") CHILD BEGIN");
if(nw instanceof Window) {
((Window)nw).sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
- if(deep) {
- ((Window)nw).destroy(deep);
+ if(unrecoverable) {
+ ((Window)nw).destroy(unrecoverable);
}
} else {
nw.destroy();
}
- System.out.println("Window.destroy(deep: "+deep+") CHILD END");
+ System.out.println("Window.destroy(unrecoverable: "+unrecoverable+") CHILD END");
}
}
// Now us ..
- if(deep) {
+ if(unrecoverable) {
synchronized(childWindowsLock) {
childWindows = new ArrayList();
}
@@ -444,24 +451,20 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer
mouseListeners = new ArrayList();
keyListeners = new ArrayList();
}
- Display dpy = null;
Screen scr = null;
if( null != screen && 0 != windowHandle ) {
scr = screen;
- dpy = screen.getDisplay();
- closeNative();
+ closeNativeImpl();
}
- invalidate(deep);
- if(deep) {
+ invalidate(unrecoverable);
+ if(unrecoverable) {
if(null!=scr) {
- scr.destroy();
- }
- if(null!=dpy) {
- dpy.destroy();
+ // only once .. at final destruction
+ scr.removeReference();
}
}
if(DEBUG_IMPLEMENTATION) {
- System.out.println("Window.destroy(deep: "+deep+") END "+getThreadName()+", "+Window.this);
+ System.out.println("Window.destroy(unrecoverable: "+unrecoverable+") END "+getThreadName()+", "+Window.this);
}
} finally {
windowUnlock();
@@ -486,18 +489,18 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer
}
/**
- * @param deep if false only the native window handle is invalidated, otherwise all
- * states (references and properties) are reset. Be aware that if you call
- * this method with deep = true, you will not be able to regenerate the Window.
+ * @param unrecoverable If true, all states, size, position, parent handles,
+ * reference to it's Screen are reset.
+ * Otherwise you can recreate the window, via setVisible(true)
.
* @see #invalidate()
* @see #destroy()
* @see #destroy(boolean)
*/
- public void invalidate(boolean deep) {
+ public void invalidate(boolean unrecoverable) {
windowLock();
try{
if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) {
- String msg = new String("!!! Window Invalidate(deep: "+deep+") "+getThreadName());
+ String msg = new String("!!! Window Invalidate(unrecoverable: "+unrecoverable+") "+getThreadName());
//System.out.println(msg);
Exception e = new Exception(msg);
e.printStackTrace();
@@ -506,7 +509,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer
visible = false;
fullscreen = false;
- if(deep) {
+ if(unrecoverable) {
screen = null;
parentWindowHandle = 0;
parentNativeWindow = null;
@@ -523,13 +526,24 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer
}
}
- /** @return true if the native window handle is valid and ready to operate */
- public boolean isNativeWindowValid() {
- return 0 != windowHandle ;
+ /** @return true if the native window handle is valid and ready to operate, ie
+ * if the native window has been created, otherwise false.
+ *
+ * @see #setVisible(boolean)
+ * @see #destroy(boolean)
+ */
+ public boolean isNativeValid() {
+ return null != screen && 0 != windowHandle ;
}
- public boolean isDestroyed() {
- return null == screen ;
+ /** @return True if native window is valid, can be created or recovered.
+ * Otherwise false, ie this window is unrecoverable due to a destroy(true)
call.
+ *
+ * @see #destroy(boolean)
+ * @see #setVisible(boolean)
+ */
+ public boolean isValid() {
+ return null != screen ;
}
public boolean surfaceSwap() {
@@ -713,7 +727,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer
* this Screen is being used.
*/
public void reparentWindow(NativeWindow newParent, Screen newScreen) {
- if(!isDestroyed()) {
+ if(isValid()) {
runOnEDTIfAvail(true, new ReparentAction(newParent, newScreen));
if( isVisible() ) {
sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener
@@ -730,7 +744,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer
public void run() {
windowLock();
try{
- if( !isDestroyed() ) {
+ if( isValid() ) {
if(!visible && childWindows.size()>0) {
synchronized(childWindowsLock) {
for(Iterator i = childWindows.iterator(); i.hasNext(); ) {
@@ -805,7 +819,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer
Exception ee = new Exception(msg);
ee.printStackTrace();
}
- if(!isDestroyed()) {
+ if(isValid()) {
runOnEDTIfAvail(true, new VisibleAction(visible));
}
}
@@ -985,7 +999,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer
}
public void enqueueEvent(boolean wait, com.jogamp.newt.event.NEWTEvent event) {
- if(!getInnerWindow().isDestroyed()) {
+ if(getInnerWindow().isValid()) {
getInnerWindow().getScreen().getDisplay().enqueueEvent(wait, event);
}
}
@@ -1523,7 +1537,7 @@ public abstract class Window implements NativeWindow, NEWTEventConsumer
enqueueWindowEvent(false, WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
- if(handleDestroyNotify && !isDestroyed()) {
+ if(handleDestroyNotify && isValid()) {
destroy();
}
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index 57647df5c..d7e75a5b9 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -55,7 +55,7 @@ import com.jogamp.newt.Window;
import com.jogamp.newt.impl.Debug;
public class NewtCanvasAWT extends java.awt.Canvas {
- public static final boolean DEBUG_IMPLEMENTATION = Debug.debug("Window");
+ public static final boolean DEBUG = Debug.debug("Window");
NativeWindow parent = null;
Window newtChild = null;
@@ -93,7 +93,7 @@ public class NewtCanvasAWT extends java.awt.Canvas {
class FocusActionImpl implements Runnable {
public final boolean result = false; // NEWT shall always proceed requesting the native focus
public void run() {
- if(DEBUG_IMPLEMENTATION) {
+ if(DEBUG) {
System.out.println("FocusActionImpl.run() "+Window.getThreadName());
}
NewtCanvasAWT.this.requestFocusAWTParent();
@@ -150,7 +150,7 @@ public class NewtCanvasAWT extends java.awt.Canvas {
super.addNotify();
disableBackgroundErase();
java.awt.Container cont = getContainer(this);
- if(DEBUG_IMPLEMENTATION) {
+ if(DEBUG) {
// if ( isShowing() == false ) -> Container was not visible yet.
// if ( isShowing() == true ) -> Container is already visible.
System.err.println("NewtCanvasAWT.addNotify: "+newtChild+", "+this+", visible "+isVisible()+", showing "+isShowing()+
@@ -161,7 +161,7 @@ public class NewtCanvasAWT extends java.awt.Canvas {
public void removeNotify() {
java.awt.Container cont = getContainer(this);
- if(DEBUG_IMPLEMENTATION) {
+ if(DEBUG) {
System.err.println("NewtCanvasAWT.removeNotify: "+newtChild+", from "+cont);
}
reparentWindow(false, cont);
@@ -178,15 +178,19 @@ public class NewtCanvasAWT extends java.awt.Canvas {
parent = NewtFactoryAWT.getNativeWindow(this, newtChild.getRequestedCapabilities());
}
if(null!=parent) {
- if(DEBUG_IMPLEMENTATION) {
+ if(DEBUG) {
System.err.println("NewtCanvasAWT.reparentWindow: "+newtChild);
}
setSize(cont.getWidth(), cont.getHeight());
newtChild.setSize(cont.getWidth(), cont.getHeight());
Screen screen = null;
- if( !newtChild.isNativeWindowValid() ) {
- screen = NewtFactoryAWT.createCompatibleScreen(parent);
+ if( !newtChild.isNativeValid() ) {
+ Screen currentScreen = newtChild.getScreen();
+ screen = NewtFactoryAWT.createCompatibleScreen(parent, currentScreen);
+ if( currentScreen != screen ) {
+ screen.setDestroyWhenUnused(true);
+ }
}
newtChild.reparentWindow(parent, screen);
newtChild.setVisible(true);
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java
index 6409ab7a8..bd5a6cd73 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtFactoryAWT.java
@@ -86,15 +86,57 @@ public class NewtFactoryAWT extends NewtFactory {
}
public static Screen createCompatibleScreen(NativeWindow parent) {
+ return createCompatibleScreen(parent, null);
+ }
+
+ public static Screen createCompatibleScreen(NativeWindow parent, Screen childScreen) {
// Get parent's NativeWindow details
AWTGraphicsConfiguration parentConfig = (AWTGraphicsConfiguration) parent.getGraphicsConfiguration();
AWTGraphicsScreen parentScreen = (AWTGraphicsScreen) parentConfig.getScreen();
AWTGraphicsDevice parentDevice = (AWTGraphicsDevice) parentScreen.getDevice();
- // Prep NEWT's Display and Screen according to the parent
final String type = NativeWindowFactory.getNativeWindowType(true);
- Display display = NewtFactory.wrapDisplay(type, parentDevice.getHandle());
+
+ if(null != childScreen) {
+ // check if child Display/Screen is compatible already
+ Display childDisplay = childScreen.getDisplay();
+ String parentDisplayName = childDisplay.validateDisplayName(null, parentDevice.getHandle());
+ String childDisplayName = childDisplay.getName();
+ boolean displayEqual = parentDisplayName.equals( childDisplayName );
+ boolean screenEqual = parentScreen.getIndex() == childScreen.getIndex();
+ if(DEBUG_IMPLEMENTATION) {
+ System.out.println("NewtFactoryAWT.createCompatibleScreen: Display: "+
+ parentDisplayName+" =? "+childDisplayName+" : "+displayEqual+"; Screen: "+
+ parentScreen.getIndex()+" =? "+childScreen.getIndex()+" : "+screenEqual);
+ }
+ if( displayEqual && screenEqual ) {
+ // match: display/screen
+ return childScreen;
+ }
+ }
+
+ // Prep NEWT's Display and Screen according to the parent
+ Display display = NewtFactory.createDisplay(type, parentDevice.getHandle());
return NewtFactory.createScreen(type, display, parentScreen.getIndex());
}
+
+ public static boolean isScreenCompatible(NativeWindow parent, Screen childScreen) {
+ // Get parent's NativeWindow details
+ AWTGraphicsConfiguration parentConfig = (AWTGraphicsConfiguration) parent.getGraphicsConfiguration();
+ AWTGraphicsScreen parentScreen = (AWTGraphicsScreen) parentConfig.getScreen();
+ AWTGraphicsDevice parentDevice = (AWTGraphicsDevice) parentScreen.getDevice();
+
+ Display childDisplay = childScreen.getDisplay();
+ String parentDisplayName = childDisplay.validateDisplayName(null, parentDevice.getHandle());
+ String childDisplayName = childDisplay.getName();
+ if( ! parentDisplayName.equals( childDisplayName ) ) {
+ return false;
+ }
+
+ if( parentScreen.getIndex() != childScreen.getIndex() ) {
+ return false;
+ }
+ return true;
+ }
}
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java
index 9f0944ea0..c5a60226f 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java
@@ -104,7 +104,7 @@ public class AWTParentWindowAdapter
if(DEBUG_IMPLEMENTATION) {
System.out.println("AWT: hierarchyChanged SHOWING_CHANGED: showing "+showing+", "+changed);
}
- if(!newtWindow.isDestroyed()) {
+ if(newtWindow.isValid()) {
newtWindow.runOnEDTIfAvail(false, new Runnable() {
public void run() {
newtWindow.setVisible(showing);
diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
index 875401544..5df853610 100644
--- a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
+++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java
@@ -131,7 +131,7 @@ public class AWTWindowAdapter
}
/**
if(null==newtListener) {
- if(!newtWindow.isDestroyed()) {
+ if(newtWindow.isValid()) {
newtWindow.runOnEDTIfAvail(false, new Runnable() {
public void run() {
newtWindow.setVisible(true);
@@ -148,7 +148,7 @@ public class AWTWindowAdapter
}
/**
if(null==newtListener) {
- if(!newtWindow.isDestroyed()) {
+ if(newtWindow.isValid()) {
newtWindow.runOnEDTIfAvail(false, new Runnable() {
public void run() {
newtWindow.setVisible(false);
diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java
index 92c4e53eb..c9c6c63fc 100644
--- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java
@@ -44,7 +44,7 @@ public class AWTDisplay extends Display {
public AWTDisplay() {
}
- protected void createNative() {
+ protected void createNativeImpl() {
aDevice = (AWTGraphicsDevice) AWTGraphicsDevice.createDevice(null); // default
}
@@ -52,7 +52,7 @@ public class AWTDisplay extends Display {
aDevice = d;
}
- protected void closeNative() { }
+ protected void closeNativeImpl() { }
protected boolean getShallRunOnEDT() {
return false;
diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTScreen.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTScreen.java
index 8702686c0..eec83d721 100644
--- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTScreen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTScreen.java
@@ -42,7 +42,7 @@ public class AWTScreen extends Screen {
public AWTScreen() {
}
- protected void createNative(int index) {
+ protected void createNativeImpl() {
aScreen = new AWTGraphicsScreen((AWTGraphicsDevice)display.getGraphicsDevice());
DisplayMode mode = ((AWTGraphicsDevice)getDisplay().getGraphicsDevice()).getGraphicsDevice().getDisplayMode();
@@ -60,6 +60,6 @@ public class AWTScreen extends Screen {
super.setScreenSize(w, h);
}
- protected void closeNative() { }
+ protected void closeNativeImpl() { }
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java
index db55aee6f..9da1eb860 100644
--- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTWindow.java
@@ -148,7 +148,7 @@ public class AWTWindow extends Window {
this.windowHandle = 1; // just a marker ..
}
- protected void closeNative() {
+ protected void closeNativeImpl() {
this.windowHandle = 0; // just a marker ..
if(null!=container) {
runOnEDT(true, new Runnable() {
diff --git a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java
index d19aaf796..c8e69dac6 100644
--- a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java
+++ b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Display.java
@@ -58,7 +58,7 @@ public class Display extends com.jogamp.newt.Display {
public Display() {
}
- protected void createNative() {
+ protected void createNativeImpl() {
synchronized(Display.class) {
if(0==initCounter) {
displayHandle = CreateDisplay();
@@ -71,7 +71,7 @@ public class Display extends com.jogamp.newt.Display {
aDevice = new DefaultGraphicsDevice(NativeWindowFactory.TYPE_DEFAULT, displayHandle);
}
- protected void closeNative() {
+ protected void closeNativeImpl() {
if(0==displayHandle) {
throw new NativeWindowException("displayHandle null; initCnt "+initCounter);
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Screen.java b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Screen.java
index 3d9a5a309..3aded5df3 100644
--- a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Screen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Screen.java
@@ -45,13 +45,13 @@ public class Screen extends com.jogamp.newt.Screen {
public Screen() {
}
- protected void createNative(int index) {
+ protected void createNativeImpl() {
AbstractGraphicsDevice adevice = getDisplay().getGraphicsDevice();
- GetScreenInfo(adevice.getHandle(), index);
- aScreen = new DefaultGraphicsScreen(adevice, index);
+ GetScreenInfo(adevice.getHandle(), idx);
+ aScreen = new DefaultGraphicsScreen(adevice, idx);
}
- protected void closeNative() { }
+ protected void closeNativeImpl() { }
//----------------------------------------------------------------------
// Internals only
diff --git a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java
index 14621807a..5f40a35ae 100644
--- a/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java
+++ b/src/newt/classes/com/jogamp/newt/impl/intel/gdl/Window.java
@@ -67,7 +67,7 @@ public class Window extends com.jogamp.newt.Window {
}
}
- protected void closeNative() {
+ protected void closeNativeImpl() {
if(0!=surfaceHandle) {
synchronized(Window.class) {
CloseSurface(getDisplayHandle(), surfaceHandle);
diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java
index 11f825282..9b8689114 100644
--- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java
@@ -65,31 +65,24 @@ public class MacDisplay extends Display {
dispatchMessages0();
}
- protected void createNative() {
+ protected void createNativeImpl() {
aDevice = new MacOSXGraphicsDevice();
}
- protected void closeNative() { }
+ protected void closeNativeImpl() { }
- public EDTUtil getEDTUtil() {
- if( null == edtUtil ) {
- synchronized (this) {
- if( null == edtUtil ) {
- if(NewtFactory.useEDT()) {
- final Display f_dpy = this;
- MainThread.addPumpMessage(this,
- new Runnable() {
- public void run() {
- if(null!=f_dpy.getGraphicsDevice()) {
- f_dpy.dispatchMessages();
- } } } );
- edtUtil = MainThread.getSingleton();
- edtUtil.start();
- }
- }
- }
+ protected void createEDTUtil() {
+ if(NewtFactory.useEDT()) {
+ final Display f_dpy = this;
+ MainThread.addPumpMessage(this,
+ new Runnable() {
+ public void run() {
+ if(null!=f_dpy.getGraphicsDevice()) {
+ f_dpy.dispatchMessages();
+ } } } );
+ edtUtil = MainThread.getSingleton();
+ edtUtil.start();
}
- return edtUtil;
}
protected void releaseEDTUtil() {
diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java
index d7deb13ee..317a3161c 100644
--- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacScreen.java
@@ -44,12 +44,12 @@ public class MacScreen extends Screen {
public MacScreen() {
}
- protected void createNative(int index) {
- aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index);
- setScreenSize(getWidthImpl0(getIndex()), getHeightImpl0(getIndex()));
+ protected void createNativeImpl() {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), idx);
+ setScreenSize(getWidthImpl0(idx), getHeightImpl0(idx));
}
- protected void closeNative() { }
+ protected void closeNativeImpl() { }
private static native int getWidthImpl0(int scrn_idx);
private static native int getHeightImpl0(int scrn_idx);
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 a8e6febf5..7571c05be 100644
--- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java
@@ -149,7 +149,7 @@ public class MacWindow extends Window {
}
}
- protected void closeNative() {
+ protected void closeNativeImpl() {
nsViewLock.lock();
try {
if(DEBUG_IMPLEMENTATION) { System.out.println("MacWindow.CloseAction "+Thread.currentThread().getName()); }
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java
index c2d323e56..8b8ce1f41 100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Display.java
@@ -56,7 +56,7 @@ public class Display extends com.jogamp.newt.Display {
public Display() {
}
- protected void createNative() {
+ protected void createNativeImpl() {
long handle = CreateDisplay(Screen.fixedWidth, Screen.fixedHeight);
if (handle == EGL.EGL_NO_DISPLAY) {
throw new NativeWindowException("BC EGL CreateDisplay failed");
@@ -64,7 +64,7 @@ public class Display extends com.jogamp.newt.Display {
aDevice = new EGLGraphicsDevice(handle);
}
- protected void closeNative() {
+ protected void closeNativeImpl() {
if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) {
DestroyDisplay(aDevice.getHandle());
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java
index e30896468..f38e7b4dc 100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Screen.java
@@ -45,12 +45,12 @@ public class Screen extends com.jogamp.newt.Screen {
public Screen() {
}
- protected void createNative(int index) {
- aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index);
+ protected void createNativeImpl() {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), idx);
setScreenSize(fixedWidth, fixedHeight);
}
- protected void closeNative() { }
+ protected void closeNativeImpl() { }
//----------------------------------------------------------------------
// Internals only
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java
index ca06699f5..d6b802a85 100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/broadcom/egl/Window.java
@@ -64,7 +64,7 @@ public class Window extends com.jogamp.newt.Window {
}
}
- protected void closeNative() {
+ protected void closeNativeImpl() {
if(0!=windowHandleClose) {
CloseWindow(getDisplayHandle(), windowHandleClose);
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java
index 2ab30773f..1845342a0 100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDDisplay.java
@@ -57,7 +57,7 @@ public class KDDisplay extends Display {
public KDDisplay() {
}
- protected void createNative() {
+ protected void createNativeImpl() {
// FIXME: map name to EGL_*_DISPLAY
long handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY);
if (handle == EGL.EGL_NO_DISPLAY) {
@@ -69,7 +69,7 @@ public class KDDisplay extends Display {
aDevice = new EGLGraphicsDevice(handle);
}
- protected void closeNative() {
+ protected void closeNativeImpl() {
if (aDevice.getHandle() != EGL.EGL_NO_DISPLAY) {
EGL.eglTerminate(aDevice.getHandle());
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java
index d570d9f5b..c7db047f6 100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDScreen.java
@@ -44,11 +44,11 @@ public class KDScreen extends Screen {
public KDScreen() {
}
- protected void createNative(int index) {
- aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index);
+ protected void createNativeImpl() {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), idx);
}
- protected void closeNative() { }
+ protected void closeNativeImpl() { }
// elevate access to this package ..
protected void setScreenSize(int w, int h) {
diff --git a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java
index 2f534548b..43e4ac021 100644
--- a/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/opengl/kd/KDWindow.java
@@ -78,7 +78,7 @@ public class KDWindow extends Window {
windowHandleClose = eglWindowHandle;
}
- protected void closeNative() {
+ protected void closeNativeImpl() {
if(0!=windowHandleClose) {
CloseWindow(windowHandleClose, windowUserData);
windowUserData=0;
diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java
index ef033d1c8..cfc35e1f8 100644
--- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java
+++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java
@@ -60,11 +60,11 @@ public class WindowsDisplay extends Display {
public WindowsDisplay() {
}
- protected void createNative() {
+ protected void createNativeImpl() {
aDevice = new WindowsGraphicsDevice();
}
- protected void closeNative() {
+ protected void closeNativeImpl() {
// Can't do .. only at application shutdown
// UnregisterWindowClass0(getWindowClassAtom(), getHInstance());
}
diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java
index 1b4be0d55..2197667cd 100644
--- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsScreen.java
@@ -45,12 +45,12 @@ public class WindowsScreen extends Screen {
public WindowsScreen() {
}
- protected void createNative(int index) {
- aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), index);
- setScreenSize(getWidthImpl0(getIndex()), getHeightImpl0(getIndex()));
+ protected void createNativeImpl() {
+ aScreen = new DefaultGraphicsScreen(getDisplay().getGraphicsDevice(), idx);
+ setScreenSize(getWidthImpl0(idx), getHeightImpl0(idx));
}
- protected void closeNative() { }
+ protected void closeNativeImpl() { }
private native int getWidthImpl0(int scrn_idx);
private native int getHeightImpl0(int scrn_idx);
diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java
index 69cd62201..15d9ac8b0 100644
--- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java
+++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java
@@ -115,14 +115,14 @@ public class WindowsWindow extends Window {
}
}
- protected void closeNative() {
+ protected void closeNativeImpl() {
if (hdc != 0) {
if(windowHandleClose != 0) {
try {
ReleaseDC0(windowHandleClose, hdc);
} catch (Throwable t) {
if(DEBUG_IMPLEMENTATION) {
- Exception e = new Exception("closeNative failed - "+Thread.currentThread().getName(), t);
+ Exception e = new Exception("closeNativeImpl failed - "+Thread.currentThread().getName(), t);
e.printStackTrace();
}
}
@@ -134,7 +134,7 @@ public class WindowsWindow extends Window {
DestroyWindow0(windowHandleClose);
} catch (Throwable t) {
if(DEBUG_IMPLEMENTATION) {
- Exception e = new Exception("closeNative failed - "+Thread.currentThread().getName(), t);
+ Exception e = new Exception("closeNativeImpl failed - "+Thread.currentThread().getName(), t);
e.printStackTrace();
}
} finally {
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 6701d6c8e..22b5e8470 100644
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java
@@ -61,26 +61,26 @@ public class X11Display extends Display {
public X11Display() {
}
- protected String validateDisplayName(String name, long handle) {
+ public String validateDisplayName(String name, long handle) {
return X11Util.validateDisplayName(name, handle);
}
- protected void createNative() {
- long handle = X11Util.createThreadLocalDisplay(name);
+ protected void createNativeImpl() {
+ long handle = X11Util.createDisplay(name);
if( 0 == handle ) {
throw new RuntimeException("Error creating display: "+name);
}
try {
CompleteDisplay0(handle);
} catch(RuntimeException e) {
- X11Util.closeThreadLocalDisplay(name);
+ X11Util.closeDisplay(handle);
throw e;
}
aDevice = new X11GraphicsDevice(handle);
}
- protected void closeNative() {
- X11Util.closeThreadLocalDisplay(name);
+ protected void closeNativeImpl() {
+ X11Util.closeDisplay(getHandle());
}
protected void dispatchMessagesNative() {
diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
index 453d8e5e1..aa53ea5d0 100644
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Screen.java
@@ -46,17 +46,17 @@ public class X11Screen extends Screen {
public X11Screen() {
}
- protected void createNative(int index) {
- long handle = GetScreen0(display.getHandle(), index);
+ protected void createNativeImpl() {
+ long handle = GetScreen0(display.getHandle(), idx);
if (handle == 0 ) {
- throw new RuntimeException("Error creating screen: "+index);
+ throw new RuntimeException("Error creating screen: "+idx);
}
- aScreen = new X11GraphicsScreen((X11GraphicsDevice)getDisplay().getGraphicsDevice(), index);
- setScreenSize(getWidth0(display.getHandle(), index),
- getHeight0(display.getHandle(), index));
+ aScreen = new X11GraphicsScreen((X11GraphicsDevice)getDisplay().getGraphicsDevice(), idx);
+ setScreenSize(getWidth0(display.getHandle(), idx),
+ getHeight0(display.getHandle(), idx));
}
- protected void closeNative() { }
+ protected void closeNativeImpl() { }
//----------------------------------------------------------------------
// Internals only
diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java
index 7a770f770..894de9ae5 100644
--- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java
+++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Window.java
@@ -67,7 +67,7 @@ public class X11Window extends Window {
windowHandleClose = windowHandle;
}
- protected void closeNative() {
+ protected void closeNativeImpl() {
if(0!=windowHandleClose && null!=getScreen() ) {
X11Display display = (X11Display) getScreen().getDisplay();
try {
@@ -75,7 +75,7 @@ public class X11Window extends Window {
display.getJavaObjectAtom(), display.getWindowDeleteAtom());
} catch (Throwable t) {
if(DEBUG_IMPLEMENTATION) {
- Exception e = new Exception("closeNative failed - "+Thread.currentThread().getName(), t);
+ Exception e = new Exception("closeNativeImpl failed - "+Thread.currentThread().getName(), t);
e.printStackTrace();
}
} finally {
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
index 99b4314a3..2aca37cab 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
@@ -82,8 +82,8 @@ public class GLWindow extends Window implements GLAutoDrawable {
if( !windowIsLocked() && null == getAnimator() ) {
destroy();
} else {
- sendDestroy = true;
- }
+ sendDestroy = true;
+ }
}
});
}
@@ -125,12 +125,12 @@ public class GLWindow extends Window implements GLAutoDrawable {
return new GLWindow(window);
}
- public boolean isNativeWindowValid() {
- return (null!=window)?window.isNativeWindowValid():false;
+ public boolean isNativeValid() {
+ return (null!=window)?window.isNativeValid():false;
}
- public boolean isDestroyed() {
- return (null!=window)?window.isDestroyed():true;
+ public boolean isValid() {
+ return (null!=window)?window.isValid():true;
}
public final Window getInnerWindow() {
@@ -145,7 +145,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
shouldNotCallThis();
}
- protected void closeNative() {
+ protected void closeNativeImpl() {
shouldNotCallThis();
}
@@ -158,23 +158,23 @@ public class GLWindow extends Window implements GLAutoDrawable {
private DisposeAction disposeAction = new DisposeAction();
class DestroyAction implements Runnable {
- boolean deep;
- public DestroyAction(boolean deep) {
- this.deep = deep;
+ boolean unrecoverable;
+ public DestroyAction(boolean unrecoverable) {
+ this.unrecoverable = unrecoverable;
}
public void run() {
// Lock: Have to cover whole workflow (dispose all, context, drawable and window)
windowLock();
try {
- if( isDestroyed() ) {
+ if( !isValid() ) {
return; // nop
}
if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) {
- Exception e1 = new Exception("GLWindow.destroy("+deep+") "+Thread.currentThread()+", start: "+GLWindow.this);
+ Exception e1 = new Exception("GLWindow.destroy("+unrecoverable+") "+Thread.currentThread()+", start: "+GLWindow.this);
e1.printStackTrace();
}
- if( window.isNativeWindowValid() && null != drawable && drawable.isRealized() ) {
+ if( window.isNativeValid() && null != drawable && drawable.isRealized() ) {
if( null != context && context.isCreated() ) {
// Catch dispose GLExceptions by GLEventListener, just 'print' them
// so we can continue with the destruction.
@@ -193,14 +193,14 @@ public class GLWindow extends Window implements GLAutoDrawable {
}
if(null!=window) {
- window.destroy(deep);
+ window.destroy(unrecoverable);
}
- if(deep) {
+ if(unrecoverable) {
helper=null;
}
if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) {
- System.out.println("GLWindow.destroy("+deep+") "+Thread.currentThread()+", fin: "+GLWindow.this);
+ System.out.println("GLWindow.destroy("+unrecoverable+") "+Thread.currentThread()+", fin: "+GLWindow.this);
}
} finally {
windowUnlock();
@@ -208,15 +208,9 @@ public class GLWindow extends Window implements GLAutoDrawable {
}
}
- /**
- * @param deep If true, all resources, ie listeners, parent handles, size, position
- * and the referenced NEWT screen and display, will be destroyed as well. Be aware that if you call
- * this method with deep = true, you will not be able to regenerate the Window.
- * @see #destroy()
- */
- public void destroy(boolean deep) {
- if( !isDestroyed() ) {
- runOnEDTIfAvail(true, new DestroyAction(deep));
+ public void destroy(boolean unrecoverable) {
+ if( isValid() ) {
+ runOnEDTIfAvail(true, new DestroyAction(unrecoverable));
}
}
@@ -269,7 +263,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
}
public void setVisible(boolean visible) {
- if(!isDestroyed()) {
+ if(isValid()) {
runOnEDTIfAvail(true, new VisibleAction(visible));
}
}
@@ -512,17 +506,17 @@ public class GLWindow extends Window implements GLAutoDrawable {
if( null == window ) { return; }
if(sendDestroy || ( null!=window && window.hasDeviceChanged() && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED ) ) {
- sendDestroy=false;
- destroy();
- return;
- }
+ sendDestroy=false;
+ destroy();
+ return;
+ }
if( null == context && window.isVisible() ) {
// retry native window and drawable/context creation
setVisible(true);
}
- if( window.isVisible() && window.isNativeWindowValid() && null != context ) {
+ if( window.isVisible() && window.isNativeValid() && null != context ) {
if(forceReshape) {
sendReshape = true;
}
diff --git a/src/newt/classes/com/jogamp/newt/util/DefaultEDTUtil.java b/src/newt/classes/com/jogamp/newt/util/DefaultEDTUtil.java
index 87dfdb9d8..96bfc50e0 100644
--- a/src/newt/classes/com/jogamp/newt/util/DefaultEDTUtil.java
+++ b/src/newt/classes/com/jogamp/newt/util/DefaultEDTUtil.java
@@ -47,8 +47,8 @@ public class DefaultEDTUtil implements EDTUtil {
private ThreadGroup threadGroup;
private volatile boolean shouldStop = false;
private EventDispatchThread edt = null;
- private Object edtLock = new Object();
- private ArrayList tasks = new ArrayList(); // one shot tasks
+ private Object edtLock = new Object(); // locking the EDT start/stop state
+ private ArrayList edtTasks = new ArrayList(); // one shot tasks
private String name;
private Runnable pumpMessages;
@@ -56,123 +56,137 @@ public class DefaultEDTUtil implements EDTUtil {
this.threadGroup = tg;
this.name=new String(Thread.currentThread().getName()+"-"+"EDT-"+name);
this.pumpMessages=pumpMessages;
+ this.edt = new EventDispatchThread(threadGroup, name);
}
- public void start() {
+ public final void reset() {
synchronized(edtLock) {
- if(null==edt) {
- edt = new EventDispatchThread(threadGroup, name);
+ waitUntilStopped();
+ if(edtTasks.size()>0) {
+ throw new RuntimeException("Remaining EDTTasks: "+edtTasks.size());
}
+ this.edt = new EventDispatchThread(threadGroup, name);
+ }
+ }
+
+ public final void start() {
+ synchronized(edtLock) {
if(!edt.isRunning()) {
shouldStop = false;
edt.start();
+ if(DEBUG) {
+ System.out.println(Thread.currentThread()+": EDT START");
+ }
}
- edtLock.notifyAll();
}
}
- public void stop() {
+ public final void stop() {
synchronized(edtLock) {
- if(null!=edt && edt.isRunning()) {
+ if(edt.isRunning()) {
shouldStop = true;
+ if(DEBUG) {
+ System.out.println(Thread.currentThread()+": EDT signal STOP");
+ }
}
edtLock.notifyAll();
- if(DEBUG) {
- System.out.println(Thread.currentThread()+": EDT signal STOP");
- }
}
}
- public boolean isCurrentThreadEDT() {
- return null!=edt && edt == Thread.currentThread();
- }
-
- public boolean isRunning() {
- return null!=edt && edt.isRunning() ;
+ public final boolean isCurrentThreadEDT() {
+ return edt == Thread.currentThread();
}
- private void invokeLater(Runnable task) {
- synchronized(edtLock) {
- if(null!=edt && edt.isRunning() && edt != Thread.currentThread() ) {
- tasks.add(task);
- edtLock.notifyAll();
- } else {
- // if !running or isEDTThread, do it right away
- task.run();
- }
- }
+ public final boolean isRunning() {
+ return !shouldStop && edt.isRunning() ;
}
public void invoke(boolean wait, Runnable task) {
if(task == null) {
return;
}
- boolean doWait = wait && null!=edt && edt.isRunning() && edt != Thread.currentThread();
- Object lock = new Object();
- RunnableTask rTask = new RunnableTask(task, doWait?lock:null, true);
Throwable throwable = null;
- synchronized(lock) {
- invokeLater(rTask);
- if( doWait ) {
+ RunnableTask rTask = null;
+ Object rTaskLock = new Object();
+ synchronized(rTaskLock) { // lock the optional task execution
+ synchronized(edtLock) { // lock the EDT status
+ start(); // start if not started yet
+ if(isRunning() && edt != Thread.currentThread() ) {
+ rTask = new RunnableTask(task, wait?rTaskLock:null, true);
+ synchronized(edtTasks) {
+ edtTasks.add(rTask);
+ edtTasks.notifyAll();
+ }
+ } else {
+ // if !running or isEDTThread, do it right away
+ wait = false;
+ task.run();
+ }
+ }
+ // wait until task finished, if requested
+ // and no stop() call slipped through.
+ if( wait && !shouldStop ) {
try {
- lock.wait();
+ rTaskLock.wait();
} catch (InterruptedException ie) {
throwable = ie;
}
+ if(null==throwable) {
+ throwable = rTask.getThrowable();
+ }
+ if(null!=throwable) {
+ throw new RuntimeException(throwable);
+ }
}
}
- if(null==throwable) {
- throwable = rTask.getThrowable();
- }
- if(null!=throwable) {
- throw new RuntimeException(throwable);
- }
}
public void waitUntilIdle() {
- synchronized(edtLock) {
- if(null!=edt && edt.isRunning() && tasks.size()>0 && edt != Thread.currentThread() ) {
- try {
- edtLock.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
+ if(edt.isRunning() && edt != Thread.currentThread()) {
+ synchronized(edtTasks) {
+ while(edt.isRunning() && edtTasks.size()>0) {
+ try {
+ edtTasks.wait();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
}
}
}
public void waitUntilStopped() {
- synchronized(edtLock) {
- while(null!=edt && edt.isRunning() && edt != Thread.currentThread() ) {
- try {
- edtLock.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
+ if(edt.isRunning() && edt != Thread.currentThread() ) {
+ synchronized(edtLock) {
+ while(edt.isRunning()) {
+ try {
+ edtLock.wait();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
}
}
}
class EventDispatchThread extends Thread {
- boolean isRunning = false;
+ volatile boolean isRunning = false;
public EventDispatchThread(ThreadGroup tg, String name) {
super(tg, name);
}
- public synchronized boolean isRunning() {
+ public final boolean isRunning() {
return isRunning;
}
public void start() throws IllegalThreadStateException {
- synchronized(this) {
- isRunning = true;
- }
+ isRunning = true;
super.start();
}
/**
- * Utilizing edtLock only for local resources and task execution,
+ * Utilizing locking only on edtTasks and its execution,
* not for event dispatching.
*/
public void run() {
@@ -180,41 +194,39 @@ public class DefaultEDTUtil implements EDTUtil {
System.out.println(Thread.currentThread()+": EDT run() START");
}
try {
- while(!shouldStop) {
- // wait for something todo
- while(!shouldStop && tasks.size()==0) {
- synchronized(edtLock) {
- if(!shouldStop && tasks.size()==0) {
- try {
- edtLock.wait(defaultEDTPollGranularity);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- pumpMessages.run(); // event dispatch
+ do {
+ // event dispatch
+ if(!shouldStop) {
+ pumpMessages.run();
}
- if(!shouldStop && tasks.size()>0) {
- synchronized(edtLock) {
- if(!shouldStop && tasks.size()>0) {
- Runnable task = (Runnable) tasks.remove(0);
- task.run(); // FIXME: could be run outside of lock
- edtLock.notifyAll();
+ // wait and work on tasks
+ synchronized(edtTasks) {
+ // wait for tasks
+ while(!shouldStop && edtTasks.size()==0) {
+ try {
+ edtTasks.wait(defaultEDTPollGranularity);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
}
- pumpMessages.run(); // event dispatch
+ // execute one task, if available
+ if(edtTasks.size()>0) {
+ Runnable task = (Runnable) edtTasks.remove(0);
+ task.run();
+ edtTasks.notifyAll();
+ }
}
- }
+ } while(!shouldStop || edtTasks.size()>0) ;
} catch (Throwable t) {
// handle errors ..
shouldStop = true;
throw new RuntimeException(t);
} finally {
- synchronized(this) {
+ // check for tasks
+ // sync for waitUntilStopped()
+ synchronized(edtLock) {
isRunning = !shouldStop;
- }
- if(!isRunning) {
- synchronized(edtLock) {
+ if(!isRunning) {
edtLock.notifyAll();
}
}
diff --git a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
index 1af102f43..91f35459b 100644
--- a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
+++ b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java
@@ -44,6 +44,8 @@ public interface EDTUtil {
public static final long defaultEDTPollGranularity = 10; // 10ms, 1/100s
+ public void reset();
+
public void start();
public void stop();
@@ -52,6 +54,7 @@ public interface EDTUtil {
public boolean isRunning();
+ /** Shall start the thread if not running */
public void invoke(boolean wait, Runnable task);
public void waitUntilIdle();
diff --git a/src/newt/classes/com/jogamp/newt/util/MainThread.java b/src/newt/classes/com/jogamp/newt/util/MainThread.java
index ba886ade8..cb5c87a89 100644
--- a/src/newt/classes/com/jogamp/newt/util/MainThread.java
+++ b/src/newt/classes/com/jogamp/newt/util/MainThread.java
@@ -243,6 +243,10 @@ public class MainThread implements EDTUtil {
}
}
+ public void reset() {
+ // nop
+ }
+
public void start() {
// nop
}
--
cgit v1.2.3