From 7e76df3a05b7eb2404cb4584ee0b34ea287eb9bf Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 9 Sep 2019 09:36:50 +0200 Subject: Bug 1393: OSXUtil: Optionally inject Apple's 'Main Thread Checker' To allow proper testing of whether all AppKit calls are performed on its Main-Thread where required, we inject the libMainThreadChecker.dylib when property 'nativewindow.debug.OSXUtil.MainThreadChecker' is set. See Lib-Name: /Applications/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib --- make/build-newt.xml | 2 ++ make/scripts/tests.sh | 13 ++++++++++-- .../jogamp/nativewindow/macosx/OSXUtil.java | 23 ++++++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/make/build-newt.xml b/make/build-newt.xml index b01249415..f33142e0a 100644 --- a/make/build-newt.xml +++ b/make/build-newt.xml @@ -586,6 +586,8 @@ + + diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 75faeae3a..6255812b4 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -120,7 +120,10 @@ function jrun() { #D_ARGS="-Djogamp.debug=all -Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all" #D_ARGS="-Dnativewindow.debug.JAWT -Djogamp.debug.UnsafeUtil" - #D_ARGS="-Dnativewindow.debug.OSXUtil -Dnativewindow.debug.JAWT -Djogl.debug.GLContext -Djogl.debug.GLCanvas" + #D_ARGS="-Dnativewindow.debug.OSXUtil -Dnativewindow.debug.JAWT -Djogl.debug.GLContext" + #D_ARGS="-Dnewt.debug.Window" + #D_ARGS="-Dnewt.debug.Window -Djogamp.common.utils.locks.Lock.timeout=600000 -Dnewt.debug.EDT" + D_ARGS="-Djogamp.common.utils.locks.Lock.timeout=600000 -Dnativewindow.debug.OSXUtil.MainThreadChecker" #X_ARGS="--illegal-access=warn" #D_ARGS="-Djogamp.debug.NativeLibrary=true -Djogamp.debug.JNILibLoader=true" @@ -949,8 +952,14 @@ function testawtswt() { # 2.4.0 Regressions # # OSX -testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWT $* +#testawt com.jogamp.opengl.test.junit.jogl.awt.TestAWT02WindowClosing +#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $* +#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWT $* #testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01dAWT $* +testnoawt com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext01VSyncAnimNEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext11VSyncAnimNEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext02FPSAnimNEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext12FPSAnimNEWT $* # Linux Mesa/AMD: #testnoawt com.jogamp.opengl.test.junit.jogl.util.texture.TestGLReadBufferUtilTextureIOWrite01NEWT $* diff --git a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java index 196cdff57..f84955e69 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/macosx/OSXUtil.java @@ -31,6 +31,11 @@ import com.jogamp.nativewindow.NativeWindowException; import com.jogamp.nativewindow.NativeWindowFactory; import com.jogamp.nativewindow.util.Insets; import com.jogamp.nativewindow.util.Point; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +import com.jogamp.common.os.NativeLibrary; import com.jogamp.common.util.Function; import com.jogamp.common.util.FunctionTask; import com.jogamp.common.util.InterruptedRuntimeException; @@ -55,12 +60,26 @@ public class OSXUtil implements ToolkitProperties { */ public static synchronized void initSingleton() { if(!isInit) { - if(DEBUG) { - System.out.println("OSXUtil.initSingleton()"); + final boolean useMainThreadChecker = Debug.debug("OSXUtil.MainThreadChecker"); + if(DEBUG || useMainThreadChecker) { + System.out.println("OSXUtil.initSingleton() - useMainThreadChecker "+useMainThreadChecker); } if(!NWJNILibLoader.loadNativeWindow("macosx")) { throw new NativeWindowException("NativeWindow MacOSX native library load error."); } + if( useMainThreadChecker ) { + final String libMainThreadChecker = "/Applications/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib"; + final NativeLibrary lib = AccessController.doPrivileged(new PrivilegedAction() { + @Override + public NativeLibrary run() { + return NativeLibrary.open(libMainThreadChecker, false, false, OSXUtil.class.getClassLoader(), true); + } } ); + if( null == lib ) { + System.err.println("Could not load "+libMainThreadChecker); + } else { + System.err.println("Loaded "+lib); + } + } if( !initIDs0() ) { throw new NativeWindowException("MacOSX: Could not initialized native stub"); -- cgit v1.2.3