mirror of
https://gitcode.com/gh_mirrors/se/Semi.Avalonia
synced 2026-05-02 14:01:28 +08:00
Merge pull request #272 from irihitech/drm
Running on Raspberry Pi with Drm
This commit is contained in:
@@ -1,59 +1,53 @@
|
|||||||
using Avalonia;
|
using System;
|
||||||
using Avalonia.Dialogs;
|
using System.Globalization;
|
||||||
using Avalonia.Media;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Avalonia;
|
||||||
|
|
||||||
namespace Semi.Avalonia.Demo.Drm
|
namespace Semi.Avalonia.Demo.Drm;
|
||||||
|
|
||||||
|
class Program
|
||||||
{
|
{
|
||||||
internal class Program
|
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||||
|
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||||
|
// yet and stuff might break.
|
||||||
|
[STAThread]
|
||||||
|
public static int Main(string[] args)
|
||||||
{
|
{
|
||||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
var builder = BuildAvaloniaApp();
|
||||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
|
||||||
// yet and stuff might break.
|
double GetScaling()
|
||||||
[STAThread]
|
|
||||||
public static void Main(string[] args)
|
|
||||||
{
|
{
|
||||||
var builder = BuildAvaloniaApp();
|
var idx = Array.IndexOf(args, "--scaling");
|
||||||
builder.With(new FontManagerOptions
|
if (idx != 0 && args.Length > idx + 1 &&
|
||||||
{
|
double.TryParse(args[idx + 1], NumberStyles.Any, CultureInfo.InvariantCulture, out var scaling))
|
||||||
FontFallbacks = new[]
|
return scaling;
|
||||||
{
|
return 1;
|
||||||
new FontFallback
|
|
||||||
{
|
|
||||||
FontFamily = new FontFamily("Microsoft YaHei")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (args.Contains("--drm"))
|
|
||||||
{
|
|
||||||
SilenceConsole();
|
|
||||||
builder.StartLinuxDrm(args: args, card: "/dev/dri/card0", scaling: 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
builder.StartWithClassicDesktopLifetime(args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avalonia configuration, don't remove; also used by visual designer.
|
if (args.Contains("--drm"))
|
||||||
public static AppBuilder BuildAvaloniaApp()
|
|
||||||
=> AppBuilder.Configure<App>()
|
|
||||||
.UseManagedSystemDialogs()
|
|
||||||
.UsePlatformDetect()
|
|
||||||
.With(new Win32PlatformOptions())
|
|
||||||
.LogToTrace();
|
|
||||||
|
|
||||||
private static void SilenceConsole()
|
|
||||||
{
|
{
|
||||||
new Thread(() =>
|
SilenceConsole();
|
||||||
|
return builder.StartLinuxDrm(args: args, card: "/dev/dri/card1", scaling: GetScaling());
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.StartWithClassicDesktopLifetime(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Avalonia configuration, don't remove; also used by visual designer.
|
||||||
|
public static AppBuilder BuildAvaloniaApp()
|
||||||
|
=> AppBuilder.Configure<App>()
|
||||||
|
.UsePlatformDetect()
|
||||||
|
.LogToTrace();
|
||||||
|
|
||||||
|
private static void SilenceConsole()
|
||||||
|
{
|
||||||
|
new Thread(() =>
|
||||||
{
|
{
|
||||||
Console.CursorVisible = false;
|
Console.CursorVisible = false;
|
||||||
while (true)
|
while (true)
|
||||||
Console.ReadKey(true);
|
Console.ReadKey(true);
|
||||||
})
|
})
|
||||||
{ IsBackground = true }.Start();
|
{ IsBackground = true }.Start();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,3 +54,24 @@ sudo kmscube
|
|||||||
|
|
||||||
解决方法:
|
解决方法:
|
||||||
>sudo chmod +x ./Semi.Avalonia.Demo.Drm
|
>sudo chmod +x ./Semi.Avalonia.Demo.Drm
|
||||||
|
|
||||||
|
4. 报错内容
|
||||||
|
>Unhandled exception. System.ComponentModel.Win32Exception (95): drmModeGetResources failed
|
||||||
|
at Avalonia.LinuxFramebuffer.Output.DrmResources..ctor(Int32 fd, Boolean connectorsForceProbe) in /_/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmBindings.cs:line 91
|
||||||
|
at Avalonia.LinuxFramebuffer.Output.DrmCard.GetResources(Boolean connectorsForceProbe) in /_/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmBindings.cs:line 171
|
||||||
|
at Avalonia.LinuxFramebuffer.Output.DrmOutput..ctor(String path, Boolean connectorsForceProbe, DrmOutputOptions options) in /_/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs:line 60
|
||||||
|
at LinuxFramebufferPlatformExtensions.StartLinuxDrm(AppBuilder builder, String[] args, String card, Double scaling, IInputBackend inputBackend) in /_/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs:line 166
|
||||||
|
at Semi.Avalonia.Demo.Drm.Program.Main(String[] args)
|
||||||
|
|
||||||
|
解决方法:
|
||||||
|
>`program.cs`的显卡路径错误,可能不是`dev/dri/card1`,看在`dev/dri`目录下有无其他的显卡如`card0`。
|
||||||
|
|
||||||
|
5. 报错内容
|
||||||
|
>Unhandled exception. System.ComponentModel.Win32Exception (2): Couldn't open /dev/dri/card1
|
||||||
|
at Avalonia.LinuxFramebuffer.Output.DrmCard..ctor(String ) in /_/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmBindings.cs:line 167
|
||||||
|
at Avalonia.LinuxFramebuffer.Output.DrmOutput..ctor(String , Boolean , DrmOutputOptions ) in /_/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs:line 58
|
||||||
|
at LinuxFramebufferPlatformExtensions.StartLinuxDrm(AppBuilder, String[], String , Double , IInputBackend ) in /_/src/Linux/Avalonia.LinuxFramebuffer/LinuxFramebufferPlatform.cs:line 166
|
||||||
|
at Semi.Avalonia.Demo.Drm.Program.Main(String[])
|
||||||
|
|
||||||
|
解决办法:
|
||||||
|
>找不到显卡路径`dev/dri/card1`,可能是显卡挂载到别的文件夹下了,待解决。
|
||||||
Reference in New Issue
Block a user