summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-11-05 05:58:57 +0100
committerSven Gothel <[email protected]>2011-11-05 05:58:57 +0100
commit5d6cbbcc2e0e819c3663e3ec451eefaf133f6435 (patch)
treef8d0b32947c2d07d6dde039185ff0d2d8e38e2a3 /src
parent6d57bd7717834afcd5f1dc3b60d696eda1997fe8 (diff)
Impl layeredSurface (java/native):
- OSXUtil: NSView backing creation - OSXUtil: AttachJAWTSurfaceLayer - MacOSXCGLContext.create(): Attach NSOpenGLLayer if layered - MacOSXCGLDrawable.updateHandle(): if direct: add NSView backing layer - MacOSXCGLDrawable: Add getNSViewHandle() to distinguish between NSView and none (CGL/pbuffer)
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java105
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java66
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java21
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java2
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLDrawable.java3
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java7
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java160
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java17
-rw-r--r--src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java2
9 files changed, 314 insertions, 69 deletions
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
index 1fe47f60b..2efdf958d 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
@@ -46,16 +46,19 @@ import java.util.Map;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.DefaultGraphicsConfiguration;
+import javax.media.nativewindow.NativeSurface;
import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
+import jogamp.nativewindow.jawt.macosx.MacOSXJAWTWindow;
import jogamp.opengl.GLContextImpl;
import jogamp.opengl.GLContextShareSet;
import jogamp.opengl.GLDrawableImpl;
import jogamp.opengl.GLGraphicsConfigurationUtil;
import jogamp.opengl.macosx.cgl.MacOSXCGLDrawable.GLBackendType;
+import jogamp.opengl.macosx.cgl.MacOSXCGLDrawable.LayeredSurfaceType;
import com.jogamp.common.nio.PointerBuffer;
import com.jogamp.common.os.Platform;
@@ -403,31 +406,53 @@ public abstract class MacOSXCGLContext extends GLContextImpl
// NSOpenGLContext-based implementation
class NSOpenGLImpl implements GLBackendImpl {
+ long nsOpenGLLayer = 0;
+ long nsOpenGLLayerPFmt = 0;
+
public boolean isNSContext() { return true; }
public long create(long share, int ctp, int major, int minor) {
long ctx = 0;
- MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
- GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
+ final MacOSXCGLDrawable drawable = (MacOSXCGLDrawable) MacOSXCGLContext.this.drawable;
+ final NativeSurface surface = drawable.getNativeSurface();
+ final MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) surface.getGraphicsConfiguration().getNativeGraphicsConfiguration();
+ final boolean isBackingLayerView = LayeredSurfaceType.None != drawable.getLayeredSurfaceType();
+ /**
+ final GLCapabilitiesImmutable chosenCaps;
+ {
+ final GLCapabilitiesImmutable _chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
+ if(isBackingLayerView) {
+ chosenCaps = GLGraphicsConfigurationUtil.fixSingleBufferGLCapabilities(_chosenCaps);
+ } else {
+ chosenCaps = _chosenCaps;
+ }
+ } */
+ final GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
long pixelFormat = MacOSXCGLGraphicsConfiguration.GLCapabilities2NSPixelFormat(chosenCaps, ctp, major, minor);
if (pixelFormat == 0) {
throw new GLException("Unable to allocate pixel format with requested GLCapabilities");
}
config.setChosenPixelFormat(pixelFormat);
+ if(DEBUG) {
+ System.err.println("NS create OSX>=lion "+isLionOrLater);
+ System.err.println("NS create drawable layeredType: "+drawable.getLayeredSurfaceType()+", backingLayerView "+isBackingLayerView);
+ System.err.println("NS create share: "+share);
+ System.err.println("NS create chosenCaps: "+chosenCaps);
+ System.err.println("NS create pixelFormat: "+toHexString(pixelFormat));
+ System.err.println("NS create drawable native-handle: "+toHexString(drawable.getHandle()));
+ System.err.println("NS create drawable NSView-handle: "+toHexString(drawable.getNSViewHandle()));
+ }
try {
int[] viewNotReady = new int[1];
// Try to allocate a context with this
ctx = CGL.createContext(share,
- drawable.getHandle(),
+ drawable.getNSViewHandle(), isBackingLayerView,
pixelFormat,
chosenCaps.isBackgroundOpaque(),
viewNotReady, 0);
if (0 == ctx) {
- if (viewNotReady[0] == 1) {
- if (DEBUG) {
- System.err.println("!!! View not ready for " + getClass().getName());
- }
- // View not ready at the window system level
+ if(DEBUG) {
+ System.err.println("NS create failed: viewNotReady: "+ (1 == viewNotReady[0]));
}
return 0;
}
@@ -439,22 +464,52 @@ public abstract class MacOSXCGLContext extends GLContextImpl
if(DEBUG) {
GLCapabilitiesImmutable caps0 = MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(null, pixelFormat);
- System.err.println("NS created(>=lion "+isLionOrLater+"): "+caps0);
+ System.err.println("NS create pixelformat2GLCaps: "+caps0);
+ }
+ GLCapabilitiesImmutable fixedCaps = MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(chosenCaps.getGLProfile(), pixelFormat);
+ fixedCaps = GLGraphicsConfigurationUtil.fixOpaqueGLCapabilities(fixedCaps, chosenCaps.isBackgroundOpaque());
+ config.setChosenCapabilities(fixedCaps);
+ if(DEBUG) {
+ System.err.println("NS create fixedCaps: "+fixedCaps);
}
- GLCapabilitiesImmutable caps = MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(chosenCaps.getGLProfile(), pixelFormat);
- caps = GLGraphicsConfigurationUtil.fixOpaqueGLCapabilities(caps, chosenCaps.isBackgroundOpaque());
- config.setChosenCapabilities(caps);
- if(caps.isPBuffer()) {
+ if(fixedCaps.isPBuffer()) {
// Must now associate the pbuffer with our newly-created context
CGL.setContextPBuffer(ctx, drawable.getHandle());
- }
+ }
+ //
+ // handled layered surface (same path for direct and parented)
+ //
+ if(isBackingLayerView) {
+ final MacOSXJAWTWindow lsh = MacOSXCGLDrawableFactory.getLayeredSurfaceHost(surface);
+ nsOpenGLLayerPFmt = pixelFormat;
+ pixelFormat = 0;
+ nsOpenGLLayer = CGL.createNSOpenGLLayer(ctx, nsOpenGLLayerPFmt, drawable.getNSViewHandle(), fixedCaps.isBackgroundOpaque());
+ if (DEBUG) {
+ System.err.println("NS create nsOpenGLLayer "+toHexString(nsOpenGLLayer));
+ }
+ lsh.attachSurfaceLayer(nsOpenGLLayer);
+ }
} finally {
- CGL.deletePixelFormat(pixelFormat);
+ if(0!=pixelFormat) {
+ CGL.deletePixelFormat(pixelFormat);
+ }
}
return ctx;
}
public boolean destroy(long ctx) {
+ if(0 != nsOpenGLLayer) {
+ final NativeSurface surface = drawable.getNativeSurface();
+ final MacOSXJAWTWindow lsh = MacOSXCGLDrawableFactory.getLayeredSurfaceHost(surface);
+ if (DEBUG) {
+ System.err.println("NS destroy nsOpenGLLayer "+toHexString(nsOpenGLLayer));
+ }
+ lsh.attachSurfaceLayer(0);
+ CGL.releaseNSOpenGLLayer(nsOpenGLLayer);
+ CGL.deletePixelFormat(nsOpenGLLayerPFmt);
+ nsOpenGLLayerPFmt = 0;
+ nsOpenGLLayer = 0;
+ }
return CGL.deleteContext(ctx, true);
}
@@ -476,10 +531,22 @@ public abstract class MacOSXCGLContext extends GLContextImpl
return true;
}
public boolean swapBuffers(boolean isOnscreen) {
- if(isOnscreen) {
- return CGL.flushBuffer(contextHandle);
- }
- return true;
+ /*
+ boolean res = true;
+ if(isOnscreen) {
+ res = CGL.flushBuffer(contextHandle);
+ }
+ if(res && 0 != nsOpenGLLayer) {
+ CGL.setNSOpenGLLayerNeedsDisplay(nsOpenGLLayer);
+ }
+ return res; */
+
+ if(0 != nsOpenGLLayer) {
+ CGL.setNSOpenGLLayerNeedsDisplay(nsOpenGLLayer);
+ } else if(isOnscreen) {
+ return CGL.flushBuffer(contextHandle);
+ }
+ return true;
}
}
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java
index 5a35f661d..6ac0af6e8 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java
@@ -44,6 +44,8 @@ import javax.media.nativewindow.NativeSurface;
import javax.media.opengl.GLDrawableFactory;
import javax.media.opengl.GLException;
+import jogamp.nativewindow.jawt.macosx.MacOSXJAWTWindow;
+import jogamp.nativewindow.macosx.OSXUtil;
import jogamp.opengl.GLDrawableImpl;
import jogamp.opengl.GLDynamicLookupHelper;
@@ -87,18 +89,80 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl {
this.id = id;
}
}
+ public enum LayeredSurfaceType {
+ None(0), Direct(1), Parented(2);
+
+ public final int id;
+
+ LayeredSurfaceType(int id){
+ this.id = id;
+ }
+ }
private boolean haveSetOpenGLMode = false;
private GLBackendType openGLMode = GLBackendType.NSOPENGL;
+ protected LayeredSurfaceType layeredSurfaceType = LayeredSurfaceType.None;
public MacOSXCGLDrawable(GLDrawableFactory factory, NativeSurface comp, boolean realized) {
super(factory, comp, realized);
initOpenGLImpl(getOpenGLMode());
- }
+ }
+
+ public final LayeredSurfaceType getLayeredSurfaceType() { return layeredSurfaceType; }
protected void setRealizedImpl() {
}
+ protected long getNSViewHandle() {
+ return GLBackendType.NSOPENGL == openGLMode ? getHandle() : null;
+ }
+
+ @Override
+ protected void destroyHandle() {
+ if(layeredSurfaceType == LayeredSurfaceType.Direct) {
+ // direct surface host, eg. AWT GLCanvas
+ final MacOSXJAWTWindow lsh = MacOSXCGLDrawableFactory.getLayeredSurfaceHost(surface);
+ if (DEBUG) {
+ System.err.println("destroyHandle: layerType " + layeredSurfaceType + ", backingLayer "+toHexString(lsh.getSurfaceHandle()) + " -> 0");
+ }
+ OSXUtil.DestroyNSView(lsh.getSurfaceHandle());
+ lsh.setSurfaceHandle(0);
+ } else if (DEBUG) {
+ System.err.println("destroyHandle: layerType " + layeredSurfaceType);
+ }
+ }
+
+ @Override
+ protected void updateHandle() {
+ final MacOSXJAWTWindow lsh = MacOSXCGLDrawableFactory.getLayeredSurfaceHost(surface);
+ if (null != lsh) {
+ if(lsh == surface) {
+ // direct surface host, eg. AWT GLCanvas
+ layeredSurfaceType = LayeredSurfaceType.Direct;
+ final long oldNSBackingView = lsh.getSurfaceHandle();
+ if(0 != oldNSBackingView) {
+ OSXUtil.DestroyNSView(oldNSBackingView);
+ }
+ final long newNSBackingView = OSXUtil.CreateNSView(0, 0, getWidth(), getHeight());
+ lsh.setSurfaceHandle(newNSBackingView);
+ if (DEBUG) {
+ System.err.println("updateHandle: layerType " + layeredSurfaceType + ", backingLayer "+toHexString(newNSBackingView) + " -> "+toHexString(oldNSBackingView));
+ }
+ } else {
+ // parent surface host, eg. via native parenting w/ NewtCanvasAWT
+ layeredSurfaceType = LayeredSurfaceType.Parented;
+ if (DEBUG) {
+ System.err.println("updateHandle: layerType " + layeredSurfaceType + ", backingLayer "+toHexString(getHandle()));
+ }
+ }
+ } else {
+ layeredSurfaceType = LayeredSurfaceType.None;
+ if (DEBUG) {
+ System.err.println("updateHandle: layerType " + layeredSurfaceType);
+ }
+ }
+ }
+
public GLDynamicLookupHelper getGLDynamicLookupHelper() {
return getFactoryImpl().getGLDynamicLookupHelper(0);
}
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
index 5c726bc54..14af0a544 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
@@ -49,6 +49,7 @@ import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.AbstractGraphicsScreen;
import javax.media.nativewindow.DefaultGraphicsScreen;
import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowFactory;
import javax.media.nativewindow.ProxySurface;
import javax.media.nativewindow.macosx.MacOSXGraphicsDevice;
@@ -61,6 +62,7 @@ import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
import jogamp.nativewindow.WrappedSurface;
+import jogamp.nativewindow.jawt.macosx.MacOSXJAWTWindow;
import jogamp.opengl.DesktopGLDynamicLookupHelper;
import jogamp.opengl.GLDrawableFactoryImpl;
import jogamp.opengl.GLDrawableImpl;
@@ -219,6 +221,25 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
return MacOSXCGLGraphicsConfiguration.getAvailableCapabilities(this, device);
}
+ protected static MacOSXJAWTWindow getLayeredSurfaceHost(NativeSurface surface) {
+ if(surface instanceof NativeWindow) {
+ final NativeWindow nwThis = (NativeWindow) surface;
+ if( nwThis instanceof MacOSXJAWTWindow) {
+ // direct surface host, eg. via AWT GLCanvas
+ final MacOSXJAWTWindow r = (MacOSXJAWTWindow) nwThis;
+ return r.isLayeredSurface() ? r : null;
+ } else {
+ // parent surface host, eg. via native parenting w/ NewtCanvasAWT
+ final NativeWindow nwParent = nwThis.getParent();
+ if(null != nwParent && nwParent instanceof MacOSXJAWTWindow) {
+ final MacOSXJAWTWindow r = (MacOSXJAWTWindow) nwParent;
+ return r.isLayeredSurface() ? r : null;
+ }
+ }
+ }
+ return null;
+ }
+
protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) {
if (target == null) {
throw new IllegalArgumentException("Null target");
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java
index a429720db..865238f06 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java
@@ -222,7 +222,7 @@ public class MacOSXCGLGraphicsConfiguration extends DefaultGraphicsConfiguration
// Use attribute array to select pixel format
PointerBuffer fmt = PointerBuffer.allocateDirect(1);
- long[] numScreens = new long[1];
+ int[] numScreens = new int[1];
int res = CGL.CGLChoosePixelFormat(attrs, 0, fmt, numScreens, 0);
if (res != CGL.kCGLNoError) {
throw new GLException("Error code " + res + " while choosing pixel format");
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLDrawable.java
index 24276c39e..2e1c24d91 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLDrawable.java
@@ -49,9 +49,10 @@ import javax.media.nativewindow.NativeSurface;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLDrawableFactory;
+
public class MacOSXOnscreenCGLDrawable extends MacOSXCGLDrawable {
private List<WeakReference<MacOSXCGLContext>> createdContexts = new ArrayList<WeakReference<MacOSXCGLContext>>();
-
+
protected MacOSXOnscreenCGLDrawable(GLDrawableFactory factory, NativeSurface component) {
super(factory, component, false);
}
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java
index fdbfaf6d6..ac76cfe6c 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java
@@ -112,6 +112,13 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable {
}
}
+ @Override
+ protected long getNSViewHandle() {
+ // pbuffer handle is NSOpenGLPixelBuffer
+ return 0;
+ }
+
+ @Override
public long getHandle() {
return pBuffer;
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
index 8b196b70e..8fbc91176 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
@@ -45,37 +45,94 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.media.nativewindow.AbstractGraphicsConfiguration;
+import javax.media.nativewindow.SurfaceChangeable;
import javax.media.nativewindow.NativeWindow;
import javax.media.nativewindow.NativeWindowException;
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;
import jogamp.nativewindow.jawt.JAWT_Rectangle;
import jogamp.nativewindow.macosx.OSXUtil;
-// import jogamp.nativewindow.macosx.OSXUtil;
-public class MacOSXJAWTWindow extends JAWTWindow {
+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 );
+ dumpInfo();
}
protected void validateNative() throws NativeWindowException {
+ }
+
+ protected void invalidateNative() {
}
+ public final boolean isLayeredSurface() {
+ return isLayeredSurface;
+ }
+
+ public long getSurfaceHandle() {
+ return isLayeredSurface ? surfaceHandle : super.getSurfaceHandle() ;
+ }
+
+ public void setSurfaceHandle(long surfaceHandle) {
+ if( !isLayeredSurface() ) {
+ throw new java.lang.UnsupportedOperationException("Not using CALAYER");
+ }
+ if(DEBUG) {
+ System.err.println("MacOSXJAWTWindow.setSurfaceHandle(): 0x"+Long.toHexString(surfaceHandle));
+ }
+ this.surfaceHandle = surfaceHandle;
+ }
+
+ /*
+ public long getSurfaceLayer() {
+ if( !isLayeredSurface() ) {
+ throw new java.lang.UnsupportedOperationException("Not using CALAYER");
+ }
+ if( !dsLocked ) {
+ throw new NativeWindowException("Not locked");
+ }
+ // return macosxsl.getLayer();
+ return getSurfaceLayers().getLayer();
+ } */
+
+ public void attachSurfaceLayer(long layerHandle) {
+ if( !isLayeredSurface() ) {
+ throw new java.lang.UnsupportedOperationException("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));
+ }
+ OSXUtil.AttachJAWTSurfaceLayer0(dsi, layerHandle);
+ /*
+ if( null == macosxsl) {
+ throw new NativeWindowException("Not locked and/or SurfaceLayers null");
+ }
+ macosxsl.setLayer(layerHandle); */
+ // getSurfaceLayers().setLayer(layerHandle);
+ }
+
protected int lockSurfaceImpl() throws NativeWindowException {
- final JAWT jawt = JAWT.getJAWT();
int ret = NativeWindow.LOCK_SURFACE_NOT_READY;
- ds = jawt.GetDrawingSurface(component);
- if (ds == null) {
- // Widget not yet realized
- unlockSurfaceImpl();
- return NativeWindow.LOCK_SURFACE_NOT_READY;
+ if(null == ds) {
+ final JAWT jawt = JAWT.getJAWT();
+ ds = jawt.GetDrawingSurface(component);
+ if (ds == null) {
+ // Widget not yet realized
+ unlockSurfaceImpl();
+ return NativeWindow.LOCK_SURFACE_NOT_READY;
+ }
}
int res = ds.Lock();
dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ;
@@ -91,25 +148,27 @@ public class MacOSXJAWTWindow extends JAWTWindow {
if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) {
ret = NativeWindow.LOCK_SURFACE_CHANGED;
}
- if (firstLock) {
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- public Object run() {
- dsi = ds.GetDrawingSurfaceInfo();
- return null;
+ if(null == dsi) {
+ if (firstLock) {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ dsi = ds.GetDrawingSurfaceInfo();
+ return null;
+ }
+ });
+ if(DEBUG) {
+ dumpInfo();
}
- });
- } else {
- dsi = ds.GetDrawingSurfaceInfo();
- }
- if (dsi == null) {
- unlockSurfaceImpl();
- return NativeWindow.LOCK_SURFACE_NOT_READY;
- }
- if(DEBUG && firstLock) {
- dumpInfo();
+ } else {
+ dsi = ds.GetDrawingSurfaceInfo();
+ }
+ if (dsi == null) {
+ unlockSurfaceImpl();
+ return NativeWindow.LOCK_SURFACE_NOT_READY;
+ }
}
firstLock = false;
- if( 0 == ( jawt.getVersionCached() & JAWT.JAWT_MACOSX_USE_CALAYER ) ) {
+ if( !isLayeredSurface ) {
macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo();
if (macosxdsi == null) {
unlockSurfaceImpl();
@@ -124,11 +183,15 @@ public class MacOSXJAWTWindow extends JAWTWindow {
ret = NativeWindow.LOCK_SUCCESS;
}
} else {
+ /**
macosxsl = (JAWT_SurfaceLayers) dsi.platformInfo();
- if (macosxsl == null) {
+ if (null == macosxsl) {
unlockSurfaceImpl();
return NativeWindow.LOCK_SURFACE_NOT_READY;
- }
+ } else {
+ ret = NativeWindow.LOCK_SUCCESS;
+ } */
+ ret = NativeWindow.LOCK_SUCCESS;
}
if(NativeWindow.LOCK_SURFACE_CHANGED <= ret) {
@@ -136,21 +199,6 @@ public class MacOSXJAWTWindow extends JAWTWindow {
}
return ret;
}
-
- public boolean isSetWindowHandleSupported() {
- return 0 != ( JAWT.getJAWT().getVersionCached() & JAWT.JAWT_MACOSX_USE_CALAYER ) ;
- }
-
- public void setWindowHandle(long handle) {
- if( !isSetWindowHandleSupported() ) {
- throw new java.lang.UnsupportedOperationException("Not using CALAYER");
- }
- if( null == macosxsl) {
- throw new NativeWindowException("Not locked and/or SurfaceLayers null");
- }
- drawable = handle;
- macosxsl.setLayer(drawable);
- }
protected void unlockSurfaceImpl() throws NativeWindowException {
if(null!=ds) {
@@ -164,14 +212,32 @@ public class MacOSXJAWTWindow extends JAWTWindow {
}
ds = null;
dsi = null;
- macosxdsi = null;
+ // macosxsl = null;
}
+ /**
+ protected JAWT_SurfaceLayers getSurfaceLayers() {
+ if( !dsLocked || null == dsi ) {
+ throw new NativeWindowException("Locked: "+dsLocked+", dsi valid: "+(null!=dsi));
+ }
+ final JAWT_SurfaceLayers macosxsl = (JAWT_SurfaceLayers) dsi.platformInfo();
+ if (null == macosxsl) {
+ throw new NativeWindowException("SurfaceLayer null");
+ }
+ return macosxsl;
+ } */
+
private void dumpInfo() {
+ System.err.println("MaxOSXJAWTWindow: 0x"+Integer.toHexString(this.hashCode())+" - thread: "+Thread.currentThread().getName());
+ // System.err.println(this);
System.err.println("JAWT version: 0x"+Integer.toHexString(JAWT.getJAWT().getVersionCached())+
- ", CA_LAYER: "+ (0!=(JAWT.getJAWT().getVersionCached() & JAWT.JAWT_MACOSX_USE_CALAYER)));
- JAWT_Rectangle r = dsi.getBounds();
- System.err.println("dsi bounds: "+r.getX()+"/"+r.getY()+" "+r.getWidth()+"x"+r.getHeight());
+ ", CA_LAYER: "+ (0!=(JAWT.getJAWT().getVersionCached() & JAWT.JAWT_MACOSX_USE_CALAYER))+
+ ", isLayeredSurface "+isLayeredSurface());
+ if(null != dsi) {
+ JAWT_Rectangle r = dsi.getBounds();
+ System.err.println("dsi bounds: "+r.getX()+"/"+r.getY()+" "+r.getWidth()+"x"+r.getHeight());
+ }
+ // Thread.dumpStack();
}
protected Point getLocationOnScreenImpl(final int x0, final int y0) {
@@ -192,7 +258,7 @@ public class MacOSXJAWTWindow extends JAWTWindow {
private JAWT_DrawingSurfaceInfo dsi;
private JAWT_MacOSXDrawingSurfaceInfo macosxdsi;
- private JAWT_SurfaceLayers macosxsl;
+ // private JAWT_SurfaceLayers macosxsl;
// 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 cd558c05d..db7764723 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -1,10 +1,13 @@
package jogamp.nativewindow.macosx;
+import java.nio.Buffer;
+
import javax.media.nativewindow.NativeWindowException;
import javax.media.nativewindow.util.Point;
import jogamp.nativewindow.Debug;
import jogamp.nativewindow.NWJNILibLoader;
+import jogamp.nativewindow.jawt.JAWT_DrawingSurfaceInfo;
public class OSXUtil {
private static boolean isInit = false;
@@ -34,6 +37,17 @@ public class OSXUtil {
return (Point) GetLocationOnScreen0(windowOrView, src_x, src_y);
}
+ public static long CreateNSView(int x, int y, int width, int height) {
+ return CreateNSView0(x, y, width, height);
+ }
+ public static void DestroyNSView(long nsView) {
+ DestroyNSView0(nsView);
+ }
+
+ public static boolean AttachJAWTSurfaceLayer0(JAWT_DrawingSurfaceInfo dsi, long caLayer) {
+ return AttachJAWTSurfaceLayer0(dsi.getBuffer(), caLayer);
+ }
+
public static void RunOnMainThread(boolean waitUntilDone, Runnable runnable) {
if(IsMainThread0()) {
runnable.run(); // don't leave the JVM
@@ -48,6 +62,9 @@ public class OSXUtil {
private static native boolean initIDs0();
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 boolean AttachJAWTSurfaceLayer0(Buffer jawtDrawingSurfaceInfoBuffer, long caLayer);
private static native void RunOnMainThread0(boolean waitUntilDone, Runnable runnable);
private static native boolean IsMainThread0();
}
diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java
index d09ac72ba..d57910957 100644
--- a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java
+++ b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java
@@ -143,6 +143,7 @@ public class MacWindow extends WindowImpl {
public MacWindow() {
}
+ @Override
protected void createNativeImpl() {
config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(
capsRequested, capsRequested, capabilitiesChooser, getScreen().getGraphicsScreen());
@@ -155,6 +156,7 @@ public class MacWindow extends WindowImpl {
}
}
+ @Override
protected void closeNativeImpl() {
try {
if(DEBUG_IMPLEMENTATION) { System.err.println("MacWindow.CloseAction "+Thread.currentThread().getName()); }