diff --git a/src/Windows/Avalonia.Win32/Win32Platform.cs b/src/Windows/Avalonia.Win32/Win32Platform.cs index aaf6fed624..5082c76d0c 100644 --- a/src/Windows/Avalonia.Win32/Win32Platform.cs +++ b/src/Windows/Avalonia.Win32/Win32Platform.cs @@ -99,9 +99,24 @@ namespace Avalonia.Win32 .Bind().ToConstant(NonPumpingWaitHelperImpl.Instance) .Bind().ToConstant(new WindowsMountedVolumeInfoProvider()) .Bind().ToConstant(s_instance); - - var platformGraphics = options.CustomPlatformGraphics - ?? Win32GlManager.Initialize(); + + IPlatformGraphics? platformGraphics; + if (options.CustomPlatformGraphics is not null) + { + if (options.CompositionMode.HasValue + && options.CompositionMode != Win32CompositionMode.RedirectionSurface) + { + throw new InvalidOperationException( + $"{nameof(Win32PlatformOptions)}.{nameof(Win32PlatformOptions.CustomPlatformGraphics)} is only " + + $"compatible with {nameof(Win32CompositionMode)}.{nameof(Win32CompositionMode.RedirectionSurface)}"); + } + + platformGraphics = options.CustomPlatformGraphics; + } + else + { + platformGraphics = Win32GlManager.Initialize(); + } if (OleContext.Current != null) AvaloniaLocator.CurrentMutable.Bind().ToSingleton(); diff --git a/src/Windows/Avalonia.Win32/Win32PlatformOptions.cs b/src/Windows/Avalonia.Win32/Win32PlatformOptions.cs index aaebedb8c5..3c7e32f774 100644 --- a/src/Windows/Avalonia.Win32/Win32PlatformOptions.cs +++ b/src/Windows/Avalonia.Win32/Win32PlatformOptions.cs @@ -91,7 +91,7 @@ public class Win32PlatformOptions /// /// Render directly on the UI thread instead of using a dedicated render thread. - /// Only applicable if is set to . + /// Only applicable if is set to . /// This setting is only recommended for interop with systems that must render on the UI thread, such as WPF. /// This setting is false by default. /// @@ -108,7 +108,8 @@ public class Win32PlatformOptions /// /// Provides a way to use a custom-implemented graphics context such as a custom ISkiaGpu. - /// When this property set and are completely ignored. + /// When this property set is ignored + /// and only accepts null or . /// public IPlatformGraphics? CustomPlatformGraphics { get; set; } }