From bf584fba26561a1905f37251d681ac100d4a0779 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 3 Oct 2009 21:56:30 -0700 Subject: NativeWindow extends SurfaceUpdatedListener for 'surfaceUpdated' propagation. GLDrawableFactory.createGLDrawable() propagates NativeWindow to offscreen NullWindow. --- .../com/sun/opengl/impl/GLDrawableFactoryImpl.java | 32 +++++++++------ .../com/sun/opengl/impl/GLDrawableImpl.java | 2 +- .../com/sun/nativewindow/impl/NullWindow.java | 15 ++++++- .../com/sun/nativewindow/impl/jawt/JAWTWindow.java | 2 +- .../javax/media/nativewindow/NativeWindow.java | 11 +---- .../media/nativewindow/SurfaceUpdatedListener.java | 46 +++++++++++++++++++++ .../sun/javafx/newt/SurfaceUpdatedListener.java | 48 ---------------------- src/newt/classes/com/sun/javafx/newt/Window.java | 8 ++-- .../com/sun/javafx/newt/opengl/GLWindow.java | 15 ++++++- 9 files changed, 98 insertions(+), 81 deletions(-) create mode 100644 src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java delete mode 100644 src/newt/classes/com/sun/javafx/newt/SurfaceUpdatedListener.java (limited to 'src') diff --git a/src/jogl/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java b/src/jogl/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java index caa250597..66abcf841 100644 --- a/src/jogl/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java +++ b/src/jogl/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java @@ -44,6 +44,7 @@ import javax.media.nativewindow.*; import javax.media.opengl.*; import com.sun.gluegen.runtime.*; import com.sun.nativewindow.impl.NWReflection; +import com.sun.nativewindow.impl.NullWindow; import java.lang.reflect.*; /** Extends GLDrawableFactory with a few methods for handling @@ -57,43 +58,48 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { //--------------------------------------------------------------------------- // Dispatching GLDrawable construction in respect to the NativeWindow Capabilities // - public GLDrawable createGLDrawable(NativeWindow target, GLCapabilitiesChooser chooser) { - if (target == null) { + public GLDrawable createGLDrawable(NativeWindow target0, GLCapabilitiesChooser chooser) { + if (target0 == null) { throw new IllegalArgumentException("Null target"); } - AbstractGraphicsConfiguration config = target.getGraphicsConfiguration().getNativeGraphicsConfiguration(); - target = NativeWindowFactory.getNativeWindow(target, config); - GLCapabilities caps = (GLCapabilities) target.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); + AbstractGraphicsConfiguration config = target0.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + NativeWindow target1 = NativeWindowFactory.getNativeWindow(target0, config); + GLCapabilities caps = (GLCapabilities) target1.getGraphicsConfiguration().getNativeGraphicsConfiguration().getChosenCapabilities(); GLDrawable result = null; if(caps.isOnscreen()) { if(caps.isPBuffer()) { throw new IllegalArgumentException("Onscreen target can't be PBuffer: "+caps); } if(DEBUG) { - System.out.println("GLDrawableFactoryImpl.createGLDrawable -> OnscreenDrawable: "+target); + System.out.println("GLDrawableFactoryImpl.createGLDrawable -> OnscreenDrawable: "+target1); } - result = createOnscreenDrawable(target); + result = createOnscreenDrawable(target1); } else { GLCapabilities caps2 = (GLCapabilities) caps.clone(); // OFFSCREEN !DOUBLE_BUFFER caps2.setDoubleBuffered(false); if(caps2.isPBuffer() && canCreateGLPbuffer()) { if(DEBUG) { - System.out.println("GLDrawableFactoryImpl.createGLDrawable -> PbufferDrawable: "+target); + System.out.println("GLDrawableFactoryImpl.createGLDrawable -> PbufferDrawable: "+target1); } result = createGLPbufferDrawable(caps2, chooser, - target.getWidth(), - target.getHeight()); + target1.getWidth(), + target1.getHeight()); } if(null==result) { if(DEBUG) { - System.out.println("GLDrawableFactoryImpl.createGLDrawable -> OffScreenDrawable: "+target); + System.out.println("GLDrawableFactoryImpl.createGLDrawable -> OffScreenDrawable: "+target1); } result = createOffscreenDrawable(caps2, chooser, - target.getWidth(), - target.getHeight()); + target1.getWidth(), + target1.getHeight()); + } + // Set upstream NativeWindow from caller to NullWindow for SurfaceUpdatedListener event + NativeWindow nw = result.getNativeWindow(); + if(nw instanceof NullWindow) { + ((NullWindow)nw).setUpstreamNativeWindow(target0); } } if(DEBUG) { diff --git a/src/jogl/classes/com/sun/opengl/impl/GLDrawableImpl.java b/src/jogl/classes/com/sun/opengl/impl/GLDrawableImpl.java index dddba9460..020bea9f0 100644 --- a/src/jogl/classes/com/sun/opengl/impl/GLDrawableImpl.java +++ b/src/jogl/classes/com/sun/opengl/impl/GLDrawableImpl.java @@ -82,7 +82,7 @@ public abstract class GLDrawableImpl implements GLDrawable { ctx.getGL().glFinish(); } } - component.surfaceUpdated(this); + component.surfaceUpdated(this, component, System.currentTimeMillis()); } protected abstract void swapBuffersImpl(); diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java index c5a617990..6f568df13 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NullWindow.java @@ -96,7 +96,17 @@ public class NullWindow implements NativeWindow { return false; } - public void surfaceUpdated(Object updater) { } + NativeWindow upstreamNW = null; + + public void setUpstreamNativeWindow(NativeWindow upstream) { + upstreamNW = upstream; + } + + public void surfaceUpdated(Object updater, NativeWindow window, long when) { + if(null!=upstreamNW) { + upstreamNW.surfaceUpdated(updater, upstreamNW, when); + } + } public long getDisplayHandle() { return displayHandle; @@ -142,7 +152,8 @@ public class NullWindow implements NativeWindow { return "NullWindow[config "+config+ ", displayHandle 0x"+Long.toHexString(getDisplayHandle())+ ", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+ - ", size "+getWidth()+"x"+getHeight()+"]"; + ", size "+getWidth()+"x"+getHeight()+ + ", upstream "+upstreamNW+"]"; } } diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java index b4975706d..e821f9b3a 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/jawt/JAWTWindow.java @@ -129,7 +129,7 @@ public abstract class JAWTWindow implements NativeWindow { return false; } - public void surfaceUpdated(Object updater) { } + public void surfaceUpdated(Object updater, NativeWindow window, long when) { } public long getDisplayHandle() { return config.getScreen().getDevice().getHandle(); diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java index 1b000072e..37606e8d8 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindow.java @@ -52,7 +52,7 @@ package javax.media.nativewindow; it, and any time it is visible and locked, provide information such as the window handle. */ -public interface NativeWindow { +public interface NativeWindow extends SurfaceUpdatedListener { /** Returned by {@link #lockSurface()} if the surface is not ready to be locked. */ public static final int LOCK_SURFACE_NOT_READY = 1; @@ -123,15 +123,6 @@ public interface NativeWindow { */ public boolean surfaceSwap(); - /** - * Method invoked after the render toolkit (e.g. JOGL) - * swapped/changed the buffer/surface. - * - * @param updater is the caller object who updated the surface, - * e.g. a JOGL GLDrawable. - */ - public void surfaceUpdated(Object updater); - /** * render all native window information invalid, * as if the native window was destroyed diff --git a/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java b/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java new file mode 100644 index 000000000..7be15408c --- /dev/null +++ b/src/nativewindow/classes/javax/media/nativewindow/SurfaceUpdatedListener.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + */ + +package javax.media.nativewindow; + +public interface SurfaceUpdatedListener { + /** Notification of a surface update event. + * + * @param updater is the caller object who updated the surface, + * e.g. a JOGL GLDrawable. + * @param window the NativeWindow, which surface is updated + * @param when the time in ms, when the surface was updated + */ + public void surfaceUpdated(Object updater, NativeWindow window, long when) ; +} + diff --git a/src/newt/classes/com/sun/javafx/newt/SurfaceUpdatedListener.java b/src/newt/classes/com/sun/javafx/newt/SurfaceUpdatedListener.java deleted file mode 100644 index a1b0918e6..000000000 --- a/src/newt/classes/com/sun/javafx/newt/SurfaceUpdatedListener.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * - Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. ALL - * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN - * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR - * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR - * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR - * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR - * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE - * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, - * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF - * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - * - */ - -package com.sun.javafx.newt; - -import javax.media.nativewindow.NativeWindow; - -public interface SurfaceUpdatedListener extends EventListener { - /** Notification of a surface update event. - * - * @param updater is the caller object who updated the surface, - * e.g. a JOGL GLDrawable. - * @param window the NativeWindow, which surface is updated - * @param when the time in ms, when the surface was updated - */ - public void surfaceUpdated(Object updater, NativeWindow window, long when) ; -} - diff --git a/src/newt/classes/com/sun/javafx/newt/Window.java b/src/newt/classes/com/sun/javafx/newt/Window.java index 1f55eee26..3b0c3b970 100755 --- a/src/newt/classes/com/sun/javafx/newt/Window.java +++ b/src/newt/classes/com/sun/javafx/newt/Window.java @@ -186,7 +186,7 @@ public abstract class Window implements NativeWindow for (Iterator iter = surfaceUpdatedListeners.iterator(); iter.hasNext(); ) { sb.append(iter.next()+", "); } - sb.append(", WindowListeners num "+windowListeners.size()+" ["); + sb.append("], WindowListeners num "+windowListeners.size()+" ["); for (Iterator iter = windowListeners.iterator(); iter.hasNext(); ) { sb.append(iter.next()+", "); } @@ -488,16 +488,14 @@ public abstract class Window implements NativeWindow } } - public void surfaceUpdated(Object updater) { - long when = System.currentTimeMillis(); - + public void surfaceUpdated(Object updater, NativeWindow window, long when) { ArrayList listeners = null; synchronized(surfaceUpdatedListeners) { listeners = surfaceUpdatedListeners; } for(Iterator i = listeners.iterator(); i.hasNext(); ) { SurfaceUpdatedListener l = (SurfaceUpdatedListener) i.next(); - l.surfaceUpdated(updater, this, when); + l.surfaceUpdated(updater, window, when); } } 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 6e9d4aaf6..52f368148 100644 --- a/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/opengl/GLWindow.java @@ -366,6 +366,19 @@ public class GLWindow extends Window implements GLAutoDrawable { return window.isFullscreen(); } + public void addSurfaceUpdatedListener(SurfaceUpdatedListener l) { + window.addSurfaceUpdatedListener(l); + } + public void removeSurfaceUpdatedListener(SurfaceUpdatedListener l) { + window.removeSurfaceUpdatedListener(l); + } + public SurfaceUpdatedListener[] getSurfaceUpdatedListener() { + return window.getSurfaceUpdatedListener(); + } + public void surfaceUpdated(Object updater, NativeWindow window0, long when) { + window.surfaceUpdated(updater, window, when); + } + public void addMouseListener(MouseListener l) { window.addMouseListener(l); } @@ -403,7 +416,7 @@ public class GLWindow extends Window implements GLAutoDrawable { } public String toString() { - return "NEWT-GLWindow[ "+drawable+", \n\t"+window+", \n\t"+helper+", \n\t"+factory+"]"; + return "NEWT-GLWindow[ \n\tDrawable: "+drawable+", \n\tWindow: "+window+", \n\tHelper: "+helper+", \n\tFactory: "+factory+"]"; } //---------------------------------------------------------------------- -- cgit v1.2.3