Add basic ICanvasEffectFactoryNative support code
このコミットが含まれているのは:
1 親
a110dce0ef
コミット
5ca2792892
3ファイル変更
+74
-1
検索条件に一致するファイルはありません
@@ -47,7 +47,7 @@ internal unsafe struct ICanvasEffectFactoryNative
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new inspectable wrapper for an inpute D2D effect previosly registered through <see cref="ICanvasFactoryNative.RegisterEffectFactory"/>.
|
||||
/// Creates a new inspectable wrapper for an input D2D effect previosly registered through <see cref="ICanvasFactoryNative.RegisterEffectFactory"/>.
|
||||
/// </summary>
|
||||
/// <param name="device">The input canvas device.</param>
|
||||
/// <param name="resource">The input native effect to create a wrapper for.</param>
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ResourceManager.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Loaders\D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Loaders\D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.ICanvasEffectFactoryNative.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.ICanvasEffect.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)PixelShaderEffect{T}.ICanvasImage.cs" />
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
#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;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using TerraFX.Interop.WinRT;
|
||||
|
||||
#if WINDOWS_UWP
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
#else
|
||||
namespace ComputeSharp.D2D1.WinUI;
|
||||
#endif
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <inheritdoc cref="ICanvasEffectFactoryNative.CreateWrapper"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
private delegate int CreateWrapperDelegate(ICanvasDevice* device, ID2D1Effect* resource, float dpi, IInspectable** wrapper);
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="CreateWrapperDelegate"/> instance wrapping <see cref="CreateWrapper"/>.
|
||||
/// </summary>
|
||||
private static readonly CreateWrapperDelegate CreateWrapperWrapper = CreateWrapper;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="PixelShaderEffect{T}"/> instance for an input D2D effect and marshals it as an <see cref="IInspectable"/> wrapper.
|
||||
/// </summary>
|
||||
/// <param name="device"><inheritdoc cref="ICanvasEffectFactoryNative.CreateWrapper" path="/param[@name='device']"/></param>
|
||||
/// <param name="resource"><inheritdoc cref="ICanvasEffectFactoryNative.CreateWrapper" path="/param[@name='resource']"/></param>
|
||||
/// <param name="dpi"><inheritdoc cref="ICanvasEffectFactoryNative.CreateWrapper" path="/param[@name='dpi']"/></param>
|
||||
/// <param name="wrapper"><inheritdoc cref="ICanvasEffectFactoryNative.CreateWrapper" path="/param[@name='wrapper']"/></param>
|
||||
/// <returns>This method always returns <see cref="S.S_OK"/> (any exceptions will be marshalled by the delegate stub).</returns>
|
||||
private static int CreateWrapper(ICanvasDevice* device, ID2D1Effect* resource, float dpi, IInspectable** wrapper)
|
||||
{
|
||||
PixelShaderEffect<T> @this = new();
|
||||
|
||||
@this.InitializeFromNativeResource(device, resource);
|
||||
|
||||
RcwMarshaller.GetNativeObject(@this, wrapper);
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a <see cref="PixelShaderEffect{T}"/> instance from an external realized D2D1 effect.
|
||||
/// </summary>
|
||||
/// <param name="device"><inheritdoc cref="ICanvasEffectFactoryNative.CreateWrapper" path="/param[@name='device']"/></param>
|
||||
/// <param name="resource"><inheritdoc cref="ICanvasEffectFactoryNative.CreateWrapper" path="/param[@name='resource']"/></param>
|
||||
private void InitializeFromNativeResource(ICanvasDevice* device, ID2D1Effect* resource)
|
||||
{
|
||||
using ComPtr<ID2D1Device1> d2D1Device1 = default;
|
||||
|
||||
// Get the underlying ID2D1Device1 instance for the input device
|
||||
device->GetD2DDevice(d2D1Device1.GetAddressOf()).Assert();
|
||||
|
||||
// Initialize the effect state
|
||||
device->CopyTo(ref this.canvasDevice).Assert();
|
||||
d2D1Device1.CopyTo(ref this.d2D1RealizationDevice).Assert();
|
||||
resource->CopyTo(ref this.d2D1Effect).Assert();
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする