From 8e0f3ad54b5aa8ef4d71e0b85f84a34be4987b5e Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 17 Dec 2011 21:53:48 +0100 Subject: 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 --- .../classes/com/jogamp/newt/awt/NewtCanvasAWT.java | 31 ++++++++-------------- .../classes/jogamp/newt/awt/NewtFactoryAWT.java | 10 ++++++- 2 files changed, 20 insertions(+), 21 deletions(-) (limited to 'src/newt') 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(); + } + } -- cgit v1.2.3