Make ICanvasEffectFactoryNative bindings AOT safe
このコミットが含まれているのは:
1 親
736610e741
コミット
f1fc6a8410
3ファイル変更
+107
-86
検索条件に一致するファイルはありません
+101
-82
@@ -8,105 +8,124 @@ using IInspectable = ComputeSharp.Win32.IInspectable;
|
||||
|
||||
#pragma warning disable CS0649, IDE0055, IDE1006
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// The interop Win2D interface for factories of external effects.
|
||||
/// </summary>
|
||||
[NativeTypeName("class ICanvasEffectFactoryNative : IUnknown")]
|
||||
[NativeInheritance("IUnknown")]
|
||||
internal unsafe struct ICanvasEffectFactoryNative : IComObject
|
||||
namespace ABI.Microsoft.Graphics.Canvas
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
static Guid* IComObject.IID
|
||||
/// <summary>
|
||||
/// The interop Win2D interface for factories of external effects.
|
||||
/// </summary>
|
||||
[NativeTypeName("class ICanvasEffectFactoryNative : IUnknown")]
|
||||
[NativeInheritance("IUnknown")]
|
||||
internal unsafe struct ICanvasEffectFactoryNative : IComObject
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
/// <inheritdoc/>
|
||||
public static Guid* IID
|
||||
{
|
||||
ReadOnlySpan<byte> data =
|
||||
[
|
||||
0x1F, 0x1A, 0xBA, 0x29,
|
||||
0xFE, 0x1C,
|
||||
0xC3, 0x44,
|
||||
0x98, 0x4D,
|
||||
0x42,
|
||||
0x6D,
|
||||
0x61,
|
||||
0xB5,
|
||||
0x14,
|
||||
0x27
|
||||
];
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
ReadOnlySpan<byte> data =
|
||||
[
|
||||
0x1F, 0x1A, 0xBA, 0x29,
|
||||
0xFE, 0x1C,
|
||||
0xC3, 0x44,
|
||||
0x98, 0x4D,
|
||||
0x42,
|
||||
0x6D,
|
||||
0x61,
|
||||
0xB5,
|
||||
0x14,
|
||||
0x27
|
||||
];
|
||||
|
||||
return (Guid*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data));
|
||||
return (Guid*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data));
|
||||
}
|
||||
}
|
||||
|
||||
public void** lpVtbl;
|
||||
|
||||
/// <inheritdoc cref="IUnknown.QueryInterface"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(0)]
|
||||
public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject)
|
||||
{
|
||||
return ((delegate* unmanaged[MemberFunction]<ICanvasEffectFactoryNative*, Guid*, void**, int>)this.lpVtbl[0])((ICanvasEffectFactoryNative*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[MemberFunction]<ICanvasEffectFactoryNative*, uint>)this.lpVtbl[1])((ICanvasEffectFactoryNative*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[MemberFunction]<ICanvasEffectFactoryNative*, uint>)this.lpVtbl[2])((ICanvasEffectFactoryNative*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// <param name="dpi">The realization DPIs for <paramref name="resource"/>.</param>
|
||||
/// <param name="wrapper">The resulting wrapper for <paramref name="resource"/>.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
/// <remarks>
|
||||
/// All parameters are directly forwarded from the ones the caller passed to <see cref="ICanvasFactoryNative.GetOrCreate"/>. The returned
|
||||
/// wrapper should implement <see cref="global::Microsoft.Graphics.Canvas.ICanvasImage"/> to be returned correctly from Win2D after this call.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(3)]
|
||||
public HRESULT CreateWrapper(ICanvasDevice* device, ID2D1Effect* resource, float dpi, IInspectable** wrapper)
|
||||
{
|
||||
return ((delegate* unmanaged[MemberFunction]<ICanvasEffectFactoryNative*, ICanvasDevice*, ID2D1Effect*, float, IInspectable**, int>)this.lpVtbl[3])(
|
||||
(ICanvasEffectFactoryNative*)Unsafe.AsPointer(ref this),
|
||||
device,
|
||||
resource,
|
||||
dpi,
|
||||
wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
public void** lpVtbl;
|
||||
|
||||
/// <inheritdoc cref="IUnknown.QueryInterface"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(0)]
|
||||
public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject)
|
||||
{
|
||||
return ((delegate* unmanaged[MemberFunction]<ICanvasEffectFactoryNative*, Guid*, void**, int>)this.lpVtbl[0])((ICanvasEffectFactoryNative*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[MemberFunction]<ICanvasEffectFactoryNative*, uint>)this.lpVtbl[1])((ICanvasEffectFactoryNative*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[MemberFunction]<ICanvasEffectFactoryNative*, uint>)this.lpVtbl[2])((ICanvasEffectFactoryNative*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new inspectable wrapper for an input D2D effect previosly registered through <see cref="ICanvasFactoryNative.RegisterEffectFactory"/>.
|
||||
/// The ABI methods for <see cref="ICanvasEffectFactoryNative"/>.
|
||||
/// </summary>
|
||||
/// <param name="device">The input canvas device.</param>
|
||||
/// <param name="resource">The input native effect to create a wrapper for.</param>
|
||||
/// <param name="dpi">The realization DPIs for <paramref name="resource"/>.</param>
|
||||
/// <param name="wrapper">The resulting wrapper for <paramref name="resource"/>.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
/// <remarks>
|
||||
/// All parameters are directly forwarded from the ones the caller passed to <see cref="ICanvasFactoryNative.GetOrCreate"/>. The returned
|
||||
/// wrapper should implement <see cref="global::Microsoft.Graphics.Canvas.ICanvasImage"/> to be returned correctly from Win2D after this call.
|
||||
/// </remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(3)]
|
||||
public HRESULT CreateWrapper(ICanvasDevice* device, ID2D1Effect* resource, float dpi, IInspectable** wrapper)
|
||||
[Guid("E042D1F7-F9AD-4479-A713-67627EA31863")]
|
||||
internal static unsafe class ICanvasEffectFactoryNativeMethods
|
||||
{
|
||||
return ((delegate* unmanaged[MemberFunction]<ICanvasEffectFactoryNative*, ICanvasDevice*, ID2D1Effect*, float, IInspectable**, int>)this.lpVtbl[3])(
|
||||
(ICanvasEffectFactoryNative*)Unsafe.AsPointer(ref this),
|
||||
device,
|
||||
resource,
|
||||
dpi,
|
||||
wrapper);
|
||||
/// <inheritdoc cref="ICanvasEffectFactoryNative.IID"/>
|
||||
public static Guid IID => *ICanvasEffectFactoryNative.IID;
|
||||
|
||||
/// <inheritdoc cref="global::Microsoft.Graphics.Canvas.ICanvasEffectFactoryNative.Vftbl.AbiToProjectionVftablePtr"/>
|
||||
public static IntPtr AbiToProjectionVftablePtr => global::Microsoft.Graphics.Canvas.ICanvasEffectFactoryNative.Vftbl.AbiToProjectionVftablePtr;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Microsoft.Graphics.Canvas
|
||||
{
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// The managed implementation of <see cref="ICanvasEffectFactoryNative"/>.
|
||||
/// The managed implementation of <see cref="ABI.Microsoft.Graphics.Canvas.ICanvasEffectFactoryNative"/>.
|
||||
/// </summary>
|
||||
[Guid("29BA1A1F-1CFE-44C3-984D-426D61B51427")]
|
||||
[WindowsRuntimeType]
|
||||
[WindowsRuntimeHelperType(typeof(Interface))]
|
||||
public interface Interface
|
||||
[WindowsRuntimeHelperType(typeof(ICanvasEffectFactoryNative))]
|
||||
internal unsafe interface ICanvasEffectFactoryNative
|
||||
{
|
||||
/// <inheritdoc cref="ICanvasEffectFactoryNative.CreateWrapper"/>
|
||||
/// <inheritdoc cref="ABI.Microsoft.Graphics.Canvas.ICanvasEffectFactoryNative.CreateWrapper"/>
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
int CreateWrapper(ICanvasDevice* device, ID2D1Effect* resource, float dpi, IInspectable** wrapper);
|
||||
|
||||
/// <summary>
|
||||
/// The vtable type for <see cref="Interface"/>.
|
||||
/// The vtable type for <see cref="ICanvasEffectFactoryNative"/>.
|
||||
/// </summary>
|
||||
[Guid("29BA1A1F-1CFE-44C3-984D-426D61B51427")]
|
||||
public struct Vftbl
|
||||
@@ -117,9 +136,9 @@ internal unsafe struct ICanvasEffectFactoryNative : IComObject
|
||||
public static readonly IntPtr AbiToProjectionVftablePtr = InitVtbl();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the custom method table pointer for <see cref="Interface"/>.
|
||||
/// Builds the custom method table pointer for <see cref="ICanvasEffectFactoryNative"/>.
|
||||
/// </summary>
|
||||
/// <returns>The method table pointer for <see cref="Interface"/>.</returns>
|
||||
/// <returns>The method table pointer for <see cref="ICanvasEffectFactoryNative"/>.</returns>
|
||||
private static IntPtr InitVtbl()
|
||||
{
|
||||
Vftbl* lpVtbl = (Vftbl*)ComWrappersSupport.AllocateVtableMemory(typeof(Vftbl), sizeof(Vftbl));
|
||||
@@ -140,14 +159,14 @@ internal unsafe struct ICanvasEffectFactoryNative : IComObject
|
||||
/// </summary>
|
||||
private delegate* unmanaged[MemberFunction]<IntPtr, ICanvasDevice*, ID2D1Effect*, float, IInspectable**, int> CreateWrapper;
|
||||
|
||||
/// <inheritdoc cref="Interface.CreateWrapper"/>
|
||||
/// <inheritdoc cref="ICanvasEffectFactoryNative.CreateWrapper"/>
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvMemberFunction)])]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
private static int CreateWrapperFromAbi(IntPtr thisPtr, ICanvasDevice* device, ID2D1Effect* resource, float dpi, IInspectable** wrapper)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ComWrappersSupport.FindObject<Interface>(thisPtr).CreateWrapper(device, resource, dpi, wrapper);
|
||||
return ComWrappersSupport.FindObject<ICanvasEffectFactoryNative>(thisPtr).CreateWrapper(device, resource, dpi, wrapper);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using WinRT;
|
||||
namespace ComputeSharp.D2D1.WinUI.Helpers;
|
||||
|
||||
using CanvasDevice = Microsoft.Graphics.Canvas.CanvasDevice;
|
||||
using ICanvasEffectFactoryNative = Microsoft.Graphics.Canvas.ICanvasEffectFactoryNative;
|
||||
using IInspectable = Win32.IInspectable;
|
||||
|
||||
/// <summary>
|
||||
@@ -86,13 +87,13 @@ internal static unsafe class ResourceManager
|
||||
/// </summary>
|
||||
/// <param name="effectId">The id of the effects to register a factory for.</param>
|
||||
/// <param name="factory">The input factory to create wrappers of native effects.</param>
|
||||
public static void RegisterEffectFactory(Guid effectId, ICanvasEffectFactoryNative.Interface factory)
|
||||
public static void RegisterEffectFactory(Guid effectId, ICanvasEffectFactoryNative factory)
|
||||
{
|
||||
using ComPtr<ICanvasFactoryNative> canvasFactoryNative = default;
|
||||
|
||||
GetActivationFactory(canvasFactoryNative.GetAddressOf());
|
||||
|
||||
using ComPtr<ICanvasEffectFactoryNative> canvasEffectFactoryNative = default;
|
||||
using ComPtr<ABI.Microsoft.Graphics.Canvas.ICanvasEffectFactoryNative> canvasEffectFactoryNative = default;
|
||||
|
||||
RcwMarshaller.GetNativeInterface(factory, canvasEffectFactoryNative.GetAddressOf()).Assert();
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.WinUI.Extensions;
|
||||
using ComputeSharp.D2D1.WinUI.Helpers;
|
||||
using ComputeSharp.Win32;
|
||||
using ICanvasEffectFactoryNative = Microsoft.Graphics.Canvas.ICanvasEffectFactoryNative;
|
||||
|
||||
namespace ComputeSharp.D2D1.WinUI;
|
||||
|
||||
@@ -74,10 +75,10 @@ unsafe partial class PixelShaderEffect<T>
|
||||
/// <summary>
|
||||
/// A managed implementation of <see cref="ICanvasEffectFactoryNative"/> for <see cref="PixelShaderEffect{T}"/>.
|
||||
/// </summary>
|
||||
private sealed class EffectFactory : ICanvasEffectFactoryNative.Interface
|
||||
private sealed class EffectFactory : ICanvasEffectFactoryNative
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
int ICanvasEffectFactoryNative.Interface.CreateWrapper(ICanvasDevice* device, ID2D1Effect* resource, float dpi, IInspectable** wrapper)
|
||||
int ICanvasEffectFactoryNative.CreateWrapper(ICanvasDevice* device, ID2D1Effect* resource, float dpi, IInspectable** wrapper)
|
||||
{
|
||||
PixelShaderEffect<T> @this;
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする