diff options
Diffstat (limited to 'src/newt/classes')
5 files changed, 153 insertions, 50 deletions
diff --git a/src/newt/classes/com/sun/javafx/newt/Window.java b/src/newt/classes/com/sun/javafx/newt/Window.java index d55829a5d..10a31f451 100755 --- a/src/newt/classes/com/sun/javafx/newt/Window.java +++ b/src/newt/classes/com/sun/javafx/newt/Window.java @@ -181,7 +181,7 @@ public abstract class Window implements NativeWindow for (Iterator iter = keyListeners.iterator(); iter.hasNext(); ) { sb.append(iter.next()+", "); } - sb.append("]"); + sb.append("] ]"); return sb.toString(); } @@ -189,7 +189,7 @@ public abstract class Window implements NativeWindow protected AbstractGraphicsConfiguration config; protected long windowHandle; - protected boolean locked=false; + protected Exception lockedStack = null; protected boolean fullscreen, visible; protected int width, height, x, y; protected int eventMask; @@ -220,23 +220,29 @@ public abstract class Window implements NativeWindow // NativeWindow impl // - public int lockSurface() throws NativeWindowException { - if (locked) { - throw new NativeWindowException("Surface already locked"); + public synchronized int lockSurface() throws NativeWindowException { + if (null!=lockedStack) { + lockedStack.printStackTrace(); + throw new NativeWindowException("Surface already locked - "+this); } - // locked = true; - // return LOCK_SUCCESS; - return LOCK_NOT_SUPPORTED; + lockedStack = new Exception("NEWT-Window previously locked by "+Thread.currentThread().getName()); + return LOCK_SUCCESS; } - public void unlockSurface() { - if (locked) { - locked = false; + public synchronized void unlockSurface() { + if (null!=lockedStack) { + lockedStack = null; + } else { + throw new NativeWindowException("NEWT-Window not locked"); } } - public boolean isSurfaceLocked() { - return locked; + public synchronized boolean isSurfaceLocked() { + return null!=lockedStack; + } + + public synchronized Exception getLockedStack() { + return lockedStack; } public synchronized void destroy() { @@ -258,10 +264,8 @@ public abstract class Window implements NativeWindow } public void invalidate(boolean internal) { - unlockSurface(); screen = null; windowHandle = 0; - locked = false; fullscreen=false; visible=false; eventMask = 0; diff --git a/src/newt/classes/com/sun/javafx/newt/WindowEvent.java b/src/newt/classes/com/sun/javafx/newt/WindowEvent.java index 634672f32..c5aa65e3d 100644 --- a/src/newt/classes/com/sun/javafx/newt/WindowEvent.java +++ b/src/newt/classes/com/sun/javafx/newt/WindowEvent.java @@ -39,6 +39,7 @@ public class WindowEvent extends Event { public static final int EVENT_WINDOW_DESTROY_NOTIFY = 102; public static final int EVENT_WINDOW_GAINED_FOCUS = 103; public static final int EVENT_WINDOW_LOST_FOCUS = 104; + // public static final int EVENT_WINDOW_REPAINT = 105; // TODO public WindowEvent(int eventType, Window source, long when) { this(false, eventType, source, when); @@ -55,6 +56,7 @@ public class WindowEvent extends Event { case EVENT_WINDOW_DESTROY_NOTIFY: return "EVENT_WINDOW_DESTROY_NOTIFY"; case EVENT_WINDOW_GAINED_FOCUS: return "EVENT_WINDOW_GAINED_FOCUS"; case EVENT_WINDOW_LOST_FOCUS: return "EVENT_WINDOW_LOST_FOCUS"; + // case EVENT_WINDOW_REPAINT: return "EVENT_WINDOW_REPAINT"; default: return "unknown (" + type + ")"; } } diff --git a/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java b/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java index 6c20cfbcf..cb8c56d55 100644 --- a/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/awt/AWTWindow.java @@ -67,6 +67,7 @@ public class AWTWindow extends Window { private boolean gotDisplaySize; private int displayWidth; private int displayHeight; + private volatile boolean awtCreated=false; public void setTitle(String title) { super.setTitle(title); @@ -75,28 +76,47 @@ public class AWTWindow extends Window { } } + Object syncObj = new Object(); + protected void createNative(Capabilities caps) { config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); if (config == null) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } + runOnEDT(new Runnable() { public void run() { - frame = new Frame(getTitle()); - frame.setUndecorated(isUndecorated()); - frame.setLayout(new BorderLayout()); - canvas = new Canvas(); - Listener listener = new Listener(); - canvas.addMouseListener(listener); - canvas.addMouseMotionListener(listener); - canvas.addKeyListener(listener); - canvas.addComponentListener(listener); - frame.add(canvas, BorderLayout.CENTER); - frame.setSize(width, height); - frame.setLocation(x, y); - frame.addComponentListener(new MoveListener()); + synchronized (syncObj) { + frame = new Frame(getTitle()); + frame.setUndecorated(isUndecorated()); + frame.setLayout(new BorderLayout()); + canvas = new Canvas( ((AWTGraphicsConfiguration) config).getGraphicsConfiguration() ); + Listener listener = new Listener(); + canvas.addMouseListener(listener); + canvas.addMouseMotionListener(listener); + canvas.addKeyListener(listener); + canvas.addComponentListener(listener); + frame.add(canvas, BorderLayout.CENTER); + frame.setSize(width, height); + frame.setLocation(x, y); + frame.addComponentListener(new MoveListener()); + frame.addWindowListener(new WindowEventListener()); + awtCreated=true; + syncObj.notifyAll(); + } } }); + + // make sure we are finished .. + while(!awtCreated) { + synchronized (syncObj) { + if(!awtCreated) { + try { + syncObj.wait(); + } catch (InterruptedException e) {} + } + } + } } protected void closeNative() { @@ -179,6 +199,7 @@ public class AWTWindow extends Window { switch (w.getType()) { case com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_RESIZED: case com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_MOVED: + case com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY: if ((eventMask & com.sun.javafx.newt.EventListener.WINDOW) != 0) { sendWindowEvent(w.getType()); } @@ -360,4 +381,22 @@ public class AWTWindow extends Window { enqueueEvent(com.sun.javafx.newt.KeyEvent.EVENT_KEY_TYPED, e); } } + + class WindowEventListener implements WindowListener { + public void windowActivated(WindowEvent e) { + } + public void windowClosed(WindowEvent e) { + } + public void windowClosing(WindowEvent e) { + enqueueEvent(com.sun.javafx.newt.WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY, null); + } + public void windowDeactivated(WindowEvent e) { + } + public void windowDeiconified(WindowEvent e) { + } + public void windowIconified(WindowEvent e) { + } + public void windowOpened(WindowEvent e) { + } + } } 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 ec7458539..f769aed27 100644 --- a/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java @@ -91,7 +91,7 @@ public class GLWindow extends Window implements GLAutoDrawable { } public void windowDestroyNotify(WindowEvent e) { - sendDispose = true; + sendDestroy = true; } }); } @@ -151,9 +151,9 @@ public class GLWindow extends Window implements GLAutoDrawable { shouldNotCallThis(); } - public synchronized void destroy() { - if(Window.DEBUG_WINDOW_EVENT) { - Exception e1 = new Exception("GLWindow.destroy 1: "+this); + public synchronized void dispose(boolean regenerate) { + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + Exception e1 = new Exception("GLWindow.destroy("+regenerate+") 1: "+this); e1.printStackTrace(); } @@ -166,6 +166,27 @@ public class GLWindow extends Window implements GLAutoDrawable { drawable.setRealized(false); } + if(regenerate) { + drawable.setRealized(true); + if(getSurfaceHandle()==0) { + throw new GLException("SurfaceHandle==NULL after setRealize(true) "+this); + } + context = drawable.createContext(null); + } + + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + System.out.println("GLWindow.dispose("+regenerate+") fin: "+this); + } + } + + public synchronized void destroy() { + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { + Exception e1 = new Exception("GLWindow.destroy 1: "+this); + e1.printStackTrace(); + } + + dispose(false); + Screen _screen = null; Display _device = null; if(null!=window) { @@ -178,7 +199,7 @@ public class GLWindow extends Window implements GLAutoDrawable { window.destroy(); } - if(Window.DEBUG_WINDOW_EVENT) { + if(Window.DEBUG_WINDOW_EVENT || window.DEBUG_IMPLEMENTATION) { System.out.println("GLWindow.destroy fin: "+this); } @@ -271,10 +292,13 @@ public class GLWindow extends Window implements GLAutoDrawable { if (window.getWrappedWindow() != null) { nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), nw.getGraphicsConfiguration()); } - factory = GLDrawableFactory.getFactory(nw); + GLCapabilities glCaps = (GLCapabilities) nw.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + factory = GLDrawableFactory.getFactory(glCaps.getGLProfile()); drawable = factory.createGLDrawable(nw); - window.setVisible(true); drawable.setRealized(true); + if(getSurfaceHandle()==0) { + throw new GLException("SurfaceHandle==NULL after setRealize(true) "+this); + } context = drawable.createContext(null); } } @@ -372,7 +396,7 @@ public class GLWindow extends Window implements GLAutoDrawable { } public String toString() { - return "NEWT-GLWindow[ "+drawable+", "+helper+", "+factory+"]"; + return "NEWT-GLWindow[ "+drawable+", \n\t"+window+", \n\t"+helper+", \n\t"+factory+"]"; } //---------------------------------------------------------------------- @@ -386,7 +410,7 @@ public class GLWindow extends Window implements GLAutoDrawable { private GLDrawableHelper helper = new GLDrawableHelper(); // To make reshape events be sent immediately before a display event private boolean sendReshape=false; - private boolean sendDispose=false; + private boolean sendDestroy=false; private boolean perfLog = false; public GLDrawableFactory getFactory() { @@ -423,11 +447,11 @@ public class GLWindow extends Window implements GLAutoDrawable { } public void display() { - if(window.getSurfaceHandle()!=0) { + if(getSurfaceHandle()!=0) { pumpMessages(); - if (sendDispose) { + if (sendDestroy) { destroy(); - sendDispose=false; + sendDestroy=false; } else { helper.invokeGL(drawable, context, displayAction, initAction); } @@ -435,7 +459,7 @@ public class GLWindow extends Window implements GLAutoDrawable { } private void sendDisposeEvent() { - if(disposeAction!=null && drawable!=null && context != null && window!=null && window.getSurfaceHandle()!=0) { + if(disposeAction!=null && drawable!=null && context != null && window!=null && getSurfaceHandle()!=0) { helper.invokeGL(drawable, context, disposeAction, null); } } @@ -449,7 +473,7 @@ public class GLWindow extends Window implements GLAutoDrawable { } public void swapBuffers() { - if(window.getSurfaceHandle()!=0) { + if(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); @@ -531,6 +555,44 @@ public class GLWindow extends Window implements GLAutoDrawable { private SwapBuffersAction swapBuffersAction = new SwapBuffersAction(); //---------------------------------------------------------------------- + // GLDrawable methods + // + + public NativeWindow getNativeWindow() { + return null!=drawable ? drawable.getNativeWindow() : null; + } + + public synchronized int lockSurface() throws NativeWindowException { + if(null!=drawable) return drawable.getNativeWindow().lockSurface(); + return NativeWindow.LOCK_SURFACE_NOT_READY; + } + + public synchronized void unlockSurface() { + if(null!=drawable) drawable.getNativeWindow().unlockSurface(); + else throw new NativeWindowException("NEWT-GLWindow not locked"); + } + + public synchronized boolean isSurfaceLocked() { + if(null!=drawable) return drawable.getNativeWindow().isSurfaceLocked(); + return false; + } + + public synchronized Exception getLockedStack() { + if(null!=drawable) return drawable.getNativeWindow().getLockedStack(); + return null; + } + + public long getWindowHandle() { + if(null!=drawable) return drawable.getNativeWindow().getWindowHandle(); + return super.getWindowHandle(); + } + + public long getSurfaceHandle() { + if(null!=drawable) return drawable.getNativeWindow().getSurfaceHandle(); + return super.getSurfaceHandle(); + } + + //---------------------------------------------------------------------- // GLDrawable methods that are not really needed // @@ -541,12 +603,12 @@ public class GLWindow extends Window implements GLAutoDrawable { public void setRealized(boolean realized) { } - public GLCapabilities getGLCapabilities() { + public GLCapabilities getChosenGLCapabilities() { if (drawable == null) { throw new GLException("No drawable yet"); } - return drawable.getGLCapabilities(); + return drawable.getChosenGLCapabilities(); } public GLProfile getGLProfile() { @@ -557,10 +619,6 @@ public class GLWindow extends Window implements GLAutoDrawable { return drawable.getGLProfile(); } - public NativeWindow getNativeWindow() { - return drawable.getNativeWindow(); - } - //---------------------------------------------------------------------- // Internals only below this point // diff --git a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java index e5a34a264..587bf185e 100755 --- a/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/opengl/kd/KDWindow.java @@ -63,8 +63,8 @@ public class KDWindow extends Window { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } - GLCapabilities eglCaps = (GLCapabilities)config.getCapabilities(); - int[] eglAttribs = EGLGraphicsConfiguration.GLCapabilities2AttribList(eglCaps); + GLCapabilities eglCaps = (GLCapabilities)config.getChosenCapabilities(); + int[] eglAttribs = EGLGraphicsConfiguration.GLCapabilities2AttribList(eglCaps, EGL.EGL_WINDOW_BIT); windowHandle = 0; windowID = ++_windowID; |