Add initial version of D2D1AnimatedPixelShaderPanel

このコミットが含まれているのは:
Sergio Pedri committed 2023-01-21 20:03:25 +01:00
1 親 ffd3b79aed
コミット 5369832bd7
5ファイル変更
+117 -1

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

+1
ファイルの表示
@@ -453,6 +453,7 @@ Global
samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{f8bf7666-7ccf-4fe4-b055-2eba4bcd4564}*SharedItemsImports = 13
src\ComputeSharp.UI\ComputeSharp.UI.projitems*{fa18ba9f-76bf-4de0-8d24-02fc7657e6cb}*SharedItemsImports = 5
samples\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems*{fbd388a5-7855-4408-98ff-e689f509db5a}*SharedItemsImports = 4
samples\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems*{fbd388a5-7855-4408-98ff-e689f509db5a}*SharedItemsImports = 4
samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems*{fbd388a5-7855-4408-98ff-e689f509db5a}*SharedItemsImports = 4
EndGlobalSection
EndGlobal
+6 -1
ファイルの表示
@@ -3,6 +3,11 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<ResourceDictionary Source="Controls/D2D1AnimatedPixelShaderPanel.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
+9
ファイルの表示
@@ -79,6 +79,7 @@
<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" />
@@ -192,17 +193,25 @@
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.Uwp\ComputeSharp.D2D1.Uwp.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp\ComputeSharp.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.Uwp\ComputeSharp.Uwp.csproj" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Page Include="Controls\D2D1AnimatedPixelShaderPanel.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\MainView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="..\ComputeSharp.SwapChain.Shaders.D2D1.Shared\ComputeSharp.SwapChain.Shaders.D2D1.Shared.projitems" Label="Shared" />
<Import Project="..\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems" Label="Shared" />
<Import Project="..\ComputeSharp.SwapChain.Core.Shared\ComputeSharp.SwapChain.Core.Shared.projitems" Label="Shared" />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
+85
ファイルの表示
@@ -0,0 +1,85 @@
using ComputeSharp.SwapChain.Core.Shaders;
using Microsoft.Graphics.Canvas.UI.Xaml;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
#nullable enable
namespace ComputeSharp.SwapChain.Uwp.Views;
/// <summary>
/// A custom <see cref="Control"/> that can be used to render animated backgrounds via Win2D.
/// </summary>
[TemplatePart(Name = "PART_CanvasAnimatedControl", Type = typeof(CanvasAnimatedControl))]
public sealed class D2D1AnimatedPixelShaderPanel : Control
{
/// <summary>
/// The wrapped <see cref="CanvasAnimatedControl"/> instance used to render frames.
/// </summary>
private CanvasAnimatedControl? canvasAnimatedControl;
/// <summary>
/// The <see cref="ID2D1ShaderRunner"/> instance currently in use, if any.
/// </summary>
private volatile ID2D1ShaderRunner? shaderRunner;
/// <summary>
/// Creates a new <see cref="D2D1AnimatedPixelShaderPanel"/> instance.
/// </summary>
public D2D1AnimatedPixelShaderPanel()
{
DefaultStyleKey = typeof(D2D1AnimatedPixelShaderPanel);
}
/// <inheritdoc/>
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
this.canvasAnimatedControl = (CanvasAnimatedControl)GetTemplateChild("PART_CanvasAnimatedControl")!;
this.canvasAnimatedControl.Draw += CanvasAnimatedControl_Draw;
}
/// <summary>
/// Draws a new frame on the wrapped <see cref="CanvasAnimatedControl"/> instance.
/// </summary>
/// <inheritdoc cref="ID2D1ShaderRunner.Execute"/>
private void CanvasAnimatedControl_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
{
this.shaderRunner?.Execute(sender, args);
}
/// <summary>
/// Gets or sets the <see cref="ID2D1ShaderRunner"/> instance to use to render content.
/// </summary>
public ID2D1ShaderRunner? ShaderRunner
{
get => (ID2D1ShaderRunner?)GetValue(ShaderRunnerProperty);
set => SetValue(ShaderRunnerProperty, value);
}
/// <summary>
/// The <see cref="DependencyProperty"/> backing <see cref="ShaderRunner"/>.
/// </summary>
public static readonly DependencyProperty ShaderRunnerProperty = DependencyProperty.Register(
nameof(ShaderRunner),
typeof(ID2D1ShaderRunner),
typeof(D2D1AnimatedPixelShaderPanel),
new PropertyMetadata(null, OnShaderRunnerPropertyChanged));
/// <inheritdoc cref="DependencyPropertyChangedCallback"/>
private static void OnShaderRunnerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
D2D1AnimatedPixelShaderPanel @this = (D2D1AnimatedPixelShaderPanel)d;
ID2D1ShaderRunner? shaderRunner = (ID2D1ShaderRunner?)e.NewValue;
// Save the new shader runner for later (as the dependency property cannot be accessed by the render thread)
@this.shaderRunner = shaderRunner;
// Pause or start the render thread if a runner is available
if (@this.canvasAnimatedControl is { } canvasAnimatedControl)
{
canvasAnimatedControl.Paused = e.NewValue is not ID2D1ShaderRunner;
}
}
}
+16
ファイルの表示
@@ -0,0 +1,16 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="using:ComputeSharp.SwapChain.Uwp.Views"
xmlns:win2d="using:Microsoft.Graphics.Canvas.UI.Xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/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>