aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/classes/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-11-12 16:15:54 +0100
committerSven Gothel <[email protected]>2011-11-12 16:15:54 +0100
commit8a16d590fe2c739badbabe4906cbe9d60b20e2b9 (patch)
tree57d7c0794437d2025aae7c29b340af952b5043bb /src/newt/classes/com
parent33aaa037e31ec7d411f4acaeea63a383037f027d (diff)
OS X Layered View Part8: Generalize OffscreenLayerSurface ; Use local JAWT instance ; Applet's on OS X are working
Generalize OffscreenLayerSurface - Using new OffscreenLayerSurface allows using this functionality in a clean manner, ie. no 'dirty' usage of MacOSXJAWTWindow in a JOGL GL class. - 'Promoting' OffscreenLayerSurface functionality to JAWTWindow and it's handling to GLDrawableFactoryImpl::createGLDrawable(). - Move MacOSXCGLDrawableFactory's "MacOSXJAWTWindow getLayeredSurfaceHost(NativeSurface surface)" to NativeWindowFactory "OffscreenLayerSurface getOffscreenLayerSurface(NativeSurface surface, boolean ifEnabled)" Use local JAWT instance - Only w/ a local JAWT instance per JAWTWindow it is possible to switch between offscreen-layer and onscreen. We also have to determing offscreen-layer lazy at surface lock, since only at that time we have knowledge whether it's an Applet or not. +++ ContextUpdater: Use local pthread mutex, add DEBUG output JAWTWindow/NewtCanvasAWT: Adding methods to request offscreen-layer-surface (if supported), besides 'if applet' this may trigger the new functionality. +++ Applet's on OS X are working: - OS X 10.6.4 - Safari: - Hangs for a while at start .. whole screen freezes .. approx. 10s - Sometimes crashes when Applet stops - after all our resources are released! - Keyboard input isn't assigned sometimes. - Otherwise .. works well, incl. offscreen/onscreen parenting - Firefox 8.0: - Hangs for a while at start .. whole screen freezes .. approx. 10s - Sometimes crashes when Applet stops - after all our resources are released! - Keyboard input is never assigned. - Otherwise .. works well, incl. offscreen/onscreen parenting - OS X 10.7 - Safari: - Sometimes crashes when Applet stops - after all our resources are released! - Keyboard input isn't assigned sometimes. - Otherwise .. works well, incl. offscreen/onscreen parenting - Firefox 8.0: - Sometimes crashes when Applet stops - after all our resources are released! - Keyboard input is never assigned. - Otherwise .. works well, incl. offscreen/onscreen parenting
Diffstat (limited to 'src/newt/classes/com')
-rw-r--r--src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java48
-rwxr-xr-xsrc/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java89
-rwxr-xr-xsrc/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java44
3 files changed, 153 insertions, 28 deletions
diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
index 1ce8f09ca..8a0cb8d6c 100644
--- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
+++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java
@@ -47,6 +47,7 @@ import javax.media.nativewindow.awt.AWTWindowClosingProtocol;
import javax.swing.MenuSelectionManager;
import jogamp.nativewindow.awt.AWTMisc;
+import jogamp.nativewindow.jawt.JAWTWindow;
import jogamp.newt.Debug;
import jogamp.newt.awt.event.AWTParentWindowAdapter;
import jogamp.newt.awt.event.NewtFactoryAWT;
@@ -64,7 +65,7 @@ import com.jogamp.newt.event.awt.AWTMouseAdapter;
public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProtocol {
public static final boolean DEBUG = Debug.debug("Window");
- NativeWindow nativeWindow = null;
+ JAWTWindow jawtWindow = null;
Window newtChild = null;
boolean isNewtChildOnscreen = true;
int newtChildCloseOp;
@@ -130,7 +131,38 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
}
private final void createNativeWindow(CapabilitiesImmutable caps) {
- nativeWindow = NewtFactoryAWT.getNativeWindow(this, caps);
+ jawtWindow = NewtFactoryAWT.getNativeWindow(this, caps);
+ }
+
+ /**
+ * 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) {
+ jawtWindow.setShallUseOffscreenLayer(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();
+ }
+
+ /**
+ * 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,
+ * ie. before adding the component to the AWT tree and make it visible.
+ */
+ public boolean isApplet() {
+ return jawtWindow.isApplet();
}
class FocusAction implements Window.FocusRunnable {
@@ -195,7 +227,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
/** @return this AWT Canvas NativeWindow representation, may be null in case {@link #removeNotify()} has been called,
* or {@link #addNotify()} hasn't been called yet.*/
- public NativeWindow getNativeWindow() { return nativeWindow; }
+ public NativeWindow getNativeWindow() { return jawtWindow; }
public int getDefaultCloseOperation() {
return awtWindowClosingProtocol.getDefaultCloseOperation();
@@ -285,7 +317,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
newtChild.setFocusAction(null); // no AWT focus traversal ..
if(add) {
- NewtFactoryAWT.updateGraphicsConfiguration(nativeWindow, this);
+ NewtFactoryAWT.updateGraphicsConfiguration(jawtWindow, this);
if(DEBUG) {
System.err.println("NewtCanvasAWT.reparentWindow: "+newtChild);
}
@@ -308,7 +340,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
}
setSize(w, h);
newtChild.setSize(w, h);
- newtChild.reparentWindow(nativeWindow);
+ newtChild.reparentWindow(jawtWindow);
newtChild.setVisible(true);
configureNewtChild(true);
newtChild.sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); // trigger a resize/relayout to listener
@@ -338,9 +370,9 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto
System.err.println("NewtCanvasAWT.destroy(): "+newtChild+", from "+cont);
}
configureNewtChild(false);
- if(null!=nativeWindow) {
- nativeWindow.destroy();
- nativeWindow=null;
+ if(null!=jawtWindow) {
+ jawtWindow.destroy();
+ jawtWindow=null;
}
newtChild.setVisible(false);
newtChild.reparentWindow(null);
diff --git a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java
index 2e86cb512..7ba892b37 100755
--- a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java
+++ b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtApplet1Run.java
@@ -1,20 +1,50 @@
+/**
+ * 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.newt.awt.applet;
-import java.applet.*;
+import java.applet.Applet;
+import java.awt.BorderLayout;
+import java.awt.Button;
import java.awt.Component;
import java.awt.Container;
-import java.awt.Label;
+import java.awt.event.KeyListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
-import java.awt.event.KeyListener;
-import javax.media.opengl.*;
+import javax.media.opengl.FPSCounter;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+
+import jogamp.newt.Debug;
import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.opengl.GLWindow;
-import java.awt.BorderLayout;
-
-import jogamp.newt.Debug;
/**
* Simple GLEventListener deployment as an applet using JOGL. This demo must be
@@ -62,7 +92,7 @@ import jogamp.newt.Debug;
*/
@SuppressWarnings("serial")
public class JOGLNewtApplet1Run extends Applet {
- public static final boolean DEBUG = Debug.debug("Applet");
+ public static final boolean DEBUG = JOGLNewtAppletBase.DEBUG;
GLWindow glWindow;
NewtCanvasAWT newtCanvasAWT;
@@ -72,6 +102,9 @@ public class JOGLNewtApplet1Run extends Applet {
boolean glStandalone = false;
public void init() {
+ if(DEBUG) {
+ System.err.println("JOGLNewtApplet1Run.init() START");
+ }
if(!(this instanceof Container)) {
throw new RuntimeException("This Applet is not a AWT Container");
}
@@ -88,6 +121,7 @@ public class JOGLNewtApplet1Run extends Applet {
int glAlphaBits=0;
int glNumMultisampleBuffer=0;
boolean glNoDefaultKeyListener = false;
+ boolean appletDebugTestBorder = false;
try {
glEventListenerClazzName = getParameter("gl_event_listener_class");
glProfileName = getParameter("gl_profile");
@@ -104,6 +138,7 @@ public class JOGLNewtApplet1Run extends Applet {
glWidth = JOGLNewtAppletBase.str2Int(getParameter("gl_width"), glWidth);
glHeight = JOGLNewtAppletBase.str2Int(getParameter("gl_height"), glHeight);
glNoDefaultKeyListener = JOGLNewtAppletBase.str2Bool(getParameter("gl_nodefaultkeyListener"), glNoDefaultKeyListener);
+ appletDebugTestBorder = JOGLNewtAppletBase.str2Bool(getParameter("appletDebugTestBorder"), appletDebugTestBorder);
} catch (Exception e) {
e.printStackTrace();
}
@@ -149,18 +184,19 @@ public class JOGLNewtApplet1Run extends Applet {
glWindow.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
glWindow.setUndecorated(glUndecorated);
glWindow.setAlwaysOnTop(glAlwaysOnTop);
+ container.setLayout(new BorderLayout());
+ if(appletDebugTestBorder) {
+ container.add(new Button("North"), BorderLayout.NORTH);
+ container.add(new Button("South"), BorderLayout.SOUTH);
+ container.add(new Button("East"), BorderLayout.EAST);
+ container.add(new Button("West"), BorderLayout.WEST);
+ }
if(glStandalone) {
newtCanvasAWT = null;
} else {
newtCanvasAWT = new NewtCanvasAWT(glWindow);
- container.setLayout(new BorderLayout());
container.add(newtCanvasAWT, BorderLayout.CENTER);
- }
- if(DEBUG) {
- container.add(new Label("North"), BorderLayout.NORTH);
- container.add(new Label("South"), BorderLayout.SOUTH);
- container.add(new Label("East"), BorderLayout.EAST);
- container.add(new Label("West"), BorderLayout.WEST);
+ container.validate();
}
base.init(glWindow);
if(base.isValid()) {
@@ -179,9 +215,15 @@ public class JOGLNewtApplet1Run extends Applet {
} catch (Throwable t) {
throw new RuntimeException(t);
}
+ if(DEBUG) {
+ System.err.println("JOGLNewtApplet1Run.init() END");
+ }
}
public void start() {
+ if(DEBUG) {
+ System.err.println("JOGLNewtApplet1Run.start() START");
+ }
this.validate();
this.setVisible(true);
@@ -195,21 +237,35 @@ public class JOGLNewtApplet1Run extends Applet {
while (null != topC.getParent()) {
topC = topC.getParent();
}
+ System.err.println("JOGLNewtApplet1Run start:");
System.err.println("TopComponent: "+topC.getLocation()+" rel, "+topC.getLocationOnScreen()+" screen, visible "+topC.isVisible()+", "+topC);
System.err.println("Applet Pos: "+this.getLocation()+" rel, "+p0+" screen, visible "+this.isVisible()+", "+this);
if(null != newtCanvasAWT) {
System.err.println("NewtCanvasAWT Pos: "+newtCanvasAWT.getLocation()+" rel, "+newtCanvasAWT.getLocationOnScreen()+" screen, visible "+newtCanvasAWT.isVisible()+", "+newtCanvasAWT);
}
System.err.println("GLWindow Pos: "+glWindow.getX()+"/"+glWindow.getY()+" rel, "+glWindow.getLocationOnScreen(null)+" screen");
+ System.err.println("GLWindow: "+glWindow);
}
base.start();
+ if(DEBUG) {
+ System.err.println("JOGLNewtApplet1Run.stop() END");
+ }
}
public void stop() {
+ if(DEBUG) {
+ System.err.println("JOGLNewtApplet1Run.stop() START");
+ }
base.stop();
+ if(DEBUG) {
+ System.err.println("JOGLNewtApplet1Run.stop() END");
+ }
}
public void destroy() {
+ if(DEBUG) {
+ System.err.println("JOGLNewtApplet1Run.destroy() START");
+ }
glWindow.setVisible(false); // hide 1st
if(!glStandalone) {
glWindow.reparentWindow(null); // get out of newtCanvasAWT
@@ -217,6 +273,9 @@ public class JOGLNewtApplet1Run extends Applet {
}
base.destroy(); // destroy glWindow unrecoverable
base=null;
+ if(DEBUG) {
+ System.err.println("JOGLNewtApplet1Run.destroy() END");
+ }
}
}
diff --git a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java
index b1061dd14..6b135976b 100755
--- a/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java
+++ b/src/newt/classes/com/jogamp/newt/awt/applet/JOGLNewtAppletBase.java
@@ -1,18 +1,52 @@
+/**
+ * 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.newt.awt.applet;
-import java.lang.reflect.*;
+import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.media.nativewindow.NativeWindow;
-import javax.media.opengl.*;
+import javax.media.opengl.FPSCounter;
+import javax.media.opengl.GL;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLPipelineFactory;
import jogamp.newt.Debug;
-import com.jogamp.opengl.util.*;
-
-import com.jogamp.newt.event.*;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.event.KeyListener;
+import com.jogamp.newt.event.MouseListener;
+import com.jogamp.newt.event.WindowListener;
import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.util.Animator;
+
/** Shows how to deploy an applet using JOGL. This demo must be
referenced from a web page via an &lt;applet&gt; tag. */