diff options
author | Sven Gothel <[email protected]> | 2019-12-04 04:54:22 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-12-04 04:54:22 +0100 |
commit | e57de40bd0e1a318d59ca70f20a6f7d8a8921c74 (patch) | |
tree | b3f061723b57c7b156ea298130084d5b2cc7b6af | |
parent | 22ee0cfa7dc3f3a7ac5e30322537196dcab8b310 (diff) |
Bug 1406: DRMUtil: Probe DRM device whether it has resources attached (and is the desired one)
First issue was that the proper DRM file had to be queries,
as Raspberry 4 may have two of them:
<--
/dev/dri/dri0
/dev/dri/dri0
/dev/dri/by-path/platform-fec00000.v3d-card -> ../card0
/dev/dri/by-path/platform-soc:gpu-card -> ../card1
-->
This patch attempts to probe all /dev/dri/card[0..99]
using this arbitrary range.
The test loop ends if:
- drmOpenFile succeeds and drmModeGetResources delivers non-null value
- the iterated probed file doesn't even exist
- 100 files has been tested ;-)
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/drm/DRMUtil.java | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/drm/DRMUtil.java b/src/nativewindow/classes/jogamp/nativewindow/drm/DRMUtil.java index 176ebccb0..a179ce223 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/drm/DRMUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/drm/DRMUtil.java @@ -35,6 +35,8 @@ import jogamp.nativewindow.Debug; import jogamp.nativewindow.NWJNILibLoader; import jogamp.nativewindow.ToolkitProperties; +import java.io.File; + import com.jogamp.common.ExceptionUtils; /** @@ -44,12 +46,45 @@ public class DRMUtil implements ToolkitProperties { /* pp */ static final boolean DEBUG = Debug.debug("DRMUtil"); /** FIXME: Add support for other OS implementing DRM/GBM, e.g. FreeBSD, OpenBSD, ..? */ - private static final String dri0Linux = "/dev/dri/card0"; + private static final String driXLinux = "/dev/dri/card"; private static volatile boolean isInit = false; /** DRM file descriptor, valid if >= 0 */ private static int drmFd = -1; + private static int openDrmDevice(final String[] lastFilename) { + for(int i=0; i<100; i++) { + final String driXFilename = driXLinux + i; + lastFilename[0] = driXFilename; + final File driXFile = new File(driXFilename); + if( !driXFile.exists() ) { + if(DEBUG) { + System.err.println("DRMUtil.initSingleton(): drmDevice["+driXFilename+"]: not existing"); + } + // end of search, failure + return -1; + } + final int fd = DRMLib.drmOpenFile(driXFilename); + if( 0 <= fd ) { + // test .. + final drmModeRes resources = DRMLib.drmModeGetResources(fd); + if(DEBUG) { + System.err.println("DRMUtil.initSingleton(): drmDevice["+driXFilename+"]: fd "+fd+": has resources: "+(null!=resources)); + } + if( null == resources ) { + // nope, not working - continue testing + DRMLib.drmClose(fd); + continue; + } else { + // OK + DRMLib.drmModeFreeResources(resources); + return fd; + } + } + } + return -1; + } + /** * Called by {@link NativeWindowFactory#initSingleton()} * @see ToolkitProperties @@ -65,8 +100,9 @@ public class DRMUtil implements ToolkitProperties { if(!NWJNILibLoader.loadNativeWindow("drm")) { throw new NativeWindowException("NativeWindow DRM native library load error."); } + final String[] lastFilename = new String[] { null }; if( initialize0(DEBUG) ) { - drmFd = DRMLib.drmOpenFile(dri0Linux); + drmFd = openDrmDevice(lastFilename); } if(DEBUG) { System.err.println("DRMUtil.initSingleton(): OK "+(0 <= drmFd)+", drmFd "+drmFd+"]"); @@ -77,6 +113,9 @@ public class DRMUtil implements ToolkitProperties { } // Thread.dumpStack(); } + if( 0 > drmFd ) { + throw new NativeWindowException("drmOpenFile("+lastFilename[0]+") failed"); + } } } } |