Merge pull request #486 from Sergio0694/dev/win2d-effects-wasdk

Add ComputeSharp.D2D1.WinUI package (for Win2D/WASDK support)
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2023-04-20 14:39:31 -07:00
コミット ab068a98f0
70ファイル変更
+1020 -286

検索条件に一致するファイルはありません

+11 -5
ファイルの表示
@@ -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
+15
ファイルの表示
@@ -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
@@ -11,13 +11,13 @@
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Constants\Error.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Constants\Event.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\D2D1AnimatedPixelShaderPanel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\RenderingPauseConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\ResolutionScaleConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Enums\RenderingMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\DebugAnalyticsService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\IAnalyticsService.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Shaders\ID2D1ShaderRunner.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Shaders\D2D1ShaderRunner{T}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Shaders\PixelShaderEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Shaders\Runners\D2D1ContouredLayersRunner.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Shaders\Runners\ContouredLayersRunner.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ViewModels\MainViewModel.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
/// <summary>
/// A custom <see cref="Control"/> that can be used to render animated backgrounds via Win2D.
@@ -19,9 +29,9 @@ public sealed class D2D1AnimatedPixelShaderPanel : Control
private CanvasAnimatedControl? canvasAnimatedControl;
/// <summary>
/// The <see cref="ID2D1ShaderRunner"/> instance currently in use, if any.
/// The <see cref="PixelShaderEffect"/> instance currently in use, if any.
/// </summary>
private volatile ID2D1ShaderRunner? shaderRunner;
private volatile PixelShaderEffect? pixelShaderEffect;
/// <summary>
/// Creates a new <see cref="D2D1AnimatedPixelShaderPanel"/> 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
/// <summary>
/// Draws a new frame on the wrapped <see cref="CanvasAnimatedControl"/> instance.
/// </summary>
/// <inheritdoc cref="ID2D1ShaderRunner.Execute"/>
/// <param name="sender">The source <see cref="ICanvasAnimatedControl"/> instance.</param>
/// <param name="args">The <see cref="CanvasAnimatedDrawEventArgs"/> object to perform drawing with.</param>
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);
}
/// <summary>
/// Gets or sets the <see cref="ID2D1ShaderRunner"/> instance to use to render content.
/// Gets or sets the <see cref="Core.Shaders.PixelShaderEffect"/> instance to use to render content.
/// </summary>
public ID2D1ShaderRunner? ShaderRunner
public PixelShaderEffect? PixelShaderEffect
{
get => (ID2D1ShaderRunner?)GetValue(ShaderRunnerProperty);
set => SetValue(ShaderRunnerProperty, value);
get => (PixelShaderEffect?)GetValue(PixelShaderEffectProperty);
set => SetValue(PixelShaderEffectProperty, value);
}
/// <summary>
/// The <see cref="DependencyProperty"/> backing <see cref="ShaderRunner"/>.
/// The <see cref="DependencyProperty"/> backing <see cref="PixelShaderEffect"/>.
/// </summary>
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));
/// <inheritdoc cref="DependencyPropertyChangedCallback"/>
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;
}
-59
ファイルの表示
@@ -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;
/// <summary>
/// A simple <see cref="ID2D1ShaderRunner"/> implementation powered by a supplied shader type.
/// </summary>
/// <typeparam name="T">The type of shader to use to render frames.</typeparam>
public sealed class D2D1ShaderRunner<T> : ID2D1ShaderRunner
where T : unmanaged, ID2D1PixelShader
{
#if WINDOWS_UWP
/// <summary>
/// The <see cref="Func{T1,T2,T3TResult}"/> instance used to create shaders to run.
/// </summary>
private readonly Func<TimeSpan, int, int, T> shaderFactory;
/// <summary>
/// The reusable <see cref="PixelShaderEffect{T}"/> instance to use to render frames.
/// </summary>
private readonly PixelShaderEffect<T> pixelShaderEffect;
#endif
/// <summary>
/// Creates a new <see cref="D2D1ShaderRunner{T}"/> instance.
/// </summary>
/// <param name="shaderFactory">The <see cref="Func{T1,TResult}"/> instance used to create shaders to run.</param>
public D2D1ShaderRunner(Func<TimeSpan, int, int, T> shaderFactory)
{
Guard.IsNotNull(shaderFactory);
#if WINDOWS_UWP
this.shaderFactory = shaderFactory;
this.pixelShaderEffect = new PixelShaderEffect<T>();
#endif
}
#if WINDOWS_UWP
/// <inheritdoc/>
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
}
-20
ファイルの表示
@@ -1,20 +0,0 @@
#if WINDOWS_UWP
using Microsoft.Graphics.Canvas.UI.Xaml;
#endif
namespace ComputeSharp.SwapChain.Core.Shaders;
/// <summary>
/// An interface for a shader runner to be used with a Win2D renderer.
/// </summary>
public interface ID2D1ShaderRunner
{
#if WINDOWS_UWP
/// <summary>
/// Draws a new frame on a target <see cref="ICanvasAnimatedControl"/> instance.
/// </summary>
/// <param name="sender">The target <see cref="ICanvasAnimatedControl"/> instance.</param>
/// <param name="args">The <see cref="CanvasAnimatedDrawEventArgs"/> instance to use to draw the new frame.</param>
void Execute(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args);
#endif
}
+121
ファイルの表示
@@ -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;
/// <summary>
/// An base effect for an animated pixel shader.
/// </summary>
public abstract class PixelShaderEffect : CanvasEffect
{
/// <summary>
/// The current elapsed time.
/// </summary>
private TimeSpan elapsedTime;
/// <summary>
/// The current screen width in raw pixels.
/// </summary>
private int screenWidth;
/// <summary>
/// The current screen height in raw pixels.
/// </summary>
private int screenHeight;
/// <summary>
/// Gets or sets the total elapsed time.
/// </summary>
public TimeSpan ElapsedTime
{
get => this.elapsedTime;
set => SetAndInvalidateEffectGraph(ref this.elapsedTime, value);
}
/// <summary>
/// Gets or sets the screen width in raw pixels.
/// </summary>
public int ScreenWidth
{
get => this.screenWidth;
set => SetAndInvalidateEffectGraph(ref this.screenWidth, value);
}
/// <summary>
/// Gets or sets the screen height in raw pixels.
/// </summary>
public int ScreenHeight
{
get => this.screenHeight;
set => SetAndInvalidateEffectGraph(ref this.screenHeight, value);
}
/// <summary>
/// An effect for an animated pixel shader.
/// </summary>
/// <typeparam name="T">The type of pixel shader to render.</typeparam>
public sealed class For<T> : PixelShaderEffect
where T : unmanaged, ID2D1PixelShader
{
/// <summary>
/// The <typeparamref name="T"/> factory to use.
/// </summary>
private readonly Factory factory;
/// <summary>
/// The <see cref="PixelShaderEffect{T}"/> instance in use.
/// </summary>
private PixelShaderEffect<T>? effect;
/// <summary>
/// Creates a new <see cref="For{T}"/> instance with the specified parameters.
/// </summary>
/// <param name="factory">The input <typeparamref name="T"/> factory.</param>
public For(Factory factory)
{
this.factory = factory;
}
/// <inheritdoc/>
protected override ICanvasImage BuildEffectGraph()
{
this.effect = new PixelShaderEffect<T>();
return this.effect;
}
/// <inheritdoc/>
protected override void ConfigureEffectGraph()
{
this.effect!.ConstantBuffer = this.factory(ElapsedTime, ScreenWidth, ScreenHeight);
}
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
this.effect?.Dispose();
}
}
/// <summary>
/// A factory of a given shader instance.
/// </summary>
/// <param name="elapsedTime">The total elapsed time.</param>
/// <param name="screenWidth">The screen width in raw pixels.</param>
/// <param name="screenHeight">The screen height in raw pixels.</param>
/// <returns>A shader instance to render.</returns>
public delegate T Factory(TimeSpan elapsedTime, int screenWidth, int screenHeight);
}
}
+46 -42
ファイルの表示
@@ -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;
/// <summary>
/// A specialized <see cref="ID2D1ShaderRunner"/> for <see cref="ContouredLayers"/>.
/// A specialized <see cref="PixelShaderEffect"/> for <see cref="ContouredLayers"/>.
/// </summary>
public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner
public sealed class D2D1ContouredLayersEffect : PixelShaderEffect
{
#if WINDOWS_UWP
/// <summary>
/// The reusable <see cref="PixelShaderEffect{T}"/> instance to use to render frames.
/// </summary>
private PixelShaderEffect<ContouredLayers>? pixelShaderEffect;
/// <inheritdoc/>
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<Rgba32, float4> readOnlyTexture = GraphicsDevice.GetDefault().LoadReadOnlyTexture2D<Rgba32, float4>(filename);
using ReadBackTexture2D<Rgba32> readBackTexture = GraphicsDevice.GetDefault().AllocateReadBackTexture2D<Rgba32>(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<Rgba32, float4> readOnlyTexture = GraphicsDevice.GetDefault().LoadReadOnlyTexture2D<Rgba32, float4>(filename);
using ReadBackTexture2D<Rgba32> readBackTexture = GraphicsDevice.GetDefault().AllocateReadBackTexture2D<Rgba32>(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<byte>(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<byte>(dataBuffer, bufferSize),
strides: stackalloc uint[] { (uint)strideInBytes });
// Create the new pixel shader effect
this.pixelShaderEffect = new PixelShaderEffect<ContouredLayers>() { ResourceTextureManagers = { [0] = resourceTextureManager } };
}
// Create the new pixel shader effect
this.pixelShaderEffect = new PixelShaderEffect<ContouredLayers>() { 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));
/// <inheritdoc/>
protected override void ConfigureEffectGraph()
{
this.pixelShaderEffect!.ConstantBuffer = new ContouredLayers((float)ElapsedTime.TotalSeconds, new int2(ScreenWidth, ScreenHeight));
}
// Draw the shader
args.DrawingSession.DrawImage(this.pixelShaderEffect);
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
this.pixelShaderEffect?.Dispose();
}
}
#endif
}
+10 -10
ファイルの表示
@@ -95,40 +95,40 @@ public sealed partial class MainViewModel : ObservableObject
new(
nameof(ColorfulInfinity),
new ShaderRunner<ColorfulInfinity>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.ColorfulInfinity>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.ColorfulInfinity>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(FractalTiling),
new ShaderRunner<FractalTiling>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.FractalTiling>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.FractalTiling>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(MengerJourney),
new ShaderRunner<MengerJourney>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.MengerJourney>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.MengerJourney>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(Octagrams),
new ShaderRunner<Octagrams>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.Octagrams>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.Octagrams>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(ProteanClouds),
new ShaderRunner<ProteanClouds>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.ProteanClouds>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.ProteanClouds>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(TwoTiledTruchet),
new ShaderRunner<TwoTiledTruchet>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.TwoTiledTruchet>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.TwoTiledTruchet>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(PyramidPattern),
new ShaderRunner<PyramidPattern>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.PyramidPattern>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.PyramidPattern>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(
nameof(TriangleGridContouring),
new ShaderRunner<TriangleGridContouring>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.TriangleGridContouring>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(nameof(ContouredLayers), new ContouredLayersRunner(), new D2D1ContouredLayersRunner()),
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.TriangleGridContouring>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new(nameof(ContouredLayers), new ContouredLayersRunner(), new D2D1ContouredLayersEffect()),
new(
nameof(TerracedHills),
new ShaderRunner<TerracedHills>(static time => new((float)time.TotalSeconds)),
new D2D1ShaderRunner<SwapChain.Shaders.D2D1.TerracedHills>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
new PixelShaderEffect.For<SwapChain.Shaders.D2D1.TerracedHills>(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height)))),
};
/// <summary>
+5 -5
ファイルの表示
@@ -18,12 +18,12 @@ public sealed partial class ShaderRunnerViewModel : ObservableObject
/// </summary>
/// <param name="shaderType">The name of the shader type to execute.</param>
/// <param name="shaderRunner">The <see cref="IShaderRunner"/> instance to execute.</param>
/// <param name="d2D1ShaderRunner">The <see cref="ID2D1ShaderRunner"/> instance to execute.</param>
public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, ID2D1ShaderRunner d2D1ShaderRunner)
/// <param name="pixelShaderEffect">The <see cref="Shaders.PixelShaderEffect"/> instance to execute.</param>
public ShaderRunnerViewModel(string shaderType, IShaderRunner shaderRunner, PixelShaderEffect pixelShaderEffect)
{
ShaderType = shaderType;
ShaderRunner = shaderRunner;
D2D1ShaderRunner = d2D1ShaderRunner;
PixelShaderEffect = pixelShaderEffect;
}
/// <summary>
@@ -37,9 +37,9 @@ public sealed partial class ShaderRunnerViewModel : ObservableObject
public IShaderRunner ShaderRunner { get; }
/// <summary>
/// Gets the <see cref="ID2D1ShaderRunner"/> instance to execute.
/// Gets the <see cref="PixelShaderEffect"/> instance to execute.
/// </summary>
public ID2D1ShaderRunner D2D1ShaderRunner { get; }
public PixelShaderEffect PixelShaderEffect { get; }
/// <summary>
/// Gets or sets whether the current shader is selected.
+1 -1
ファイルの表示
@@ -6,7 +6,7 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<ResourceDictionary Source="Controls/D2D1AnimatedPixelShaderPanel.xaml"/>
<ResourceDictionary Source="Controls/D2D1AnimatedPixelShaderPanel.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
-1
ファイルの表示
@@ -79,7 +79,6 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Assets\Generated\ServiceTokens.g.cs" />
<Compile Include="Controls\D2D1AnimatedPixelShaderPanel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\AppCenterService.cs" />
<Compile Include="Services\ServiceCollectionExtensions.cs" />
+3 -3
ファイルの表示
@@ -1,14 +1,14 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ComputeSharp.SwapChain.Uwp.Views"
xmlns:win2d="using:Microsoft.Graphics.Canvas.UI.Xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:win2d="using:Microsoft.Graphics.Canvas.UI.Xaml">
<Style TargetType="local:D2D1AnimatedPixelShaderPanel">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:D2D1AnimatedPixelShaderPanel">
<win2d:CanvasAnimatedControl x:Name="PART_CanvasAnimatedControl"/>
<win2d:CanvasAnimatedControl x:Name="PART_CanvasAnimatedControl" />
</ControlTemplate>
</Setter.Value>
</Setter>
+3 -5
ファイルの表示
@@ -148,7 +148,7 @@
<!-- Shader switches (for DirectX 12 or Win2D) -->
<controls:SwitchPresenter Grid.Row="1" Value="{x:Bind ViewModel.SelectedRenderingMode, Mode=OneWay}">
<controls:Case Value="{x:Bind enums:RenderingMode.DirectX12}" IsDefault="True">
<controls:Case IsDefault="True" Value="{x:Bind enums:RenderingMode.DirectX12}">
<!-- DirectX 12 shader -->
<computesharp:AnimatedComputeShaderPanel
@@ -157,14 +157,12 @@
IsVerticalSyncEnabled="{x:Bind ViewModel.IsVerticalSyncEnabled, Mode=OneWay}"
RenderingFailed="MainShaderPanel_RenderingFailed"
ResolutionScale="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToScale(ViewModel.SelectedResolutionScale), Mode=OneWay}"
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}"/>
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}" />
</controls:Case>
<controls:Case Value="{x:Bind enums:RenderingMode.Win2D}">
<!-- Win2D shader -->
<views:D2D1AnimatedPixelShaderPanel
IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}"
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.D2D1ShaderRunner, Mode=OneWay}"/>
<views:D2D1AnimatedPixelShaderPanel IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}" PixelShaderEffect="{x:Bind ViewModel.SelectedComputeShader.PixelShaderEffect, Mode=OneWay}" />
</controls:Case>
</controls:SwitchPresenter>
+1
ファイルの表示
@@ -6,6 +6,7 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<ResourceDictionary Source="Controls/D2D1AnimatedPixelShaderPanel.xaml" />
<ResourceDictionary>
<!-- Override the title bar colors to keep it transparent -->
+11 -1
ファイルの表示
@@ -28,11 +28,12 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230217.4" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230331000" />
<PackageReference Include="CommunityToolkit.Diagnostics" Version="8.1.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Core" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Media" Version="7.1.2" />
<PackageReference Include="PolySharp" Version="1.12.1" PrivateAssets="all" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
@@ -56,12 +57,21 @@
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.WinUI\ComputeSharp.D2D1.WinUI.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.WinUI\ComputeSharp.WinUI.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
</ItemGroup>
<!-- Resource dictionary for D2D1AnimatedPixelShaderPanel -->
<ItemGroup>
<None Remove="Controls\D2D1AnimatedPixelShaderPanel.xaml" />
<Page Update="Controls\D2D1AnimatedPixelShaderPanel.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<Import Project="..\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems" Label="Shared" />
<Import Project="..\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems" Label="Shared" />
<Import Project="..\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems" Label="Shared" />
+16
ファイルの表示
@@ -0,0 +1,16 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ComputeSharp.SwapChain.WinUI.Views"
xmlns:win2d="using:Microsoft.Graphics.Canvas.UI.Xaml">
<Style TargetType="local:D2D1AnimatedPixelShaderPanel">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:D2D1AnimatedPixelShaderPanel">
<win2d:CanvasAnimatedControl x:Name="PART_CanvasAnimatedControl" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
@@ -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;
/// <summary>
/// XAML control intended for displaying animating content.
/// </summary>
public sealed class CanvasAnimatedControl : Grid, ICanvasAnimatedControl, IDisposable
{
/// <summary>
/// The <see cref="CanvasControl"/> instance to use.
/// </summary>
private readonly CanvasControl canvasControl;
/// <summary>
/// The <see cref="Stopwatch"/> used to track the elapsed time.
/// </summary>
private readonly Stopwatch stopwatch;
/// <summary>
/// The <see cref="Timer"/> used to render frames.
/// </summary>
private readonly Timer timer;
/// <summary>
/// Indicates whether rendering is paused.
/// </summary>
private bool paused;
/// <summary>
/// Indicates whether a new frame is currently being drawn.
/// </summary>
private volatile int isDrawing;
/// <summary>
/// Hook this event to draw the contents of the control.
/// </summary>
public TypedEventHandler<ICanvasAnimatedControl, CanvasAnimatedDrawEventArgs>? Draw;
/// <summary>
/// Creates a new <see cref="CanvasAnimatedControl"/> instance.
/// </summary>
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);
}
/// <summary>
/// Gets or sets whether rendering has paused
/// </summary>
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();
}
}
}
}
/// <inheritdoc/>
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;
}
}
/// <inheritdoc/>
Size ICanvasAnimatedControl.Size => this.canvasControl.Size;
/// <inheritdoc/>
int ICanvasAnimatedControl.ConvertDipsToPixels(float dips, CanvasDpiRounding dpiRounding)
{
return this.canvasControl.ConvertDipsToPixels(dips, dpiRounding);
}
}
@@ -0,0 +1,15 @@
namespace Microsoft.Graphics.Canvas.UI.Xaml;
/// <summary>
/// Provides data for the <see cref="CanvasAnimatedControl.Draw"/> event.
/// </summary>
public sealed class CanvasAnimatedDrawEventArgs
{
/// <inheritdoc cref="CanvasDrawEventArgs.DrawingSession"/>
public required CanvasDrawingSession DrawingSession { get; init; }
/// <summary>
/// Gets the control's timing information for use by the event handler.
/// </summary>
public required CanvasTimingInformation Timing { get; init; }
}
@@ -0,0 +1,15 @@
using Windows.Foundation;
namespace Microsoft.Graphics.Canvas.UI.Xaml;
/// <summary>
/// XAML control intended for displaying animating content.
/// </summary>
public interface ICanvasAnimatedControl
{
/// <inheritdoc cref="CanvasControl.Size"/>
Size Size { get; }
/// <inheritdoc cref="CanvasControl.ConvertDipsToPixels"/>
int ConvertDipsToPixels(float dips, CanvasDpiRounding dpiRounding);
}
@@ -0,0 +1,15 @@
using System;
using Microsoft.Graphics.Canvas.UI.Xaml;
namespace Microsoft.Graphics.Canvas.UI;
/// <summary>
/// Contains information about a <see cref="CanvasAnimatedControl"/>'s timer.
/// </summary>
public readonly struct CanvasTimingInformation
{
/// <summary>
/// Represents the elapsed time, in ticks, for which this control has ever been running.
/// </summary>
public required TimeSpan TotalTime { get; init; }
}
+73 -16
ファイルの表示
@@ -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">
<Grid x:Name="Root">
<Grid.Resources>
@@ -119,7 +118,10 @@
<Grid>
<!-- Shader preview -->
<computesharp:AnimatedComputeShaderPanel Loaded="AnimatedComputeShaderPanel_Loaded" ShaderRunner="{x:Bind ShaderRunner}" />
<computesharp:AnimatedComputeShaderPanel
Loaded="AnimatedComputeShaderPanel_Loaded"
RenderingFailed="SelectionShaderPanel_RenderingFailed"
ShaderRunner="{x:Bind ShaderRunner}" />
<!--
Note: here we have a selection property to work around {x:Bind} not working correctly outside of the
@@ -146,15 +148,26 @@
</Border>
</Grid.Resources>
<!-- Shader -->
<computesharp:AnimatedComputeShaderPanel
x:Name="ShaderPanel"
Grid.Row="1"
IsDynamicResolutionEnabled="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=OneWay}"
IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}"
IsVerticalSyncEnabled="{x:Bind ViewModel.IsVerticalSyncEnabled, Mode=OneWay}"
ResolutionScale="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToScale(ViewModel.SelectedResolutionScale), Mode=OneWay}"
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}" />
<!-- Shader switches (for DirectX 12 or Win2D) -->
<controls:SwitchPresenter Grid.Row="1" Value="{x:Bind ViewModel.SelectedRenderingMode, Mode=OneWay}">
<controls:Case IsDefault="True" Value="{x:Bind enums:RenderingMode.DirectX12}">
<!-- DirectX 12 shader -->
<computesharp:AnimatedComputeShaderPanel
x:Name="ShaderPanel"
IsDynamicResolutionEnabled="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=OneWay}"
IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}"
IsVerticalSyncEnabled="{x:Bind ViewModel.IsVerticalSyncEnabled, Mode=OneWay}"
RenderingFailed="MainShaderPanel_RenderingFailed"
ResolutionScale="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToScale(ViewModel.SelectedResolutionScale), Mode=OneWay}"
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}" />
</controls:Case>
<controls:Case Value="{x:Bind enums:RenderingMode.Win2D}">
<!-- Win2D shader -->
<views:D2D1AnimatedPixelShaderPanel IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}" PixelShaderEffect="{x:Bind ViewModel.SelectedComputeShader.PixelShaderEffect, Mode=OneWay}" />
</controls:Case>
</controls:SwitchPresenter>
<!-- Settings panel -->
<StackPanel
@@ -190,7 +203,25 @@
<SymbolIcon Symbol="Setting" />
<Button.Flyout>
<MenuFlyout>
<ToggleMenuFlyoutItem IsChecked="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=TwoWay}" Text="Dynamic resolution" />
<ToggleMenuFlyoutItem
Command="{x:Bind ViewModel.SetRenderingModeCommand}"
CommandParameter="{x:Bind enums:RenderingMode.DirectX12}"
IsChecked="{x:Bind ViewModel.SelectedRenderingMode.Equals(enums:RenderingMode.DirectX12), Mode=OneWay}"
Text="DirectX 12" />
<ToggleMenuFlyoutItem
Command="{x:Bind ViewModel.SetRenderingModeCommand}"
CommandParameter="{x:Bind enums:RenderingMode.Win2D}"
IsChecked="{x:Bind ViewModel.SelectedRenderingMode.Equals(enums:RenderingMode.Win2D), Mode=OneWay}"
Text="Win2D (Direct2D)" />
<MenuFlyoutSeparator />
<ToggleMenuFlyoutItem
IsChecked="{x:Bind ViewModel.IsVerticalSyncEnabled, Mode=TwoWay}"
IsEnabled="{x:Bind ViewModel.SelectedRenderingMode.Equals(enums:RenderingMode.DirectX12), Mode=OneWay}"
Text="Vertical sync" />
<ToggleMenuFlyoutItem
IsChecked="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=TwoWay}"
IsEnabled="{x:Bind ViewModel.SelectedRenderingMode.Equals(enums:RenderingMode.DirectX12), Mode=OneWay}"
Text="Dynamic resolution" />
<MenuFlyoutSeparator />
<ToggleMenuFlyoutItem
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
@@ -224,9 +255,35 @@
<!-- Invisible title bar -->
<Rectangle
x:Name="TitleBarRectangle"
Height="28"
Height="32"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Fill="Transparent" />
<!-- Info bar -->
<InfoBar
x:Name="RenderingErrorInfoBar"
Title="Rendering error"
Margin="80"
Message="There was an error that caused the rendering to fail. Try pausing and starting the rendering again, or restarting the app. If the issue persists, please report it by opening an issue on GitHub."
Severity="Error">
<InfoBar.ActionButton>
<HyperlinkButton Content="Report the issue" NavigateUri="https://github.com/Sergio0694/ComputeSharp/issues" />
</InfoBar.ActionButton>
<animations:Implicit.ShowAnimations>
<animations:OpacityAnimation
From="0"
To="1.0"
Duration="0:0:0.5" />
<animations:TranslationAnimation
From="0,20,0"
To="0"
Duration="0:0:0.5" />
</animations:Implicit.ShowAnimations>
<animations:Implicit.HideAnimations>
<animations:OpacityAnimation To="0" Duration="0:0:0.5" />
<animations:TranslationAnimation To="0,20,0" Duration="0:0:0.5" />
</animations:Implicit.HideAnimations>
</InfoBar>
</Grid>
</Window>
+14 -2
ファイルの表示
@@ -9,7 +9,7 @@ using Microsoft.UI.Xaml.Input;
namespace ComputeSharp.SwapChain.WinUI.Views;
/// <summary>
/// A view for <see cref="Core.ViewModels.MainViewModel"/>.
/// A view for <see cref="MainViewModel"/>.
/// </summary>
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;
}
}
+1
ファイルの表示
@@ -14,6 +14,7 @@
<InternalsVisibleTo Include="ComputeSharp.WinUI, PublicKey=$(AssemblySignPublicKey)" />
<InternalsVisibleTo Include="ComputeSharp.D2D1, PublicKey=$(AssemblySignPublicKey)" />
<InternalsVisibleTo Include="ComputeSharp.D2D1.Uwp, PublicKey=$(AssemblySignPublicKey)" />
<InternalsVisibleTo Include="ComputeSharp.D2D1.WinUI, PublicKey=$(AssemblySignPublicKey)" />
</ItemGroup>
<!-- .NET Standard 2.0 polyfill packages -->
@@ -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
}
/// <summary>
/// The <see cref="ComImportAttribute"/> implementation of <see cref="ICanvasImageInterop"/>.
/// The managed implementation of <see cref="ICanvasImageInterop"/>.
/// </summary>
[ComImport]
[Guid("E042D1F7-F9AD-4479-A713-67627EA31863")]
#if WINDOWS_UWP
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
#else
[WindowsRuntimeType]
[WindowsRuntimeHelperType(typeof(Interface))]
#endif
public interface Interface
{
/// <inheritdoc cref="ICanvasImageInterop.GetDevice"/>
#if WINDOWS_UWP
[PreserveSig]
#endif
[return: NativeTypeName("HRESULT")]
int GetDevice(ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type);
/// <inheritdoc cref="ICanvasImageInterop.GetD2DImage"/>
#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
/// <summary>
/// The vtable type for <see cref="Interface"/>.
/// </summary>
[Guid("E042D1F7-F9AD-4479-A713-67627EA31863")]
public struct Vftbl
{
/// <summary>
/// Allows CsWinRT to retrieve a pointer to the projection vtable (the name is hardcoded by convention).
/// </summary>
public static readonly IntPtr AbiToProjectionVftablePtr = InitVtbl();
/// <summary>
/// Builds the custom method table pointer for <see cref="Interface"/>.
/// </summary>
/// <returns>The method table pointer for <see cref="Interface"/>.</returns>
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;
}
/// <summary>
/// The IUnknown vtable.
/// </summary>
internal IUnknownVftbl IUnknownVftbl;
/// <summary>
/// Function pointer for <see cref="GetDeviceFromAbi"/>.
/// </summary>
internal delegate* unmanaged[Stdcall]<IntPtr, ICanvasDevice**, WIN2D_GET_DEVICE_ASSOCIATION_TYPE*, int> GetDevice;
/// <summary>
/// Function pointer for <see cref="GetD2DImageFromAbi"/>.
/// </summary>
internal delegate* unmanaged[Stdcall]<IntPtr, ICanvasDevice*, ID2D1DeviceContext*, WIN2D_GET_D2D_IMAGE_FLAGS, float, float*, ID2D1Image**, int> GetD2DImage;
/// <inheritdoc cref="Interface.GetDevice"/>
[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<Interface>(thisPtr).GetDevice(device, type);
}
catch (Exception e)
{
ExceptionHelpers.SetErrorInfo(e);
return Marshal.GetHRForException(e);
}
}
/// <inheritdoc cref="Interface.GetDevice"/>
[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<Interface>(thisPtr).GetD2DImage(device, deviceContext, flags, targetDpi, realizeDpi, ppImage);
}
catch (Exception e)
{
ExceptionHelpers.SetErrorInfo(e);
return Marshal.GetHRForException(e);
}
}
}
#endif
}
}
差分なしでファイル名を変更。
@@ -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
/// <summary>
/// A fixed buffer type containing 16 <see cref="IGraphicsEffectSource"/> fields.
@@ -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
/// <summary>
/// A fixed buffer type containing 16 <see cref="D2D1ResourceTextureManager"/> fields.
@@ -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
/// <summary>
/// A wrapper type for an input <see cref="IGraphicsEffectSource"/> and its underlying native D2D images.
@@ -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
/// <inheritdoc/>
unsafe partial class CanvasEffect
@@ -31,7 +40,7 @@ unsafe partial class CanvasEffect
{
using ComPtr<ICanvasImageInterop> 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<ICanvasImageInterop> 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
/// </summary>
/// <returns>The current <see cref="ICanvasImage"/> instance.</returns>
/// <exception cref="ObjectDisposedException">Thrown if the current instance is disposed.</exception>
[MemberNotNull(nameof(canvasImage))]
private ICanvasImage GetCanvasImage()
{
lock (this.lockObject)
@@ -75,17 +85,4 @@ unsafe partial class CanvasEffect
return this.canvasImage;
}
}
/// <summary>
/// Gets the <see cref="ICanvasImageInterop"/> object currently in use.
/// </summary>
/// <param name="canvasImageInterop">A pointer to the <see cref="ICanvasImageInterop"/> object currently in use.</param>
private void GetCanvasImageInterop(ICanvasImageInterop** canvasImageInterop)
{
using ComPtr<IUnknown> canvasImageUnknown = default;
canvasImageUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(GetCanvasImage()));
canvasImageUnknown.CopyTo(canvasImageInterop).Assert();
}
}
+12 -8
ファイルの表示
@@ -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
/// <summary>
/// A base type to implement packaged and easy to use <see cref="ICanvasImage"/>-based effects that can be used with Win2D.
@@ -151,14 +155,6 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I
InvalidateEffectGraph(invalidationType);
}
/// <inheritdoc/>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Disposes any disposable resources in the current instance.
/// </summary>
@@ -207,6 +203,14 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I
this.isDisposed = true;
}
/// <inheritdoc/>
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Indicates the invalidation type to request when invoking <see cref="InvalidateEffectGraph"/> and related methods.
/// </summary>
@@ -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
/// <summary>
/// Shared helpers for all types implementing <see cref="IFixedCountList{T}"/>.
@@ -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
/// <summary>
/// An interface for a list with a fixed collection.
+52
ファイルの表示
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>902d7b44-2c6c-4fcd-840b-ebcae811ee63</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>ComputeSharp.D2D1.UI</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)ABI.Microsoft.Graphics.Canvas\ICanvasDevice.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ABI.Microsoft.Graphics.Canvas\ICanvasEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ABI.Microsoft.Graphics.Canvas\ICanvasFactoryNative.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ABI.Microsoft.Graphics.Canvas\ICanvasImageInterop.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ABI.Microsoft.Graphics.Canvas\ICanvasResourceCreator.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ABI.Microsoft.Graphics.Canvas\ICanvasResourceCreatorWithDpi.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ABI.Microsoft.Graphics.Canvas\ICanvasResourceWrapperNative.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ABI.Microsoft.Graphics.Canvas\ID2D1DeviceContextLease.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ABI.Microsoft.Graphics.Canvas\ID2D1DeviceContextPool.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ABI.Microsoft.Graphics.Canvas\Win2D.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ABI.Microsoft.Graphics.Canvas\WIN2D_GET_D2D_IMAGE_FLAGS.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ABI.Microsoft.Graphics.Canvas\WIN2D_GET_DEVICE_ASSOCIATION_TYPE.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Buffers\GraphicsEffectSourceBuffer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Buffers\ResourceTextureManagerBuffer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Buffers\SourceReference.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CanvasEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CanvasEffect.Interop.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Collections\FixedCountList{T}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Collections\IFixedCountList{T}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ICanvasDeviceExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ID2D1DeviceContextExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ID2D1EffectExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IUnknownExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\RcwMarshaller.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ResourceManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Loaders\D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Loaders\D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.ICanvasEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.ICanvasImage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.ICanvasImageInterop.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.Properties.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.Properties.Interop.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.Properties.Interop.Sources.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.Properties.SourceCollection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.ReferenceTracking.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\ComputeSharp\Graphics\Interop\IReferenceTrackedObject.cs" Link="Interop\IReferenceTrackedObject.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\ComputeSharp\Graphics\Interop\ReferenceTracker.cs" Link="Interop\ReferenceTracker.cs" />
</ItemGroup>
</Project>
+13
ファイルの表示
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>902d7b44-2c6c-4fcd-840b-ebcae811ee63</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="ComputeSharp.D2D1.UI.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
@@ -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
/// <summary>
/// A <see langword="class"/> with extensions for the <see cref="ICanvasDevice"/> type.
@@ -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
/// <summary>
/// A <see langword="class"/> with extensions for the <see cref="ID2D1DeviceContext"/> type.
@@ -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
/// <summary>
/// A <see langword="class"/> with extensions for the <see cref="ID2D1Effect"/> type.
@@ -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
/// <summary>
/// Helper methods for working with the <see cref="IUnknown"/> type.
+64
ファイルの表示
@@ -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
/// <summary>
/// A helper type to handle marshalling of RCW instances.
/// </summary>
internal static class RcwMarshaller
{
/// <summary>
/// Gets or creates a managed object of a specified type for an input native object.
/// </summary>
/// <typeparam name="T">The interface type to retrieve an instance of.</typeparam>
/// <param name="nativeObject">A pointer to the native object to get a managed wrapper for.</param>
/// <returns>The resulting managed object wrapping <paramref name="nativeObject"/>.</returns>
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<T>.FromAbi((IntPtr)nativeObject);
#endif
}
/// <summary>
/// Retrieves the underlying native object for an input RCW and casts it to the specified type.
/// </summary>
/// <typeparam name="TFrom">The type of managed object to unwrap.</typeparam>
/// <typeparam name="TTo">The interface type to retrieve an instance of.</typeparam>
/// <param name="managedObject">The input RCW instance to unwrap.</param>
/// <param name="nativeObject">A pointer to the resulting native object to retrieve.</param>
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
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<IUnknown> 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<TFrom>.FromManaged(managedObject));
#endif
// QueryInterface to the specific interface we need
return unknownObject.CopyTo(nativeObject);
}
}
@@ -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
/// <summary>
/// A helper type to replicate Win2D's <c>ResourceManager</c> 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<IGraphicsEffectSource>(wrapperUnknown.Get());
}
}
@@ -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
/// <inheritdoc/>
unsafe partial class PixelShaderEffect<T>
@@ -89,12 +98,10 @@ unsafe partial class PixelShaderEffect<T>
Rect result;
using ComPtr<IUnknown> canvasEffectUnknown = default;
using ComPtr<ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect> 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<T>
// Get the underlying ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect object for each input effect
for (int i = 0; i < sourceEffects.Length; i++)
{
using ComPtr<IUnknown> 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<T>
ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi** resourceCreatorWithDpi,
ICanvasImageInterop** canvasImageInterop)
{
using ComPtr<IUnknown> 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<IUnknown> 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();
}
}
@@ -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
/// <inheritdoc/>
unsafe partial class PixelShaderEffect<T>
@@ -25,24 +32,20 @@ unsafe partial class PixelShaderEffect<T>
return GetBounds(resourceCreator, &transform);
}
/// <inheritdoc cref="ICanvasImage.GetBounds(ICanvasResourceCreator, Matrix3x2)"/>
/// <inheritdoc cref="Microsoft.Graphics.Canvas.ICanvasImage.GetBounds(ICanvasResourceCreator, Matrix3x2)"/>
private Rect GetBounds(ICanvasResourceCreator resourceCreator, Matrix3x2* transform)
{
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
using ComPtr<IUnknown> resourceCreatorUnknown = default;
using ComPtr<ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreator> 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<IUnknown> canvasImageInteropUnknown = default;
using ComPtr<ICanvasImageInterop> 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;
@@ -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
/// <inheritdoc/>
unsafe partial class PixelShaderEffect<T>
@@ -353,14 +363,10 @@ unsafe partial class PixelShaderEffect<T>
}
else
{
using ComPtr<IUnknown> canvasImageInteropUnknown = default;
using ComPtr<ICanvasImageInterop> 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<ID2D1Image> d2D1Image = default;
@@ -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
/// <inheritdoc/>
unsafe partial class PixelShaderEffect<T>
@@ -127,15 +138,10 @@ unsafe partial class PixelShaderEffect<T>
if (value is not null)
{
using ComPtr<IUnknown> canvasImageUnknown = default;
// Get the underlying IUnknown object for the input source
canvasImageUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(value));
using ComPtr<ICanvasImageInterop> 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))
{
@@ -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
/// <inheritdoc/>
unsafe partial class PixelShaderEffect<T>
@@ -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
/// <inheritdoc/>
partial class PixelShaderEffect<T>
@@ -117,7 +126,7 @@ partial class PixelShaderEffect<T>
}
/// <inheritdoc/>
int IList.Add(object value)
int IList.Add(object? value)
{
return default(NotSupportedException).Throw<int>();
}
@@ -141,7 +150,7 @@ partial class PixelShaderEffect<T>
}
/// <inheritdoc/>
bool IList.Contains(object value)
bool IList.Contains(object? value)
{
return FixedCountList<D2D1ResourceTextureManager?>.IndexOf(this, (D2D1ResourceTextureManager?)value) != -1;
}
@@ -177,7 +186,7 @@ partial class PixelShaderEffect<T>
}
/// <inheritdoc/>
int IList.IndexOf(object value)
int IList.IndexOf(object? value)
{
return FixedCountList<D2D1ResourceTextureManager?>.IndexOf(this, (D2D1ResourceTextureManager?)value);
}
@@ -189,7 +198,7 @@ partial class PixelShaderEffect<T>
}
/// <inheritdoc/>
void IList.Insert(int index, object value)
void IList.Insert(int index, object? value)
{
default(NotSupportedException).Throw();
}
@@ -201,7 +210,7 @@ partial class PixelShaderEffect<T>
}
/// <inheritdoc/>
void IList.Remove(object value)
void IList.Remove(object? value)
{
default(NotSupportedException).Throw();
}
@@ -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
/// <inheritdoc/>
partial class PixelShaderEffect<T>
@@ -103,7 +112,7 @@ partial class PixelShaderEffect<T>
}
/// <inheritdoc/>
int IList.Add(object value)
int IList.Add(object? value)
{
return default(NotSupportedException).Throw<int>();
}
@@ -127,7 +136,7 @@ partial class PixelShaderEffect<T>
}
/// <inheritdoc/>
bool IList.Contains(object value)
bool IList.Contains(object? value)
{
return FixedCountList<IGraphicsEffectSource?>.IndexOf(this, (IGraphicsEffectSource?)value) != -1;
}
@@ -163,7 +172,7 @@ partial class PixelShaderEffect<T>
}
/// <inheritdoc/>
int IList.IndexOf(object value)
int IList.IndexOf(object? value)
{
return FixedCountList<IGraphicsEffectSource?>.IndexOf(this, (IGraphicsEffectSource?)value);
}
@@ -175,7 +184,7 @@ partial class PixelShaderEffect<T>
}
/// <inheritdoc/>
void IList.Insert(int index, object value)
void IList.Insert(int index, object? value)
{
default(NotSupportedException).Throw();
}
@@ -187,7 +196,7 @@ partial class PixelShaderEffect<T>
}
/// <inheritdoc/>
void IList.Remove(object value)
void IList.Remove(object? value)
{
default(NotSupportedException).Throw();
}
@@ -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
/// <inheritdoc/>
partial class PixelShaderEffect<T>
@@ -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
/// <inheritdoc/>
partial class PixelShaderEffect<T>
@@ -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
/// <summary>
/// A custom <see cref="ICanvasEffect"/> implementation powered by a supplied shader type.
+3 -6
ファイルの表示
@@ -25,20 +25,17 @@
<PackageTags>$(PackageTags) uwp winui</PackageTags>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\ComputeSharp\Graphics\Interop\IReferenceTrackedObject.cs" Link="Interop\IReferenceTrackedObject.cs" />
<Compile Include="..\ComputeSharp\Graphics\Interop\ReferenceTracker.cs" Link="Interop\ReferenceTracker.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\ComputeSharp.Core.Package\icon.png" Pack="true" PackagePath="\icon.png" Visible="False" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Win2D.uwp" Version="1.27.0-preview2" />
<PackageReference Include="Win2D.uwp" Version="1.27.0-preview3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
</ItemGroup>
<Import Project="..\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.projitems" Label="Shared" />
</Project>
+32
ファイルの表示
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows10.0.22621.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>ComputeSharp.D2D1.WinUI</RootNamespace>
<Platforms>x64;ARM64</Platforms>
<RuntimeIdentifiers>win10-x64;win10-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup>
<PackageId>ComputeSharp.D2D1.WinUI</PackageId>
<Title>ComputeSharp.D2D1.WinUI</Title>
<Description>A WinUI 3 library with APIs to leverage D2D1 functionality with D2D1 pixel shaders powered by ComputeSharp.D2D1</Description>
<PackageTags>$(PackageTags) winui winui3 wasdk</PackageTags>
</PropertyGroup>
<ItemGroup>
<None Include="..\ComputeSharp.Core.Package\icon.png" Pack="true" PackagePath="\icon.png" Visible="False" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.1.0-preview1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230331000" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
</ItemGroup>
<Import Project="..\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.projitems" Label="Shared" />
</Project>
+12
ファイルの表示
@@ -0,0 +1,12 @@
<Project>
<Import Project="..\..\build\Directory.Build.props" />
<PropertyGroup>
<!-- Ignore some warnings about ambiguous cref attribute references (happens for ICanvasImage but it's not really clear why) -->
<NoWarn>$(NoWarn);CS0419</NoWarn>
<!-- Ignore warnings for usings outside of a namespace (needed for some WinRT type aliases) -->
<NoWarn>$(NoWarn);IDE0065</NoWarn>
</PropertyGroup>
</Project>
+1
ファイルの表示
@@ -8,6 +8,7 @@
<ItemGroup>
<InternalsVisibleTo Include="ComputeSharp.D2D1.Uwp, PublicKey=$(AssemblySignPublicKey)" />
<InternalsVisibleTo Include="ComputeSharp.D2D1.WinUI, PublicKey=$(AssemblySignPublicKey)" />
</ItemGroup>
<ItemGroup>
+1 -2
ファイルの表示
@@ -5,7 +5,6 @@
<RootNamespace>ComputeSharp.WinUI</RootNamespace>
<Platforms>x64;ARM64</Platforms>
<RuntimeIdentifiers>win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
</PropertyGroup>
<PropertyGroup>
@@ -20,7 +19,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230217.4" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230331000" />
</ItemGroup>
<ItemGroup>
+10
ファイルの表示
@@ -1,6 +1,16 @@
<Project>
<Import Project="..\build\Directory.Build.props" />
<PropertyGroup>
<!--
This ignores the following warning:
"DNG02: NuGetizer uses SponsorLink to properly attribute your sponsorship with
devlooped. Please install the GitHub app at https://github.com/apps/sponsorlink.
-->
<NoWarn>$(NoWarn);DNG02</NoWarn>
</PropertyGroup>
<!-- Reference NuGetizer to manage the packaging process -->
<ItemGroup>
<PackageReference Include="NuGetizer" Version="0.9.5" PrivateAssets="all" />
+12 -10
ファイルの表示
@@ -2,14 +2,16 @@
<Project>
<Import Project="..\build\Directory.Build.targets" />
<!-- Enable trimming support on .NET 6 -->
<Target Name="ConfigureAssemblyTrimmingIfNeeded"
BeforeTargets="PrepareForBuild">
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
</Target>
<!--
Enable trimming support on .NET 6 (we need to use StartsWith since it
could be a Windows TFM too). This can't be in a target unlike the other
properties set below, because if that is the case the trimmable attribute
will be set but the analyzers will not run, so warnings will be skipped.
-->
<PropertyGroup Condition="$(TargetFramework.StartsWith('net6.0'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
<!-- Emit the [SupportedOSVersion] attribute if needed -->
<Target Name="EmitSupportedOSVersionAttributeForTargetOS"
@@ -21,10 +23,10 @@
</ItemGroup>
</Target>
<!-- Emit the [ComVisible(false)] attribute for UWP targets -->
<!-- Emit the [ComVisible(false)] attribute for UWP and WinUI targets -->
<Target Name="EmitComVisibleAttributeForUwpProjects"
BeforeTargets="PrepareForBuild">
<ItemGroup Condition="$(TargetFramework.StartsWith('uap10.0'))">
<ItemGroup Condition="$(TargetFramework.StartsWith('uap10.0')) OR $(TargetFramework.StartsWith('net6.0-windows'))">
<AssemblyAttribute Include="System.Runtime.InteropServices.ComVisibleAttribute">
<_Parameter1>false</_Parameter1>
</AssemblyAttribute>