diff options
-rw-r--r-- | make/build.xml | 1 | ||||
-rwxr-xr-x | src/java/com/jogamp/common/os/DynamicLibraryBundle.java | 12 | ||||
-rw-r--r-- | src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java | 11 | ||||
-rw-r--r-- | src/java/com/jogamp/common/os/Platform.java | 17 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/ReflectionUtil.java | 9 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/RunnableExecutor.java | 4 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/VersionUtil.java | 4 | ||||
-rw-r--r-- | src/java/jogamp/common/awt/AWTEDTExecutor.java | 65 |
8 files changed, 118 insertions, 5 deletions
diff --git a/make/build.xml b/make/build.xml index 7e1b6c0..96c3f62 100644 --- a/make/build.xml +++ b/make/build.xml @@ -138,6 +138,7 @@ <property name="archive" value="${build}/${archive.name}" /> <property name="jogamp.android-launcher.classes" value="jogamp/android/launcher/**"/> + <property name="jogamp.awt.classes" value="jogamp/common/awt/**"/> <property name="gluegen.excludes.all" value="${gluegen.excludes.nsig} ${jogamp.android-launcher.classes}" /> <property name="gluegen-rt.classes" value="com/jogamp/gluegen/runtime/**"/> <property name="jogamp.common.classes" value="com/jogamp/common/** jogamp/common/**"/> diff --git a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java index efb6d89..b86a701 100755 --- a/src/java/com/jogamp/common/os/DynamicLibraryBundle.java +++ b/src/java/com/jogamp/common/os/DynamicLibraryBundle.java @@ -33,7 +33,10 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; +import jogamp.common.awt.AWTEDTExecutor; + import com.jogamp.common.jvm.JNILibLoaderBase; +import com.jogamp.common.util.RunnableExecutor; /** * Provides bundling of:<br> @@ -69,6 +72,15 @@ public class DynamicLibraryBundle implements DynamicLookupHelper { private HashSet<String> toolGetProcAddressFuncNameSet; private List<String> toolGetProcAddressFuncNameList; + /** Returns an AWT-EDT {@link RunnableExecutor} implementation if AWT is available, otherwise {@link RunnableExecutor#currentThreadExecutor}. */ + public static RunnableExecutor getDefaultRunnableExecutor() { + if(Platform.AWT_AVAILABLE) { + return AWTEDTExecutor.singleton; + } else { + return RunnableExecutor.currentThreadExecutor; + } + } + /** Instantiates and loads all {@link NativeLibrary}s incl. JNI libraries. */ public DynamicLibraryBundle(DynamicLibraryBundleInfo info) { if(null==info) { diff --git a/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java b/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java index 6178048..8532548 100644 --- a/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java +++ b/src/java/com/jogamp/common/os/DynamicLibraryBundleInfo.java @@ -86,6 +86,17 @@ public interface DynamicLibraryBundleInfo { /** @return true if the dynamic symbol lookup shall happen system wide, over all loaded libraries. Otherwise only the loaded native libraries are used for lookup, which shall be the default. */ public boolean shallLookupGlobal(); + /** + * Returns a suitable {@link RunnableExecutor} implementation, which is being used + * to load the <code>tool</code> native libraries. + * <p> + * This allows the generic {@link DynamicLibraryBundle} implementation to + * load the <code>tool</code> native libraries on a designated thread. + * </p> + * <p> + * An implementation may return {@link DynamicLibraryBundle#getDefaultRunnableExecutor()}. + * </p> + */ public RunnableExecutor getLibLoaderExecutor(); } diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java index dc1ce91..6553b07 100644 --- a/src/java/com/jogamp/common/os/Platform.java +++ b/src/java/com/jogamp/common/os/Platform.java @@ -38,6 +38,7 @@ import java.util.concurrent.TimeUnit; import com.jogamp.common.nio.Buffers; import com.jogamp.common.util.JarUtil; +import com.jogamp.common.util.ReflectionUtil; import com.jogamp.common.util.VersionNumber; import com.jogamp.common.util.cache.TempJarCache; @@ -61,6 +62,9 @@ public class Platform { public static final boolean USE_TEMP_JAR_CACHE; private static final String useTempJarCachePropName = "jogamp.gluegen.UseTempJarCache"; + /** <code>true</code> if AWT is available and not in headless mode, otherwise <code>false</code>. */ + public static final boolean AWT_AVAILABLE; + public static final boolean JAVA_SE; public static final boolean LITTLE_ENDIAN; public static final String OS; @@ -225,6 +229,19 @@ public class Platform { } machineDescription = md; is32Bit = machineDescription.is32Bit(); + + { + final ClassLoader cl = Platform.class.getClassLoader(); + boolean _AWT_AVAILABLE = false; + if( !Debug.getBooleanProperty("java.awt.headless", true) && + ReflectionUtil.isClassAvailable(ReflectionUtil.AWTNames.ComponentClass, cl) && + ReflectionUtil.isClassAvailable(ReflectionUtil.AWTNames.GraphicsEnvironmentClass, cl) ) { + try { + _AWT_AVAILABLE = false == ((Boolean)ReflectionUtil.callStaticMethod(ReflectionUtil.AWTNames.GraphicsEnvironmentClass, ReflectionUtil.AWTNames.isHeadlessMethod, null, null, cl)).booleanValue(); + } catch (Throwable t) { } + } + AWT_AVAILABLE = _AWT_AVAILABLE; + } } private Platform() {} diff --git a/src/java/com/jogamp/common/util/ReflectionUtil.java b/src/java/com/jogamp/common/util/ReflectionUtil.java index db98d6e..f6b9efb 100644 --- a/src/java/com/jogamp/common/util/ReflectionUtil.java +++ b/src/java/com/jogamp/common/util/ReflectionUtil.java @@ -46,6 +46,11 @@ public final class ReflectionUtil { public static final boolean DEBUG = Debug.debug("ReflectionUtil"); + public static class AWTNames { + public static final String ComponentClass = "java.awt.Component" ; + public static final String GraphicsEnvironmentClass = "java.awt.GraphicsEnvironment"; + public static final String isHeadlessMethod = "isHeadless"; + } private static final Class<?>[] zeroTypes = new Class[0]; /** @@ -261,11 +266,11 @@ public final class ReflectionUtil { } public static boolean isAWTComponent(Object target) { - return instanceOf(target, "java.awt.Component"); + return instanceOf(target, AWTNames.ComponentClass); } public static boolean isAWTComponent(Class<?> clazz) { - return instanceOf(clazz, "java.awt.Component"); + return instanceOf(clazz, AWTNames.ComponentClass); } /** diff --git a/src/java/com/jogamp/common/util/RunnableExecutor.java b/src/java/com/jogamp/common/util/RunnableExecutor.java index 7e6289b..7bf9685 100644 --- a/src/java/com/jogamp/common/util/RunnableExecutor.java +++ b/src/java/com/jogamp/common/util/RunnableExecutor.java @@ -28,8 +28,8 @@ package com.jogamp.common.util; public interface RunnableExecutor { - /** {@link RunnableExecutor} implementation simply invoking {@link Runnable#run()}, - * i.e. on the current thread at the time of calling {@link #invoke(boolean, Runnable)}. + /** This {@link RunnableExecutor} implementation simply invokes {@link Runnable#run()} + * on the current thread. */ public static final RunnableExecutor currentThreadExecutor = new CurrentThreadExecutor(); diff --git a/src/java/com/jogamp/common/util/VersionUtil.java b/src/java/com/jogamp/common/util/VersionUtil.java index 30b23f2..4d2d0f2 100644 --- a/src/java/com/jogamp/common/util/VersionUtil.java +++ b/src/java/com/jogamp/common/util/VersionUtil.java @@ -69,7 +69,9 @@ public class VersionUtil { // JVM/JRE sb.append("Platform: Java Version: ").append(Platform.getJavaVersion()).append(", VM: ").append(Platform.getJavaVMName()); sb.append(", Runtime: ").append(Platform.getJavaRuntimeName()).append(Platform.getNewline()); - sb.append("Platform: Java Vendor: ").append(Platform.getJavaVendor()).append(", ").append(Platform.getJavaVendorURL()).append(", is JavaSE: ").append(Platform.isJavaSE()); + sb.append("Platform: Java Vendor: ").append(Platform.getJavaVendor()).append(", ").append(Platform.getJavaVendorURL()); + sb.append(", is JavaSE: ").append(Platform.isJavaSE()); + sb.append(", AWT enabled: ").append(Platform.AWT_AVAILABLE); sb.append(Platform.getNewline()).append(SEPERATOR); return sb; diff --git a/src/java/jogamp/common/awt/AWTEDTExecutor.java b/src/java/jogamp/common/awt/AWTEDTExecutor.java new file mode 100644 index 0000000..dcf9818 --- /dev/null +++ b/src/java/jogamp/common/awt/AWTEDTExecutor.java @@ -0,0 +1,65 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package jogamp.common.awt; + +import java.awt.EventQueue; +import java.lang.reflect.InvocationTargetException; + +import com.jogamp.common.util.RunnableExecutor; + +/** + * AWT EDT implementation of RunnableExecutor + */ +public class AWTEDTExecutor implements RunnableExecutor { + /** {@link RunnableExecutor} implementation invoking {@link Runnable#run()} + * on the AWT EDT. + */ + public static final RunnableExecutor singleton = new AWTEDTExecutor(); + + private AWTEDTExecutor() {} + + @Override + public void invoke(boolean wait, Runnable r) { + if(EventQueue.isDispatchThread()) { + r.run(); + } else { + try { + if(wait) { + EventQueue.invokeAndWait(r); + } else { + EventQueue.invokeLater(r); + } + } catch (InvocationTargetException e) { + throw new RuntimeException(e.getTargetException()); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + +} |