diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index c7347cf0..eaa46939 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -58,6 +58,12 @@ jobs: run: > msbuild src\ComputeSharp.WinUI\ComputeSharp.WinUI.csproj -t:restore /p:Configuration=Release; msbuild src\ComputeSharp.WinUI\ComputeSharp.WinUI.csproj -t:pack /p:Configuration=Release + - name: Build ComputeSharp.D2D1.WinUI project + run: > + msbuild src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj -t:restore /p:Configuration=Release; + msbuild src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj -t:pack /p:Configuration=Release + + # Upload the packages to the pipeline artifacts - name: Upload package artifacts uses: actions/upload-artifact@v3 with: @@ -96,13 +102,13 @@ jobs: name: Run ComputeSharp.Tests.SourceGenerators run: dotnet test tests\ComputeSharp.Tests.SourceGenerators\ComputeSharp.Tests.SourceGenerators.csproj -v n -l "console;verbosity=detailed" - # DirectX 12 device lost unit tests. - # These tests are run one class at a time to ensure there's no accidental conflicts between any of them. This is because - # the code paths being tested in this project are heavily dependent on process-wide mutable state (ie. DirectX 12 devices). + # DirectX 12 device lost unit tests. + # These tests are run one class at a time to ensure there's no accidental conflicts between any of them. This is because + # the code paths being tested in this project are heavily dependent on process-wide mutable state (ie. DirectX 12 devices). - name: Run ComputeSharp.Tests.DeviceLost "DeviceDisposal" run: dotnet test tests\ComputeSharp.Tests.DeviceLost\ComputeSharp.Tests.DeviceLost.csproj --filter "TestCategory=DeviceDisposal" -c Release -f ${{matrix.framework}} -v n -l "console;verbosity=detailed" - # These tests are failing randomly in the CI on .NET Framework, disabling them just for now + # These tests are failing randomly in the CI on .NET Framework, disabling them just for now - if: matrix.framework != 'net472' name: Run ComputeSharp.Tests.DeviceLost "DeviceLost" run: dotnet test tests\ComputeSharp.Tests.DeviceLost\ComputeSharp.Tests.DeviceLost.csproj --filter "TestCategory=DeviceLost" -c Release -f ${{matrix.framework}} -v n -l "console;verbosity=detailed" @@ -110,7 +116,7 @@ jobs: name: Run ComputeSharp.Tests.DeviceLost "GetDefaultDevice" run: dotnet test tests\ComputeSharp.Tests.DeviceLost\ComputeSharp.Tests.DeviceLost.csproj --filter "TestCategory=GetDefaultDevice" -c Release -f ${{matrix.framework}} -v n -l "console;verbosity=detailed" - # D2D1 unit tests + # D2D1 unit tests - name: Run ComputeSharp.D2D1.Tests run: dotnet test tests\ComputeSharp.D2D1.Tests\ComputeSharp.D2D1.Tests.csproj -c Release -f ${{matrix.framework}} -v n -l "console;verbosity=detailed" - name: Run ComputeSharp.D2D1.Tests.AssemblyLevelAttributes diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 62a59ed2..7b49c5d0 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -136,6 +136,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.D2D1.Uwp", "sr EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ComputeSharp.SwapChain.Shaders.D2D1.Shared", "samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.shproj", "{F8BF7666-7CCF-4FE4-B055-2EBA4BCD4564}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.D2D1.WinUI", "src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj", "{BD9E6556-357E-4C20-BFCD-FB131F9372FA}" +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ComputeSharp.D2D1.UI", "src\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.shproj", "{902D7B44-2C6C-4FCD-840B-EBCAE811EE63}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{568E7009-5C13-4153-9C94-0AC7A3E6883C}" ProjectSection(SolutionItems) = preProject samples\Directory.Build.props = samples\Directory.Build.props @@ -397,6 +401,14 @@ Global {E60A3B1E-FC5D-41AC-ACF0-C2D75B6590D2}.Release|ARM64.Build.0 = Release|ARM64 {E60A3B1E-FC5D-41AC-ACF0-C2D75B6590D2}.Release|x64.ActiveCfg = Release|x64 {E60A3B1E-FC5D-41AC-ACF0-C2D75B6590D2}.Release|x64.Build.0 = Release|x64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Debug|ARM64.Build.0 = Debug|ARM64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Debug|x64.ActiveCfg = Debug|x64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Debug|x64.Build.0 = Debug|x64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Release|ARM64.ActiveCfg = Release|ARM64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Release|ARM64.Build.0 = Release|ARM64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Release|x64.ActiveCfg = Release|x64 + {BD9E6556-357E-4C20-BFCD-FB131F9372FA}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -452,10 +464,12 @@ Global samples\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems*{751bb05b-563d-4b3a-94c6-15e2d79d35ea}*SharedItemsImports = 13 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{764bc0f5-0c5e-49ad-abaa-e3874c0f3286}*SharedItemsImports = 5 src\TerraFX.Interop.Windows.Dynamic\TerraFX.Interop.Windows.Dynamic.projitems*{76c66257-fdaa-47ab-85e7-ef757eab10c0}*SharedItemsImports = 5 + src\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.projitems*{902d7b44-2c6c-4fcd-840b-ebcae811ee63}*SharedItemsImports = 13 src\ComputeSharp.SourceGeneration.Hlsl\ComputeSharp.SourceGeneration.Hlsl.projitems*{9ac496a3-bbf0-4c8f-a50d-a20bf01c5e05}*SharedItemsImports = 13 src\TerraFX.Interop.Windows.D2D1\TerraFX.Interop.Windows.D2D1.projitems*{9da1da9f-f8b2-4b25-be80-c21f773029e3}*SharedItemsImports = 13 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{a5997814-d8d2-4541-87ac-c3e53caa67c0}*SharedItemsImports = 13 src\ComputeSharp.UI\ComputeSharp.UI.projitems*{afaafdc9-be42-45d4-8c79-0ee8c8edbf52}*SharedItemsImports = 5 + src\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.projitems*{bd9e6556-357e-4c20-bfcd-fb131f9372fa}*SharedItemsImports = 5 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{bfb003d1-788b-48de-8065-39479c162cb0}*SharedItemsImports = 5 src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{bfb003d1-788b-48de-8065-39479c162cb0}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{c12d7ace-98ed-4813-8118-6667c34f484f}*SharedItemsImports = 5 @@ -463,6 +477,7 @@ Global src\ComputeSharp.SourceGeneration.Hlsl\ComputeSharp.SourceGeneration.Hlsl.projitems*{e44053bd-a761-47fb-aa78-087a599672ea}*SharedItemsImports = 5 src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{e44053bd-a761-47fb-aa78-087a599672ea}*SharedItemsImports = 5 src\TerraFX.Interop.Windows.D2D1\TerraFX.Interop.Windows.D2D1.projitems*{e44053bd-a761-47fb-aa78-087a599672ea}*SharedItemsImports = 5 + src\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.projitems*{e60a3b1e-fc5d-41ac-acf0-c2d75b6590d2}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{e7c9247d-016b-4819-af9f-0e9b3591e04b}*SharedItemsImports = 5 samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{e91f4d24-922a-4921-a8d7-9c45a143c45d}*SharedItemsImports = 5 src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{eb52cb67-4162-4722-874b-44ea8da5450e}*SharedItemsImports = 5 diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems b/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems index 35a54357..8fd7c01f 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems +++ b/samples/ComputeSharp.SwapChain.Core.Shared/ComputeSharp.SwapChain.Core.Shared.projitems @@ -11,13 +11,13 @@ + - - + diff --git a/samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs similarity index 65% rename from samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.cs rename to samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs index cf7bbeba..38351f58 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Controls/D2D1AnimatedPixelShaderPanel.cs @@ -1,11 +1,21 @@ using ComputeSharp.SwapChain.Core.Shaders; +using Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas.UI.Xaml; +#if WINDOWS_UWP using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; +#else +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +#endif #nullable enable +#if WINDOWS_UWP namespace ComputeSharp.SwapChain.Uwp.Views; +#else +namespace ComputeSharp.SwapChain.WinUI.Views; +#endif /// /// A custom that can be used to render animated backgrounds via Win2D. @@ -19,9 +29,9 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control private CanvasAnimatedControl? canvasAnimatedControl; /// - /// The instance currently in use, if any. + /// The instance currently in use, if any. /// - private volatile ID2D1ShaderRunner? shaderRunner; + private volatile PixelShaderEffect? pixelShaderEffect; /// /// Creates a new instance. @@ -47,7 +57,7 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control private void D2D1AnimatedPixelShaderPanel_Loaded(object sender, RoutedEventArgs e) { if (this.canvasAnimatedControl is { } canvasAnimatedControl && - ShaderRunner is not null && + PixelShaderEffect is not null && !IsPaused) { canvasAnimatedControl.Paused = false; @@ -66,43 +76,50 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control /// /// Draws a new frame on the wrapped instance. /// - /// + /// The source instance. + /// The object to perform drawing with. private void CanvasAnimatedControl_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) { - this.shaderRunner?.Execute(sender, args); + // Set the effect properties + this.pixelShaderEffect!.ElapsedTime = args.Timing.TotalTime; + this.pixelShaderEffect.ScreenWidth = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round); + this.pixelShaderEffect.ScreenHeight = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round); + + // Draw the effect + args.DrawingSession.DrawImage(this.pixelShaderEffect); } /// - /// Gets or sets the instance to use to render content. + /// Gets or sets the instance to use to render content. /// - public ID2D1ShaderRunner? ShaderRunner + public PixelShaderEffect? PixelShaderEffect { - get => (ID2D1ShaderRunner?)GetValue(ShaderRunnerProperty); - set => SetValue(ShaderRunnerProperty, value); + get => (PixelShaderEffect?)GetValue(PixelShaderEffectProperty); + set => SetValue(PixelShaderEffectProperty, value); } /// - /// The backing . + /// The backing . /// - public static readonly DependencyProperty ShaderRunnerProperty = DependencyProperty.Register( - nameof(ShaderRunner), - typeof(ID2D1ShaderRunner), + public static readonly DependencyProperty PixelShaderEffectProperty = DependencyProperty.Register( + nameof(PixelShaderEffect), + typeof(PixelShaderEffect), typeof(D2D1AnimatedPixelShaderPanel), - new PropertyMetadata(null, OnShaderRunnerPropertyChanged)); + new PropertyMetadata(null, OnPixelShaderEffectPropertyChanged)); /// - private static void OnShaderRunnerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + private static void OnPixelShaderEffectPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { D2D1AnimatedPixelShaderPanel @this = (D2D1AnimatedPixelShaderPanel)d; - ID2D1ShaderRunner? shaderRunner = (ID2D1ShaderRunner?)e.NewValue; + PixelShaderEffect? pixelShaderEffect = (PixelShaderEffect?)e.NewValue; - // Save the new shader runner for later (as the dependency property cannot be accessed by the render thread) - @this.shaderRunner = shaderRunner; + // Save the new pixel shader effect for later (as the dependency property cannot be accessed by the render thread) + @this.pixelShaderEffect = pixelShaderEffect; - // Pause or start the render thread if a runner is available + // Pause or start the render thread if an effect is available if (@this.canvasAnimatedControl is { } canvasAnimatedControl) { - bool shouldRender = @this.IsLoaded && !@this.IsPaused && shaderRunner is not null; + bool shouldRender = @this.IsLoaded && !@this.IsPaused && pixelShaderEffect is not null; canvasAnimatedControl.Paused = !shouldRender; } @@ -134,7 +151,7 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control if (@this.canvasAnimatedControl is { } canvasAnimatedControl) { - bool shouldRender = @this.IsLoaded && !isPaused && @this.ShaderRunner is ID2D1ShaderRunner; + bool shouldRender = @this.IsLoaded && !isPaused && @this.PixelShaderEffect is not null; canvasAnimatedControl.Paused = !shouldRender; } diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs deleted file mode 100644 index 7a01a45c..00000000 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/D2D1ShaderRunner{T}.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using CommunityToolkit.Diagnostics; -using ComputeSharp.D2D1; -#if WINDOWS_UWP -using ComputeSharp.D2D1.Uwp; -using Microsoft.Graphics.Canvas; -using Microsoft.Graphics.Canvas.UI.Xaml; -#endif - -namespace ComputeSharp.SwapChain.Core.Shaders; - -/// -/// A simple implementation powered by a supplied shader type. -/// -/// The type of shader to use to render frames. -public sealed class D2D1ShaderRunner : ID2D1ShaderRunner - where T : unmanaged, ID2D1PixelShader -{ -#if WINDOWS_UWP - /// - /// The instance used to create shaders to run. - /// - private readonly Func shaderFactory; - - /// - /// The reusable instance to use to render frames. - /// - private readonly PixelShaderEffect pixelShaderEffect; -#endif - - /// - /// Creates a new instance. - /// - /// The instance used to create shaders to run. - public D2D1ShaderRunner(Func shaderFactory) - { - Guard.IsNotNull(shaderFactory); - -#if WINDOWS_UWP - this.shaderFactory = shaderFactory; - this.pixelShaderEffect = new PixelShaderEffect(); -#endif - } - -#if WINDOWS_UWP - /// - public void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) - { - int widthInPixels = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round); - int heightInPixels = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round); - - // Set the constant buffer - this.pixelShaderEffect.ConstantBuffer = this.shaderFactory(args.Timing.TotalTime, widthInPixels, heightInPixels); - - // Draw the shader - args.DrawingSession.DrawImage(this.pixelShaderEffect); - } -#endif -} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs deleted file mode 100644 index cb1a3bb4..00000000 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/ID2D1ShaderRunner.cs +++ /dev/null @@ -1,20 +0,0 @@ -#if WINDOWS_UWP -using Microsoft.Graphics.Canvas.UI.Xaml; -#endif - -namespace ComputeSharp.SwapChain.Core.Shaders; - -/// -/// An interface for a shader runner to be used with a Win2D renderer. -/// -public interface ID2D1ShaderRunner -{ -#if WINDOWS_UWP - /// - /// Draws a new frame on a target instance. - /// - /// The target instance. - /// The instance to use to draw the new frame. - void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args); -#endif -} \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs new file mode 100644 index 00000000..e0257d28 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/PixelShaderEffect.cs @@ -0,0 +1,121 @@ +using System; +using ComputeSharp.D2D1; +#if WINDOWS_UWP +using ComputeSharp.D2D1.Uwp; +#else +using ComputeSharp.D2D1.WinUI; +#endif +using Microsoft.Graphics.Canvas; + +#nullable enable + +namespace ComputeSharp.SwapChain.Core.Shaders; + +/// +/// An base effect for an animated pixel shader. +/// +public abstract class PixelShaderEffect : CanvasEffect +{ + /// + /// The current elapsed time. + /// + private TimeSpan elapsedTime; + + /// + /// The current screen width in raw pixels. + /// + private int screenWidth; + + /// + /// The current screen height in raw pixels. + /// + private int screenHeight; + + /// + /// Gets or sets the total elapsed time. + /// + public TimeSpan ElapsedTime + { + get => this.elapsedTime; + set => SetAndInvalidateEffectGraph(ref this.elapsedTime, value); + } + + /// + /// Gets or sets the screen width in raw pixels. + /// + public int ScreenWidth + { + get => this.screenWidth; + set => SetAndInvalidateEffectGraph(ref this.screenWidth, value); + } + + /// + /// Gets or sets the screen height in raw pixels. + /// + public int ScreenHeight + { + get => this.screenHeight; + set => SetAndInvalidateEffectGraph(ref this.screenHeight, value); + } + + /// + /// An effect for an animated pixel shader. + /// + /// The type of pixel shader to render. + public sealed class For : PixelShaderEffect + where T : unmanaged, ID2D1PixelShader + { + /// + /// The factory to use. + /// + private readonly Factory factory; + + /// + /// The instance in use. + /// + private PixelShaderEffect? effect; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The input factory. + public For(Factory factory) + { + this.factory = factory; + } + + /// + protected override ICanvasImage BuildEffectGraph() + { + this.effect = new PixelShaderEffect(); + + return this.effect; + } + + /// + protected override void ConfigureEffectGraph() + { + this.effect!.ConstantBuffer = this.factory(ElapsedTime, ScreenWidth, ScreenHeight); + } + + /// + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + if (disposing) + { + this.effect?.Dispose(); + } + } + + /// + /// A factory of a given shader instance. + /// + /// The total elapsed time. + /// The screen width in raw pixels. + /// The screen height in raw pixels. + /// A shader instance to render. + public delegate T Factory(TimeSpan elapsedTime, int screenWidth, int screenHeight); + } +} diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs index 225da1b1..9707c246 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/Shaders/Runners/D2D1ContouredLayersRunner.cs @@ -1,76 +1,80 @@ -#if WINDOWS_UWP using System; using System.IO; using ComputeSharp.D2D1; using ComputeSharp.D2D1.Interop; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp; +#else +using ComputeSharp.D2D1.WinUI; #endif using ComputeSharp.SwapChain.Shaders.D2D1; -#if WINDOWS_UWP using Microsoft.Graphics.Canvas; -using Microsoft.Graphics.Canvas.UI.Xaml; using Windows.ApplicationModel; -#endif #nullable enable namespace ComputeSharp.SwapChain.Core.Shaders.Runners; /// -/// A specialized for . +/// A specialized for . /// -public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner +public sealed class D2D1ContouredLayersEffect : PixelShaderEffect { -#if WINDOWS_UWP /// /// The reusable instance to use to render frames. /// private PixelShaderEffect? pixelShaderEffect; /// - public unsafe void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args) + protected override unsafe ICanvasImage BuildEffectGraph() { - if (this.pixelShaderEffect is null) - { - string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png"); + string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png"); - // As a temporary workaround for the lack of image decoding helpers for D2D1ResourceTextureManager, and in order to - // keep the code here synchronous and simple, we can just leverage the DirectX 12 APIs to load textures. That is, we - // first load a texture (which will use WIC behind the scenes) to get the decoded image data in GPU memory, and then - // copy the data in a readback texture we can read from on the CPU. We can't just load an upload texture and read - // from it, as that type of texture can only be written to from the CPU. From there, we create a D2D resource texture. - using ReadOnlyTexture2D readOnlyTexture = GraphicsDevice.GetDefault().LoadReadOnlyTexture2D(filename); - using ReadBackTexture2D readBackTexture = GraphicsDevice.GetDefault().AllocateReadBackTexture2D(readOnlyTexture.Width, readOnlyTexture.Height); + // As a temporary workaround for the lack of image decoding helpers for D2D1ResourceTextureManager, and in order to + // keep the code here synchronous and simple, we can just leverage the DirectX 12 APIs to load textures. That is, we + // first load a texture (which will use WIC behind the scenes) to get the decoded image data in GPU memory, and then + // copy the data in a readback texture we can read from on the CPU. We can't just load an upload texture and read + // from it, as that type of texture can only be written to from the CPU. From there, we create a D2D resource texture. + using ReadOnlyTexture2D readOnlyTexture = GraphicsDevice.GetDefault().LoadReadOnlyTexture2D(filename); + using ReadBackTexture2D readBackTexture = GraphicsDevice.GetDefault().AllocateReadBackTexture2D(readOnlyTexture.Width, readOnlyTexture.Height); - readOnlyTexture.CopyTo(readBackTexture); + readOnlyTexture.CopyTo(readBackTexture); - // Get the buffer pointer, the stride, and calculate the buffer size without the trailing padding. - // That is, the area between the end of the data in the last row and the stride is not included. - Rgba32* dataBuffer = readBackTexture.View.DangerousGetAddressAndByteStride(out int strideInBytes); - int bufferSize = ((readBackTexture.Height - 1) * strideInBytes) + (readBackTexture.View.Width * sizeof(Rgba32)); + // Get the buffer pointer, the stride, and calculate the buffer size without the trailing padding. + // That is, the area between the end of the data in the last row and the stride is not included. + Rgba32* dataBuffer = readBackTexture.View.DangerousGetAddressAndByteStride(out int strideInBytes); + int bufferSize = ((readBackTexture.Height - 1) * strideInBytes) + (readBackTexture.View.Width * sizeof(Rgba32)); - // Create the resource texture manager to use in the shader - D2D1ResourceTextureManager resourceTextureManager = new( - extents: stackalloc uint[] { (uint)readBackTexture.Height, (uint)readBackTexture.Width }, - bufferPrecision: D2D1BufferPrecision.UInt8Normalized, - channelDepth: D2D1ChannelDepth.Four, - filter: D2D1Filter.MinMagMipLinear, - extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror }, - data: new ReadOnlySpan(dataBuffer, bufferSize), - strides: stackalloc uint[] { (uint)strideInBytes }); + // Create the resource texture manager to use in the shader + D2D1ResourceTextureManager resourceTextureManager = new( + extents: stackalloc uint[] { (uint)readBackTexture.Height, (uint)readBackTexture.Width }, + bufferPrecision: D2D1BufferPrecision.UInt8Normalized, + channelDepth: D2D1ChannelDepth.Four, + filter: D2D1Filter.MinMagMipLinear, + extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Mirror, D2D1ExtendMode.Mirror }, + data: new ReadOnlySpan(dataBuffer, bufferSize), + strides: stackalloc uint[] { (uint)strideInBytes }); - // Create the new pixel shader effect - this.pixelShaderEffect = new PixelShaderEffect() { ResourceTextureManagers = { [0] = resourceTextureManager } }; - } + // Create the new pixel shader effect + this.pixelShaderEffect = new PixelShaderEffect() { ResourceTextureManagers = { [0] = resourceTextureManager } }; - int widthInPixels = sender.ConvertDipsToPixels((float)sender.Size.Width, CanvasDpiRounding.Round); - int heightInPixels = sender.ConvertDipsToPixels((float)sender.Size.Height, CanvasDpiRounding.Round); + return this.pixelShaderEffect; + } - // Set the constant buffer - this.pixelShaderEffect.ConstantBuffer = new ContouredLayers((float)args.Timing.TotalTime.TotalSeconds, new int2(widthInPixels, heightInPixels)); + /// + protected override void ConfigureEffectGraph() + { + this.pixelShaderEffect!.ConstantBuffer = new ContouredLayers((float)ElapsedTime.TotalSeconds, new int2(ScreenWidth, ScreenHeight)); + } - // Draw the shader - args.DrawingSession.DrawImage(this.pixelShaderEffect); + /// + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + if (disposing) + { + this.pixelShaderEffect?.Dispose(); + } } -#endif } \ No newline at end of file diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/MainViewModel.cs b/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/MainViewModel.cs index 076a6dc0..3944abaa 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/MainViewModel.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/MainViewModel.cs @@ -95,40 +95,40 @@ public sealed partial class MainViewModel : ObservableObject new( nameof(ColorfulInfinity), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(FractalTiling), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(MengerJourney), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(Octagrams), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(ProteanClouds), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(TwoTiledTruchet), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(PyramidPattern), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), new( nameof(TriangleGridContouring), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), - new(nameof(ContouredLayers), new ContouredLayersRunner(), new D2D1ContouredLayersRunner()), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new(nameof(ContouredLayers), new ContouredLayersRunner(), new D2D1ContouredLayersEffect()), new( nameof(TerracedHills), new ShaderRunner(static time => new((float)time.TotalSeconds)), - new D2D1ShaderRunner(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))), }; /// diff --git a/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/ShaderRunnerViewModel.cs b/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/ShaderRunnerViewModel.cs index eb8d1ef6..7ff1af01 100644 --- a/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/ShaderRunnerViewModel.cs +++ b/samples/ComputeSharp.SwapChain.Core.Shared/ViewModels/ShaderRunnerViewModel.cs @@ -18,12 +18,12 @@ public sealed partial class ShaderRunnerViewModel : ObservableObject /// /// The name of the shader type to execute. /// The instance to execute. - /// The instance to execute. - public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, ID2D1ShaderRunner d2D1ShaderRunner) + /// The instance to execute. + public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, PixelShaderEffect pixelShaderEffect) { ShaderType = shaderType; ShaderRunner = shaderRunner; - D2D1ShaderRunner = d2D1ShaderRunner; + PixelShaderEffect = pixelShaderEffect; } /// @@ -37,9 +37,9 @@ public sealed partial class ShaderRunnerViewModel : ObservableObject public IShaderRunner ShaderRunner { get; } /// - /// Gets the instance to execute. + /// Gets the instance to execute. /// - public ID2D1ShaderRunner D2D1ShaderRunner { get; } + public PixelShaderEffect PixelShaderEffect { get; } /// /// Gets or sets whether the current shader is selected. diff --git a/samples/ComputeSharp.SwapChain.Uwp/App.xaml b/samples/ComputeSharp.SwapChain.Uwp/App.xaml index 8d04ab03..69db7e92 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/App.xaml +++ b/samples/ComputeSharp.SwapChain.Uwp/App.xaml @@ -6,7 +6,7 @@ - + diff --git a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj index 7efde0fe..440921fd 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj +++ b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj @@ -79,7 +79,6 @@ App.xaml - diff --git a/samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.xaml b/samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.xaml index 3ca0e723..b7c172e8 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.xaml +++ b/samples/ComputeSharp.SwapChain.Uwp/Controls/D2D1AnimatedPixelShaderPanel.xaml @@ -1,14 +1,14 @@ + xmlns:win2d="using:Microsoft.Graphics.Canvas.UI.Xaml"> + diff --git a/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedControl.cs b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedControl.cs new file mode 100644 index 00000000..24002362 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedControl.cs @@ -0,0 +1,135 @@ +using System; +using System.Diagnostics; +using System.Threading; +using Microsoft.UI.Xaml.Controls; +using Windows.Foundation; + +namespace Microsoft.Graphics.Canvas.UI.Xaml; + +/// +/// XAML control intended for displaying animating content. +/// +public sealed class CanvasAnimatedControl : Grid, ICanvasAnimatedControl, IDisposable +{ + /// + /// The instance to use. + /// + private readonly CanvasControl canvasControl; + + /// + /// The used to track the elapsed time. + /// + private readonly Stopwatch stopwatch; + + /// + /// The used to render frames. + /// + private readonly Timer timer; + + /// + /// Indicates whether rendering is paused. + /// + private bool paused; + + /// + /// Indicates whether a new frame is currently being drawn. + /// + private volatile int isDrawing; + + /// + /// Hook this event to draw the contents of the control. + /// + public TypedEventHandler? Draw; + + /// + /// Creates a new instance. + /// + public CanvasAnimatedControl() + { + this.canvasControl = new CanvasControl(); + this.stopwatch = new Stopwatch(); + this.timer = new Timer( + callback: static canvasControl => ((CanvasControl)canvasControl!).Invalidate(), + state: this.canvasControl, + dueTime: TimeSpan.Zero, + period: TimeSpan.FromSeconds(1 / 60.0)); + + // Register the draw callback for the canvas control + this.canvasControl.Draw += CanvasControl_Draw; + + // Start the render stopwatch (the render timer has already started) + this.stopwatch.Start(); + + // Add the canvas control to the visual tree + Children.Add(this.canvasControl); + } + + /// + /// Gets or sets whether rendering has paused + /// + public bool Paused + { + get => this.paused; + set + { + if (this.paused != value) + { + this.paused = value; + + // Start or stop the timers as needed + if (value) + { + _ = this.timer.Change(Timeout.Infinite, Timeout.Infinite); + + this.stopwatch.Stop(); + } + else + { + _ = this.timer.Change(TimeSpan.Zero, TimeSpan.FromSeconds(1 / 60.0f)); + + this.stopwatch.Start(); + } + } + } + } + + /// + public void Dispose() + { + this.timer.Dispose(); + } + + // Forward the Draw event as a CanvasAnimatedControl sender + private void CanvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args) + { + // If another frame is already being concurrently drawn, do nothing + if (Interlocked.CompareExchange(ref this.isDrawing, 1, 0) == 1) + { + return; + } + + try + { + this.Draw?.Invoke( + sender: this, + args: new CanvasAnimatedDrawEventArgs + { + DrawingSession = args.DrawingSession, + Timing = new CanvasTimingInformation { TotalTime = this.stopwatch.Elapsed } + }); + } + finally + { + this.isDrawing = 0; + } + } + + /// + Size ICanvasAnimatedControl.Size => this.canvasControl.Size; + + /// + int ICanvasAnimatedControl.ConvertDipsToPixels(float dips, CanvasDpiRounding dpiRounding) + { + return this.canvasControl.ConvertDipsToPixels(dips, dpiRounding); + } +} diff --git a/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedDrawEventArgs.cs b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedDrawEventArgs.cs new file mode 100644 index 00000000..10deefba --- /dev/null +++ b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/CanvasAnimatedDrawEventArgs.cs @@ -0,0 +1,15 @@ +namespace Microsoft.Graphics.Canvas.UI.Xaml; + +/// +/// Provides data for the event. +/// +public sealed class CanvasAnimatedDrawEventArgs +{ + /// + public required CanvasDrawingSession DrawingSession { get; init; } + + /// + /// Gets the control's timing information for use by the event handler. + /// + public required CanvasTimingInformation Timing { get; init; } +} diff --git a/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/ICanvasAnimatedControl.cs b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/ICanvasAnimatedControl.cs new file mode 100644 index 00000000..e7eb1646 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI.Xaml/ICanvasAnimatedControl.cs @@ -0,0 +1,15 @@ +using Windows.Foundation; + +namespace Microsoft.Graphics.Canvas.UI.Xaml; + +/// +/// XAML control intended for displaying animating content. +/// +public interface ICanvasAnimatedControl +{ + /// + Size Size { get; } + + /// + int ConvertDipsToPixels(float dips, CanvasDpiRounding dpiRounding); +} diff --git a/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI/CanvasTimingInformation.cs b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI/CanvasTimingInformation.cs new file mode 100644 index 00000000..54e3a9c8 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.WinUI/Controls/Microsoft.Graphics.Canvas.UI/CanvasTimingInformation.cs @@ -0,0 +1,15 @@ +using System; +using Microsoft.Graphics.Canvas.UI.Xaml; + +namespace Microsoft.Graphics.Canvas.UI; + +/// +/// Contains information about a 's timer. +/// +public readonly struct CanvasTimingInformation +{ + /// + /// Represents the elapsed time, in ticks, for which this control has ever been running. + /// + public required TimeSpan TotalTime { get; init; } +} diff --git a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml index 9d8692d9..410e1310 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml +++ b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml @@ -6,13 +6,12 @@ xmlns:computesharp="using:ComputeSharp.WinUI" xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls" xmlns:converters="using:ComputeSharp.SwapChain.Core.Converters" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:enums="using:ComputeSharp.SwapChain.Core.Enums" xmlns:media="using:CommunityToolkit.WinUI.UI.Media" xmlns:ui="using:CommunityToolkit.WinUI.UI" xmlns:viewmodels="using:ComputeSharp.SwapChain.Core.ViewModels" - SizeChanged="UserControl_SizeChanged" - mc:Ignorable="d"> + xmlns:views="using:ComputeSharp.SwapChain.WinUI.Views" + SizeChanged="Window_SizeChanged"> @@ -119,7 +118,10 @@ - + - + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + diff --git a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs index 59f54119..b9846241 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs @@ -9,7 +9,7 @@ using Microsoft.UI.Xaml.Input; namespace ComputeSharp.SwapChain.WinUI.Views; /// -/// A view for . +/// A view for . /// public sealed partial class MainWindow : Window { @@ -62,7 +62,7 @@ public sealed partial class MainWindow : Window } // Updates the size of the shaders list panel - private void UserControl_SizeChanged(object sender, WindowSizeChangedEventArgs e) + private void Window_SizeChanged(object sender, WindowSizeChangedEventArgs e) { this.ShadersListContainerPanel.Height = Math.Round(e.Size.Height * 0.35); } @@ -72,4 +72,16 @@ public sealed partial class MainWindow : Window { this.shaderPanels.AddOrUpdate((AnimatedComputeShaderPanel)sender, null); } + + // Logs rendering failed in the main panel + private void MainShaderPanel_RenderingFailed(AnimatedComputeShaderPanel sender, RenderingFailedEventArgs args) + { + this.RenderingErrorInfoBar.IsOpen = true; + } + + // Logs rendering failed in a secondary panel + private void SelectionShaderPanel_RenderingFailed(AnimatedComputeShaderPanel sender, RenderingFailedEventArgs args) + { + this.RenderingErrorInfoBar.IsOpen = true; + } } \ No newline at end of file diff --git a/src/ComputeSharp.Core/ComputeSharp.Core.csproj b/src/ComputeSharp.Core/ComputeSharp.Core.csproj index 52fe9c3d..6a4268e3 100644 --- a/src/ComputeSharp.Core/ComputeSharp.Core.csproj +++ b/src/ComputeSharp.Core/ComputeSharp.Core.csproj @@ -14,6 +14,7 @@ + diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasDevice.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasDevice.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasDevice.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasDevice.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasEffect.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasEffect.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasEffect.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasEffect.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs similarity index 57% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs index a4bb8cb9..b63aed7f 100644 --- a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs +++ b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasImageInterop.cs @@ -4,6 +4,10 @@ using System.Runtime.InteropServices; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; using TerraFX.Interop; +#if !WINDOWS_UWP +using WinRT; +using WinRT.Interop; +#endif #pragma warning disable CS0649, IDE1006 @@ -79,20 +83,29 @@ internal unsafe struct ICanvasImageInterop } /// - /// The implementation of . + /// The managed implementation of . /// - [ComImport] [Guid("E042D1F7-F9AD-4479-A713-67627EA31863")] +#if WINDOWS_UWP + [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +#else + [WindowsRuntimeType] + [WindowsRuntimeHelperType(typeof(Interface))] +#endif public interface Interface { /// +#if WINDOWS_UWP [PreserveSig] +#endif [return: NativeTypeName("HRESULT")] int GetDevice(ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type); /// +#if WINDOWS_UWP [PreserveSig] +#endif [return: NativeTypeName("HRESULT")] int GetD2DImage( ICanvasDevice* device, @@ -101,5 +114,90 @@ internal unsafe struct ICanvasImageInterop float targetDpi, float* realizeDpi, ID2D1Image** ppImage); + +#if !WINDOWS_UWP + /// + /// The vtable type for . + /// + [Guid("E042D1F7-F9AD-4479-A713-67627EA31863")] + public struct Vftbl + { + /// + /// Allows CsWinRT to retrieve a pointer to the projection vtable (the name is hardcoded by convention). + /// + public static readonly IntPtr AbiToProjectionVftablePtr = InitVtbl(); + + /// + /// Builds the custom method table pointer for . + /// + /// The method table pointer for . + private static IntPtr InitVtbl() + { + Vftbl* lpVtbl = (Vftbl*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(Vftbl)); + + lpVtbl->IUnknownVftbl = IUnknownVftbl.AbiToProjectionVftbl; + lpVtbl->GetDevice = &GetDeviceFromAbi; + lpVtbl->GetD2DImage = &GetD2DImageFromAbi; + + return (IntPtr)lpVtbl; + } + + /// + /// The IUnknown vtable. + /// + internal IUnknownVftbl IUnknownVftbl; + + /// + /// Function pointer for . + /// + internal delegate* unmanaged[Stdcall] GetDevice; + + /// + /// Function pointer for . + /// + internal delegate* unmanaged[Stdcall] GetD2DImage; + + /// + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + [return: NativeTypeName("HRESULT")] + private static int GetDeviceFromAbi(IntPtr thisPtr, ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type) + { + try + { + return ComWrappersSupport.FindObject(thisPtr).GetDevice(device, type); + } + catch (Exception e) + { + ExceptionHelpers.SetErrorInfo(e); + + return Marshal.GetHRForException(e); + } + } + + /// + [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + [return: NativeTypeName("HRESULT")] + private static int GetD2DImageFromAbi( + IntPtr thisPtr, + ICanvasDevice* device, + ID2D1DeviceContext* deviceContext, + WIN2D_GET_D2D_IMAGE_FLAGS flags, + float targetDpi, + float* realizeDpi, + ID2D1Image** ppImage) + { + try + { + return ComWrappersSupport.FindObject(thisPtr).GetD2DImage(device, deviceContext, flags, targetDpi, realizeDpi, ppImage); + } + catch (Exception e) + { + ExceptionHelpers.SetErrorInfo(e); + + return Marshal.GetHRForException(e); + } + } + } +#endif } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreator.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreator.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreator.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreator.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreatorWithDpi.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreatorWithDpi.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreatorWithDpi.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasResourceCreatorWithDpi.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasResourceWrapperNative.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasResourceWrapperNative.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ICanvasResourceWrapperNative.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ICanvasResourceWrapperNative.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextLease.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextLease.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextLease.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextLease.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextPool.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextPool.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextPool.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/ID2D1DeviceContextPool.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_D2D_IMAGE_FLAGS.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_D2D_IMAGE_FLAGS.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_D2D_IMAGE_FLAGS.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_D2D_IMAGE_FLAGS.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_DEVICE_ASSOCIATION_TYPE.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_DEVICE_ASSOCIATION_TYPE.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_DEVICE_ASSOCIATION_TYPE.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/WIN2D_GET_DEVICE_ASSOCIATION_TYPE.cs diff --git a/src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/Win2D.cs b/src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/Win2D.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/ABI.Microsoft.Graphics.Canvas/Win2D.cs rename to src/ComputeSharp.D2D1.UI/ABI.Microsoft.Graphics.Canvas/Win2D.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Buffers/GraphicsEffectSourceBuffer.cs b/src/ComputeSharp.D2D1.UI/Buffers/GraphicsEffectSourceBuffer.cs similarity index 97% rename from src/ComputeSharp.D2D1.Uwp/Buffers/GraphicsEffectSourceBuffer.cs rename to src/ComputeSharp.D2D1.UI/Buffers/GraphicsEffectSourceBuffer.cs index 56a0bfba..f689c6df 100644 --- a/src/ComputeSharp.D2D1.Uwp/Buffers/GraphicsEffectSourceBuffer.cs +++ b/src/ComputeSharp.D2D1.UI/Buffers/GraphicsEffectSourceBuffer.cs @@ -3,7 +3,11 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Windows.Graphics.Effects; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Buffers; +#else +namespace ComputeSharp.D2D1.WinUI.Buffers; +#endif /// /// A fixed buffer type containing 16 fields. diff --git a/src/ComputeSharp.D2D1.Uwp/Buffers/ResourceTextureManagerBuffer.cs b/src/ComputeSharp.D2D1.UI/Buffers/ResourceTextureManagerBuffer.cs similarity index 98% rename from src/ComputeSharp.D2D1.Uwp/Buffers/ResourceTextureManagerBuffer.cs rename to src/ComputeSharp.D2D1.UI/Buffers/ResourceTextureManagerBuffer.cs index af57a6db..5efb789a 100644 --- a/src/ComputeSharp.D2D1.Uwp/Buffers/ResourceTextureManagerBuffer.cs +++ b/src/ComputeSharp.D2D1.UI/Buffers/ResourceTextureManagerBuffer.cs @@ -3,7 +3,11 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using ComputeSharp.D2D1.Interop; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Buffers; +#else +namespace ComputeSharp.D2D1.WinUI.Buffers; +#endif /// /// A fixed buffer type containing 16 fields. diff --git a/src/ComputeSharp.D2D1.Uwp/Buffers/SourceReference.cs b/src/ComputeSharp.D2D1.UI/Buffers/SourceReference.cs similarity index 97% rename from src/ComputeSharp.D2D1.Uwp/Buffers/SourceReference.cs rename to src/ComputeSharp.D2D1.UI/Buffers/SourceReference.cs index b128c63a..d9f917b2 100644 --- a/src/ComputeSharp.D2D1.Uwp/Buffers/SourceReference.cs +++ b/src/ComputeSharp.D2D1.UI/Buffers/SourceReference.cs @@ -1,13 +1,22 @@ using System; using System.Runtime.CompilerServices; using ABI.Microsoft.Graphics.Canvas; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Extensions; using ComputeSharp.D2D1.Uwp.Helpers; +#else +using ComputeSharp.D2D1.WinUI.Extensions; +using ComputeSharp.D2D1.WinUI.Helpers; +#endif using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; using Windows.Graphics.Effects; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Buffers; +#else +namespace ComputeSharp.D2D1.WinUI.Buffers; +#endif /// /// A wrapper type for an input and its underlying native D2D images. diff --git a/src/ComputeSharp.D2D1.Uwp/CanvasEffect.Interop.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs similarity index 75% rename from src/ComputeSharp.D2D1.Uwp/CanvasEffect.Interop.cs rename to src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs index 875e71a3..58399b07 100644 --- a/src/ComputeSharp.D2D1.Uwp/CanvasEffect.Interop.cs +++ b/src/ComputeSharp.D2D1.UI/CanvasEffect.Interop.cs @@ -1,15 +1,24 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Numerics; -using System.Runtime.InteropServices; using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; +#if WINDOWS_UWP +using ComputeSharp.D2D1.Uwp.Helpers; +#else +using ComputeSharp.D2D1.WinUI.Helpers; +#endif using Microsoft.Graphics.Canvas; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; using Windows.Foundation; using ICanvasResourceCreator = Microsoft.Graphics.Canvas.ICanvasResourceCreator; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// unsafe partial class CanvasEffect @@ -31,7 +40,7 @@ unsafe partial class CanvasEffect { using ComPtr canvasImageInterop = default; - GetCanvasImageInterop(canvasImageInterop.GetAddressOf()); + RcwMarshaller.GetNativeObject(GetCanvasImage(), canvasImageInterop.GetAddressOf()).Assert(); return canvasImageInterop.Get()->GetDevice(device, type); } @@ -47,7 +56,7 @@ unsafe partial class CanvasEffect { using ComPtr canvasImageInterop = default; - GetCanvasImageInterop(canvasImageInterop.GetAddressOf()); + RcwMarshaller.GetNativeObject(GetCanvasImage(), canvasImageInterop.GetAddressOf()).Assert(); return canvasImageInterop.Get()->GetD2DImage(device, deviceContext, flags, targetDpi, realizeDpi, ppImage); } @@ -57,6 +66,7 @@ unsafe partial class CanvasEffect /// /// The current instance. /// Thrown if the current instance is disposed. + [MemberNotNull(nameof(canvasImage))] private ICanvasImage GetCanvasImage() { lock (this.lockObject) @@ -75,17 +85,4 @@ unsafe partial class CanvasEffect return this.canvasImage; } } - - /// - /// Gets the object currently in use. - /// - /// A pointer to the object currently in use. - private void GetCanvasImageInterop(ICanvasImageInterop** canvasImageInterop) - { - using ComPtr canvasImageUnknown = default; - - canvasImageUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(GetCanvasImage())); - - canvasImageUnknown.CopyTo(canvasImageInterop).Assert(); - } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.Uwp/CanvasEffect.cs b/src/ComputeSharp.D2D1.UI/CanvasEffect.cs similarity index 99% rename from src/ComputeSharp.D2D1.Uwp/CanvasEffect.cs rename to src/ComputeSharp.D2D1.UI/CanvasEffect.cs index 96bf107c..efef99d5 100644 --- a/src/ComputeSharp.D2D1.Uwp/CanvasEffect.cs +++ b/src/ComputeSharp.D2D1.UI/CanvasEffect.cs @@ -4,7 +4,11 @@ using System.Diagnostics.CodeAnalysis; using ABI.Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// /// A base type to implement packaged and easy to use -based effects that can be used with Win2D. @@ -151,14 +155,6 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I InvalidateEffectGraph(invalidationType); } - /// - public void Dispose() - { - Dispose(disposing: true); - - GC.SuppressFinalize(this); - } - /// /// Disposes any disposable resources in the current instance. /// @@ -207,6 +203,14 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I this.isDisposed = true; } + /// + public void Dispose() + { + Dispose(disposing: true); + + GC.SuppressFinalize(this); + } + /// /// Indicates the invalidation type to request when invoking and related methods. /// diff --git a/src/ComputeSharp.D2D1.Uwp/Collections/FixedCountList{T}.cs b/src/ComputeSharp.D2D1.UI/Collections/FixedCountList{T}.cs similarity index 97% rename from src/ComputeSharp.D2D1.Uwp/Collections/FixedCountList{T}.cs rename to src/ComputeSharp.D2D1.UI/Collections/FixedCountList{T}.cs index 74dd8fe9..8f93a9b0 100644 --- a/src/ComputeSharp.D2D1.Uwp/Collections/FixedCountList{T}.cs +++ b/src/ComputeSharp.D2D1.UI/Collections/FixedCountList{T}.cs @@ -1,7 +1,11 @@ using System; using System.Collections.Generic; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Collections; +#else +namespace ComputeSharp.D2D1.WinUI.Collections; +#endif /// /// Shared helpers for all types implementing . diff --git a/src/ComputeSharp.D2D1.Uwp/Collections/IFixedCountList{T}.cs b/src/ComputeSharp.D2D1.UI/Collections/IFixedCountList{T}.cs similarity index 87% rename from src/ComputeSharp.D2D1.Uwp/Collections/IFixedCountList{T}.cs rename to src/ComputeSharp.D2D1.UI/Collections/IFixedCountList{T}.cs index 2cc4b735..c3672855 100644 --- a/src/ComputeSharp.D2D1.Uwp/Collections/IFixedCountList{T}.cs +++ b/src/ComputeSharp.D2D1.UI/Collections/IFixedCountList{T}.cs @@ -1,7 +1,11 @@ using System.Collections.Generic; using System.Collections.Immutable; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Collections; +#else +namespace ComputeSharp.D2D1.WinUI.Collections; +#endif /// /// An interface for a list with a fixed collection. diff --git a/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems new file mode 100644 index 00000000..086fc849 --- /dev/null +++ b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems @@ -0,0 +1,52 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 902d7b44-2c6c-4fcd-840b-ebcae811ee63 + + + ComputeSharp.D2D1.UI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.shproj b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.shproj new file mode 100644 index 00000000..7cb7c873 --- /dev/null +++ b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.shproj @@ -0,0 +1,13 @@ + + + + 902d7b44-2c6c-4fcd-840b-ebcae811ee63 + 14.0 + + + + + + + + diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/ICanvasDeviceExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs similarity index 98% rename from src/ComputeSharp.D2D1.Uwp/Extensions/ICanvasDeviceExtensions.cs rename to src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs index bea0e059..ed84a11b 100644 --- a/src/ComputeSharp.D2D1.Uwp/Extensions/ICanvasDeviceExtensions.cs +++ b/src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs @@ -4,7 +4,11 @@ using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; using Win32 = TerraFX.Interop.Windows.Windows; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Extensions; +#else +namespace ComputeSharp.D2D1.WinUI.Extensions; +#endif /// /// A with extensions for the type. diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1DeviceContextExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1DeviceContextExtensions.cs similarity index 97% rename from src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1DeviceContextExtensions.cs rename to src/ComputeSharp.D2D1.UI/Extensions/ID2D1DeviceContextExtensions.cs index c2304839..7a3b47db 100644 --- a/src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1DeviceContextExtensions.cs +++ b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1DeviceContextExtensions.cs @@ -2,7 +2,11 @@ using ComputeSharp.D2D1.Extensions; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Extensions; +#else +namespace ComputeSharp.D2D1.WinUI.Extensions; +#endif /// /// A with extensions for the type. diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1EffectExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs similarity index 99% rename from src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1EffectExtensions.cs rename to src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs index 7e3cfc78..e00f5304 100644 --- a/src/ComputeSharp.D2D1.Uwp/Extensions/ID2D1EffectExtensions.cs +++ b/src/ComputeSharp.D2D1.UI/Extensions/ID2D1EffectExtensions.cs @@ -11,7 +11,11 @@ using TerraFX.Interop.Windows; #pragma warning disable CS0618 +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Extensions; +#else +namespace ComputeSharp.D2D1.WinUI.Extensions; +#endif /// /// A with extensions for the type. diff --git a/src/ComputeSharp.D2D1.Uwp/Extensions/IUnknownExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/IUnknownExtensions.cs similarity index 97% rename from src/ComputeSharp.D2D1.Uwp/Extensions/IUnknownExtensions.cs rename to src/ComputeSharp.D2D1.UI/Extensions/IUnknownExtensions.cs index f3847d30..37a6ca88 100644 --- a/src/ComputeSharp.D2D1.Uwp/Extensions/IUnknownExtensions.cs +++ b/src/ComputeSharp.D2D1.UI/Extensions/IUnknownExtensions.cs @@ -3,7 +3,11 @@ using ComputeSharp.D2D1.Extensions; using TerraFX.Interop.Windows; using Win32 = TerraFX.Interop.Windows.Windows; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Extensions; +#else +namespace ComputeSharp.D2D1.WinUI.Extensions; +#endif /// /// Helper methods for working with the type. diff --git a/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs b/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs new file mode 100644 index 00000000..c7afd40d --- /dev/null +++ b/src/ComputeSharp.D2D1.UI/Helpers/RcwMarshaller.cs @@ -0,0 +1,64 @@ +using System; +using System.Diagnostics.CodeAnalysis; +#if WINDOWS_UWP +using System.Runtime.InteropServices; +#endif +using TerraFX.Interop.Windows; +#if !WINDOWS_UWP +using WinRT; +#endif + +#if WINDOWS_UWP +namespace ComputeSharp.D2D1.Uwp.Helpers; +#else +namespace ComputeSharp.D2D1.WinUI.Helpers; +#endif + +/// +/// A helper type to handle marshalling of RCW instances. +/// +internal static class RcwMarshaller +{ + /// + /// Gets or creates a managed object of a specified type for an input native object. + /// + /// The interface type to retrieve an instance of. + /// A pointer to the native object to get a managed wrapper for. + /// The resulting managed object wrapping . + public static unsafe T GetOrCreateManagedObject<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] T>(IUnknown* nativeObject) + where T : class + { +#if WINDOWS_UWP + // On UWP, Marshal.GetObjectForIUnknown handles all the marshalling/wrapping logic + return (T)Marshal.GetObjectForIUnknown((IntPtr)nativeObject); +#else + return MarshalInspectable.FromAbi((IntPtr)nativeObject); +#endif + } + + /// + /// Retrieves the underlying native object for an input RCW and casts it to the specified type. + /// + /// The type of managed object to unwrap. + /// The interface type to retrieve an instance of. + /// The input RCW instance to unwrap. + /// A pointer to the resulting native object to retrieve. + /// The for the operation. + public static unsafe HRESULT GetNativeObject<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] TFrom, TTo>(TFrom managedObject, TTo** nativeObject) + where TFrom : class + where TTo : unmanaged // IUnknown + { + using ComPtr unknownObject = default; + +#if WINDOWS_UWP + // On UWP, due to built-in COM/WinRT support, Marshal.GetIUnknownForObject can handle all the logic + unknownObject.Attach((IUnknown*)Marshal.GetIUnknownForObject(managedObject)); +#else + // On WinUI 3, delegate the RCW unwrapping or CCW creation logic to CsWinRT's APIs + unknownObject.Attach((IUnknown*)MarshalInspectable.FromManaged(managedObject)); +#endif + + // QueryInterface to the specific interface we need + return unknownObject.CopyTo(nativeObject); + } +} diff --git a/src/ComputeSharp.D2D1.Uwp/Helpers/ResourceManager.cs b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs similarity index 92% rename from src/ComputeSharp.D2D1.Uwp/Helpers/ResourceManager.cs rename to src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs index bd37235c..798354a8 100644 --- a/src/ComputeSharp.D2D1.Uwp/Helpers/ResourceManager.cs +++ b/src/ComputeSharp.D2D1.UI/Helpers/ResourceManager.cs @@ -1,12 +1,17 @@ using System; -using System.Runtime.InteropServices; using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; using TerraFX.Interop.Windows; using TerraFX.Interop.WinRT; using Windows.Graphics.Effects; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp.Helpers; +#else +namespace ComputeSharp.D2D1.WinUI.Helpers; + +using WinRT = TerraFX.Interop.WinRT.WinRT; +#endif /// /// A helper type to replicate Win2D's ResourceManager type. @@ -61,8 +66,6 @@ internal static class ResourceManager wrapper: wrapperUnknown.GetVoidAddressOf()).Assert(); // Get the runtime-provided RCW for the resulting WinRT wrapper - object wrapper = Marshal.GetObjectForIUnknown((IntPtr)wrapperUnknown.Get()); - - return (IGraphicsEffectSource)wrapper; + return RcwMarshaller.GetOrCreateManagedObject(wrapperUnknown.Get()); } } diff --git a/src/ComputeSharp.D2D1.Uwp/Loaders/D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs b/src/ComputeSharp.D2D1.UI/Loaders/D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Loaders/D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs rename to src/ComputeSharp.D2D1.UI/Loaders/D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs diff --git a/src/ComputeSharp.D2D1.Uwp/Loaders/D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs b/src/ComputeSharp.D2D1.UI/Loaders/D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs similarity index 100% rename from src/ComputeSharp.D2D1.Uwp/Loaders/D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs rename to src/ComputeSharp.D2D1.UI/Loaders/D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasEffect.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs similarity index 90% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasEffect.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs index 8cf7ff40..ac6a5cc2 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasEffect.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasEffect.cs @@ -3,13 +3,22 @@ using System.Buffers; using System.Runtime.InteropServices; using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; +#if WINDOWS_UWP +using ComputeSharp.D2D1.Uwp.Helpers; +#else +using ComputeSharp.D2D1.WinUI.Helpers; +#endif using ComputeSharp.Interop; using TerraFX.Interop.Windows; using Windows.Foundation; using ICanvasEffect = Microsoft.Graphics.Canvas.Effects.ICanvasEffect; using ICanvasResourceCreatorWithDpi = Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// unsafe partial class PixelShaderEffect @@ -89,12 +98,10 @@ unsafe partial class PixelShaderEffect Rect result; - using ComPtr canvasEffectUnknown = default; using ComPtr canvasEffectAbi = default; // Get the ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect object from the input interface - canvasEffectUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(sourceEffect)); - canvasEffectUnknown.CopyTo(canvasEffectAbi.GetAddressOf()).Assert(); + RcwMarshaller.GetNativeObject(sourceEffect, canvasEffectAbi.GetAddressOf()).Assert(); Win2D.GetRequiredSourceRectanglesForICanvasImageInterop( resourceCreator: resourceCreatorWithDpi.Get(), @@ -148,10 +155,7 @@ unsafe partial class PixelShaderEffect // Get the underlying ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect object for each input effect for (int i = 0; i < sourceEffects.Length; i++) { - using ComPtr canvasEffectUnknown = default; - - canvasEffectUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(sourceEffects[i])); - canvasEffectUnknown.CopyTo(canvasEffects[i].GetAddressOf()).Assert(); + RcwMarshaller.GetNativeObject(sourceEffects[i], canvasEffects[i].GetAddressOf()).Assert(); } Rect[] result = new Rect[sourceEffects.Length]; @@ -205,16 +209,10 @@ unsafe partial class PixelShaderEffect ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi** resourceCreatorWithDpi, ICanvasImageInterop** canvasImageInterop) { - using ComPtr resourceCreatorUnknown = default; - // Get the ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi object from the input interface - resourceCreatorUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(resourceCreator)); - resourceCreatorUnknown.CopyTo(resourceCreatorWithDpi).Assert(); - - using ComPtr canvasImageInteropUnknown = default; + RcwMarshaller.GetNativeObject(resourceCreator, resourceCreatorWithDpi).Assert(); // Get the ICanvasImageInterop object from the current instance - canvasImageInteropUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(this)); - canvasImageInteropUnknown.CopyTo(canvasImageInterop).Assert(); + RcwMarshaller.GetNativeObject(this, canvasImageInterop).Assert(); } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImage.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs similarity index 71% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImage.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs index d0f24e97..be000836 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImage.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImage.cs @@ -1,14 +1,21 @@ using System.Numerics; -using System.Runtime.InteropServices; using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; +#if WINDOWS_UWP +using ComputeSharp.D2D1.Uwp.Helpers; +#else +using ComputeSharp.D2D1.WinUI.Helpers; +#endif using ComputeSharp.Interop; -using Microsoft.Graphics.Canvas; using TerraFX.Interop.Windows; using Windows.Foundation; using ICanvasResourceCreator = Microsoft.Graphics.Canvas.ICanvasResourceCreator; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// unsafe partial class PixelShaderEffect @@ -25,24 +32,20 @@ unsafe partial class PixelShaderEffect return GetBounds(resourceCreator, &transform); } - /// + /// private Rect GetBounds(ICanvasResourceCreator resourceCreator, Matrix3x2* transform) { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); - using ComPtr resourceCreatorUnknown = default; using ComPtr resourceCreatorAbi = default; // Get the ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreator object from the input interface - resourceCreatorUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(resourceCreator)); - resourceCreatorUnknown.CopyTo(resourceCreatorAbi.GetAddressOf()).Assert(); + RcwMarshaller.GetNativeObject(resourceCreator, resourceCreatorAbi.GetAddressOf()).Assert(); - using ComPtr canvasImageInteropUnknown = default; using ComPtr canvasImageInterop = default; // Get the ICanvasImageInterop object from the current instance - canvasImageInteropUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(this)); - canvasImageInteropUnknown.CopyTo(canvasImageInterop.GetAddressOf()).Assert(); + RcwMarshaller.GetNativeObject(this, canvasImageInterop.GetAddressOf()).Assert(); Rect bounds; diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs similarity index 98% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs index fb7eb262..5f376fdf 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ICanvasImageInterop.cs @@ -5,7 +5,13 @@ using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Interop.Effects; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Extensions; +using ComputeSharp.D2D1.Uwp.Helpers; +#else +using ComputeSharp.D2D1.WinUI.Extensions; +using ComputeSharp.D2D1.WinUI.Helpers; +#endif using ComputeSharp.Interop; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; @@ -14,7 +20,11 @@ using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_D2D_IMAGE_FLAGS; using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_DEVICE_ASSOCIATION_TYPE; using Win32 = TerraFX.Interop.Windows.Windows; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// unsafe partial class PixelShaderEffect @@ -353,14 +363,10 @@ unsafe partial class PixelShaderEffect } else { - using ComPtr canvasImageInteropUnknown = default; using ComPtr canvasImageInterop = default; - // Get the underlying IUnknown object for the current source - canvasImageInteropUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(source)); - // Convert to ICanvasImageInterop (this must always succeed, and throws if it doesn't) - canvasImageInteropUnknown.CopyTo(canvasImageInterop.GetAddressOf()).Assert(); + RcwMarshaller.GetNativeObject(source, canvasImageInterop.GetAddressOf()).Assert(); using ComPtr d2D1Image = default; diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs similarity index 98% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs index 30db4eda..264b610a 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.Sources.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.Sources.cs @@ -3,8 +3,15 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using ABI.Microsoft.Graphics.Canvas; using ComputeSharp.D2D1.Extensions; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Buffers; using ComputeSharp.D2D1.Uwp.Extensions; +using ComputeSharp.D2D1.Uwp.Helpers; +#else +using ComputeSharp.D2D1.WinUI.Buffers; +using ComputeSharp.D2D1.WinUI.Extensions; +using ComputeSharp.D2D1.WinUI.Helpers; +#endif using ComputeSharp.Interop; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; @@ -17,7 +24,11 @@ using static TerraFX.Interop.DirectX.D2D1_DPICOMPENSATION_PROP; using static TerraFX.Interop.DirectX.D2D1_PROPERTY_TYPE; using Win32 = TerraFX.Interop.Windows.Windows; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// unsafe partial class PixelShaderEffect @@ -127,15 +138,10 @@ unsafe partial class PixelShaderEffect if (value is not null) { - using ComPtr canvasImageUnknown = default; - - // Get the underlying IUnknown object for the input source - canvasImageUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(value)); - using ComPtr canvasImageInterop = default; // Try to get the ICanvasImageInterop interface from the input source - HRESULT hresult = canvasImageUnknown.CopyTo(canvasImageInterop.GetAddressOf()); + HRESULT hresult = RcwMarshaller.GetNativeObject(value, canvasImageInterop.GetAddressOf()); if (!Win32.SUCCEEDED(hresult)) { diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs similarity index 98% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs index 88862939..30546024 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Interop.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.Interop.cs @@ -1,10 +1,18 @@ using ComputeSharp.D2D1.Interop; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Extensions; +#else +using ComputeSharp.D2D1.WinUI.Extensions; +#endif using ComputeSharp.Interop; using Microsoft.Graphics.Canvas; using TerraFX.Interop.DirectX; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// unsafe partial class PixelShaderEffect diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs similarity index 95% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs index e458491f..94dbdfad 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs @@ -6,12 +6,21 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Shaders.Loaders; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Buffers; using ComputeSharp.D2D1.Uwp.Collections; +#else +using ComputeSharp.D2D1.WinUI.Buffers; +using ComputeSharp.D2D1.WinUI.Collections; +#endif #pragma warning disable CS0618, CS8767 +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// partial class PixelShaderEffect @@ -117,7 +126,7 @@ partial class PixelShaderEffect } /// - int IList.Add(object value) + int IList.Add(object? value) { return default(NotSupportedException).Throw(); } @@ -141,7 +150,7 @@ partial class PixelShaderEffect } /// - bool IList.Contains(object value) + bool IList.Contains(object? value) { return FixedCountList.IndexOf(this, (D2D1ResourceTextureManager?)value) != -1; } @@ -177,7 +186,7 @@ partial class PixelShaderEffect } /// - int IList.IndexOf(object value) + int IList.IndexOf(object? value) { return FixedCountList.IndexOf(this, (D2D1ResourceTextureManager?)value); } @@ -189,7 +198,7 @@ partial class PixelShaderEffect } /// - void IList.Insert(int index, object value) + void IList.Insert(int index, object? value) { default(NotSupportedException).Throw(); } @@ -201,7 +210,7 @@ partial class PixelShaderEffect } /// - void IList.Remove(object value) + void IList.Remove(object? value) { default(NotSupportedException).Throw(); } diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.SourceCollection.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs similarity index 94% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.SourceCollection.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs index 167d43cf..8fe5889b 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.SourceCollection.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.SourceCollection.cs @@ -4,11 +4,20 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Runtime.CompilerServices; using ComputeSharp.D2D1.Interop; +#if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Buffers; using ComputeSharp.D2D1.Uwp.Collections; +#else +using ComputeSharp.D2D1.WinUI.Buffers; +using ComputeSharp.D2D1.WinUI.Collections; +#endif using Windows.Graphics.Effects; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// partial class PixelShaderEffect @@ -103,7 +112,7 @@ partial class PixelShaderEffect } /// - int IList.Add(object value) + int IList.Add(object? value) { return default(NotSupportedException).Throw(); } @@ -127,7 +136,7 @@ partial class PixelShaderEffect } /// - bool IList.Contains(object value) + bool IList.Contains(object? value) { return FixedCountList.IndexOf(this, (IGraphicsEffectSource?)value) != -1; } @@ -163,7 +172,7 @@ partial class PixelShaderEffect } /// - int IList.IndexOf(object value) + int IList.IndexOf(object? value) { return FixedCountList.IndexOf(this, (IGraphicsEffectSource?)value); } @@ -175,7 +184,7 @@ partial class PixelShaderEffect } /// - void IList.Insert(int index, object value) + void IList.Insert(int index, object? value) { default(NotSupportedException).Throw(); } @@ -187,7 +196,7 @@ partial class PixelShaderEffect } /// - void IList.Remove(object value) + void IList.Remove(object? value) { default(NotSupportedException).Throw(); } diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.cs similarity index 96% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.cs index 71882ab1..d171e39f 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.cs @@ -3,7 +3,11 @@ using System.Diagnostics.CodeAnalysis; using ComputeSharp.D2D1.Interop; using Microsoft.Graphics.Canvas; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// partial class PixelShaderEffect diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ReferenceTracking.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs similarity index 95% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ReferenceTracking.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs index 08548bb1..dd5695ee 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ReferenceTracking.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.ReferenceTracking.cs @@ -2,7 +2,11 @@ using System; using ComputeSharp.Interop; using System.Runtime.CompilerServices; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// partial class PixelShaderEffect diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs similarity index 97% rename from src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.cs rename to src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs index 7c3c389c..99d2a0c9 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.cs +++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.cs @@ -6,7 +6,11 @@ using Microsoft.Graphics.Canvas.Effects; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +#if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; +#else +namespace ComputeSharp.D2D1.WinUI; +#endif /// /// A custom implementation powered by a supplied shader type. diff --git a/src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj b/src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj index 8b654835..1c8ecc34 100644 --- a/src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj +++ b/src/ComputeSharp.D2D1.Uwp/ComputeSharp.D2D1.Uwp.csproj @@ -25,20 +25,17 @@ $(PackageTags) uwp winui - - - - - - + + + \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj b/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj new file mode 100644 index 00000000..cb372053 --- /dev/null +++ b/src/ComputeSharp.D2D1.WinUI/ComputeSharp.D2D1.WinUI.csproj @@ -0,0 +1,32 @@ + + + + net6.0-windows10.0.22621.0 + 10.0.17763.0 + ComputeSharp.D2D1.WinUI + x64;ARM64 + win10-x64;win10-arm64 + + + + ComputeSharp.D2D1.WinUI + ComputeSharp.D2D1.WinUI + A WinUI 3 library with APIs to leverage D2D1 functionality with D2D1 pixel shaders powered by ComputeSharp.D2D1 + $(PackageTags) winui winui3 wasdk + + + + + + + + + + + + + + + + + diff --git a/src/ComputeSharp.D2D1.WinUI/Directory.Build.props b/src/ComputeSharp.D2D1.WinUI/Directory.Build.props new file mode 100644 index 00000000..4ec7dd9c --- /dev/null +++ b/src/ComputeSharp.D2D1.WinUI/Directory.Build.props @@ -0,0 +1,12 @@ + + + + + + + $(NoWarn);CS0419 + + + $(NoWarn);IDE0065 + + \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/ComputeSharp.D2D1.csproj b/src/ComputeSharp.D2D1/ComputeSharp.D2D1.csproj index c1ce7b65..75c00014 100644 --- a/src/ComputeSharp.D2D1/ComputeSharp.D2D1.csproj +++ b/src/ComputeSharp.D2D1/ComputeSharp.D2D1.csproj @@ -8,6 +8,7 @@ + diff --git a/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj b/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj index a37c0b0e..c4f220cb 100644 --- a/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj +++ b/src/ComputeSharp.WinUI/ComputeSharp.WinUI.csproj @@ -5,7 +5,6 @@ ComputeSharp.WinUI x64;ARM64 win10-x64;win10-arm64 - true @@ -20,7 +19,7 @@ - + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index c21734fc..33e5456a 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,6 +1,16 @@ + + + + $(NoWarn);DNG02 + + diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets index f7812f87..7ef82c2f 100644 --- a/src/Directory.Build.targets +++ b/src/Directory.Build.targets @@ -2,14 +2,16 @@ - - - - true - true - - + + + true + true + - + - + <_Parameter1>false