Jogamp
Bug 1290: Expand query whether BCM IV is being used, exclude '/dev/dri/card0' master pulled rc
authorSven Gothel <sgothel@jausoft.com>
Tue, 16 Jan 2018 05:45:46 +0000 (06:45 +0100)
committerSven Gothel <sgothel@jausoft.com>
Tue, 16 Jan 2018 05:45:46 +0000 (06:45 +0100)
Also refactor query to jogamp.nativewindow.BcmVCArtifacts

src/jogl/classes/jogamp/opengl/egl/EGLES2DynamicLibraryBundleInfo.java
src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java
src/nativewindow/classes/jogamp/nativewindow/BcmVCArtifacts.java [new file with mode: 0644]

index 6b4a3ea..038194d 100644 (file)
 
 package jogamp.opengl.egl;
 
-import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
+import jogamp.nativewindow.BcmVCArtifacts;
+
 /**
  * <p>
  * Covering ES3 and ES2.
@@ -42,21 +43,20 @@ public final class EGLES2DynamicLibraryBundleInfo extends EGLDynamicLibraryBundl
         super();
     }
 
+
     @Override
     public final List<List<String>> getToolLibNames() {
 
-        // Prefer libGLESv2.so over libGLESv2.so.2 for Broadcom graphics
-        // when the VC4 DRM driver isn't present
-        final File vcliblocation = new File(
-            "/opt/vc/lib/libbcm_host.so");
-        final File vc4modlocation = new File(
-            "/sys/module/vc4");
-        final boolean bcm_vc_iv_quirk = vcliblocation.isFile() && !vc4modlocation.isDirectory();
-
         final List<List<String>> libsList = new ArrayList<List<String>>();
         {
             final List<String> libsGL = new ArrayList<String>();
 
+            /**
+             * Prefer libGLESv2.so over libGLESv2.so.2 for proprietary
+             * Broadcom graphics when the VC4 DRM Xorg driver isn't present
+             */
+            final boolean bcm_vc_iv_quirk = BcmVCArtifacts.guessVCIVUsed();
+
             // ES3: This is the default lib name, according to the spec
             libsGL.add("libGLESv3.so.3");
 
index 448c9d2..ebd4984 100644 (file)
@@ -33,7 +33,6 @@
 
 package com.jogamp.nativewindow;
 
-import java.io.File;
 import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -46,6 +45,7 @@ import java.util.Map;
 import com.jogamp.nativewindow.util.PointImmutable;
 
 import jogamp.common.os.PlatformPropsImpl;
+import jogamp.nativewindow.BcmVCArtifacts;
 import jogamp.nativewindow.Debug;
 import jogamp.nativewindow.NativeWindowFactoryImpl;
 import jogamp.nativewindow.ToolkitProperties;
@@ -136,22 +136,6 @@ public abstract class NativeWindowFactory {
     protected NativeWindowFactory() {
     }
 
-    private static final boolean guessBroadcomVCIV() {
-        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
-            private final File vcliblocation = new File(
-                    "/opt/vc/lib/libbcm_host.so");
-            private final File vc4modlocation = new File(
-                    "/sys/module/vc4");
-                @Override
-                public Boolean run() {
-                    if ( vcliblocation.isFile() && !vc4modlocation.isDirectory() ) {
-                        return Boolean.TRUE;
-                    }
-                    return Boolean.FALSE;
-                }
-        } ).booleanValue();
-    }
-
     private static String _getNativeWindowingType() {
         switch(PlatformPropsImpl.OS_TYPE) {
             case ANDROID:
@@ -168,7 +152,7 @@ public abstract class NativeWindowFactory {
             case SUNOS:
             case HPUX:
             default:
-              if( guessBroadcomVCIV() ) {
+              if( BcmVCArtifacts.guessVCIVUsed() ) {
                 return TYPE_BCM_VC_IV;
               }
               return TYPE_X11;
diff --git a/src/nativewindow/classes/jogamp/nativewindow/BcmVCArtifacts.java b/src/nativewindow/classes/jogamp/nativewindow/BcmVCArtifacts.java
new file mode 100644 (file)
index 0000000..216c55a
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+ * Copyright 2018 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.nativewindow;
+
+import java.io.File;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Heuristics about Broadcom (BCM) VideoCore (VC) existence and usage
+ */
+public class BcmVCArtifacts {
+    static final boolean hasVCLib;
+    static final boolean hasVC4ModLocation;
+    static final boolean hasDriCard0File;
+
+    static {
+        final File vcLibLocation = new File(
+            "/opt/vc/lib/libbcm_host.so");
+        final File vc4ModLocation = new File(
+            "/sys/module/vc4");
+        final File driCard0Location = new File(
+            "/dev/dri/card0");
+        final boolean[] res = new boolean [3];
+        AccessController.doPrivileged(new PrivilegedAction<Object>() {
+                @Override
+                public Object run() {
+                    res[0] = vcLibLocation.isFile();
+                    res[1] = vc4ModLocation.isDirectory();
+                    res[2] = driCard0Location.isFile();
+                    return null;
+                } } );
+        hasVCLib = res[0];
+        hasVC4ModLocation = res[1];
+        hasDriCard0File = res[2];
+    }
+
+    /**
+     * @return True if proprietary BCM VC IV is probably being present
+     */
+    public static final boolean guessVCIVPresent() {
+        return hasVCLib;
+    }
+    /**
+     * @return True if proprietary BCM VC IV is probably being used and not Xorg drivers
+     */
+    public static final boolean guessVCIVUsed() {
+        return hasVCLib && !hasVC4ModLocation && !hasDriCard0File;
+    }
+}
http://JogAmp.org git info: FAQ, tutorial and man pages.