aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-11-09 01:11:40 +0100
committerSven Gothel <[email protected]>2011-11-09 01:11:40 +0100
commitd8fa00d35a49f4faf5f04aeb7e2bba4e972965f5 (patch)
tree4dba00d6fcd0d6146b30553375eb018438197c27 /src/nativewindow/classes/jogamp
parent0d7bcd240542df38dd5ff7855f31660f5f0a7be9 (diff)
OS X Layered View: Part3 JAWTWindow/MacOSXJAWTWindow (Java/Native)
JAWTWindow: - Add comment about caller of cstr, since it uses reflection - Field 'config' is of type AWTGraphicsConfiguration, validate and type it - Impl. NativeSurfaceHolder/NativeWindowHolder 'hooks' MacOSXJAWTWindow: - Use agnostic JAWTUtil.isJAWTVersionUsingOffscreenLayer() to determine 'isOffscreenLayeredSurface'. We may promote this notion to JAWTWindow, which already holds 'isApplet' - lockSurface() case 'isOffscreenLayeredSurface': - Create dummy NSWindow (OSXUtil) for getWindowHandle() - Fix chosen caps: offscreen
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java25
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java69
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java9
3 files changed, 80 insertions, 23 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
index e168ea757..3f10fa983 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
@@ -49,6 +49,7 @@ import javax.media.nativewindow.NativeSurface;
import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.SurfaceUpdatedListener;
+import javax.media.nativewindow.awt.AWTGraphicsConfiguration;
import javax.media.nativewindow.util.Insets;
import javax.media.nativewindow.util.InsetsImmutable;
import javax.media.nativewindow.util.Point;
@@ -63,18 +64,28 @@ public abstract class JAWTWindow implements NativeWindow {
// lifetime: forever
protected Component component;
protected boolean isApplet;
- protected AbstractGraphicsConfiguration config;
+ protected AWTGraphicsConfiguration config;
private SurfaceUpdatedHelper surfaceUpdatedHelper = new SurfaceUpdatedHelper();
// lifetime: valid after lock, forever until invalidate
protected long drawable;
protected Rectangle bounds;
- public JAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
+ /**
+ * Constructed by {@link jogamp.nativewindow.NativeWindowFactoryImpl#getNativeWindow(Object, AbstractGraphicsConfiguration)}
+ * via this platform's specialization (X11, OSX, Windows, ..).
+ *
+ * @param comp
+ * @param config
+ */
+ protected JAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
if (config == null) {
throw new NativeWindowException("Error: AbstractGraphicsConfiguration is null");
}
- this.config = config;
+ if(! ( config instanceof AWTGraphicsConfiguration ) ) {
+ throw new NativeWindowException("Error: AbstractGraphicsConfiguration is not an AWTGraphicsConfiguration");
+ }
+ this.config = (AWTGraphicsConfiguration) config;
init((Component)comp);
}
@@ -147,6 +158,10 @@ public abstract class JAWTWindow implements NativeWindow {
// NativeSurface
//
+ public NativeSurface getNativeSurface() {
+ return this;
+ }
+
private RecursiveLock surfaceLock = LockFactory.createRecursiveLock();
protected abstract int lockSurfaceImpl() throws NativeWindowException;
@@ -239,6 +254,10 @@ public abstract class JAWTWindow implements NativeWindow {
// NativeWindow
//
+ public NativeWindow getNativeWindow() {
+ return this;
+ }
+
public synchronized void destroy() {
invalidate();
if(null!=component) {
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
index 8fbc91176..b75bb3f4d 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
@@ -45,6 +45,8 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.Capabilities;
+import javax.media.nativewindow.NativeSurface;
import javax.media.nativewindow.SurfaceChangeable;
import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowException;
@@ -52,6 +54,7 @@ import javax.media.nativewindow.util.Point;
import jogamp.nativewindow.jawt.JAWT;
import jogamp.nativewindow.jawt.JAWTFactory;
+import jogamp.nativewindow.jawt.JAWTUtil;
import jogamp.nativewindow.jawt.JAWTWindow;
import jogamp.nativewindow.jawt.JAWT_DrawingSurface;
import jogamp.nativewindow.jawt.JAWT_DrawingSurfaceInfo;
@@ -59,12 +62,9 @@ import jogamp.nativewindow.jawt.JAWT_Rectangle;
import jogamp.nativewindow.macosx.OSXUtil;
public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
- final boolean isLayeredSurface;
- long surfaceHandle = 0;
-
public MacOSXJAWTWindow(Object comp, AbstractGraphicsConfiguration config) {
super(comp, config);
- isLayeredSurface = 0 != ( JAWT.getJAWT().getVersionCached() & JAWT.JAWT_MACOSX_USE_CALAYER );
+ isOffscreenLayeredSurface = JAWTUtil.isJAWTVersionUsingOffscreenLayer();
dumpInfo();
}
@@ -72,14 +72,19 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
}
protected void invalidateNative() {
+ surfaceHandle=0;
+ if(isOffscreenLayeredSurface && 0 == drawable) {
+ OSXUtil.DestroyNSWindow(drawable);
+ drawable = 0;
+ }
}
public final boolean isLayeredSurface() {
- return isLayeredSurface;
+ return isOffscreenLayeredSurface;
}
public long getSurfaceHandle() {
- return isLayeredSurface ? surfaceHandle : super.getSurfaceHandle() ;
+ return isOffscreenLayeredSurface ? surfaceHandle : super.getSurfaceHandle() ;
}
public void setSurfaceHandle(long surfaceHandle) {
@@ -106,15 +111,20 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
public void attachSurfaceLayer(long layerHandle) {
if( !isLayeredSurface() ) {
- throw new java.lang.UnsupportedOperationException("Not using CALAYER");
+ throw new NativeWindowException("Not using CALAYER");
}
- if( !dsLocked || null == dsi ) {
- throw new NativeWindowException("Locked: "+dsLocked+", dsi valid: "+(null!=dsi));
- }
- if(DEBUG) {
- System.err.println("MacOSXJAWTWindow.attachSurfaceLayer(): 0x"+Long.toHexString(layerHandle));
+ int lockRes = lockSurface();
+ if (NativeSurface.LOCK_SURFACE_NOT_READY >= lockRes) {
+ throw new NativeWindowException("Could not lock layeredSurfaceHost: "+this);
+ }
+ try {
+ if(DEBUG) {
+ System.err.println("MacOSXJAWTWindow.attachSurfaceLayer(): 0x"+Long.toHexString(layerHandle));
+ }
+ OSXUtil.AttachJAWTSurfaceLayer0(dsi, layerHandle);
+ } finally {
+ unlockSurface();
}
- OSXUtil.AttachJAWTSurfaceLayer0(dsi, layerHandle);
/*
if( null == macosxsl) {
throw new NativeWindowException("Not locked and/or SurfaceLayers null");
@@ -156,9 +166,6 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
return null;
}
});
- if(DEBUG) {
- dumpInfo();
- }
} else {
dsi = ds.GetDrawingSurfaceInfo();
}
@@ -167,8 +174,12 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
return NativeWindow.LOCK_SURFACE_NOT_READY;
}
}
+ updateBounds(dsi.getBounds());
+ if (DEBUG && firstLock) {
+ dumpInfo();
+ }
firstLock = false;
- if( !isLayeredSurface ) {
+ if( !isOffscreenLayeredSurface ) {
macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo();
if (macosxdsi == null) {
unlockSurfaceImpl();
@@ -184,6 +195,24 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
}
} else {
/**
+ * Only create a fake invisible NSWindow for the drawable handle
+ * to please frameworks requiring such (eg. NEWT).
+ *
+ * The actual surface/ca-layer shall be created/attached
+ * by the upper framework (JOGL) since they require more information.
+ */
+ if(0 == drawable) {
+ drawable = OSXUtil.CreateNSWindow(0, 0, getBounds().getWidth(), getBounds().getHeight());
+ if(0 == drawable) {
+ unlockSurfaceImpl();
+ throw new NativeWindowException("Unable to created dummy NSWindow (layered case)");
+ }
+ // fix caps reflecting offscreen!
+ Capabilities caps = (Capabilities) config.getChosenCapabilities().cloneMutable();
+ caps.setOnscreen(false);
+ config.setChosenCapabilities(caps);
+ }
+ /**
macosxsl = (JAWT_SurfaceLayers) dsi.platformInfo();
if (null == macosxsl) {
unlockSurfaceImpl();
@@ -194,9 +223,6 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
ret = NativeWindow.LOCK_SUCCESS;
}
- if(NativeWindow.LOCK_SURFACE_CHANGED <= ret) {
- updateBounds(dsi.getBounds());
- }
return ret;
}
@@ -259,6 +285,9 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
private JAWT_MacOSXDrawingSurfaceInfo macosxdsi;
// private JAWT_SurfaceLayers macosxsl;
+
+ final boolean isOffscreenLayeredSurface;
+ long surfaceHandle = 0;
// Workaround for instance of 4796548
private boolean firstLock = true;
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index db7764723..79ac24686 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -44,6 +44,13 @@ public class OSXUtil {
DestroyNSView0(nsView);
}
+ public static long CreateNSWindow(int x, int y, int width, int height) {
+ return CreateNSWindow0(x, y, width, height);
+ }
+ public static void DestroyNSWindow(long nsWindow) {
+ DestroyNSWindow0(nsWindow);
+ }
+
public static boolean AttachJAWTSurfaceLayer0(JAWT_DrawingSurfaceInfo dsi, long caLayer) {
return AttachJAWTSurfaceLayer0(dsi.getBuffer(), caLayer);
}
@@ -64,6 +71,8 @@ public class OSXUtil {
private static native Object GetLocationOnScreen0(long windowOrView, int src_x, int src_y);
private static native long CreateNSView0(int x, int y, int width, int height);
private static native void DestroyNSView0(long nsView);
+ private static native long CreateNSWindow0(int x, int y, int width, int height);
+ private static native void DestroyNSWindow0(long nsWindow);
private static native boolean AttachJAWTSurfaceLayer0(Buffer jawtDrawingSurfaceInfoBuffer, long caLayer);
private static native void RunOnMainThread0(boolean waitUntilDone, Runnable runnable);
private static native boolean IsMainThread0();