diff options
author | Sven Gothel <[email protected]> | 2009-06-11 07:05:29 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-06-11 07:05:29 +0000 |
commit | 0dec290ca2ff1245f16787bb3ccc62dab4bd9bfb (patch) | |
tree | 5dbeb595e2683333401a260ccbd92c550f70fffa /src/newt/classes | |
parent | 3c5704666a2f64f66de432ef21ac223cc81131e8 (diff) |
- Fixing SPEC documentation for bindings JOGL and NativeWindow,
lot's of javadoc changes/fixes.
- Fixing transparency values RGB[A] in GLX and EGL, adding those in GLCapabilities.
- Adding EGLPbuffer (untested yet)
Added EGLOnscreenContext, EGLOnscreenDrawable and EGLPbufferContext, EGLPbufferDrawable,
which completes the now abstract EGLContext and EGLDrawable.
- Decoupling EGLDrawableFactory and DynamicLookupHelper:
Since OpenGL ES has 2 libraries and hence 2 DynamicLookupHelper, one for each,
these are decoupled in EGLES1DynamicLookupHelper and EGLES2DynamicLookupHelper,
where each uses the base class EGLDynamicLookupHelper.
EGLDynamicLookupHelper act's also as the owner of these singleton instances.
EGLDrawableFactory is now pure singleton,
and has no more relation to the ES[12] libraries.
Still, GLDrawableFactory.getFactory(GLProfile) stays, due to the selection
of the right factory, ie EGLDrawableFactory or a native one (X11GLX, WindowsWGL or MacOSXCGL).
Added GLDrawableImpl.getDynamicLookupHelper().
DynamicLookupHelper implementation is pushed down to the specialisation of GLDrawableImpl,
hence removed GLDrawableImpl implements DynamicLookupHelper.
- Fixing Locking
- Always throw an Exception if unlock is called without being locked.
- Removed NativeWindow.LOCK_NOT_SUPPORTED, since it made the locking state ambiguos.
- Using a generated Exception at locking to mark the object locked,
and to let it throw in case of double locking.
- Removed redundant lockToolkit() calls, where lockSurface() calls are made
- Fixing GLWindow wrapped toolkit (e.g. AWTWindow) usage
- In case the passed NativeWindow only contains a wrapper window,
we use the NativeWindowFactory.getNativeWindow() pipeline to produce a valid
NativeWindow. This object is only referenced within the drawable, hence we have
to use it for actual NativeWindow related operations.
- Add setVisible(): lockSurface()/unlockSurface() to allow getting the windowHandle
- Overwriting all drawable related Window method's, using the drawable's NativeWindow if exists.
- getNativeWindow()
- lockSurface()/unlockSurface()/..
- getWindowHandle()/getSurfaceHandle()
- Fix NativeWindowFactory.getNativeWindowType(),
so the custom and pure values are set once (static init) - not overwritten (prev. bug).
- NEWT: Added WindowEvent.EVENT_WINDOW_DESTROY_NOTIFY support in AWTWindow.
Now the proper dispose() calls are made to all GLEventListeners if the AWT window
is being closed - before it is actually destroyed.
- Threading now uses the AWTThreadingPlugin,
a ThreadingPlugin interface AWT implementation, containing the refactored
Threading code.
- Reintroduced getChosen*Capabilities and getRequested*Capabilites,
where get*Capabilities is renamed back to getRequested*Capabilities.
The semantics are necessary to allow the drawables (and NativeWindow)
to be regenerated in case of a device change in a multihead environment.
Otherwise there is a risk that recursive choosing of the Capabilities
will degenerate the result.
- Multihead logic ..
Exception: Xinerama, where all monitors share the same static configuration,
and the window handle 'survive'
X11, MacOSX and Win32 with a Xinerama behavior
1) Recognition of a display/screen/surface change
- It is prooven that the JAWT model (JAWT_LOCK_SURFACE_CHANGED)
while locking the surface is not reliably propagated, ie doesn't work here,
if the display change happens.
- AWT's Canvas.getGraphicsConfiguration() can reliably being used
to detect this case, ie compare the old GraphicsConfiguration with the new one.
- A solution for other native windowing toolkits must be found,
ie query the current underlying pixel-configuration, if it changed - act.
In which case the the following shall be done:
2.0) - notify all GLEventListener via the dispose(GLAutoDrawable)
2.1) - destroy the OpenGL context
2.2) - call GLDrawable's setRealized(false)
2.3) - call GLDrawable's setRealized(true)
2.4) - create a new OpenGL context
2.5) - notify all GLEventListener via the init(GLAutoDrawable)
Steps 2.0 - 2.5 are executed with GLAutoDrawable's dispose(true) call.
Step 2.3, setRealized(true) on GLDrawable shall:
2.3.1) - Choose the GLCapabilities again, based on the requested ones,
and update the choosen ones in the AbstractGraphicsConfiguration.
2.3.2) - Update AbstractScreen within the new AbstractGraphicsConfiguration to
reflect the possible screen change.
DONE: Xinerama mode: X11 + Xinerama, MacOSX
DONE: Introducing GLAutoDrawable.dispose(boolean regenerate)
DONE: 2.3.1 on setRealized(true): Windows, MacOSX (implicit on createContext)
TODO: Windows setRealized(true) on AWT Canvas getGraphicsConfiguration(),
can't lock the JAWT surface sometimes - exception, code disabled, see GLCanvas.java
TODO: 2.3.1 on setRealized(true): X11 and EGL
TODO: Find a test case, without Xinerama behavior
TODO: Code for Newt/NativeWindow to detect (1) and propagate GLAutoDrawable's dispose(true).
TESTS:
- MacOSX (Xinerama) OK
- X11
-TwinView (NV) OK
-Xinerama (NV) OK
- Win32 (Xinerama) OK
- GLAutoDrawable's dispose(true)
-
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1929 232f8b59-042b-4e1e-8c03-345bb8c30851
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; |