Share D2D1 rendering code between UWP/WinUI samples
このコミットが含まれているのは:
1 親
63ce21aa06
コミット
7254f1774c
10ファイル変更
+64
-28
検索条件に一致するファイルはありません
@@ -3,9 +3,11 @@ using CommunityToolkit.Diagnostics;
|
||||
using ComputeSharp.D2D1;
|
||||
#if WINDOWS_UWP
|
||||
using ComputeSharp.D2D1.Uwp;
|
||||
#else
|
||||
using ComputeSharp.D2D1.WinUI;
|
||||
#endif
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using Microsoft.Graphics.Canvas.UI.Xaml;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Shaders;
|
||||
|
||||
@@ -13,10 +15,9 @@ namespace ComputeSharp.SwapChain.Core.Shaders;
|
||||
/// 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
|
||||
public sealed class D2D1ShaderRunner<T> : ID2D1ShaderRunner, IDisposable
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
#if WINDOWS_UWP
|
||||
/// <summary>
|
||||
/// The <see cref="Func{T1,T2,T3TResult}"/> instance used to create shaders to run.
|
||||
/// </summary>
|
||||
@@ -26,7 +27,6 @@ public sealed class D2D1ShaderRunner<T> : ID2D1ShaderRunner
|
||||
/// 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.
|
||||
@@ -36,13 +36,10 @@ public sealed class D2D1ShaderRunner<T> : ID2D1ShaderRunner
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -55,5 +52,10 @@ public sealed class D2D1ShaderRunner<T> : ID2D1ShaderRunner
|
||||
// Draw the shader
|
||||
args.DrawingSession.DrawImage(this.pixelShaderEffect);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
this.pixelShaderEffect.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
#if WINDOWS_UWP
|
||||
using Microsoft.Graphics.Canvas.UI.Xaml;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Shaders;
|
||||
|
||||
@@ -9,12 +7,10 @@ namespace ComputeSharp.SwapChain.Core.Shaders;
|
||||
/// </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
|
||||
}
|
||||
+10
-6
@@ -1,16 +1,16 @@
|
||||
#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
|
||||
|
||||
@@ -19,9 +19,8 @@ namespace ComputeSharp.SwapChain.Core.Shaders.Runners;
|
||||
/// <summary>
|
||||
/// A specialized <see cref="ID2D1ShaderRunner"/> for <see cref="ContouredLayers"/>.
|
||||
/// </summary>
|
||||
public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner
|
||||
public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner, IDisposable
|
||||
{
|
||||
#if WINDOWS_UWP
|
||||
/// <summary>
|
||||
/// The reusable <see cref="PixelShaderEffect{T}"/> instance to use to render frames.
|
||||
/// </summary>
|
||||
@@ -72,5 +71,10 @@ public sealed class D2D1ContouredLayersRunner : ID2D1ShaderRunner
|
||||
// Draw the shader
|
||||
args.DrawingSession.DrawImage(this.pixelShaderEffect);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
this.pixelShaderEffect?.Dispose();
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする