From 12e20b80a50906dcb24f45dc85b4ee9cb40a9b16 Mon Sep 17 00:00:00 2001 From: CallumHopkins181 <100864965+CallumHopkins181@users.noreply.github.com> Date: Sun, 3 Apr 2022 10:02:23 +0100 Subject: [PATCH] Fix rpi4 drm bug (#7749) * Fix rpi4 drm bug * Change default path to include all cards * Import namespaces Co-authored-by: Jumar Macato <16554748+jmacato@users.noreply.github.com> --- .../Output/DrmBindings.cs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmBindings.cs b/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmBindings.cs index e218da5f41..64fafc65f3 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmBindings.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmBindings.cs @@ -1,7 +1,9 @@ using System; +using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Runtime.InteropServices; +using System.Text.RegularExpressions; using static Avalonia.LinuxFramebuffer.NativeUnsafeMethods; using static Avalonia.LinuxFramebuffer.Output.LibDrm; @@ -142,10 +144,28 @@ namespace Avalonia.LinuxFramebuffer.Output public int Fd { get; private set; } public DrmCard(string path = null) { - path = path ?? "/dev/dri/card0"; - Fd = open(path, 2, 0); - if (Fd == -1) - throw new Win32Exception("Couldn't open " + path); + if(path == null) + { + var files = Directory.GetFiles("/dev/dri/"); + + foreach(var file in files) + { + var match = Regex.Match(file, "card[0-9]+"); + + if(match.Success) + { + Fd = open(file, 2, 0); + if(Fd != -1) break; + } + } + + if(Fd == -1) throw new Win32Exception("Couldn't open /dev/dri/card[0-9]+"); + } + else + { + Fd = open(path, 2, 0); + if(Fd != -1) throw new Win32Exception($"Couldn't open {path}"); + } } public DrmResources GetResources() => new DrmResources(Fd);