aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-12-17 21:53:48 +0100
committerSven Gothel <[email protected]>2011-12-17 21:53:48 +0100
commit8e0f3ad54b5aa8ef4d71e0b85f84a34be4987b5e (patch)
tree5ac1839053c5d5458e48d4646f1b19499fd752ec /src/nativewindow
parent47dc069104723f3d2e8d9ebdd700182e067163d0 (diff)
New Interface 'OffscreenLayerOption', impl. by JAWTWindow (impl) and NewtCanvasAWT/GLCanvas (delegation) ; Fix GLCanvas OffscreenLayerSurface usage.
JAWTWindow.destroy(): - No more getGraphicsConfiguration().getScreen().getDevice().close() call, since the configuration (hence the device) is passed @ creation and owned by the caller. New Interface 'OffscreenLayerOption', impl. by JAWTWindow (impl) and NewtCanvasAWT/GLCanvas (delegation) - Abstract offscreenLayer option to be delegated by using classes - Allow offscreen testing of GLCanvas as well (like NewtCanvasAWT) Fix GLCanvas OffscreenLayerSurface usage - common 'createDrawableAndContext()' for context and drawable instance creation - addNotify() calls createDrawableAndContext() after super.addNotify() to be able to lock the surface (JAWTWindow) and hence to determine offscreen usage. - reshape(...) issues recreation 'dispose(true)' in case of using an offscreen layer - dispose() explicitly destroys the JAWTWindow NewtCanvasAWT: - explicitly close the device of the JAWTWindow (as GLCanvas does) Tests: com.jogamp.opengl.test.junit.newt.parenting.TestParentingOffscreenLayer01GLCanvasAWT com.jogamp.opengl.test.junit.newt.parenting.TestParentingOffscreenLayer02NewtCanvasAWT
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java16
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerOption.java61
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java3
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java29
4 files changed, 80 insertions, 29 deletions
diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
index aa0851bcf..c69b18b30 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java
@@ -528,24 +528,28 @@ public abstract class NativeWindowFactory {
* Returns the {@link OffscreenLayerSurface} instance of this {@link NativeSurface}.
* <p>
* In case this surface is a {@link NativeWindow}, we traverse from the given surface
- * up to root until a {@link OffscreenLayerSurface} is found.
+ * up to root until an implementation of {@link OffscreenLayerSurface} is found.
+ * In case <code>ifEnabled</code> is true, the surface must also implement {@link OffscreenLayerOption}
+ * where {@link OffscreenLayerOption#isOffscreenLayerSurfaceEnabled()} is <code>true</code>.
* </p>
*
* @param surface The surface to query.
- * @param ifEnabled If true, only return the enabled {@link OffscreenLayerSurface}, see {@link OffscreenLayerSurface#isOffscreenLayerSurfaceEnabled()}.
+ * @param ifEnabled If true, only return the enabled {@link OffscreenLayerSurface}, see {@link OffscreenLayerOption#isOffscreenLayerSurfaceEnabled()}.
* @return
*/
public static OffscreenLayerSurface getOffscreenLayerSurface(NativeSurface surface, boolean ifEnabled) {
- if(surface instanceof OffscreenLayerSurface) {
+ if(surface instanceof OffscreenLayerSurface &&
+ ( !ifEnabled || surface instanceof OffscreenLayerOption ) ) {
final OffscreenLayerSurface ols = (OffscreenLayerSurface) surface;
- return ( !ifEnabled || ols.isOffscreenLayerSurfaceEnabled() ) ? ols : null;
+ return ( !ifEnabled || ((OffscreenLayerOption)ols).isOffscreenLayerSurfaceEnabled() ) ? ols : null;
}
if(surface instanceof NativeWindow) {
NativeWindow nw = ((NativeWindow) surface).getParent();
while(null != nw) {
- if(nw instanceof OffscreenLayerSurface) {
+ if(nw instanceof OffscreenLayerSurface &&
+ ( !ifEnabled || nw instanceof OffscreenLayerOption ) ) {
final OffscreenLayerSurface ols = (OffscreenLayerSurface) nw;
- return ( !ifEnabled || ols.isOffscreenLayerSurfaceEnabled() ) ? ols : null;
+ return ( !ifEnabled || ((OffscreenLayerOption)ols).isOffscreenLayerSurfaceEnabled() ) ? ols : null;
}
nw = nw.getParent();
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerOption.java b/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerOption.java
new file mode 100644
index 000000000..12d30b3cd
--- /dev/null
+++ b/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerOption.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright 2011 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package javax.media.nativewindow;
+
+/**
+ * Handling requests for using an {@link OffscreenLayerSurface}
+ * within the implementation.
+ */
+public interface OffscreenLayerOption {
+ /**
+ * Request an offscreen layer, if supported.
+ * <p>
+ * Shall be called before the first {@link NativeWindow#lockSurface()},
+ * and hence before realization.
+ * </p>
+ *
+ * @see #getShallUseOffscreenLayer()
+ * @see #isOffscreenLayerSurfaceEnabled()
+ */
+ public void setShallUseOffscreenLayer(boolean v);
+
+ /** Returns the property set by {@link #setShallUseOffscreenLayer(boolean)}. */
+ public boolean getShallUseOffscreenLayer();
+
+ /**
+ * Returns true if this instance uses an offscreen layer, otherwise false.
+ * <p>
+ * This instance is an offscreen layer, if {@link #setShallUseOffscreenLayer(boolean) setShallUseOffscreenLayer(true)}
+ * has been called before it's realization and first lock and the underlying implementation supports it.
+ * </p>
+ * The return value is undefined before issuing the first {@link NativeWindow#lockSurface()}.
+ *
+ * @see #setShallUseOffscreenLayer(boolean)
+ */
+ public boolean isOffscreenLayerSurfaceEnabled();
+} \ No newline at end of file
diff --git a/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java b/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java
index 82ae0f39e..dd36509ba 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java
@@ -31,9 +31,6 @@ package javax.media.nativewindow;
* Interface specifying the offscreen layer surface protocol.
*/
public interface OffscreenLayerSurface {
- /** Returns true if this instance uses an offscreen layer, otherwise false. */
- public boolean isOffscreenLayerSurfaceEnabled();
-
/**
* Attach the offscreen layer to this offscreen layer surface.
* @see #isOffscreenLayerSurfaceEnabled()
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
index 938760801..6d2860374 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
@@ -48,6 +48,7 @@ import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.NativeSurface;
import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowException;
+import javax.media.nativewindow.OffscreenLayerOption;
import javax.media.nativewindow.OffscreenLayerSurface;
import javax.media.nativewindow.SurfaceUpdatedListener;
import javax.media.nativewindow.awt.AWTGraphicsConfiguration;
@@ -59,7 +60,7 @@ import javax.media.nativewindow.util.RectangleImmutable;
import jogamp.nativewindow.SurfaceUpdatedHelper;
-public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface {
+public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, OffscreenLayerOption {
protected static final boolean DEBUG = JAWTUtil.DEBUG;
// user properties
@@ -102,22 +103,18 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface
this.isApplet = false;
}
- /**
- * Request an JAWT offscreen layer if supported.
- * Shall be called before {@link #lockSurface()}.
- *
- * @see #getShallUseOffscreenLayer()
- * @see #isOffscreenLayerSurfaceEnabled()
- */
public void setShallUseOffscreenLayer(boolean v) {
shallUseOffscreenLayer = v;
}
- /** Returns the property set by {@link #setShallUseOffscreenLayer(boolean)}. */
public final boolean getShallUseOffscreenLayer() {
return shallUseOffscreenLayer;
}
+ public final boolean isOffscreenLayerSurfaceEnabled() {
+ return isOffscreenLayerSurface;
+ }
+
protected synchronized void invalidate() {
invalidateNative();
jawt = null;
@@ -167,14 +164,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface
/**
* {@inheritDoc}
- * @see #setShallUseOffscreenLayer(boolean)
- */
- public final boolean isOffscreenLayerSurfaceEnabled() {
- return isOffscreenLayerSurface;
- }
-
- /**
- * {@inheritDoc}
*/
public final void attachSurfaceLayer(final long layerHandle) throws NativeWindowException {
if( !isOffscreenLayerSurfaceEnabled() ) {
@@ -356,7 +345,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface
public synchronized void destroy() {
invalidate();
- getGraphicsConfiguration().getScreen().getDevice().close();
component = null; // don't dispose the AWT component, since we are merely an immutable uplink
}
@@ -454,14 +442,15 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface
return component.hasFocus();
}
- @Override
+ @Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("JAWT-Window["+
"windowHandle 0x"+Long.toHexString(getWindowHandle())+
", surfaceHandle 0x"+Long.toHexString(getSurfaceHandle())+
- ", bounds "+bounds+", insets "+insets);
+ ", bounds "+bounds+", insets "+insets+
+ ", shallUseOffscreenLayer "+shallUseOffscreenLayer+", isOffscreenLayerSurface "+isOffscreenLayerSurface);
if(null!=component) {
sb.append(", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+
", visible "+component.isVisible());