From 896e8b021b39e9415040a57a1d540d7d24b02db1 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 14 Mar 2013 10:48:44 +0100 Subject: OSX/CALayer: Revise CALayer 'RunOnMainThread' utilization, avoiding deadlocks RunOnMainThread(waitUntilDone:=true,..) can deadlock the main-thread if called from AWT-EDT, since the main-thread may call back to AWT-EDT while injecting a new main-thread task. This patch revises all RunOnMainThread CALayer usage, resulting in only one required left: - OSXUtil.AddCASublayer() w/ waitUntilDone:=false Hence the CALayer code has no more potential to deadlock main-thread/AWT-EDT. OSXUtil.AddCASublayer() must be performed on main-thread, otherwise the CALayer attachment will fail - no visible rendering result. +++ Note: A good trigger to test this deadlock is to magnify/zoom the OSX desktop (click background + ctrl-mouse_wheel) before running some unit tests. TestGLCanvasAWTActionDeadlock01AWT and TestAddRemove02GLWindowNewtCanvasAWT also have the potential to trigger the mentioned deadlock. --- make/config/jogl/cgl-macosx-CustomJavaCode.java | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'make/config/jogl/cgl-macosx-CustomJavaCode.java') diff --git a/make/config/jogl/cgl-macosx-CustomJavaCode.java b/make/config/jogl/cgl-macosx-CustomJavaCode.java index d32e0ae8f..ab1d44b64 100644 --- a/make/config/jogl/cgl-macosx-CustomJavaCode.java +++ b/make/config/jogl/cgl-macosx-CustomJavaCode.java @@ -1,9 +1,9 @@ /** - * Creates the NSOpenGLLayer for FBO/PBuffer w/ optional GL3 shader program on Main-Thread + * Creates the NSOpenGLLayer for FBO/PBuffer w/ optional GL3 shader program *

- * It is mandatory that the shared context handle ctx - * is not locked while calling this method. + * The NSOpenGLLayer will immediatly create a OpenGL context sharing the given ctx, + * which will be used to render the texture offthread. *

*

* The NSOpenGLLayer starts in enabled mode, @@ -12,10 +12,7 @@ */ public static long createNSOpenGLLayer(final long ctx, final int gl3ShaderProgramName, final long fmt, final long p, final int texID, final boolean opaque, final int texWidth, final int texHeight) { - return OSXUtil.RunOnMainThread(true, new Function() { - public Long eval(Object... args) { - return Long.valueOf( createNSOpenGLLayerImpl(ctx, gl3ShaderProgramName, fmt, p, texID, opaque, texWidth, texHeight) ); - } } ).longValue(); + return createNSOpenGLLayerImpl(ctx, gl3ShaderProgramName, fmt, p, texID, opaque, texWidth, texHeight); } /** @@ -26,19 +23,13 @@ public static long createNSOpenGLLayer(final long ctx, final int gl3ShaderProgra *

*/ public static void setNSOpenGLLayerEnabled(final long nsOpenGLLayer, final boolean enable) { - OSXUtil.RunOnMainThread(true, new Runnable() { - public void run() { - setNSOpenGLLayerEnabledImpl(nsOpenGLLayer, enable); - } } ); + setNSOpenGLLayerEnabledImpl(nsOpenGLLayer, enable); } /** - * Releases the NSOpenGLLayer on Main-Thread + * Releases the NSOpenGLLayer */ public static void releaseNSOpenGLLayer(final long nsOpenGLLayer) { - OSXUtil.RunOnMainThread(true, new Runnable() { - public void run() { - releaseNSOpenGLLayerImpl(nsOpenGLLayer); - } } ); + releaseNSOpenGLLayerImpl(nsOpenGLLayer); } -- cgit v1.2.3