From 40d179d4b4c5ff64364c67fddfc6e23869fa3cd9 Mon Sep 17 00:00:00 2001
From: ImLuJian <504439788@qq.com>
Date: Sat, 8 Jul 2023 17:57:44 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0DRM=E5=90=AF=E5=8A=A8?=
=?UTF-8?q?=E6=96=B9=E5=BC=8F=EF=BC=8C=E5=9C=A8VM=E8=99=9A=E6=8B=9F?=
=?UTF-8?q?=E6=9C=BA=E4=B8=8A=E6=B5=8B=E8=AF=95=E4=BA=86=E4=B8=80=E4=B8=8B?=
=?UTF-8?q?Ubuntu18.04=20Server=EF=BC=8C=E5=8F=AF=E4=BB=A5=E5=90=AF?=
=?UTF-8?q?=E5=8A=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
demo/Semi.Avalonia.Demo.Desktop/App.axaml.cs | 5 +-
demo/Semi.Avalonia.Demo.Desktop/Program.cs | 73 +++++++++++++++++--
.../Semi.Avalonia.Demo.Desktop.csproj | 1 +
3 files changed, 70 insertions(+), 9 deletions(-)
diff --git a/demo/Semi.Avalonia.Demo.Desktop/App.axaml.cs b/demo/Semi.Avalonia.Demo.Desktop/App.axaml.cs
index e70ba74..b534e3f 100644
--- a/demo/Semi.Avalonia.Demo.Desktop/App.axaml.cs
+++ b/demo/Semi.Avalonia.Demo.Desktop/App.axaml.cs
@@ -1,7 +1,6 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
-using Avalonia.Styling;
using Semi.Avalonia.Demo.Views;
namespace Semi.Avalonia.Demo.Desktop;
@@ -16,9 +15,9 @@ public partial class App : Application
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
- {
desktop.MainWindow = new MainWindow();
- }
+ else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
+ singleView.MainView = new MainView();
base.OnFrameworkInitializationCompleted();
}
}
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo.Desktop/Program.cs b/demo/Semi.Avalonia.Demo.Desktop/Program.cs
index d42b109..59b34db 100644
--- a/demo/Semi.Avalonia.Demo.Desktop/Program.cs
+++ b/demo/Semi.Avalonia.Demo.Desktop/Program.cs
@@ -1,7 +1,9 @@
-using System;
-using Avalonia;
+using Avalonia;
using Avalonia.Dialogs;
using Avalonia.Media;
+using System;
+using System.Linq;
+using System.Threading;
namespace Semi.Avalonia.Demo.Desktop;
@@ -11,8 +13,10 @@ class Program
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
- public static void Main(string[] args) => BuildAvaloniaApp()
- .With(new FontManagerOptions
+ public static void Main(string[] args)
+ {
+ var builder = BuildAvaloniaApp();
+ builder.With(new FontManagerOptions
{
FontFallbacks = new[]
{
@@ -21,8 +25,54 @@ class Program
FontFamily = new FontFamily("Microsoft YaHei")
}
}
- })
- .StartWithClassicDesktopLifetime(args);
+ });
+
+ //DRM启动步骤(Ubuntu18.04Server版本 虚拟机测试OK)
+ //官方文档:https://docs.avaloniaui.net/docs/next/guides/platforms/rpi/running-on-raspbian-lite-via-drm
+
+ //1.Linux端运行命令
+ //sudo apt update
+ //sudo apt upgrade
+ //sudo reboot
+ //sudo apt - get install libgbm1 libgl1 - mesa - dri libegl1 - mesa libinput10
+
+ //2.安装测试工具测试(出现一个彩色立方体说明环境安装完成)
+ //sudo apt-get install kmscube
+ //sudo kmscube
+
+ //3.添加StartLinuxDrm代码
+
+ //4.发布程序,复制到Linux系统(安装.net,怎么运行这些省略)
+ //发布文件不要裁剪,如果裁剪会报错
+ //Unhandled exception. Avalonia.Markup.Xaml.XamlLoadException: No precompiled XAML found for avares
+ //://Semi.Avalonia/Themes/Light/Light.axaml (baseUri: avares://Semi.Avalonia/Themes/Index.axaml), m
+ //ake sure to specify x:Class and include your XAML file as AvaloniaResource
+
+ //5.运行
+
+ //运行报错点:
+ //Unhandled exception. System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
+ //--->System.DllNotFoundException: Unable to load shared library 'libSkiaSharp' or one of its dependencies.In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory
+ //at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
+ //at SkiaSharp.SKImageInfo..cctor()
+
+ //解决方法:
+ //Linux命令行安装一下 apt-get install -y libfontconfig1
+ //网址:https://github.com/mono/SkiaSharp/issues/509
+
+ 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.
public static AppBuilder BuildAvaloniaApp()
@@ -31,4 +81,15 @@ class Program
.UsePlatformDetect()
.With(new Win32PlatformOptions())
.LogToTrace();
+
+ private static void SilenceConsole()
+ {
+ new Thread(() =>
+ {
+ Console.CursorVisible = false;
+ while (true)
+ Console.ReadKey(true);
+ })
+ { IsBackground = true }.Start();
+ }
}
diff --git a/demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj b/demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj
index 4e0ff0e..68489a2 100644
--- a/demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj
+++ b/demo/Semi.Avalonia.Demo.Desktop/Semi.Avalonia.Demo.Desktop.csproj
@@ -23,6 +23,7 @@
+