Browse Source

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>
pull/7921/head
CallumHopkins181 4 years ago
committed by GitHub
parent
commit
12e20b80a5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      src/Linux/Avalonia.LinuxFramebuffer/Output/DrmBindings.cs

28
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);

Loading…
Cancel
Save