doc/articles/features/using-skia-desktop.md
Uno Platform supports running applications using a common Skia Desktop shell, which is automatically used based on the running platform, using a single build output using the net10.0-desktop target framework from the Uno.Sdk.
The currently supported targets and platforms are:
The set of supported platforms can be defined by using the UnoPlatformHostBuilder, introduced in Uno Platform 5.2 and the Single Project support.
Follow the getting started guide for VS Code or Visual Studio, making sure to use the latest Uno Platform templates.
Once created, in the Platforms/Desktop/Program.cs file, you'll find the following builder:
var host = UnoPlatformHostBuilder.Create()
.App(() => new App())
.UseX11()
.UseLinuxFrameBuffer()
.UseMacOS()
.UseWin32()
.Build();
host.Run();
This builder allows us to configure the SkiaHost and setup which platforms will be supported at runtime. The builder evaluates the platform's availability one by one, in the order of definition.
[!includelinux-setup]
Enabling debug logging messages for the Skia Host can help diagnose the render surface type selection.
In your App.xaml.cs file, change the minimum log level to:
builder.SetMinimumLevel(LogLevel.Debug);
Then change the logging level of the Skia Host to Information or Debug:
builder.AddFilter("Uno.UI.Runtime.Skia", LogLevel.Information);
You may also need to initialize the logging system earlier than what is found in Uno.UI's default templates by calling this in Main:
YourAppNamespace.App.ConfigureFilters(); // Enable tracing of the Skia host
By default, Uno Platform comes with a set of SkiaSharp dependencies.
If you want to upgrade SkiaSharp to a later version, you'll need to specify all packages individually in your project as follows:
<ItemGroup>
<PackagReference Include="SkiaSharp" Version="3.119.0" />
<PackagReference Include="SkiaSharp.NativeAssets.Linux" Version="3.119.0" />
<PackageReference Update="SkiaSharp.NativeAssets.macOS" Version="3.119.0" />
<PackagReference Include="HarfBuzzSharp" Version="8.3.1.1" />
</ItemGroup>
By default, Uno Platform uses OpenGL for hardware-accelerated rendering on desktop, with an automatic fallback to software rendering. You can override this per platform using the host builder:
var host = UnoPlatformHostBuilder.Create()
.App(() => new App())
.UseX11(b => b.RenderingBackend(X11RenderingBackend.Vulkan))
.UseWin32(b => b.RenderingBackend(Win32RenderingBackend.Vulkan))
.UseMacOS()
.Build();
Each platform exposes its own RenderingBackend enum with only the backends it supports. For details, see Vulkan Rendering Backend.
Alternatively, you can use FeatureConfiguration.Rendering flags for backwards compatibility. The builder API takes precedence when both are used.
The Uno Platform Skia Desktop runtime on Windows uses a WPF shell internally. By default, Uno Platform enables RDP hardware acceleration in order to get good performance, yet this feature is disabled by default in standard WPF apps with .NET 8.
If you're having issues with the Windows support for Skia Desktop over RDP, add the following to your project:
<ItemGroup>
<RuntimeHostConfigurationOption Include="Switch.System.Windows.Media.EnableHardwareAccelerationInRdp" Value="false" />
</ItemGroup>
When running using X11 Wayland compatibility (e.g. recent Ubuntu releases), DPI scaling cannot be determined in a reliable way. In order to specify the scaling to be used by Uno Platform, set the UNO_DISPLAY_SCALE_OVERRIDE environment variable. The default value is 1.0.
The X11 support uses DBus for various interactions with the system, such as file selection. Make sure that dbus is installed.
Building an Uno Platform Skia Desktop app with .NET (7+) Native AOT requires Uno Platform 4.7 (or later).
To build an app with this feature enabled:
Add the following property in your .csproj:
<PropertyGroup>
<PublishAot>true</PublishAot>
</PropertyGroup>
Add the following items in your .csproj:
<ItemGroup>
<TrimmerRootAssembly Include="MyApp" />
</ItemGroup>
Build your app with:
dotnet publish -c Release -f net10.0-desktop
[!NOTE] Cross-compilation support is not supported as of .NET 7. To build a Native AOT app for Linux or Mac, you'll need to build on the corresponding host. [!NOTE] .NET Native AOT on Windows is not yet supported as WPF does not support it at this time.
When building an Uno Platform application head (for example, a Skia Desktop head) with Native AOT, Uno Platform automatically preserves public properties of types referenced by [Bindable] types to ensure data binding works correctly at runtime. This happens automatically when both IsUnoHead=true and PublishAot=true are set on the project (Uno head templates set IsUnoHead for you).
[!NOTE] Automatic binding preservation is only available for Uno Platform application heads. Class libraries or other projects that set
PublishAot=truebut are not marked withIsUnoHead=truewill not get this behavior.
The build system:
Microsoft.UI.Xaml.Data.BindableAttribute or Uno.Extensions.Reactive.Bindings.BindableAttributeFor example, if you have:
[Bindable]
public class MainViewModel
{
public Entity MyEntity { get; set; }
}
public record Entity(string Name);
The build system will automatically preserve the Name property of Entity, allowing {Binding MyEntity.Name} expressions to work correctly in Native AOT builds.
For more information, see the runtime documentation and the .NET Native AOT documentation.