aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/com/sun/javafx/newt
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/com/sun/javafx/newt')
-rw-r--r--src/classes/com/sun/javafx/newt/GLWindow.java78
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/Window.java69
-rw-r--r--src/classes/com/sun/javafx/newt/WindowEvent.java2
-rw-r--r--src/classes/com/sun/javafx/newt/WindowListener.java1
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/kd/KDWindow.java3
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/macosx/MacWindow.java5
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/windows/WindowsWindow.java12
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/x11/X11Window.java22
8 files changed, 150 insertions, 42 deletions
diff --git a/src/classes/com/sun/javafx/newt/GLWindow.java b/src/classes/com/sun/javafx/newt/GLWindow.java
index 53943b087..3b35beae3 100644
--- a/src/classes/com/sun/javafx/newt/GLWindow.java
+++ b/src/classes/com/sun/javafx/newt/GLWindow.java
@@ -73,6 +73,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
create()} instead. */
protected GLWindow(Window window) {
this.window = window;
+ this.window.setAutoDrawableMember(true);
window.addWindowListener(new WindowListener() {
public void windowResized(WindowEvent e) {
sendReshape = true;
@@ -80,13 +81,17 @@ public class GLWindow extends Window implements GLAutoDrawable {
public void windowMoved(WindowEvent e) {
}
+
+ public void windowDestroyNotify(WindowEvent e) {
+ sendDispose = true;
+ }
});
}
/** Creates a new GLWindow on the local display, screen 0, with a
dummy visual ID, and with the default NWCapabilities. */
public static GLWindow create() {
- return create(null, null);
+ return create(null, null, false);
}
public static GLWindow create(boolean undecorated) {
@@ -95,10 +100,10 @@ public class GLWindow extends Window implements GLAutoDrawable {
/** Creates a new GLWindow referring to the given window. */
public static GLWindow create(Window window) {
- return create(window, null);
+ return create(window, null, false);
}
public static GLWindow create(NWCapabilities caps) {
- return create(caps, false);
+ return create(null, caps, false);
}
/** Creates a new GLWindow on the local display, screen 0, with a
@@ -135,18 +140,32 @@ public class GLWindow extends Window implements GLAutoDrawable {
shouldNotCallThis();
}
- public void close() {
+ public synchronized void destroy() {
+ if(Window.DEBUG_WINDOW_EVENT) {
+ Exception e1 = new Exception("GLWindow.destroy 1: "+this);
+ e1.printStackTrace();
+ }
+
+ sendDisposeEvent();
+
if (context != null) {
- if (context == GLContext.getCurrent()) {
- context.release();
- }
context.destroy();
}
if (drawable != null) {
drawable.setRealized(false);
}
- window.close();
+ if(null!=window) {
+ window.destroy();
+ }
+
+ if(Window.DEBUG_WINDOW_EVENT) {
+ System.out.println("GLWindow.destroy fin: "+this);
+ }
+
+ drawable = null;
+ context = null;
+ window = null;
}
public boolean getPerfLogEnabled() { return perfLog; }
@@ -322,6 +341,10 @@ public class GLWindow extends Window implements GLAutoDrawable {
return window.getWindowListeners();
}
+ public String toString() {
+ return "NEWT-GLWindow[ "+drawable+", "+helper+", "+factory+"]";
+ }
+
//----------------------------------------------------------------------
// OpenGL-related methods and state
//
@@ -332,7 +355,8 @@ public class GLWindow extends Window implements GLAutoDrawable {
private GLContext context;
private GLDrawableHelper helper = new GLDrawableHelper();
// To make reshape events be sent immediately before a display event
- private boolean sendReshape;
+ private boolean sendReshape=false;
+ private boolean sendDispose=false;
private boolean perfLog = false;
public GLDrawableFactory getFactory() {
@@ -369,8 +393,21 @@ public class GLWindow extends Window implements GLAutoDrawable {
}
public void display() {
- pumpMessages();
- helper.invokeGL(drawable, context, displayAction, initAction);
+ if(window.getSurfaceHandle()!=0) {
+ pumpMessages();
+ if (sendDispose) {
+ destroy();
+ sendDispose=false;
+ } else {
+ helper.invokeGL(drawable, context, displayAction, initAction);
+ }
+ }
+ }
+
+ private void sendDisposeEvent() {
+ if(disposeAction!=null && drawable!=null && context != null && window!=null && window.getSurfaceHandle()!=0) {
+ helper.invokeGL(drawable, context, disposeAction, null);
+ }
}
public void setAutoSwapBufferMode(boolean onOrOff) {
@@ -382,11 +419,13 @@ public class GLWindow extends Window implements GLAutoDrawable {
}
public void swapBuffers() {
- if (context != null && 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();
+ if(window.getSurfaceHandle()!=0) {
+ if (context != null && 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();
+ }
}
}
@@ -403,6 +442,13 @@ public class GLWindow extends Window implements GLAutoDrawable {
}
private InitAction initAction = new InitAction();
+ class DisposeAction implements Runnable {
+ public void run() {
+ helper.dispose(GLWindow.this);
+ }
+ }
+ private DisposeAction disposeAction = new DisposeAction();
+
class DisplayAction implements Runnable {
public void run() {
if (sendReshape) {
diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java
index a1e983c3c..8ba7610b3 100755
--- a/src/classes/com/sun/javafx/newt/Window.java
+++ b/src/classes/com/sun/javafx/newt/Window.java
@@ -162,7 +162,9 @@ public abstract class Window implements NativeWindow
protected abstract void dispatchMessages(int eventMask);
public String toString() {
- return "NEWT-Window[windowHandle "+getWindowHandle()+
+ StringBuffer sb = new StringBuffer();
+
+ sb.append("NEWT-Window[windowHandle "+getWindowHandle()+
", surfaceHandle "+getSurfaceHandle()+
", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+
", visible "+isVisible()+
@@ -170,7 +172,22 @@ public abstract class Window implements NativeWindow
", visualID "+visualID+
", "+chosenCaps+
", screen handle/index "+getScreenHandle()+"/"+getScreenIndex() +
- ", display handle "+getDisplayHandle()+ "]";
+ ", display handle "+getDisplayHandle());
+
+ sb.append(", WindowListeners num "+windowListeners.size()+" [");
+ for (Iterator iter = windowListeners.iterator(); iter.hasNext(); ) {
+ sb.append(iter.next()+", ");
+ }
+ sb.append("], MouseListeners num "+mouseListeners.size()+" [");
+ for (Iterator iter = mouseListeners.iterator(); iter.hasNext(); ) {
+ sb.append(iter.next()+", ");
+ }
+ sb.append("], KeyListeners num "+keyListeners.size()+" [");
+ for (Iterator iter = keyListeners.iterator(); iter.hasNext(); ) {
+ sb.append(iter.next()+", ");
+ }
+ sb.append("]");
+ return sb.toString();
}
protected Screen screen;
@@ -233,9 +250,18 @@ public abstract class Window implements NativeWindow
return locked;
}
- public void close() {
+ public synchronized void destroy() {
+ if(DEBUG_WINDOW_EVENT) {
+ System.out.println("Window.destroy() start");
+ }
+ windowListeners = new ArrayList();
+ mouseListeners = new ArrayList();
+ keyListeners = new ArrayList();
closeNative();
invalidate();
+ if(DEBUG_WINDOW_EVENT) {
+ System.out.println("Window.destroy() end");
+ }
}
public void invalidate() {
@@ -334,6 +360,40 @@ public abstract class Window implements NativeWindow
return fullscreen;
}
+ private boolean autoDrawableMember = false;
+
+ /**
+ * If set to true,
+ * certain action will be performed by the owning
+ * AutoDrawable, ie the destroy() call within windowDestroyNotify()
+ */
+ protected void setAutoDrawableMember(boolean b) {
+ autoDrawableMember = b;
+ }
+
+ protected void windowDestroyNotify() {
+ if(DEBUG_WINDOW_EVENT) {
+ System.out.println("Window.windowDestroyeNotify start");
+ }
+
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY);
+
+ if(!autoDrawableMember) {
+ destroy();
+ }
+
+ if(DEBUG_WINDOW_EVENT) {
+ System.out.println("Window.windowDestroyeNotify end");
+ }
+ }
+
+ protected void windowDestroyed() {
+ if(DEBUG_WINDOW_EVENT) {
+ System.out.println("Window.windowDestroyed");
+ }
+ invalidate();
+ }
+
public abstract void setVisible(boolean visible);
public abstract void setSize(int width, int height);
public abstract void setPosition(int x, int y);
@@ -562,6 +622,9 @@ public abstract class Window implements NativeWindow
case WindowEvent.EVENT_WINDOW_MOVED:
l.windowMoved(e);
break;
+ case WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY:
+ l.windowDestroyNotify(e);
+ break;
default:
throw new NativeWindowException("Unexpected window event type " + e.getEventType());
}
diff --git a/src/classes/com/sun/javafx/newt/WindowEvent.java b/src/classes/com/sun/javafx/newt/WindowEvent.java
index 49cdb5497..a502e912c 100644
--- a/src/classes/com/sun/javafx/newt/WindowEvent.java
+++ b/src/classes/com/sun/javafx/newt/WindowEvent.java
@@ -36,6 +36,7 @@ package com.sun.javafx.newt;
public class WindowEvent extends Event {
public static final int EVENT_WINDOW_RESIZED = 100;
public static final int EVENT_WINDOW_MOVED = 101;
+ public static final int EVENT_WINDOW_DESTROY_NOTIFY = 102;
public WindowEvent(int eventType, Window source, long when) {
this(false, eventType, source, when);
@@ -49,6 +50,7 @@ public class WindowEvent extends Event {
switch(type) {
case EVENT_WINDOW_RESIZED: return "WINDOW_RESIZED";
case EVENT_WINDOW_MOVED: return "WINDOW_MOVED";
+ case EVENT_WINDOW_DESTROY_NOTIFY: return "EVENT_WINDOW_DESTROY_NOTIFY";
default: return "unknown (" + type + ")";
}
}
diff --git a/src/classes/com/sun/javafx/newt/WindowListener.java b/src/classes/com/sun/javafx/newt/WindowListener.java
index b76202f01..e8423cbcc 100644
--- a/src/classes/com/sun/javafx/newt/WindowListener.java
+++ b/src/classes/com/sun/javafx/newt/WindowListener.java
@@ -36,4 +36,5 @@ package com.sun.javafx.newt;
public interface WindowListener extends EventListener {
public void windowResized(WindowEvent e);
public void windowMoved(WindowEvent e);
+ public void windowDestroyNotify(WindowEvent e);
}
diff --git a/src/classes/com/sun/javafx/newt/kd/KDWindow.java b/src/classes/com/sun/javafx/newt/kd/KDWindow.java
index 01570e1bb..276fc3ebd 100755
--- a/src/classes/com/sun/javafx/newt/kd/KDWindow.java
+++ b/src/classes/com/sun/javafx/newt/kd/KDWindow.java
@@ -156,9 +156,6 @@ public class KDWindow extends Window {
sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
}
- private void windowClosed() {
- }
-
private long eglWindowHandle;
private long windowHandleClose;
private int windowID;
diff --git a/src/classes/com/sun/javafx/newt/macosx/MacWindow.java b/src/classes/com/sun/javafx/newt/macosx/MacWindow.java
index f80f0b3ab..b465f505c 100755
--- a/src/classes/com/sun/javafx/newt/macosx/MacWindow.java
+++ b/src/classes/com/sun/javafx/newt/macosx/MacWindow.java
@@ -245,11 +245,6 @@ public class MacWindow extends Window {
}
}
- private void windowClosed() {
- nativeWindow = 0;
- visible = false;
- }
-
private char convertKeyChar(char keyChar) {
if (keyChar == '\r') {
// Turn these into \n
diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
index 8b9d635e8..a0cf1e7bc 100755
--- a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
+++ b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
@@ -83,9 +83,15 @@ public class WindowsWindow extends Window {
}
if(windowHandleClose != 0) {
DestroyWindow(windowHandleClose);
+ windowHandleClose = 0;
}
}
+ protected void windowDestroyed() {
+ windowHandleClose = 0;
+ super.windowDestroyed();
+ }
+
public void setVisible(boolean visible) {
if(this.visible!=visible) {
this.visible=visible;
@@ -166,10 +172,4 @@ public class WindowsWindow extends Window {
y = newY;
sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
}
-
- private void windowClosed() {
- }
-
- private void windowDestroyed() {
- }
}
diff --git a/src/classes/com/sun/javafx/newt/x11/X11Window.java b/src/classes/com/sun/javafx/newt/x11/X11Window.java
index 312cc161d..cd69b75ef 100755
--- a/src/classes/com/sun/javafx/newt/x11/X11Window.java
+++ b/src/classes/com/sun/javafx/newt/x11/X11Window.java
@@ -68,9 +68,17 @@ public class X11Window extends Window {
protected void closeNative() {
if(0!=displayHandleClose && 0!=windowHandleClose) {
CloseWindow(displayHandleClose, windowHandleClose);
+ windowHandleClose = 0;
+ displayHandleClose = 0;
}
}
+ protected void windowDestroyed() {
+ windowHandleClose = 0;
+ displayHandleClose = 0;
+ super.windowDestroyed();
+ }
+
public void setVisible(boolean visible) {
if(this.visible!=visible) {
this.visible=visible;
@@ -108,7 +116,7 @@ public class X11Window extends Window {
}
protected void dispatchMessages(int eventMask) {
- DispatchMessages(getDisplayHandle(), windowHandle, eventMask);
+ DispatchMessages(getDisplayHandle(), windowHandle, eventMask, windowDeleteAtom);
}
//----------------------------------------------------------------------
@@ -120,7 +128,7 @@ public class X11Window extends Window {
long visualID, int x, int y, int width, int height);
private native void CloseWindow(long display, long windowHandle);
private native void setVisible0(long display, long windowHandle, boolean visible);
- private native void DispatchMessages(long display, long windowHandle, int eventMask);
+ private native void DispatchMessages(long display, long windowHandle, int eventMask, long windowDeleteAtom);
private native void setSize0(long display, long windowHandle, int width, int height, int decorationToggle, boolean isVisible);
private native void setPosition0(long display, long windowHandle, int x, int y);
@@ -144,17 +152,13 @@ public class X11Window extends Window {
sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED);
}
- private void windowCreated(long visualID, long windowHandle) {
+ private void windowCreated(long visualID, long windowHandle, long windowDeleteAtom) {
this.visualID = visualID;
this.windowHandle = windowHandle;
- }
-
- private void windowClosed() {
- }
-
- private void windowDestroyed() {
+ this.windowDeleteAtom=windowDeleteAtom;
}
private long windowHandleClose;
private long displayHandleClose;
+ private long windowDeleteAtom;
}