diff options
Diffstat (limited to 'src/newt')
-rw-r--r-- | src/newt/classes/com/jogamp/newt/NewtFactory.java | 1 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/Window.java | 9 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java | 2 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/event/InputEvent.java | 2 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/event/KeyEvent.java | 4 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/event/MouseEvent.java | 2 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/event/NEWTEvent.java | 6 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java | 2 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/opengl/GLWindow.java | 166 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/DefaultEDTUtil.java | 2 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/OffscreenWindow.java | 6 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/WindowImpl.java | 194 | ||||
-rw-r--r-- | src/newt/native/NewtCommon.c | 4 | ||||
-rw-r--r-- | src/newt/native/X11Window.c | 18 |
14 files changed, 152 insertions, 266 deletions
diff --git a/src/newt/classes/com/jogamp/newt/NewtFactory.java b/src/newt/classes/com/jogamp/newt/NewtFactory.java index 4b7eedca2..cd44df154 100644 --- a/src/newt/classes/com/jogamp/newt/NewtFactory.java +++ b/src/newt/classes/com/jogamp/newt/NewtFactory.java @@ -36,7 +36,6 @@ package com.jogamp.newt; import javax.media.nativewindow.*; import com.jogamp.common.jvm.JVMUtil; -import com.jogamp.newt.event.WindowEvent; import jogamp.newt.DisplayImpl; import jogamp.newt.ScreenImpl; import jogamp.newt.WindowImpl; diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index b78f7a9e8..5b3d93eec 100644 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -109,19 +109,12 @@ public interface Window extends NativeWindow, WindowClosingProtocol { * which will issue {@link Screen#destroy()} if the reference count becomes 0.<br> * This destruction sequence shall end up in {@link Display#destroy()}, if all reference counts become 0. * </p> - * @see #invalidate() + * @see #destroy() * @see #setVisible(boolean) */ void destroy(); /** - * Destroys the Window via {@link #destroy()} and clears all Object references, - * eg. all states, size, position, parent handles, list of child Windows and reference to it's Screen.<br> - * This Window cannot be recreated after calling this method anymore.<br> - */ - void invalidate(); - - /** * <p> * <code>setVisible</code> makes the window and children visible if <code>visible</code> is true, * otherwise the window and children becomes invisible.<br></p> diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index 0eda5c2a3..3c16abbea 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -191,7 +191,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto // 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()+ - ", displayable "+isDisplayable()+" -> "+cont); + ", displayable "+isDisplayable()+" -> "+cont); } reparentWindow(true, cont); } diff --git a/src/newt/classes/com/jogamp/newt/event/InputEvent.java b/src/newt/classes/com/jogamp/newt/event/InputEvent.java index 148787845..b0df7b4d1 100644 --- a/src/newt/classes/com/jogamp/newt/event/InputEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/InputEvent.java @@ -85,5 +85,5 @@ public abstract class InputEvent extends NEWTEvent return "InputEvent[modifiers:"+modifiers+", "+super.toString()+"]"; } - private int modifiers; + private final int modifiers; } diff --git a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java index 2c3fd9cb2..9e4fe372b 100644 --- a/src/newt/classes/com/jogamp/newt/event/KeyEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/KeyEvent.java @@ -110,8 +110,8 @@ public class KeyEvent extends InputEvent return false; } - private int keyCode; - private char keyChar; + private final int keyCode; + private final char keyChar; public static final int EVENT_KEY_PRESSED = 300; public static final int EVENT_KEY_RELEASED= 301; diff --git a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java index fbe32d41d..f3f606115 100644 --- a/src/newt/classes/com/jogamp/newt/event/MouseEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/MouseEvent.java @@ -97,7 +97,7 @@ public class MouseEvent extends InputEvent } } - private int x, y, clickCount, button, wheelRotation; + private final int x, y, clickCount, button, wheelRotation; public static final int EVENT_MOUSE_CLICKED = 200; public static final int EVENT_MOUSE_ENTERED = 201; diff --git a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java index 10673be3d..50aed2c8e 100644 --- a/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/NEWTEvent.java @@ -47,9 +47,9 @@ package com.jogamp.newt.event; * </ul><br> */ public class NEWTEvent extends java.util.EventObject { - private boolean isSystemEvent; - private int eventType; - private long when; + private final boolean isSystemEvent; + private final int eventType; + private final long when; private Object attachment; static final boolean DEBUG = false; diff --git a/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java b/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java index 7cd6ee370..505939de2 100644 --- a/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java +++ b/src/newt/classes/com/jogamp/newt/event/WindowUpdateEvent.java @@ -31,7 +31,7 @@ package com.jogamp.newt.event; import javax.media.nativewindow.util.Rectangle; public class WindowUpdateEvent extends WindowEvent { - Rectangle bounds; + final Rectangle bounds; public WindowUpdateEvent(int eventType, Object source, long when, Rectangle bounds) { diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index efbd9594b..d8eda923a 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -34,6 +34,7 @@ package com.jogamp.newt.opengl; +import java.io.PrintStream; import java.util.List; import com.jogamp.common.GlueGenVersion; @@ -48,6 +49,7 @@ import javax.media.nativewindow.util.Point; import javax.media.nativewindow.util.Insets; import javax.media.opengl.*; +import jogamp.opengl.FPSCounterImpl; import jogamp.opengl.GLDrawableHelper; import com.jogamp.opengl.JoglVersion; @@ -64,14 +66,14 @@ import com.jogamp.opengl.JoglVersion; * via {@link #invoke(boolean, javax.media.opengl.GLRunnable)} to the OpenGL command stream.<br> * <p> */ -public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { +public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer, FPSCounter { private WindowImpl window; /** * Constructor. Do not call this directly -- use {@link #create()} instead. */ protected GLWindow(Window window) { - resetCounter(); + resetFPSCounter(); this.window = (WindowImpl) window; ((WindowImpl)this.window).setHandleDestroyNotify(false); window.addWindowListener(new WindowAdapter() { @@ -339,33 +341,23 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { } context = null; drawable = null; - + + GLAnimatorControl ctrl = GLWindow.this.getAnimator(); + if ( null!=ctrl ) { + ctrl.remove(GLWindow.this); + } + // helper=null; // pending events .. + if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) { System.err.println("GLWindow.destroy() "+Thread.currentThread()+", fin"); } } - public synchronized void invalidate(boolean unrecoverable) { - if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) { - String msg = "GLWindow.invalidate("+unrecoverable+") "+Thread.currentThread()+", start"; - System.err.println(msg); - //Exception e1 = new Exception(msg); - //e1.printStackTrace(); - } - if(unrecoverable) { - GLAnimatorControl ctrl = GLWindow.this.getAnimator(); - if ( null!=ctrl ) { - ctrl.remove(GLWindow.this); - } - helper=null; - } - } - public synchronized void resetCounter() { if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) { System.err.println("GLWindow.resetCounter() "+Thread.currentThread()); } - GLWindow.this.resetCounter(); + GLWindow.this.resetFPSCounter(); } public synchronized void setVisibleActionPost(boolean visible, boolean nativeWindowCreated) { @@ -395,6 +387,7 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { } drawable.setRealized(true); context = drawable.createContext(sharedContext); + context.setContextCreationFlags(additionalCtxCreationFlags); } if(Window.DEBUG_WINDOW_EVENT || Window.DEBUG_IMPLEMENTATION) { String msg = "GLWindow.setVisibleActionPost("+visible+", "+nativeWindowCreated+") "+Thread.currentThread()+", fin"; @@ -404,19 +397,20 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { } } + private GLAnimatorControl savedAnimator = null; + public synchronized boolean pauseRenderingAction() { boolean animatorPaused = false; - GLAnimatorControl ctrl = GLWindow.this.getAnimator(); - if ( null!=ctrl ) { - animatorPaused = ctrl.pause(); + savedAnimator = GLWindow.this.getAnimator(); + if ( null != savedAnimator ) { + animatorPaused = savedAnimator.pause(); } return animatorPaused; } public synchronized void resumeRenderingAction() { - GLAnimatorControl ctrl = GLWindow.this.getAnimator(); - if ( null!=ctrl && ctrl.isPaused() ) { - ctrl.resume(); + if ( null != savedAnimator && savedAnimator.isPaused() ) { + savedAnimator.resume(); } } } @@ -426,6 +420,7 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { // private GLContext sharedContext = null; + private int additionalCtxCreationFlags = 0; private GLDrawableFactory factory; private GLDrawable drawable; private GLContext context; @@ -433,9 +428,7 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { // To make reshape events be sent immediately before a display event private boolean sendReshape=false; private boolean sendDestroy=false; - private boolean perfLog = false; - private long startTime, curTime, lastCheck; - private int totalFrames, lastFrames; + private FPSCounterImpl fpsCounter = new FPSCounterImpl(); public GLDrawableFactory getFactory() { return factory; @@ -455,6 +448,9 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { public void setContext(GLContext newCtx) { context = newCtx; + if(null != context) { + context.setContextCreationFlags(additionalCtxCreationFlags); + } } public GLContext getContext() { @@ -507,12 +503,6 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { return null; } - public boolean getPerfLogEnabled() { return perfLog; } - - public void enablePerfLog(boolean v) { - perfLog = v; - } - public void invoke(boolean wait, GLRunnable glRunnable) { if(null!=helper) { helper.invoke(this, wait, glRunnable); @@ -551,7 +541,7 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { } } } - + /** This implementation uses a static value */ public void setAutoSwapBufferMode(boolean onOrOff) { if(null!=helper) { @@ -566,24 +556,26 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { } return false; } - + public void swapBuffers() { if(drawable!=null && context != null) { - // Lock: Locked Surface/Window by MakeCurrent/Release - if (context != GLContext.getCurrent()) { - // Assume we should try to make the context current before swapping the buffers - helper.invokeGL(drawable, context, swapBuffersAction, initAction); - } else { - drawable.swapBuffers(); - } + drawable.swapBuffers(); } } + public void setContextCreationFlags(int flags) { + additionalCtxCreationFlags = flags; + } + + public int getContextCreationFlags() { + return additionalCtxCreationFlags; + } + private class InitAction implements Runnable { public final void run() { // Lock: Locked Surface/Window by MakeCurrent/Release helper.init(GLWindow.this); - resetCounter(); + resetFPSCounter(); } } private InitAction initAction = new InitAction(); @@ -598,66 +590,50 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { helper.display(GLWindow.this); - curTime = System.currentTimeMillis(); - totalFrames++; - - if(perfLog) { - long dt0, dt1; - lastFrames++; - dt0 = curTime-lastCheck; - if ( dt0 > 5000 ) { - dt1 = curTime-startTime; - System.err.println(dt0/1000 +"s: "+ lastFrames + "f, " + (lastFrames*1000)/dt0 + " fps, "+dt0/lastFrames+" ms/f; "+ - "total: "+ dt1/1000+"s, "+(totalFrames*1000)/dt1 + " fps, "+dt1/totalFrames+" ms/f"); - lastCheck=curTime; - lastFrames=0; - } - } + fpsCounter.tickFPS(); } } private DisplayAction displayAction = new DisplayAction(); - /** - * @return Time of the first display call in milliseconds. - * This value is reset if becoming visible again or reparenting. - */ - public final long getStartTime() { - return startTime; + public final void setUpdateFPSFrames(int frames, PrintStream out) { + fpsCounter.setUpdateFPSFrames(frames, out); + } + + public final void resetFPSCounter() { + fpsCounter.resetFPSCounter(); } - /** - * @return Time of the last display call in milliseconds. - * This value is reset if becoming visible again or reparenting. - */ - public final long getCurrentTime() { - return curTime; + public final int getUpdateFPSFrames() { + return fpsCounter.getUpdateFPSFrames(); + } + + public final long getFPSStartTime() { + return fpsCounter.getFPSStartTime(); } - /** - * @return Duration <code>getCurrentTime() - getStartTime()</code>. - * - * @see #getStartTime() - * @see #getCurrentTime() - */ - public final long getDuration() { - return getCurrentTime()-getStartTime(); + public final long getLastFPSUpdateTime() { + return fpsCounter.getLastFPSUpdateTime(); } - /** - * @return Number of frames displayed since the first display call, ie <code>getStartTime()</code>. - * This value is reset if becoming visible again or reparenting. - */ - public final int getTotalFrames() { - return totalFrames; + public final long getLastFPSPeriod() { + return fpsCounter.getLastFPSPeriod(); + } + + public final float getLastFPS() { + return fpsCounter.getLastFPS(); + } + + public final int getTotalFPSFrames() { + return fpsCounter.getTotalFPSFrames(); } - /** Reset all counter (startTime, currentTime, frame number) */ - public final synchronized void resetCounter() { - startTime = System.currentTimeMillis(); // overwrite startTime to real init one - curTime = startTime; - lastCheck = startTime; - totalFrames = 0; lastFrames = 0; + public final long getTotalFPSDuration() { + return fpsCounter.getTotalFPSDuration(); } + + public final float getTotalFPS() { + return fpsCounter.getTotalFPS(); + } private class SwapBuffersAction implements Runnable { public final void run() { @@ -864,10 +840,6 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { return window.surfaceSwap(); } - public final void invalidate() { - window.invalidate(); - } - public final long getWindowHandle() { return window.getWindowHandle(); @@ -932,7 +904,7 @@ public class GLWindow implements GLAutoDrawable, Window, NEWTEventConsumer { }); glWindow.setVisible(true); - glWindow.invalidate(); + glWindow.destroy(); } } diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java index 3b14f30fc..847407683 100644 --- a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java +++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java @@ -135,7 +135,7 @@ public class DefaultEDTUtil implements EDTUtil { if(stop) { edt.shouldStop = true; if(DEBUG) { - String msg = Thread.currentThread()+": EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - edt: "+edt; + String msg = Thread.currentThread()+": EDT signal STOP (on edt: "+isCurrentThreadEDT()+") - tasks: "+edt.tasks.size()+" - "+edt; System.err.println(msg); // Throwable t = new Throwable(msg); // t.printStackTrace(); diff --git a/src/newt/classes/jogamp/newt/OffscreenWindow.java b/src/newt/classes/jogamp/newt/OffscreenWindow.java index a79b1a5a1..e797a15cd 100644 --- a/src/newt/classes/jogamp/newt/OffscreenWindow.java +++ b/src/newt/classes/jogamp/newt/OffscreenWindow.java @@ -70,12 +70,6 @@ public class OffscreenWindow extends WindowImpl implements SurfaceChangeable { } @Override - protected void invalidate(boolean unrecoverable) { - super.invalidate(unrecoverable); - surfaceHandle = 0; - } - - @Override public synchronized void destroy() { super.destroy(); surfaceHandle = 0; diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index cb1c0eda2..2286fdd00 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -75,16 +75,17 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer private RecursiveLock windowLock = new RecursiveLock(); // Window instance wide lock private RecursiveLock surfaceLock = new RecursiveLock(); // Surface only lock - private long windowHandle; - private ScreenImpl screen; + private long windowHandle = 0; + private ScreenImpl screen = null; private boolean screenReferenceAdded = false; - private NativeWindow parentWindow; - private long parentWindowHandle; - protected AbstractGraphicsConfiguration config; - protected CapabilitiesImmutable capsRequested; + private NativeWindow parentWindow = null; + private long parentWindowHandle = 0; + protected AbstractGraphicsConfiguration config = null; + protected CapabilitiesImmutable capsRequested = null; protected CapabilitiesChooser capabilitiesChooser = null; // default null -> default - protected boolean fullscreen, visible, hasFocus; - protected int width, height, x, y; + protected boolean fullscreen = false, visible = false, hasFocus = false; + protected int width = 128, height = 128, x = 0, y = 0; // default values + protected int nfs_width, nfs_height, nfs_x, nfs_y; // non fullscreen dimensions .. protected String title = "Newt Window"; protected boolean undecorated = false; @@ -99,37 +100,23 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer private FocusRunnable focusAction = null; private Object surfaceUpdatedListenersLock = new Object(); - private ArrayList surfaceUpdatedListeners; + private ArrayList surfaceUpdatedListeners = new ArrayList(); private Object childWindowsLock = new Object(); - private ArrayList childWindows; + private ArrayList childWindows = new ArrayList(); - private ArrayList mouseListeners; - private int mouseButtonPressed; // current pressed mouse button number - private long lastMousePressed; // last time when a mouse button was pressed - private int lastMouseClickCount; // last mouse button click count + private ArrayList mouseListeners = new ArrayList(); + private int mouseButtonPressed = 0; // current pressed mouse button number + private long lastMousePressed = 0; // last time when a mouse button was pressed + private int lastMouseClickCount = 0; // last mouse button click count - private ArrayList keyListeners; + private ArrayList keyListeners = new ArrayList(); - private ArrayList windowListeners; + private ArrayList windowListeners = new ArrayList(); private boolean repaintQueued = false; ScreenModeListenerImpl screenModeListenerImpl = new ScreenModeListenerImpl(); - private void initializeStates() { - invalidate(true); - - childWindows = new ArrayList(); - surfaceUpdatedListeners = new ArrayList(); - windowListeners = new ArrayList(); - mouseListeners = new ArrayList(); - - mouseButtonPressed = 0; // current pressed mouse button number - lastMousePressed = 0; // last time when a mouse button was pressed - lastMouseClickCount = 0; // last mouse button click count - keyListeners = new ArrayList(); - } - // Workaround for initialization order problems on Mac OS X // between native Newt and (apparently) Fmod -- if Fmod is // initialized first then the connection to the window server @@ -179,7 +166,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer windowClass = OffscreenWindow.class; } WindowImpl window = (WindowImpl) windowClass.newInstance(); - window.initializeStates(); window.parentWindow = parentWindow; window.parentWindowHandle = parentWindowHandle; window.screen = (ScreenImpl) screen; @@ -204,7 +190,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer throw new NativeWindowException("WindowClass "+windowClass+" constructor mismatch at argument #"+argsChecked+"; Constructor: "+getTypeStrList(cstrArgumentTypes)+", arguments: "+getArgsStrList(cstrArguments)); } WindowImpl window = (WindowImpl) ReflectionUtil.createInstance( windowClass, cstrArgumentTypes, cstrArguments ) ; - window.initializeStates(); window.screen = (ScreenImpl) screen; window.capsRequested = (CapabilitiesImmutable) caps.cloneMutable(); return window; @@ -244,13 +229,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer void destroyActionInLock(); /** - * Invoked after destruction from Window's invalidate method.<br> - * Called while window is locked. - * @param unrecoverable - */ - void invalidate(boolean unrecoverable); - - /** * Invoked for expensive modifications, ie while reparenting and ScreenMode change.<br> * No lock is hold when invoked.<br> * @@ -310,26 +288,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } - private void closeAndInvalidate() { - windowLock.lock(); - try { - if( null != screen ) { - if( 0 != windowHandle ) { - screen.removeScreenModeListener(screenModeListenerImpl); - closeNativeImpl(); - removeScreenReference(); - } - Display dpy = screen.getDisplay(); - if(null != dpy) { - dpy.validateEDT(); - } - } - invalidate(false); - } finally { - windowLock.unlock(); - } - } - private boolean validateParentWindowHandle() { if(null!=parentWindow) { parentWindowHandle = getNativeWindowHandle(parentWindow); @@ -765,6 +723,10 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer return; // nop } + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + String msg = "!!! Window DestroyAction() "+getThreadName(); + System.err.println(msg); + } // Childs first .. synchronized(childWindowsLock) { if(childWindows.size()>0) { @@ -787,7 +749,17 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer lifecycleHook.destroyActionInLock(); } - closeAndInvalidate(); + if( null != screen ) { + if( 0 != windowHandle ) { + screen.removeScreenModeListener(screenModeListenerImpl); + closeNativeImpl(); + removeScreenReference(); + } + Display dpy = screen.getDisplay(); + if(null != dpy) { + dpy.validateEDT(); + } + } // send synced destroyed notification sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROYED); @@ -800,7 +772,29 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } if(animatorPaused) { lifecycleHook.resumeRenderingAction(); - } + } + windowHandle = 0; + visible = false; + fullscreen = false; + hasFocus = false; + parentWindowHandle = 0; + + // these refs shall be kept alive - resurrection + /** + if(null!=parentWindow && parentWindow instanceof Window) { + ((Window)parentWindow).removeChild(WindowImpl.this); + } + childWindows = null; + surfaceUpdatedListeners = null; + mouseListeners = null; + keyListeners = null; + capsRequested = null; + lifecycleHook = null; + + screen = null; + windowListeners = null; + parentWindow = null; + */ } } @@ -816,84 +810,6 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } } - public final void invalidate() { - destroy(); - invalidate(true); - } - - /** - * @param unrecoverable If true, all states, size, position, parent handles, - * reference to it's Screen are reset. - * Otherwise you can recreate the window, via <code>setVisible(true)</code>. - * @see #invalidate() - * @see #destroy() - * @see #destroy(boolean) - */ - protected void invalidate(boolean unrecoverable) { - windowLock.lock(); - try { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - String msg = "!!! Window Invalidate(unrecoverable: "+unrecoverable+") "+getThreadName(); - System.err.println(msg); - // Throwable t = new Throwable(msg); - // t.printStackTrace(); - } - - // Childs first .. - synchronized(childWindowsLock) { - // avoid ConcurrentModificationException: parent -> child -> parent.removeChild(this) - if(null!=childWindows && childWindows.size()>0) { - ArrayList clonedChildWindows = (ArrayList) childWindows.clone(); - while( clonedChildWindows.size() > 0 ) { - NativeWindow nw = (NativeWindow) clonedChildWindows.remove(0); - if(nw instanceof WindowImpl) { - ((WindowImpl)nw).invalidate(unrecoverable); - } - } - } - } - - if(null!=lifecycleHook) { - lifecycleHook.invalidate(unrecoverable); - } - - windowHandle = 0; - visible = false; - fullscreen = false; - hasFocus = false; - - if(unrecoverable) { - if(null!=parentWindow && parentWindow instanceof Window) { - ((Window)parentWindow).removeChild(WindowImpl.this); - } - screen = null; - - synchronized(childWindowsLock) { - childWindows = null; - } - synchronized(surfaceUpdatedListenersLock) { - surfaceUpdatedListeners = null; - } - windowListeners = null; - mouseListeners = null; - keyListeners = null; - - parentWindowHandle = 0; - parentWindow = null; - capsRequested = null; - lifecycleHook = null; - - // Default position and dimension will be re-set immediately by user - width = 128; - height = 128; - x=0; - y=0; - } - } finally { - windowLock.unlock(); - } - } - private class ReparentActionImpl implements Runnable, ReparentAction { NativeWindow newParentWindow; boolean forceDestroyCreate; diff --git a/src/newt/native/NewtCommon.c b/src/newt/native/NewtCommon.c index 0e3f99282..f44d71901 100644 --- a/src/newt/native/NewtCommon.c +++ b/src/newt/native/NewtCommon.c @@ -33,12 +33,12 @@ void NewtCommon_init(JNIEnv *env) { if(NULL==runtimeExceptionClz) { jclass c = (*env)->FindClass(env, ClazzNameRuntimeException); if(NULL==c) { - NewtCommon_FatalError(env, "NEWT X11Window: can't find %s", ClazzNameRuntimeException); + NewtCommon_FatalError(env, "NEWT: can't find %s", ClazzNameRuntimeException); } runtimeExceptionClz = (jclass)(*env)->NewGlobalRef(env, c); (*env)->DeleteLocalRef(env, c); if(NULL==runtimeExceptionClz) { - NewtCommon_FatalError(env, "NEWT X11Window: can't use %s", ClazzNameRuntimeException); + NewtCommon_FatalError(env, "NEWT: can't use %s", ClazzNameRuntimeException); } } } diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 66b036ef5..53dd97d44 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -188,7 +188,18 @@ static jmethodID displayCompletedID = NULL; * Display */ -static JNIEnv * x11ErrorHandlerJNIEnv = NULL; +static JavaVM *jvmHandle = NULL; +static int jvmVersion = 0; +static JNIEnv * jvmEnv = NULL; + +static void setupJVMVars(JNIEnv * env) { + if(0 != (*env)->GetJavaVM(env, &jvmHandle)) { + jvmHandle = NULL; + } + jvmVersion = (*env)->GetVersion(env); + jvmEnv = env; +} + static XErrorHandler origErrorHandler = NULL ; static int displayDispatchErrorHandler(Display *dpy, XErrorEvent *e) @@ -200,7 +211,7 @@ static int displayDispatchErrorHandler(Display *dpy, XErrorEvent *e) } else if (e->error_code == BadWindow) { fprintf(stderr, " BadWindow (%p): Window probably already removed\n", (void*)e->resourceid); } else { - NewtCommon_throwNewRuntimeException(x11ErrorHandlerJNIEnv, "NEWT X11 Error: Display %p, Code 0x%X, errno %s", + NewtCommon_throwNewRuntimeException(jvmEnv, "NEWT X11 Error: Display %p, Code 0x%X, errno %s", dpy, e->error_code, strerror(errno)); } @@ -210,7 +221,7 @@ static int displayDispatchErrorHandler(Display *dpy, XErrorEvent *e) static void displayDispatchErrorHandlerEnable(int onoff, JNIEnv * env) { if(onoff) { if(NULL==origErrorHandler) { - x11ErrorHandlerJNIEnv = env; + setupJVMVars(env); origErrorHandler = XSetErrorHandler(displayDispatchErrorHandler); } } else { @@ -663,6 +674,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_x11_X11Display_DispatchMessages0 (void*)evt.xclient.window, (unsigned int)evt.xclient.message_type); (*env)->CallVoidMethod(env, jwindow, windowDestroyNotifyID); // Called by Window.java: CloseWindow(); + num_events = 0; // end loop in case of destroyed display } break; |