summaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/jogamp
diff options
context:
space:
mode:
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java58
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java7
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java7
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java64
4 files changed, 85 insertions, 51 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
index d11d24664..9f76392a9 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
@@ -69,16 +69,18 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
}
}
+ @Override
protected void invalidateNative() {
if(DEBUG) {
System.err.println("MacOSXJAWTWindow.invalidateNative(): osh-enabled "+isOffscreenLayerSurfaceEnabled()+
- ", osh-set "+offscreenSurfaceHandleSet+
- ", osh "+toHexString(offscreenSurfaceHandle)+
- ", rsh "+toHexString(rootSurfaceLayer)+
+ ", osd-set "+offscreenSurfaceDrawableSet+
+ ", osd "+toHexString(offscreenSurfaceDrawable)+
+ ", osl "+toHexString(getAttachedSurfaceLayer())+
+ ", rsl "+toHexString(rootSurfaceLayer)+
", wh "+toHexString(windowHandle)+" - "+Thread.currentThread().getName());
}
- offscreenSurfaceHandle=0;
- offscreenSurfaceHandleSet=false;
+ offscreenSurfaceDrawable=0;
+ offscreenSurfaceDrawableSet=false;
if( isOffscreenLayerSurfaceEnabled() ) {
if(0 != windowHandle) {
OSXUtil.DestroyNSWindow(windowHandle);
@@ -108,29 +110,41 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
jawt.FreeDrawingSurface(ds);
}
}
- OSXUtil.DestroyCALayer(rootSurfaceLayer);
- rootSurfaceLayer = 0;
+
+ OSXUtil.RunOnMainThread(false, new Runnable() {
+ public void run() {
+ OSXUtil.DestroyCALayer(rootSurfaceLayer, false);
+ rootSurfaceLayer = 0;
+ }
+ });
}
}
windowHandle=0;
}
+ @Override
protected void attachSurfaceLayerImpl(final long layerHandle) {
OSXUtil.AddCASublayer(rootSurfaceLayer, layerHandle, getWidth(), getHeight());
}
- protected void layoutSurfaceLayerImpl() {
- final long osl = getAttachedSurfaceLayer();
- final int w = getWidth();
- final int h = getHeight();
+ @Override
+ protected void layoutSurfaceLayerImpl(long layerHandle, int width, int height) {
if(DEBUG) {
- System.err.println("JAWTWindow.fixSurfaceLayerLayout: "+toHexString(osl) + ", bounds "+bounds+", "+w+"x"+h);
+ System.err.println("JAWTWindow.layoutSurfaceLayerImpl: "+toHexString(layerHandle) + ", "+width+"x"+height+"; "+this);
}
- OSXUtil.FixCALayerLayout(rootSurfaceLayer, osl, w, h);
+ OSXUtil.FixCALayerLayout(rootSurfaceLayer, layerHandle, width, height);
}
- protected void detachSurfaceLayerImpl(final long layerHandle) {
- OSXUtil.RemoveCASublayer(rootSurfaceLayer, layerHandle);
+ @Override
+ protected void detachSurfaceLayerImpl(final long layerHandle, final Runnable detachNotify) {
+ OSXUtil.RunOnMainThread(false, new Runnable() {
+ public void run() {
+ final long l = MacOSXJAWTWindow.this.getAttachedSurfaceLayer();
+ if( 0 != l ) {
+ detachNotify.run();
+ OSXUtil.RemoveCASublayer(rootSurfaceLayer, layerHandle, false);
+ }
+ } } );
}
@Override
@@ -140,7 +154,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
@Override
public final long getSurfaceHandle() {
- return offscreenSurfaceHandleSet ? offscreenSurfaceHandle : drawable /* super.getSurfaceHandle() */ ;
+ return offscreenSurfaceDrawableSet ? offscreenSurfaceDrawable : drawable /* super.getSurfaceHandle() */ ;
}
public void setSurfaceHandle(long surfaceHandle) {
@@ -150,8 +164,8 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
if(DEBUG) {
System.err.println("MacOSXJAWTWindow.setSurfaceHandle(): "+toHexString(surfaceHandle));
}
- this.offscreenSurfaceHandle = surfaceHandle;
- this.offscreenSurfaceHandleSet = true;
+ this.offscreenSurfaceDrawable = surfaceHandle;
+ this.offscreenSurfaceDrawableSet = true;
}
protected JAWT fetchJAWTImpl() throws NativeWindowException {
@@ -257,7 +271,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
}
if(null != errMsg) {
if(0 != rootSurfaceLayer) {
- OSXUtil.DestroyCALayer(rootSurfaceLayer);
+ OSXUtil.DestroyCALayer(rootSurfaceLayer, true);
rootSurfaceLayer = 0;
}
if(0 != windowHandle) {
@@ -329,11 +343,11 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
private JAWT_MacOSXDrawingSurfaceInfo macosxdsi;
- private long rootSurfaceLayer = 0; // attached to the JAWT_SurfaceLayer
+ private volatile long rootSurfaceLayer = 0; // attached to the JAWT_SurfaceLayer
private long windowHandle = 0;
- private long offscreenSurfaceHandle = 0;
- private boolean offscreenSurfaceHandleSet = false;
+ private long offscreenSurfaceDrawable = 0;
+ private boolean offscreenSurfaceDrawableSet = false;
// Workaround for instance of 4796548
private boolean firstLock = true;
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java
index 5d1d43792..905a313d5 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/windows/WindowsJAWTWindow.java
@@ -64,13 +64,6 @@ public class WindowsJAWTWindow extends JAWTWindow {
windowHandle = 0;
}
- protected void attachSurfaceLayerImpl(final long layerHandle) {
- throw new UnsupportedOperationException("offscreen layer not supported");
- }
- protected void detachSurfaceLayerImpl(final long layerHandle) {
- throw new UnsupportedOperationException("offscreen layer not supported");
- }
-
protected JAWT fetchJAWTImpl() throws NativeWindowException {
return JAWTUtil.getJAWT(false); // no offscreen
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java
index 467809284..2e5dc7fb5 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/x11/X11JAWTWindow.java
@@ -59,13 +59,6 @@ public class X11JAWTWindow extends JAWTWindow {
protected void invalidateNative() { }
- protected void attachSurfaceLayerImpl(final long layerHandle) {
- throw new UnsupportedOperationException("offscreen layer not supported");
- }
- protected void detachSurfaceLayerImpl(final long layerHandle) {
- throw new UnsupportedOperationException("offscreen layer not supported");
- }
-
protected JAWT fetchJAWTImpl() throws NativeWindowException {
return JAWTUtil.getJAWT(false); // no offscreen
}
diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
index 703c3d972..4b102be00 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java
@@ -138,11 +138,15 @@ public class OSXUtil implements ToolkitProperties {
/**
* Create a CALayer suitable to act as a root CALayer.
- * @see #DestroyCALayer(long)
+ * @see #DestroyCALayer(long, boolean)
* @see #AddCASublayer(long, long)
*/
public static long CreateCALayer(final int x, final int y, final int width, final int height) {
- return CreateCALayer0(x, y, width, height);
+ final long l = CreateCALayer0(x, y, width, height);
+ if(DEBUG) {
+ System.err.println("OSXUtil.CreateCALayer: 0x"+Long.toHexString(l)+" - "+Thread.currentThread().getName());
+ }
+ return l;
}
/**
@@ -156,7 +160,7 @@ public class OSXUtil implements ToolkitProperties {
* they will be used for creation.
* </p>
* @see #CreateCALayer(int, int, int, int)
- * @see #RemoveCASublayer(long, long)
+ * @see #RemoveCASublayer(long, long, boolean)
*/
public static void AddCASublayer(final long rootCALayer, final long subCALayer, final int width, final int height) {
if(0==rootCALayer || 0==subCALayer) {
@@ -164,6 +168,9 @@ public class OSXUtil implements ToolkitProperties {
}
RunOnMainThread(false, new Runnable() {
public void run() {
+ if(DEBUG) {
+ System.err.println("OSXUtil.AttachCALayer: 0x"+Long.toHexString(subCALayer)+" - "+Thread.currentThread().getName());
+ }
AddCASublayer0(rootCALayer, subCALayer, width, height);
}
});
@@ -193,32 +200,48 @@ public class OSXUtil implements ToolkitProperties {
}
/**
- * Detach a sub CALayer from the root CALayer on the main-thread w/o blocking.
+ * Detach a sub CALayer from the root CALayer.
+ * @param onMainThread if <code>true</code> method will be performed on the main-thread w/o blocking.
*/
- public static void RemoveCASublayer(final long rootCALayer, final long subCALayer) {
+ public static void RemoveCASublayer(final long rootCALayer, final long subCALayer, boolean onMainThread) {
if(0==rootCALayer || 0==subCALayer) {
throw new IllegalArgumentException("rootCALayer 0x"+Long.toHexString(rootCALayer)+", subCALayer 0x"+Long.toHexString(subCALayer));
}
- RunOnMainThread(false, new Runnable() {
+ final Runnable action = new Runnable() {
public void run() {
+ if(DEBUG) {
+ System.err.println("OSXUtil.DetachCALayer: 0x"+Long.toHexString(subCALayer)+" - "+Thread.currentThread().getName());
+ }
RemoveCASublayer0(rootCALayer, subCALayer);
- }
- });
+ } };
+ if( onMainThread ) {
+ RunOnMainThread(false, action);
+ } else {
+ action.run();
+ }
}
/**
- * Destroy a CALayer on main-thread w/o blocking.
+ * Destroy a CALayer.
+ * @param onMainThread if <code>true</code> method will be performed on the main-thread w/o blocking.
* @see #CreateCALayer(int, int, int, int)
*/
- public static void DestroyCALayer(final long caLayer) {
+ public static void DestroyCALayer(final long caLayer, boolean onMainThread) {
if(0==caLayer) {
throw new IllegalArgumentException("caLayer 0x"+Long.toHexString(caLayer));
}
- RunOnMainThread(false, new Runnable() {
+ final Runnable action = new Runnable() {
public void run() {
+ if(DEBUG) {
+ System.err.println("OSXUtil.DestroyCALayer: 0x"+Long.toHexString(caLayer)+" - "+Thread.currentThread().getName());
+ }
DestroyCALayer0(caLayer);
- }
- });
+ } };
+ if( onMainThread ) {
+ RunOnMainThread(false, action);
+ } else {
+ action.run();
+ }
}
/**
@@ -238,7 +261,7 @@ public class OSXUtil implements ToolkitProperties {
// otherwise we may freeze the OSX main thread.
Throwable throwable = null;
final Object sync = new Object();
- final RunnableTask rt = new RunnableTask( runnable, waitUntilDone ? sync : null, true );
+ final RunnableTask rt = new RunnableTask( runnable, waitUntilDone ? sync : null, true, waitUntilDone ? null : System.err );
synchronized(sync) {
RunOnMainThread0(rt);
if( waitUntilDone ) {
@@ -258,6 +281,16 @@ public class OSXUtil implements ToolkitProperties {
}
}
+ /**
+ * Run later on current OSX thread.
+ *
+ * @param runnable
+ * @param delay delay to run the runnable in milliseconds
+ */
+ public static void RunLater(Runnable runnable, int delay) {
+ RunLater0(new RunnableTask( runnable, null, true, System.err ), delay);
+ }
+
private static Runnable _nop = new Runnable() { public void run() {}; };
/** Issues a {@link #RunOnMainThread(boolean, Runnable)} w/ an <i>NOP</i> runnable, while waiting until done. */
@@ -282,7 +315,7 @@ public class OSXUtil implements ToolkitProperties {
// otherwise we may freeze the OSX main thread.
Throwable throwable = null;
final Object sync = new Object();
- final FunctionTask<R,A> rt = new FunctionTask<R,A>( func, waitUntilDone ? sync : null, true );
+ final FunctionTask<R,A> rt = new FunctionTask<R,A>( func, waitUntilDone ? sync : null, true, waitUntilDone ? null : System.err );
synchronized(sync) {
rt.setArgs(args);
RunOnMainThread0(rt);
@@ -349,6 +382,7 @@ public class OSXUtil implements ToolkitProperties {
private static native void RemoveCASublayer0(long rootCALayer, long subCALayer);
private static native void DestroyCALayer0(long caLayer);
private static native void RunOnMainThread0(Runnable runnable);
+ private static native void RunLater0(Runnable runnable, int delay);
private static native boolean IsMainThread0();
private static native int GetScreenRefreshRate0(int scrn_idx);
}