Add ICanvasImageInterop raw binding type

このコミットが含まれているのは:
Sergio Pedri committed 2022-12-22 10:56:03 -08:00
1 親 a32fc9ec64
コミット c083fdc6ff
5ファイル変更
+64 -52

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

+1 -1
ファイルの表示
@@ -3,7 +3,7 @@ using System;
namespace ABI.Microsoft.Graphics.Canvas;
/// <summary>
/// Options for fine-tuning the behavior of <see cref="ICanvasImageInterop.GetD2DImage"/>.
/// Options for fine-tuning the behavior of <see cref="ICanvasImageInterop.Interface.GetD2DImage"/>.
/// </summary>
[Flags]
internal enum CanvasImageGetD2DImageFlags
+57 -44
ファイルの表示
@@ -1,60 +1,73 @@
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using TerraFX.Interop;
#pragma warning disable CS0649
namespace ABI.Microsoft.Graphics.Canvas;
/// <summary>
/// An interop Win2D interface for all images and effects that can be drawn.
/// </summary>
[ComImport]
[Guid("E042D1F7-F9AD-4479-A713-67627EA31863")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal unsafe interface ICanvasImageInterop
[NativeTypeName("class ICanvasImageInterop : IUnknown")]
[NativeInheritance("IUnknown")]
internal unsafe struct ICanvasImageInterop
{
/// <summary>
/// Gets the device that the effect is currently realized on, if any.
/// </summary>
/// <param name="device">The resulting device, if available ((as a marshalled <see cref="global::Microsoft.Graphics.Canvas.CanvasDevice"/>)).</param>
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
[PreserveSig]
[return: NativeTypeName("HRESULT")]
int GetDevice(ICanvasDevice** device);
public void** lpVtbl;
/// <summary>
/// Gets an <see cref="ID2D1Image"/> from an <see cref="ICanvasImageInterop"/> instance.
/// The <see cref="ComImportAttribute"/> implementation of <see cref="ICanvasImageInterop"/>.
/// </summary>
/// <param name="device">The input canvas device (as a marshalled <see cref="global::Microsoft.Graphics.Canvas.CanvasDevice"/>).</param>
/// <param name="deviceContext">
/// The device context in use. This value is is optional (but recommended), except when the
/// <see cref="CanvasImageGetD2DImageFlags.ReadDpiFromDeviceContext"/> flag is specified. This is because
/// not all callers of <see cref="GetD2DImage"/> have easy access to a context. It is always
/// possible to get a resource creation context from the device, but the context is only
/// actually necessary if a new effect realization needs to be created, so it is more efficient
/// to have the implementation do this lookup only if/when it turns out to be needed.
/// </param>
/// <param name="flags">The flags to use to get the image.</param>
/// <param name="targetDpi">
/// The DPI of the target device context. This is used to determine when a <c>D2D1DpiCompensation</c>
/// effect needs to be inserted. Behavior of this parameter can be overridden by the flag values
/// <see cref="CanvasImageGetD2DImageFlags.ReadDpiFromDeviceContext"/>, <see cref="CanvasImageGetD2DImageFlags.AlwaysInsertDpiCompensation"/>
/// or <see cref="CanvasImageGetD2DImageFlags.NeverInsertDpiCompensation"/>
/// </param>
/// <param name="realizeDpi">
/// The DPI of a source bitmap, or zero if the image does not have a fixed DPI. A <c>D2D1DpiCompensation</c> effect
/// will be inserted if <paramref name="targetDpi"/> and <paramref name="realizeDpi"/> are different (flags permitting).
/// </param>
/// <param name="ppImage">The resulting <see cref="ID2D1Image"/> for the effect.</param>
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
[PreserveSig]
[return: NativeTypeName("HRESULT")]
int GetD2DImage(
ICanvasDevice* device,
ID2D1DeviceContext* deviceContext,
CanvasImageGetD2DImageFlags flags,
float targetDpi,
float* realizeDpi,
ID2D1Image** ppImage);
[ComImport]
[Guid("E042D1F7-F9AD-4479-A713-67627EA31863")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface Interface
{
/// <summary>
/// Gets the device that the effect is currently realized on, if any.
/// </summary>
/// <param name="device">The resulting device, if available ((as a marshalled <see cref="global::Microsoft.Graphics.Canvas.CanvasDevice"/>)).</param>
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
[PreserveSig]
[return: NativeTypeName("HRESULT")]
int GetDevice(ICanvasDevice** device);
/// <summary>
/// Gets an <see cref="ID2D1Image"/> from an <see cref="ICanvasImageInterop.Interface"/> instance.
/// </summary>
/// <param name="device">The input canvas device (as a marshalled <see cref="global::Microsoft.Graphics.Canvas.CanvasDevice"/>).</param>
/// <param name="deviceContext">
/// The device context in use. This value is is optional (but recommended), except when the
/// <see cref="CanvasImageGetD2DImageFlags.ReadDpiFromDeviceContext"/> flag is specified. This is because
/// not all callers of <see cref="GetD2DImage"/> have easy access to a context. It is always
/// possible to get a resource creation context from the device, but the context is only
/// actually necessary if a new effect realization needs to be created, so it is more efficient
/// to have the implementation do this lookup only if/when it turns out to be needed.
/// </param>
/// <param name="flags">The flags to use to get the image.</param>
/// <param name="targetDpi">
/// The DPI of the target device context. This is used to determine when a <c>D2D1DpiCompensation</c>
/// effect needs to be inserted. Behavior of this parameter can be overridden by the flag values
/// <see cref="CanvasImageGetD2DImageFlags.ReadDpiFromDeviceContext"/>, <see cref="CanvasImageGetD2DImageFlags.AlwaysInsertDpiCompensation"/>
/// or <see cref="CanvasImageGetD2DImageFlags.NeverInsertDpiCompensation"/>
/// </param>
/// <param name="realizeDpi">
/// The DPI of a source bitmap, or zero if the image does not have a fixed DPI. A <c>D2D1DpiCompensation</c> effect
/// will be inserted if <paramref name="targetDpi"/> and <paramref name="realizeDpi"/> are different (flags permitting).
/// </param>
/// <param name="ppImage">The resulting <see cref="ID2D1Image"/> for the effect.</param>
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
[PreserveSig]
[return: NativeTypeName("HRESULT")]
int GetD2DImage(
ICanvasDevice* device,
ID2D1DeviceContext* deviceContext,
CanvasImageGetD2DImageFlags flags,
float targetDpi,
float* realizeDpi,
ID2D1Image** ppImage);
}
}
@@ -49,9 +49,8 @@ internal unsafe struct ICanvasResourceWrapperNative
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(3)]
[return: NativeTypeName("HRESULT")]
public HRESULT GetNativeResource([NativeTypeName("ICanvasDevice*")] void* device, float dpi, [NativeTypeName("REFIID")] Guid* iid, void** resource)
public HRESULT GetNativeResource(ICanvasDevice* device, float dpi, [NativeTypeName("REFIID")] Guid* iid, void** resource)
{
return ((delegate* unmanaged[Stdcall]<ICanvasResourceWrapperNative*, void*, float, Guid*, void**, int>)this.lpVtbl[3])((ICanvasResourceWrapperNative*)Unsafe.AsPointer(ref this), device, dpi, iid, resource);
return ((delegate* unmanaged[Stdcall]<ICanvasResourceWrapperNative*, ICanvasDevice*, float, Guid*, void**, int>)this.lpVtbl[3])((ICanvasResourceWrapperNative*)Unsafe.AsPointer(ref this), device, dpi, iid, resource);
}
}
+2 -2
ファイルの表示
@@ -16,7 +16,7 @@ namespace ComputeSharp.D2D1.Uwp;
unsafe partial class PixelShaderEffect<T>
{
/// <inheritdoc/>
int ICanvasImageInterop.GetDevice(ICanvasDevice** device)
int ICanvasImageInterop.Interface.GetDevice(ICanvasDevice** device)
{
using ReferenceTracker.Lease _0 = GetReferenceTracker().TryGetLease(out bool leaseTaken);
@@ -49,7 +49,7 @@ unsafe partial class PixelShaderEffect<T>
}
/// <inheritdoc/>
int ICanvasImageInterop.GetD2DImage(
int ICanvasImageInterop.Interface.GetD2DImage(
ICanvasDevice* device,
ID2D1DeviceContext* deviceContext,
CanvasImageGetD2DImageFlags flags,
+2 -2
ファイルの表示
@@ -10,7 +10,7 @@ namespace ComputeSharp.D2D1.Uwp;
/// A custom <see cref="ICanvasImage"/> implementation powered by a supplied shader type.
/// </summary>
/// <typeparam name="T">The type of shader to use to render frames.</typeparam>
public sealed partial class PixelShaderEffect<T> : IReferenceTrackedObject, ICanvasImage, ICanvasImageInterop
public sealed partial class PixelShaderEffect<T> : IReferenceTrackedObject, ICanvasImage, ICanvasImageInterop.Interface
where T : unmanaged, ID2D1PixelShader
{
/// <summary>
@@ -24,7 +24,7 @@ public sealed partial class PixelShaderEffect<T> : IReferenceTrackedObject, ICan
private readonly object lockObject = new();
/// <summary>
/// Flag to track whether a given call is recursively invoked by <see cref="ICanvasImageInterop.GetD2DImage"/>, to avoid graph cycles.
/// Flag to track whether a given call is recursively invoked by <see cref="ICanvasImageInterop.Interface.GetD2DImage"/>, to avoid graph cycles.
/// </summary>
private volatile int isInsideGetD2DImage;