mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-12-03 10:15:19 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dc1f43d385 |
@@ -14,7 +14,7 @@ public class SoftwareRenderTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Without_the_switch_the_graphics_card_draws()
|
public void Without_the_switch_it_is_not_asked_for()
|
||||||
{
|
{
|
||||||
Assert.False(SoftwareRender.AskedIn(Array.Empty<string>()));
|
Assert.False(SoftwareRender.AskedIn(Array.Empty<string>()));
|
||||||
Assert.False(SoftwareRender.AskedIn(new[] { "--software" }));
|
Assert.False(SoftwareRender.AskedIn(new[] { "--software" }));
|
||||||
@@ -25,21 +25,25 @@ public class SoftwareRenderTests
|
|||||||
{
|
{
|
||||||
var options = SoftwareRender.Win32Options;
|
var options = SoftwareRender.Win32Options;
|
||||||
|
|
||||||
|
// No WinUI composition, DirectComposition or swap chain of the graphics card's.
|
||||||
Assert.Equal(new[] { Win32RenderingMode.Software }, options.RenderingMode);
|
Assert.Equal(new[] { Win32RenderingMode.Software }, options.RenderingMode);
|
||||||
Assert.Equal(new[] { Win32CompositionMode.RedirectionSurface }, options.CompositionMode);
|
Assert.Equal(new[] { Win32CompositionMode.RedirectionSurface }, options.CompositionMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void X11_draws_on_the_processor()
|
public void X11_draws_on_the_processor_when_asked()
|
||||||
{
|
{
|
||||||
Assert.Equal(new[] { X11RenderingMode.Software }, SoftwareRender.X11Options.RenderingMode);
|
Assert.Equal(new[] { X11RenderingMode.Software }, SoftwareRender.X11Options.RenderingMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Theory]
|
||||||
public void Both_platforms_options_go_to_the_same_builder()
|
[InlineData(false)]
|
||||||
|
[InlineData(true)]
|
||||||
|
public void The_options_go_to_the_same_builder_with_or_without_the_switch(bool asked)
|
||||||
{
|
{
|
||||||
var builder = AppBuilder.Configure<Avalonia.Application>();
|
var builder = AppBuilder.Configure<Avalonia.Application>();
|
||||||
|
string[] args = asked ? new[] { SoftwareRender.Switch } : Array.Empty<string>();
|
||||||
|
|
||||||
Assert.Same(builder, SoftwareRender.ApplyTo(builder));
|
Assert.Same(builder, SoftwareRender.ApplyTo(builder, args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
using Avalonia;
|
|
||||||
using StarterNG.Infrastructure;
|
|
||||||
|
|
||||||
namespace StarterNG.Tests;
|
|
||||||
|
|
||||||
public class WindowSurfacesTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void Windows_draws_into_a_directcomposition_surface_and_never_through_winui_composition()
|
|
||||||
{
|
|
||||||
var options = WindowSurfaces.Win32Options;
|
|
||||||
|
|
||||||
Assert.Equal(Win32CompositionMode.DirectComposition, options.CompositionMode.First());
|
|
||||||
Assert.DoesNotContain(Win32CompositionMode.WinUIComposition, options.CompositionMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void The_window_surface_is_only_the_fallback()
|
|
||||||
{
|
|
||||||
// There ANGLE presents through a swap chain, and the Steam overlay draws over it.
|
|
||||||
Assert.Equal(Win32CompositionMode.RedirectionSurface, WindowSurfaces.Win32Options.CompositionMode.Last());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void No_swap_chain_of_its_own_is_asked_for()
|
|
||||||
{
|
|
||||||
Assert.DoesNotContain(Win32CompositionMode.LowLatencyDxgiSwapChain, WindowSurfaces.Win32Options.CompositionMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void The_graphics_card_still_draws()
|
|
||||||
{
|
|
||||||
Assert.Equal(new Win32PlatformOptions().RenderingMode, WindowSurfaces.Win32Options.RenderingMode);
|
|
||||||
Assert.Contains(Win32RenderingMode.AngleEgl, WindowSurfaces.Win32Options.RenderingMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(false)]
|
|
||||||
[InlineData(true)]
|
|
||||||
public void The_options_go_to_the_same_builder_with_or_without_the_processor(bool softwareRender)
|
|
||||||
{
|
|
||||||
var builder = AppBuilder.Configure<Avalonia.Application>();
|
|
||||||
|
|
||||||
Assert.Same(builder, WindowSurfaces.ApplyTo(builder, softwareRender));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,8 +6,15 @@ using Avalonia;
|
|||||||
namespace StarterNG.Infrastructure;
|
namespace StarterNG.Infrastructure;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Drawn by the processor instead of the graphics card, for a machine on which the
|
/// On Windows the processor draws the starter's windows, and each frame is copied into its window
|
||||||
/// window comes up empty. Each platform reads only its own options, so both are given.
|
/// by GDI. Every way of the graphics card's failed on some machine: Avalonia's WinUI composition
|
||||||
|
/// visual left windows black on Windows 11 25H2, the Steam overlay drew its frame counter over a
|
||||||
|
/// window's own swap chain, and with DirectComposition the starter vanished a few seconds after its
|
||||||
|
/// window came up on a Windows 10 machine with a GTX 1650, without a word in its log. A frame copied
|
||||||
|
/// by GDI has no swap chain for an overlay to hook, and lists, text and pictures are no work for the
|
||||||
|
/// processor.
|
||||||
|
/// On X11 the graphics card draws, unless <see cref="Switch"/> asks the processor, for a machine on
|
||||||
|
/// which the window comes up empty. Each platform reads only its own options.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class SoftwareRender
|
public static class SoftwareRender
|
||||||
{
|
{
|
||||||
@@ -27,6 +34,9 @@ public static class SoftwareRender
|
|||||||
RenderingMode = new[] { X11RenderingMode.Software }
|
RenderingMode = new[] { X11RenderingMode.Software }
|
||||||
};
|
};
|
||||||
|
|
||||||
public static AppBuilder ApplyTo(AppBuilder builder) =>
|
public static AppBuilder ApplyTo(AppBuilder builder, IEnumerable<string> args)
|
||||||
builder.With(Win32Options).With(X11Options);
|
{
|
||||||
|
builder.With(Win32Options);
|
||||||
|
return AskedIn(args) ? builder.With(X11Options) : builder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
using Avalonia;
|
|
||||||
|
|
||||||
namespace StarterNG.Infrastructure;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// On Windows the graphics card draws each window of the starter into a DirectComposition
|
|
||||||
/// surface, 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.
|
|
||||||
/// The window's own redirection surface is only the fallback: there ANGLE draws through a
|
|
||||||
/// swap chain of the window, and the Steam overlay, which Steam puts into the starter as
|
|
||||||
/// the game it launches, hooks that swap chain's Present and draws its frame counter and
|
|
||||||
/// notifications over the starter. A composition surface is drawn without a Present.
|
|
||||||
/// </summary>
|
|
||||||
public static class WindowSurfaces
|
|
||||||
{
|
|
||||||
public static Win32PlatformOptions Win32Options => new()
|
|
||||||
{
|
|
||||||
CompositionMode = new[]
|
|
||||||
{
|
|
||||||
Win32CompositionMode.DirectComposition,
|
|
||||||
Win32CompositionMode.RedirectionSurface
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The options a platform reads are the last given, so the processor, when asked
|
|
||||||
/// for, draws with <see cref="SoftwareRender"/>'s own and these are left out.
|
|
||||||
/// </summary>
|
|
||||||
public static AppBuilder ApplyTo(AppBuilder builder, bool softwareRender) =>
|
|
||||||
softwareRender ? SoftwareRender.ApplyTo(builder) : builder.With(Win32Options);
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,8 @@ namespace StarterNG;
|
|||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
private static bool _softwareRender;
|
// What --software-render is looked for in; none for the designer, which calls BuildAvaloniaApp itself.
|
||||||
|
private static string[] _args = Array.Empty<string>();
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
@@ -19,7 +20,7 @@ static class Program
|
|||||||
var graphics = SystemGraphicsLibraries.TakeOnWindows();
|
var graphics = SystemGraphicsLibraries.TakeOnWindows();
|
||||||
graphics?.ServeTo(typeof(Win32PlatformOptions).Assembly);
|
graphics?.ServeTo(typeof(Win32PlatformOptions).Assembly);
|
||||||
|
|
||||||
_softwareRender = SoftwareRender.AskedIn(args);
|
_args = args;
|
||||||
|
|
||||||
// Composition root first: everything below, including the crash handlers,
|
// Composition root first: everything below, including the crash handlers,
|
||||||
// resolves its collaborators from this graph.
|
// resolves its collaborators from this graph.
|
||||||
@@ -73,14 +74,14 @@ static class Program
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Without the switch the graphics card draws, into the window surfaces.
|
// On Windows the processor draws; on X11 the graphics card, unless --software-render.
|
||||||
private static AppBuilder WithSoftwareRenderIfAsked(this AppBuilder builder) =>
|
private static AppBuilder WithSoftwareRender(this AppBuilder builder) =>
|
||||||
WindowSurfaces.ApplyTo(builder, _softwareRender);
|
SoftwareRender.ApplyTo(builder, _args);
|
||||||
|
|
||||||
public static AppBuilder BuildAvaloniaApp()
|
public static AppBuilder BuildAvaloniaApp()
|
||||||
=> AppBuilder.Configure<App>()
|
=> AppBuilder.Configure<App>()
|
||||||
.UsePlatformDetect()
|
.UsePlatformDetect()
|
||||||
.WithSoftwareRenderIfAsked()
|
.WithSoftwareRender()
|
||||||
.WithInterFont()
|
.WithInterFont()
|
||||||
.WithDiagnosticsLogging()
|
.WithDiagnosticsLogging()
|
||||||
.AfterSetup(_ => LogUiExceptions());
|
.AfterSetup(_ => LogUiExceptions());
|
||||||
|
|||||||
Reference in New Issue
Block a user