aboutsummaryrefslogtreecommitdiffstats
path: root/src/nativewindow
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow')
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java14
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java25
-rw-r--r--src/nativewindow/native/macosx/OSXmisc.m58
3 files changed, 66 insertions, 31 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
index be697b3e0..aa09fc798 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/JAWTWindow.java
@@ -70,6 +70,7 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
protected Component component;
private AWTGraphicsConfiguration config; // control access due to delegation
private SurfaceUpdatedHelper surfaceUpdatedHelper = new SurfaceUpdatedHelper();
+ private RecursiveLock surfaceLock = LockFactory.createRecursiveLock();
// lifetime: valid after lock but may change with each 1st lock, purges after invalidate
private boolean isApplet;
@@ -230,8 +231,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
// NativeSurface
//
- private RecursiveLock surfaceLock = LockFactory.createRecursiveLock();
-
private void determineIfApplet() {
Component c = component;
while(!isApplet && null != c) {
@@ -252,6 +251,17 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
protected abstract JAWT fetchJAWTImpl() throws NativeWindowException;
protected abstract int lockSurfaceImpl() throws NativeWindowException;
+ protected void dumpJAWTInfo() {
+ if(null != jawt) {
+ System.err.println("JAWT version: 0x"+Integer.toHexString(jawt.getCachedVersion())+
+ ", CA_LAYER: "+ JAWTUtil.isJAWTUsingOffscreenLayer(jawt)+
+ ", isLayeredSurface "+isOffscreenLayerSurfaceEnabled()+", bounds "+bounds+", insets "+insets);
+ } else {
+ System.err.println("JAWT n/a, bounds "+bounds+", insets "+insets);
+ }
+ // Thread.dumpStack();
+ }
+
public final int lockSurface() throws NativeWindowException {
surfaceLock.lock();
int res = surfaceLock.getHoldCount() == 1 ? LOCK_SURFACE_NOT_READY : LOCK_SUCCESS; // new lock ?
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
index ab2986fbe..0435d4116 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
@@ -71,6 +71,10 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
protected void invalidateNative() {
surfaceHandle=0;
if(isOffscreenLayerSurfaceEnabled()) {
+ if(0 != rootSurfaceLayerHandle) {
+ OSXUtil.DestroyCALayer(rootSurfaceLayerHandle);
+ rootSurfaceLayerHandle = 0;
+ }
if(0 != drawable) {
OSXUtil.DestroyNSWindow(drawable);
drawable = 0;
@@ -208,7 +212,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
unlockSurfaceImpl();
throw new NativeWindowException("Could not create root CALayer: "+this);
}
- if(!AttachJAWTSurfaceLayer(dsi, rootSurfaceLayerHandle)) {
+ if(!AttachJAWTSurfaceLayer0(dsi.getBuffer(), rootSurfaceLayerHandle)) {
OSXUtil.DestroyCALayer(rootSurfaceLayerHandle);
rootSurfaceLayerHandle = 0;
OSXUtil.DestroyNSWindow(drawable);
@@ -239,14 +243,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
private void dumpInfo() {
System.err.println("MaxOSXJAWTWindow: 0x"+Integer.toHexString(this.hashCode())+" - thread: "+Thread.currentThread().getName());
- if(null != getJAWT()) {
- System.err.println("JAWT version: 0x"+Integer.toHexString(getJAWT().getCachedVersion())+
- ", CA_LAYER: "+ JAWTUtil.isJAWTUsingOffscreenLayer(getJAWT())+
- ", isLayeredSurface "+isOffscreenLayerSurfaceEnabled()+", bounds "+bounds+", insets "+insets);
- } else {
- System.err.println("JAWT n/a, bounds "+bounds+", insets "+insets);
- }
- // Thread.dumpStack();
+ dumpJAWTInfo();
}
/**
@@ -268,14 +265,8 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
}
protected Point getLocationOnScreenNativeImpl(final int x0, final int y0) { return null; }
- private static boolean AttachJAWTSurfaceLayer(JAWT_DrawingSurfaceInfo dsi, long caLayer) {
- if(0==caLayer) {
- throw new IllegalArgumentException("caLayer 0x"+Long.toHexString(caLayer));
- }
- return AttachJAWTSurfaceLayer0(dsi.getBuffer(), caLayer);
- }
-
private static native boolean AttachJAWTSurfaceLayer0(Buffer jawtDrawingSurfaceInfoBuffer, long caLayer);
+ // private static native boolean DetachJAWTSurfaceLayer0(Buffer jawtDrawingSurfaceInfoBuffer, long caLayer);
// Variables for lockSurface/unlockSurface
private JAWT_DrawingSurface ds;
@@ -284,7 +275,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements SurfaceChangeable {
private JAWT_MacOSXDrawingSurfaceInfo macosxdsi;
- private long rootSurfaceLayerHandle = 0; // is autoreleased, once it is attached to the JAWT_SurfaceLayer
+ private long rootSurfaceLayerHandle = 0; // attached to the JAWT_SurfaceLayer
private long surfaceHandle = 0;
private int sscWidth, sscHeight;
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m
index d64973b67..eec9b2a01 100644
--- a/src/nativewindow/native/macosx/OSXmisc.m
+++ b/src/nativewindow/native/macosx/OSXmisc.m
@@ -232,13 +232,8 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_CreateCALayer0
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- // CALayer* layer = [[CALayer alloc] init];
- CALayer* layer = [CALayer layer];
-
- // no animations for add/remove/swap sublayers etc
- [layer removeAnimationForKey: kCAOnOrderIn];
- [layer removeAnimationForKey: kCAOnOrderOut];
- [layer removeAnimationForKey: kCATransition];
+ CALayer* layer = [[CALayer alloc] init];
+ DBG_PRINT("CALayer::CreateCALayer.0: %p (refcnt %d)\n", layer, (int)[layer retainCount]);
// initial dummy size !
CGRect lRect = [layer frame];
@@ -247,7 +242,8 @@ JNIEXPORT jlong JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_CreateCALayer0
lRect.size.width = 32;
lRect.size.height = 32;
[layer setFrame: lRect];
- DBG_PRINT("CALayer::CreateCALayer0: %p %lf/%lf %lfx%lf\n", layer, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height);
+ DBG_PRINT("CALayer::CreateCALayer.1: %p %lf/%lf %lfx%lf\n", layer, lRect.origin.x, lRect.origin.y, lRect.size.width, lRect.size.height);
+ DBG_PRINT("CALayer::CreateCALayer.X: %p (refcnt %d)\n", layer, (int)[layer retainCount]);
[pool release];
@@ -285,6 +281,11 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_AddCASublayer0
// simple 1:1 layout !
[subLayer setFrame:lRectRoot];
[rootLayer addSublayer:subLayer];
+
+ // no animations for add/remove/swap sublayers etc
+ // doesn't work: [layer removeAnimationForKey: kCAOnOrderIn, kCAOnOrderOut, kCATransition]
+ [rootLayer removeAllAnimations];
+ [subLayer removeAllAnimations];
}];
DBG_PRINT("CALayer::AddCASublayer0.X: %p . %p (refcnt %d)\n", rootLayer, subLayer, (int)[subLayer retainCount]);
JNF_COCOA_EXIT(env);
@@ -308,7 +309,7 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_RemoveCASublayer0
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
[subLayer removeFromSuperlayer];
}];
- DBG_PRINT("CALayer::RemoveCASublayer0.X: %p . %p (refcnt %d)\n", rootLayer, subLayer, (int)[subLayer retainCount]);
+ DBG_PRINT("CALayer::RemoveCASublayer0.X: %p . %p\n", rootLayer, subLayer);
JNF_COCOA_EXIT(env);
}
@@ -327,7 +328,7 @@ JNIEXPORT void JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_DestroyCALayer0
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
[layer release]; // performs release!
}];
- DBG_PRINT("CALayer::DestroyCALayer0.X: %p (refcnt %d)\n", layer, (int)[layer retainCount]);
+ DBG_PRINT("CALayer::DestroyCALayer0.X: %p\n", layer);
JNF_COCOA_EXIT(env);
}
@@ -433,10 +434,43 @@ JNIEXPORT jboolean JNICALL Java_jogamp_nativewindow_jawt_macosx_MacOSXJAWTWindow
CALayer* layer = (CALayer*) (intptr_t) caLayer;
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
id <JAWT_SurfaceLayers> surfaceLayers = (id <JAWT_SurfaceLayers>)dsi->platformInfo;
- DBG_PRINT("CALayer::attachJAWTSurfaceLayer: %p -> %p\n", surfaceLayers.layer, layer);
- surfaceLayers.layer = [layer autorelease];
+ DBG_PRINT("CALayer::attachJAWTSurfaceLayer: %p -> %p (refcnt %d)\n", surfaceLayers.layer, layer, (int)[layer retainCount]);
+ surfaceLayers.layer = layer; // already incr. retain count
+ DBG_PRINT("CALayer::attachJAWTSurfaceLayer.X: %p (refcnt %d)\n", layer, (int)[layer retainCount]);
}];
JNF_COCOA_EXIT(env);
return JNI_TRUE;
}
+/*
+ * Class: Java_jogamp_nativewindow_jawt_macosx_MacOSXJAWTWindow
+ * Method: DetachJAWTSurfaceLayer
+ * Signature: (JJ)Z
+JNIEXPORT jboolean JNICALL Java_jogamp_nativewindow_jawt_macosx_MacOSXJAWTWindow_DetachJAWTSurfaceLayer0
+ (JNIEnv *env, jclass unused, jobject jawtDrawingSurfaceInfoBuffer, jlong caLayer)
+{
+ JNF_COCOA_ENTER(env);
+ JAWT_DrawingSurfaceInfo* dsi = (JAWT_DrawingSurfaceInfo*) (*env)->GetDirectBufferAddress(env, jawtDrawingSurfaceInfoBuffer);
+ if (NULL == dsi) {
+ NativewindowCommon_throwNewRuntimeException(env, "Argument \"jawtDrawingSurfaceInfoBuffer\" was not a direct buffer");
+ return JNI_FALSE;
+ }
+ CALayer* layer = (CALayer*) (intptr_t) caLayer;
+ {
+ id <JAWT_SurfaceLayers> surfaceLayers = (id <JAWT_SurfaceLayers>)dsi->platformInfo;
+ if(layer != surfaceLayers.layer) {
+ NativewindowCommon_throwNewRuntimeException(env, "Attached layer %p doesn't match given layer %p\n", surfaceLayers.layer, layer);
+ return JNI_FALSE;
+ }
+ }
+ // [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+ id <JAWT_SurfaceLayers> surfaceLayers = (id <JAWT_SurfaceLayers>)dsi->platformInfo;
+ DBG_PRINT("CALayer::detachJAWTSurfaceLayer: (%p) %p -> NULL\n", layer, surfaceLayers.layer);
+ surfaceLayers.layer = NULL;
+ [layer release];
+ // }];
+ JNF_COCOA_EXIT(env);
+ return JNI_TRUE;
+}
+ */
+