summaryrefslogtreecommitdiffstats
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
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
-rwxr-xr-xmake/scripts/tests.sh5
-rw-r--r--src/jogl/classes/javax/media/opengl/awt/GLCanvas.java98
-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
-rw-r--r--src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java31
-rw-r--r--src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java10
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01GLCanvasAWT.java204
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer02NewtCanvasAWT.java (renamed from src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01AWT.java)82
10 files changed, 407 insertions, 132 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index a86485d7a..6e319e0b0 100755
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -169,7 +169,7 @@ function testswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.offscreen.TestOffscreen01GLPBufferNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.offscreen.TestOffscreen02BitmapNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestMainVersionGLWindowNEWT $*
-testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestShutdownCompleteNEWT $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestShutdownCompleteNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestShutdownSharedNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestInitConcurrentNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLProfile01NEWT $*
@@ -253,7 +253,8 @@ testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestShutdownCompleteNEWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting02AWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting03AWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocusTraversal01AWT $*
-#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingOffscreenLayer01AWT $*
+testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingOffscreenLayer01GLCanvasAWT $*
+#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingOffscreenLayer02NewtCanvasAWT $*
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestTranslucentParentingAWT $*
#testawt com.jogamp.opengl.test.junit.newt.TestCloseNewtAWT
#testawt com.jogamp.opengl.test.junit.jogl.caps.TestMultisampleAWT $*
diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
index ab4276dee..e909416d9 100644
--- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
+++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java
@@ -59,8 +59,8 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
+import javax.media.nativewindow.OffscreenLayerOption;
import javax.media.nativewindow.WindowClosingProtocol;
-import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.AbstractGraphicsScreen;
import javax.media.nativewindow.GraphicsConfigurationFactory;
@@ -92,6 +92,8 @@ import com.jogamp.opengl.JoglVersion;
import com.jogamp.common.util.locks.LockFactory;
import com.jogamp.common.util.locks.RecursiveLock;
+
+import jogamp.nativewindow.jawt.JAWTWindow;
import jogamp.opengl.Debug;
import jogamp.opengl.GLContextImpl;
import jogamp.opengl.GLDrawableHelper;
@@ -136,7 +138,7 @@ import jogamp.opengl.ThreadingImpl;
*/
@SuppressWarnings("serial")
-public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosingProtocol {
+public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosingProtocol, OffscreenLayerOption {
private static final boolean DEBUG;
@@ -156,6 +158,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
private GLContext shareWith;
private int additionalCtxCreationFlags = 0;
private GraphicsDevice device;
+ private boolean shallUseOffscreenLayer = false;
private AWTWindowClosingProtocol awtWindowClosingProtocol =
new AWTWindowClosingProtocol(this, new Runnable() {
@@ -250,6 +253,22 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
this.device = device;
}
+ public void setShallUseOffscreenLayer(boolean v) {
+ shallUseOffscreenLayer = v;
+ }
+
+ public final boolean getShallUseOffscreenLayer() {
+ return shallUseOffscreenLayer;
+ }
+
+ public final boolean isOffscreenLayerSurfaceEnabled() {
+ if(null != drawable) {
+ return ((JAWTWindow)drawable.getNativeSurface()).isOffscreenLayerSurfaceEnabled();
+ }
+ return false;
+ }
+
+
/**
* Overridden to choose a GraphicsConfiguration on a parent container's
* GraphicsDevice because both devices
@@ -406,15 +425,15 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
private void dispose(boolean regenerate) {
drawableSync.lock();
try {
+ final GLAnimatorControl animator = getAnimator();
if(DEBUG) {
- Exception ex1 = new Exception("Info: dispose("+regenerate+") - start, hasContext " +
- (null!=context) + ", hasDrawable " + (null!=drawable));
+ Exception ex1 = new Exception("Info: dispose("+regenerate+") - START, hasContext " +
+ (null!=context) + ", hasDrawable " + (null!=drawable)+", "+animator);
ex1.printStackTrace();
}
if(null!=context) {
boolean animatorPaused = false;
- GLAnimatorControl animator = getAnimator();
if(null!=animator) {
// can't remove us from animator for recreational addNotify()
animatorPaused = animator.pause();
@@ -452,7 +471,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
}
if(DEBUG) {
- System.err.println("dispose("+regenerate+") - stop");
+ System.err.println("dispose("+regenerate+") - END, "+animator);
}
} finally {
drawableSync.unlock();
@@ -532,15 +551,6 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
throw new GLException("Error: NULL AWTGraphicsConfiguration");
}
- if (!Beans.isDesignTime()) {
- // no lock required, since this resource ain't available yet
- drawable = GLDrawableFactory.getFactory(capsReqUser.getGLProfile())
- .createGLDrawable(NativeWindowFactory.getNativeWindow(this, awtConfig));
- context = (GLContextImpl) drawable.createContext(shareWith);
- context.setSynchronized(true);
- context.setContextCreationFlags(additionalCtxCreationFlags);
- }
-
// before native peer is valid: X11
disableBackgroundErase();
@@ -550,6 +560,10 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
// after native peer is valid: Windows
disableBackgroundErase();
+ if (!Beans.isDesignTime()) {
+ createDrawableAndContext();
+ }
+
// init drawable by paint/display makes the init sequence more equal
// for all launch flavors (applet/javaws/..)
// validateGLDrawable();
@@ -562,6 +576,21 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
}
}
+ private void createDrawableAndContext() {
+ // no lock required, since this resource ain't available yet
+ final JAWTWindow jawtWindow = (JAWTWindow) NativeWindowFactory.getNativeWindow(this, awtConfig);
+ jawtWindow.setShallUseOffscreenLayer(shallUseOffscreenLayer);
+ jawtWindow.lockSurface();
+ try {
+ drawable = GLDrawableFactory.getFactory(capsReqUser.getGLProfile()).createGLDrawable(jawtWindow);
+ context = (GLContextImpl) drawable.createContext(shareWith);
+ context.setSynchronized(true);
+ context.setContextCreationFlags(additionalCtxCreationFlags);
+ } finally {
+ jawtWindow.unlockSurface();
+ }
+ }
+
private boolean validateGLDrawable() {
boolean realized = false;
if (!Beans.isDesignTime()) {
@@ -636,7 +665,11 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
@Override
public void reshape(int x, int y, int width, int height) {
super.reshape(x, y, width, height);
- sendReshape = true;
+ if(null != drawable && drawable.isRealized() && !drawable.getChosenGLCapabilities().isOnscreen()) {
+ dispose(true);
+ } else {
+ sendReshape = true;
+ }
}
/** <B>Overrides:</B>
@@ -811,21 +844,24 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
}
if(null!=drawable) {
+ final JAWTWindow jawtWindow = (JAWTWindow)drawable.getNativeSurface();
drawable.setRealized(false);
drawable=null;
+ if(null!=jawtWindow) {
+ jawtWindow.destroy();
+ }
}
-
+
if(disposeRegenerate) {
- // recreate GLDrawable to reflect it's new graphics configuration
- drawable = GLDrawableFactory.getFactory(capsReqUser.getGLProfile())
- .createGLDrawable(NativeWindowFactory.getNativeWindow(GLCanvas.this, awtConfig));
+ // Similar process as in addNotify()!
+
+ // Recreate GLDrawable/GLContext to reflect it's new graphics configuration
+ createDrawableAndContext();
+
if(DEBUG) {
System.err.println("GLCanvas.dispose(true): new drawable: "+drawable);
}
- drawable.setRealized(true);
- context = (GLContextImpl) drawable.createContext(shareWith);
- context.setSynchronized(true);
- sendReshape=true; // ensure a reshape is being send ..
+ validateGLDrawable(); // immediate attempt to recreate the drawable
}
}
}
@@ -843,20 +879,20 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing
class DisposeAbstractGraphicsDeviceAction implements Runnable {
public void run() {
- AbstractGraphicsConfiguration aconfig = (null!=awtConfig) ? awtConfig.getNativeGraphicsConfiguration() : null;
- AbstractGraphicsScreen ascreen = (null!=aconfig) ? aconfig.getScreen() : null;
- AbstractGraphicsDevice adevice = (null!=ascreen) ? ascreen.getDevice() : null;
- if(null!=adevice) {
- String adeviceMsg=null;
+ if(null != awtConfig) {
+ final AbstractGraphicsDevice adevice = awtConfig.getScreen().getDevice();
+ final String adeviceMsg;
if(DEBUG) {
adeviceMsg = adevice.toString();
+ } else {
+ adeviceMsg = null;
}
- boolean closed = adevice.close();
+ boolean closed = awtConfig.getScreen().getDevice().close();
if(DEBUG) {
System.err.println(Thread.currentThread().getName() + " - GLCanvas.dispose(false): closed GraphicsDevice: "+adeviceMsg+", result: "+closed);
}
+ awtConfig=null;
}
- awtConfig=null;
}
}
private DisposeAbstractGraphicsDeviceAction disposeAbstractGraphicsDeviceAction = new DisposeAbstractGraphicsDeviceAction();
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());
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index 2506710f5..a71c6106d 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -42,6 +42,7 @@ import java.security.PrivilegedAction;
import java.util.Set;
import javax.media.nativewindow.NativeWindow;
+import javax.media.nativewindow.OffscreenLayerOption;
import javax.media.nativewindow.WindowClosingProtocol;
import javax.media.nativewindow.awt.AWTWindowClosingProtocol;
import javax.swing.MenuSelectionManager;
@@ -66,7 +67,7 @@ import com.jogamp.newt.event.awt.AWTKeyAdapter;
import com.jogamp.newt.event.awt.AWTMouseAdapter;
@SuppressWarnings("serial")
-public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProtocol {
+public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProtocol, OffscreenLayerOption {
public static final boolean DEBUG = Debug.debug("Window");
private JAWTWindow jawtWindow = null;
@@ -115,28 +116,18 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
setNEWTChild(child);
}
- /**
- * Request an JAWT offscreen layer if supported it.
- * Shall be called before {@link #addNotify()} is issued,
- * ie. before adding the component to the AWT tree and make it visible.
- *
- * @see #isOffscreenLayerSurface()
- */
public void setShallUseOffscreenLayer(boolean v) {
shallUseOffscreenLayer = v;
}
- /**
- * Returns true if the underlying JAWT uses offscreen layering,
- * otherwise false. This information is valid only after {@link #addNotify()} is issued,
- * ie. before adding the component to the AWT tree and make it visible.
- *
- * @see #setShallUseOffscreenLayer(boolean)
- */
- public boolean isOffscreenLayerSurface() {
- return jawtWindow.isOffscreenLayerSurfaceEnabled();
+ public final boolean getShallUseOffscreenLayer() {
+ return shallUseOffscreenLayer;
}
+ public final boolean isOffscreenLayerSurfaceEnabled() {
+ return jawtWindow.isOffscreenLayerSurfaceEnabled();
+ }
+
/**
* Returns true if the AWT component is parented to an {@link java.applet.Applet},
* otherwise false. This information is valid only after {@link #addNotify()} is issued,
@@ -404,7 +395,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
newtChild.setVisible(false);
newtChild.reparentWindow(null);
if(null != jawtWindow) {
- jawtWindow.destroy();
+ NewtFactoryAWT.destroyNativeWindow(jawtWindow);
jawtWindow=null;
}
}
@@ -429,7 +420,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
}
configureNewtChild(false);
if(null!=jawtWindow) {
- jawtWindow.destroy();
+ NewtFactoryAWT.destroyNativeWindow(jawtWindow);
jawtWindow=null;
}
newtChild.setVisible(false);
@@ -440,7 +431,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
cont.remove(this);
}
}
- }
+ }
@Override
public void paint(Graphics g) {
diff --git a/src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java b/src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java
index ea4960053..2ca3d2cfd 100644
--- a/src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java
+++ b/src/newt/classes/jogamp/newt/awt/NewtFactoryAWT.java
@@ -28,6 +28,7 @@
package jogamp.newt.awt;
+import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.CapabilitiesImmutable;
import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowException;
@@ -74,6 +75,13 @@ public class NewtFactoryAWT extends NewtFactory {
System.err.println("NewtFactoryAWT.getNativeWindow: "+awtComp+" -> "+nw);
}
return (JAWTWindow)nw;
- }
+ }
+
+ public static void destroyNativeWindow(JAWTWindow jawtWindow) {
+ final AbstractGraphicsConfiguration config = jawtWindow.getGraphicsConfiguration();
+ jawtWindow.destroy();
+ config.getScreen().getDevice().close();
+ }
+
}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01GLCanvasAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01GLCanvasAWT.java
new file mode 100644
index 000000000..d8c75624e
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01GLCanvasAWT.java
@@ -0,0 +1,204 @@
+/**
+ * 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 com.jogamp.opengl.test.junit.newt.parenting;
+
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.media.opengl.GLAnimatorControl;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.awt.GLCanvas;
+
+import jogamp.nativewindow.jawt.JAWTUtil;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.newt.Window;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.Animator;
+
+public class TestParentingOffscreenLayer01GLCanvasAWT extends UITestCase {
+ static Dimension frameSize0;
+ static Dimension frameSize1;
+ static Dimension preferredGLSize;
+ static Dimension minGLSize;
+ static long durationPerTest = 1000;
+
+ @BeforeClass
+ public static void initClass() {
+ frameSize0 = new Dimension(500,300);
+ frameSize1 = new Dimension(800,600);
+ preferredGLSize = new Dimension(400,200);
+ minGLSize = new Dimension(200,100);
+ }
+
+ private void setupFrameAndShow(final Frame f, java.awt.Component comp) throws InterruptedException, InvocationTargetException {
+
+ Container c = new Container();
+ c.setLayout(new BorderLayout());
+ c.add(new Button("north"), BorderLayout.NORTH);
+ c.add(new Button("south"), BorderLayout.SOUTH);
+ c.add(new Button("east"), BorderLayout.EAST);
+ c.add(new Button("west"), BorderLayout.WEST);
+ c.add(comp, BorderLayout.CENTER);
+
+ f.setLayout(new BorderLayout());
+ f.add(new Button("NORTH"), BorderLayout.NORTH);
+ f.add(new Button("SOUTH"), BorderLayout.SOUTH);
+ f.add(new Button("EAST"), BorderLayout.EAST);
+ f.add(new Button("WEST"), BorderLayout.WEST);
+ f.add(c, BorderLayout.CENTER);
+
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f.validate();
+ f.setVisible(true);
+ }});
+ }
+ private void end(GLAnimatorControl actrl, final Frame f, Window w) throws InterruptedException, InvocationTargetException {
+ actrl.stop();
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ f.dispose();
+ } } );
+ if(null != w) {
+ w.destroy();
+ }
+ }
+
+ @Test
+ public void testOnscreenLayerGLCanvas_Onscreen() throws InterruptedException, InvocationTargetException {
+ testOffscreenLayerGLCanvas_Impl(false, false);
+ }
+
+ @Test
+ public void testOffscreenLayerGLCanvas_OffscreenLayerWithOffscreenClass() throws InterruptedException, InvocationTargetException {
+ testOffscreenLayerGLCanvas_Impl(true, true);
+ }
+
+ @Test
+ public void testOffscreenLayerGLCanvas_OffscreenLayerWithOnscreenClass() throws InterruptedException, InvocationTargetException {
+ testOffscreenLayerGLCanvas_Impl(true, false);
+ }
+
+ private void testOffscreenLayerGLCanvas_Impl(boolean offscreenLayer, boolean offscreenClass) throws InterruptedException, InvocationTargetException {
+ final Frame frame1 = new Frame("AWT Parent Frame");
+
+ GLCapabilities glCaps = new GLCapabilities(null);
+ if(offscreenClass) {
+ glCaps.setOnscreen(false);
+ glCaps.setPBuffer(true);
+ }
+
+ final GLCanvas glc = new GLCanvas(glCaps);
+ glc.setShallUseOffscreenLayer(offscreenLayer); // trigger offscreen layer - if supported
+ glc.setPreferredSize(preferredGLSize);
+ glc.setMinimumSize(minGLSize);
+
+ GLEventListener demo1 = new GearsES2(1);
+ glc.addGLEventListener(demo1);
+
+ frame1.setSize(frameSize0);
+ setupFrameAndShow(frame1, glc);
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glc, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(glc, true));
+ Assert.assertEquals(JAWTUtil.isOffscreenLayerSupported() && offscreenLayer,
+ glc.isOffscreenLayerSurfaceEnabled());
+
+ GLAnimatorControl animator1 = new Animator(glc);
+ animator1.start();
+
+ Thread.sleep(durationPerTest/2);
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame1.setSize(frameSize1);
+ frame1.validate();
+ }});
+
+ Thread.sleep(durationPerTest/2);
+
+ end(animator1, frame1, null);
+ }
+
+ public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
+ Assert.assertNotNull(demo);
+ Assert.assertNotNull(glWindow);
+ Window window = glWindow.getDelegatedWindow();
+ if(debug) {
+ MiscUtils.setFieldIfExists(demo, "glDebug", true);
+ MiscUtils.setFieldIfExists(demo, "glTrace", true);
+ }
+ if(!MiscUtils.setFieldIfExists(demo, "window", window)) {
+ MiscUtils.setFieldIfExists(demo, "glWindow", glWindow);
+ }
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ String tstname = TestParentingOffscreenLayer01GLCanvasAWT.class.getName();
+ /*
+ org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
+ tstname,
+ "filtertrace=true",
+ "haltOnError=false",
+ "haltOnFailure=false",
+ "showoutput=true",
+ "outputtoformatters=true",
+ "logfailedtests=true",
+ "logtestlistenerevents=true",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01AWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer02NewtCanvasAWT.java
index fb2f7342e..bc59c7378 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer01AWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParentingOffscreenLayer02NewtCanvasAWT.java
@@ -39,7 +39,8 @@ import java.lang.reflect.InvocationTargetException;
import javax.media.opengl.GLAnimatorControl;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
-import javax.media.opengl.awt.GLCanvas;
+
+import jogamp.nativewindow.jawt.JAWTUtil;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -49,19 +50,22 @@ import com.jogamp.newt.Window;
import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
import com.jogamp.opengl.test.junit.util.MiscUtils;
import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.util.Animator;
-public class TestParentingOffscreenLayer01AWT extends UITestCase {
- static Dimension frameSize;
+public class TestParentingOffscreenLayer02NewtCanvasAWT extends UITestCase {
+ static Dimension frameSize0;
+ static Dimension frameSize1;
static Dimension preferredGLSize;
static Dimension minGLSize;
- static long durationPerTest = 800;
+ static long durationPerTest = 1000;
@BeforeClass
public static void initClass() {
- frameSize = new Dimension(500,300);
+ frameSize0 = new Dimension(500,300);
+ frameSize1 = new Dimension(800,600);
preferredGLSize = new Dimension(400,200);
minGLSize = new Dimension(200,100);
}
@@ -85,7 +89,6 @@ public class TestParentingOffscreenLayer01AWT extends UITestCase {
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- // f.pack();
f.validate();
f.setVisible(true);
}});
@@ -101,48 +104,26 @@ public class TestParentingOffscreenLayer01AWT extends UITestCase {
}
}
- // @Test
- public void testOffscreenLayerPath0_GLCanvas() throws InterruptedException, InvocationTargetException {
- final Frame frame1 = new Frame("AWT Parent Frame");
-
- GLCapabilities glCaps = new GLCapabilities(null);
- final GLCanvas glc = new GLCanvas(glCaps);
- glc.setPreferredSize(preferredGLSize);
- glc.setMinimumSize(minGLSize);
-
- GLEventListener demo1 = new GearsES2(1);
- glc.addGLEventListener(demo1);
-
- frame1.setSize(frameSize);
- setupFrameAndShow(frame1, glc);
-
- GLAnimatorControl animator1 = new Animator(glc);
- animator1.start();
-
- Thread.sleep(durationPerTest);
- end(animator1, frame1, null);
- }
-
@Test
- public void testOnscreenLayer() throws InterruptedException, InvocationTargetException {
- testOffscreenLayerPath1_Impl(false, false);
+ public void testOnscreenLayerNewtCanvas_Onscreen() throws InterruptedException, InvocationTargetException {
+ testOffscreenLayerNewtCanvas_Impl(false, false);
}
@Test
- public void testOffscreenLayerPath1_NewtOffscreen() throws InterruptedException, InvocationTargetException {
- testOffscreenLayerPath1_Impl(true, true);
+ public void testOffscreenLayerNewtCanvas_OffscreenLayerWithOffscreenClass() throws InterruptedException, InvocationTargetException {
+ testOffscreenLayerNewtCanvas_Impl(true, true);
}
@Test
- public void testOffscreenLayerPath1_NewtOnscreen() throws InterruptedException, InvocationTargetException {
- testOffscreenLayerPath1_Impl(true, false);
+ public void testOffscreenLayerNewtCanvas_OffscreenLayerWithOnscreenClass() throws InterruptedException, InvocationTargetException {
+ testOffscreenLayerNewtCanvas_Impl(true, false);
}
- private void testOffscreenLayerPath1_Impl(boolean offscreenLayer, boolean newtOffscreenClass) throws InterruptedException, InvocationTargetException {
+ private void testOffscreenLayerNewtCanvas_Impl(boolean offscreenLayer, boolean offscreenClass) throws InterruptedException, InvocationTargetException {
final Frame frame1 = new Frame("AWT Parent Frame");
GLCapabilities glCaps = new GLCapabilities(null);
- if(newtOffscreenClass) {
+ if(offscreenClass) {
glCaps.setOnscreen(false);
glCaps.setPBuffer(true);
}
@@ -159,26 +140,29 @@ public class TestParentingOffscreenLayer01AWT extends UITestCase {
glWindow1.addGLEventListener(demo1);
glWindow1.addKeyListener(new NewtAWTReparentingKeyAdapter(frame1, newtCanvasAWT1, glWindow1));
- frame1.setSize(frameSize);
+ frame1.setSize(frameSize0);
setupFrameAndShow(frame1, newtCanvasAWT1);
- Assert.assertTrue(glWindow1.isNativeValid());
+ Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glWindow1, true));
+ Assert.assertEquals(true, AWTRobotUtil.waitForVisible(glWindow1, true));
Assert.assertEquals(newtCanvasAWT1.getNativeWindow(),glWindow1.getParent());
-
+ Assert.assertEquals(JAWTUtil.isOffscreenLayerSupported() && offscreenLayer,
+ newtCanvasAWT1.isOffscreenLayerSurfaceEnabled());
+
GLAnimatorControl animator1 = new Animator(glWindow1);
animator1.start();
- Thread.sleep(durationPerTest);
+ Thread.sleep(durationPerTest/2);
+ javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame1.setSize(frameSize1);
+ frame1.validate();
+ }});
+
+ Thread.sleep(durationPerTest/2);
+
end(animator1, frame1, glWindow1);
}
- // @Test
- public void testOffscreenLayerPath2_NewtOffscreen() throws InterruptedException, InvocationTargetException {
- testOffscreenLayerPath2_Impl(true);
- }
-
- private void testOffscreenLayerPath2_Impl(boolean newtOffscreenClass) throws InterruptedException, InvocationTargetException {
- }
-
public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
Assert.assertNotNull(demo);
Assert.assertNotNull(glWindow);
@@ -206,7 +190,7 @@ public class TestParentingOffscreenLayer01AWT extends UITestCase {
durationPerTest = atoi(args[++i]);
}
}
- String tstname = TestParentingOffscreenLayer01AWT.class.getName();
+ String tstname = TestParentingOffscreenLayer02NewtCanvasAWT.class.getName();
/*
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
tstname,