# DRM启动步骤

(Ubuntu18.04Server版本 虚拟机测试OK)  
(Orange Pi Zero2 Ubuntu20.04-arm64 测试OK)

Avalonia官方参考文档：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.安装.net运行时(参考网址：https://learn.microsoft.com/zh-cn/dotnet/core/install/linux?WT.mc_id=dotnet-35129-website)

4.新建一个Avalonia项目，nuget里面添加Avalonia.LinuxFramebuffer包

5.添加StartLinuxDrm代码(不知道怎么添加看Semi.Avalonia.Demo.Drm项目代码)

6.发布程序到Linux(安装.net，怎么运行这些省略)
            
7.运行 ./Semi.Avalonia.Demo.Drm --drm

## 报错处理：

1. 报错内容

>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), make sure to specify x:Class and include your XAML file as AvaloniaResource

 解决方法：
>如果使用Semi发布文件不要裁剪，如果裁剪会报错
         

2. 报错内容
>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

3. 报错内容
>Permission denied

解决方法：  
>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`，可能是显卡挂载到别的文件夹下了，待解决。