From 347271ffdd09153a2334fda593774d49050f84e0 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 16 Jan 2018 06:45:46 +0100 Subject: Bug 1290: Expand query whether BCM IV is being used, exclude '/dev/dri/card0' Also refactor query to jogamp.nativewindow.BcmVCArtifacts --- .../jogamp/nativewindow/NativeWindowFactory.java | 20 +----- .../jogamp/nativewindow/BcmVCArtifacts.java | 76 ++++++++++++++++++++++ 2 files changed, 78 insertions(+), 18 deletions(-) create mode 100644 src/nativewindow/classes/jogamp/nativewindow/BcmVCArtifacts.java (limited to 'src/nativewindow/classes') diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java index 448c9d2bf..ebd498401 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/NativeWindowFactory.java @@ -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() { - 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 index 000000000..216c55a3a --- /dev/null +++ b/src/nativewindow/classes/jogamp/nativewindow/BcmVCArtifacts.java @@ -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() { + @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; + } +} -- cgit v1.2.3