From f9939fd5669db4d952109ba30538aa83db9aedb1 Mon Sep 17 00:00:00 2001 From: maj00r Date: Wed, 25 Nov 2026 17:56:17 +0100 Subject: [PATCH] fix: windows of the starter no longer come up black on Windows 11 25H2 Avalonia composes each window through a WinUI composition visual by default, and on 25H2 that visual was often left empty: the main window or a dialog opened later stayed black while the others drew. The starter has no see-through windows or backdrops, so every window now draws into its own redirection surface, still on the graphics card. --software-render comes after and keeps its own options. --- StarterNG.Tests/WindowSurfacesTests.cs | 31 ++++++++++++++++++++++ StarterNG/Infrastructure/WindowSurfaces.cs | 21 +++++++++++++++ StarterNG/Program.cs | 5 ++++ 3 files changed, 57 insertions(+) create mode 100644 StarterNG.Tests/WindowSurfacesTests.cs create mode 100644 StarterNG/Infrastructure/WindowSurfaces.cs diff --git a/StarterNG.Tests/WindowSurfacesTests.cs b/StarterNG.Tests/WindowSurfacesTests.cs new file mode 100644 index 0000000..7e28818 --- /dev/null +++ b/StarterNG.Tests/WindowSurfacesTests.cs @@ -0,0 +1,31 @@ +using Avalonia; +using StarterNG.Infrastructure; + +namespace StarterNG.Tests; + +public class WindowSurfacesTests +{ + [Fact] + public void Windows_draws_into_the_window_surface_and_never_through_winui_composition() + { + var options = WindowSurfaces.Win32Options; + + Assert.Equal(new[] { Win32CompositionMode.RedirectionSurface }, options.CompositionMode); + Assert.DoesNotContain(Win32CompositionMode.WinUIComposition, options.CompositionMode); + } + + [Fact] + public void The_graphics_card_still_draws() + { + Assert.Equal(new Win32PlatformOptions().RenderingMode, WindowSurfaces.Win32Options.RenderingMode); + Assert.Contains(Win32RenderingMode.AngleEgl, WindowSurfaces.Win32Options.RenderingMode); + } + + [Fact] + public void The_options_go_to_the_same_builder() + { + var builder = AppBuilder.Configure(); + + Assert.Same(builder, WindowSurfaces.ApplyTo(builder)); + } +} diff --git a/StarterNG/Infrastructure/WindowSurfaces.cs b/StarterNG/Infrastructure/WindowSurfaces.cs new file mode 100644 index 0000000..641e706 --- /dev/null +++ b/StarterNG/Infrastructure/WindowSurfaces.cs @@ -0,0 +1,21 @@ +using Avalonia; + +namespace StarterNG.Infrastructure; + +/// +/// On Windows the graphics card draws each window of the starter into a surface of that +/// window, not into Avalonia's default WinUI composition visual. On Windows 11 25H2 that +/// visual was left empty on many starts: the main window, or a dialog opened later, +/// stayed black while the others drew, and came back only now and then. Composition is +/// there for see-through windows and backdrops, and the starter has none. +/// goes after this and brings its own options. +/// +public static class WindowSurfaces +{ + public static Win32PlatformOptions Win32Options => new() + { + CompositionMode = new[] { Win32CompositionMode.RedirectionSurface } + }; + + public static AppBuilder ApplyTo(AppBuilder builder) => builder.With(Win32Options); +} diff --git a/StarterNG/Program.cs b/StarterNG/Program.cs index aa0a8c8..2cbb751 100644 --- a/StarterNG/Program.cs +++ b/StarterNG/Program.cs @@ -73,12 +73,17 @@ static class Program }; } + private static AppBuilder WithWindowSurfaces(this AppBuilder builder) => + WindowSurfaces.ApplyTo(builder); + private static AppBuilder WithSoftwareRenderIfAsked(this AppBuilder builder) => _softwareRender ? SoftwareRender.ApplyTo(builder) : builder; public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() .UsePlatformDetect() + .WithWindowSurfaces() + // After the surfaces: the later options of a platform are the ones it reads. .WithSoftwareRenderIfAsked() .WithInterFont() .WithDiagnosticsLogging()