test: the system graphics libraries and the software render switch

Taking the libraries and the switch's options are apart from Main, so they are
tested on every system, not only where Windows has them to load.
This commit is contained in:
maj00r
2026-11-15 17:30:13 +01:00
parent 91c496ab48
commit 6e2dbf9eac
5 changed files with 228 additions and 54 deletions

View File

@@ -1,7 +1,6 @@
using Avalonia;
using Avalonia.Threading;
using System;
using System.Linq;
using System.Threading.Tasks;
using StarterNG.Application;
using StarterNG.Infrastructure;
@@ -11,24 +10,22 @@ namespace StarterNG;
static class Program
{
/// <summary>
/// Drawn by the processor instead of the graphics card, for a machine on which the
/// window comes up empty. Started with <c>--software-render</c>.
/// </summary>
private static bool _softwareRender;
[STAThread]
public static void Main(string[] args)
{
// Ahead of everything that could draw: what lies beside the starter is the simulator's.
SystemGraphicsLibraries.LoadFirst(typeof(Win32PlatformOptions).Assembly);
var graphics = SystemGraphicsLibraries.TakeOnWindows();
graphics?.ServeTo(typeof(Win32PlatformOptions).Assembly);
_softwareRender = args.Any(a => string.Equals(a, "--software-render", StringComparison.OrdinalIgnoreCase));
_softwareRender = SoftwareRender.AskedIn(args);
// Composition root first: everything below, including the crash handlers,
// resolves its collaborators from this graph.
AppServices.Initialize();
SystemGraphicsLibraries.LogShadowed();
if (graphics?.Note is { } note)
Diagnostics.Log(note);
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
{
@@ -76,20 +73,8 @@ static class Program
};
}
// Each platform reads only its own options, so both can be given everywhere.
private static AppBuilder WithSoftwareRenderIfAsked(this AppBuilder builder) =>
_softwareRender
? builder
.With(new Win32PlatformOptions
{
RenderingMode = new[] { Win32RenderingMode.Software },
CompositionMode = new[] { Win32CompositionMode.RedirectionSurface }
})
.With(new X11PlatformOptions
{
RenderingMode = new[] { X11RenderingMode.Software }
})
: builder;
_softwareRender ? SoftwareRender.ApplyTo(builder) : builder;
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()