diff options
author | Sven Gothel <[email protected]> | 2011-11-05 05:58:57 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-11-05 05:58:57 +0100 |
commit | 5d6cbbcc2e0e819c3663e3ec451eefaf133f6435 (patch) | |
tree | f8d0b32947c2d07d6dde039185ff0d2d8e38e2a3 /src/nativewindow/classes/jogamp | |
parent | 6d57bd7717834afcd5f1dc3b60d696eda1997fe8 (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/nativewindow/classes/jogamp')
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java | 160 | ||||
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java | 17 |
2 files changed, 130 insertions, 47 deletions
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(); } |