Browse Source

Throw an exception when CustomPlatformGraphics is used with unsupported Win32CompositionMode

pull/11898/head
Max Katz 3 years ago
parent
commit
effb12f9e0
  1. 21
      src/Windows/Avalonia.Win32/Win32Platform.cs
  2. 5
      src/Windows/Avalonia.Win32/Win32PlatformOptions.cs

21
src/Windows/Avalonia.Win32/Win32Platform.cs

@ -99,9 +99,24 @@ namespace Avalonia.Win32
.Bind<NonPumpingLockHelper.IHelperImpl>().ToConstant(NonPumpingWaitHelperImpl.Instance)
.Bind<IMountedVolumeInfoProvider>().ToConstant(new WindowsMountedVolumeInfoProvider())
.Bind<IPlatformLifetimeEventsImpl>().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<IPlatformDragSource>().ToSingleton<DragSource>();

5
src/Windows/Avalonia.Win32/Win32PlatformOptions.cs

@ -91,7 +91,7 @@ public class Win32PlatformOptions
/// <summary>
/// Render directly on the UI thread instead of using a dedicated render thread.
/// Only applicable if <see cref="CompositionMode"/> is set to <see cref="Win32CompositionMode.None"/>.
/// Only applicable if <see cref="CompositionMode"/> is set to <see cref="Win32CompositionMode.RedirectionSurface"/>.
/// 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.
/// </summary>
@ -108,7 +108,8 @@ public class Win32PlatformOptions
/// <summary>
/// Provides a way to use a custom-implemented graphics context such as a custom ISkiaGpu.
/// When this property set <see cref="RenderingMode"/> and <see cref="CompositionMode"/> are completely ignored.
/// When this property set <see cref="RenderingMode"/> is ignored
/// and <see cref="CompositionMode"/> only accepts null or <see cref="Win32CompositionMode.RedirectionSurface"/>.
/// </summary>
public IPlatformGraphics? CustomPlatformGraphics { get; set; }
}

Loading…
Cancel
Save