Move ComputeSharp.D2D1.Uwp code into shared project
このコミットが含まれているのは:
1 親
92222aafa9
コミット
1bcf612cea
40ファイル変更
+71
-6
検索条件に一致するファイルはありません
@@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649, IDE1006
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// The native WinRT interface for <see cref="global::Microsoft.Graphics.Canvas.CanvasDevice"/> objects.
|
||||
/// </summary>
|
||||
[Guid("A27F0B5D-EC2C-4D4F-948F-0AA1E95E33E6")]
|
||||
[NativeTypeName("class ICanvasDevice : IInspectable")]
|
||||
[NativeInheritance("IInspectable")]
|
||||
internal unsafe struct ICanvasDevice
|
||||
{
|
||||
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[Stdcall]<ICanvasResourceWrapperNative*, Guid*, void**, int>)this.lpVtbl[0])((ICanvasResourceWrapperNative*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasResourceWrapperNative*, uint>)this.lpVtbl[1])((ICanvasResourceWrapperNative*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasResourceWrapperNative*, uint>)this.lpVtbl[2])((ICanvasResourceWrapperNative*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649, IDE1006
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas.Effects;
|
||||
|
||||
/// <summary>
|
||||
/// The native WinRT interface for <see cref="global::Microsoft.Graphics.Canvas.Effects.ICanvasEffect"/> objects.
|
||||
/// </summary>
|
||||
[Guid("0EF96F8C-9B5E-4BF0-A399-AAD8CE53DB55")]
|
||||
[NativeTypeName("class ICanvasEffect : IInspectable")]
|
||||
[NativeInheritance("IInspectable")]
|
||||
internal unsafe struct ICanvasEffect
|
||||
{
|
||||
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[Stdcall]<ICanvasEffect*, Guid*, void**, int>)this.lpVtbl[0])((ICanvasEffect*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasEffect*, uint>)this.lpVtbl[1])((ICanvasEffect*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasEffect*, uint>)this.lpVtbl[2])((ICanvasEffect*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649, IDE1006
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// The activation factory for <see cref="global::Microsoft.Graphics.Canvas.CanvasDevice"/>.
|
||||
/// </summary>
|
||||
[Guid("695C440D-04B3-4EDD-BFD9-63E51E9F7202")]
|
||||
[NativeTypeName("class ICanvasFactoryNative : public IInspectable")]
|
||||
[NativeInheritance("IInspectable")]
|
||||
internal unsafe struct ICanvasFactoryNative
|
||||
{
|
||||
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[Stdcall]<ICanvasResourceWrapperNative*, Guid*, void**, int>)this.lpVtbl[0])((ICanvasResourceWrapperNative*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasResourceWrapperNative*, uint>)this.lpVtbl[1])((ICanvasResourceWrapperNative*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasResourceWrapperNative*, uint>)this.lpVtbl[2])((ICanvasResourceWrapperNative*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or creates an <c>IInspectable</c> Win2D wrapper for a given native D2D resource.
|
||||
/// </summary>
|
||||
/// <param name="device">The input canvas device (as a marshalled <see cref="global::Microsoft.Graphics.Canvas.CanvasDevice"/>).</param>
|
||||
/// <param name="resource">The input native resource 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>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(6)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public HRESULT GetOrCreate(ICanvasDevice* device, IUnknown* resource, float dpi, [NativeTypeName("IInspectable**")] void** wrapper)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasFactoryNative*, ICanvasDevice*, IUnknown*, float, void**, int>)this.lpVtbl[6])(
|
||||
(ICanvasFactoryNative*)Unsafe.AsPointer(ref this),
|
||||
device,
|
||||
resource,
|
||||
dpi,
|
||||
wrapper);
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using TerraFX.Interop;
|
||||
|
||||
#pragma warning disable CS0649, IDE1006
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// An interop Win2D interface for all images and effects that can be drawn.
|
||||
/// </summary>
|
||||
[Guid("E042D1F7-F9AD-4479-A713-67627EA31863")]
|
||||
[NativeTypeName("class ICanvasImageInterop : IUnknown")]
|
||||
[NativeInheritance("IUnknown")]
|
||||
internal unsafe struct ICanvasImageInterop
|
||||
{
|
||||
public void** lpVtbl;
|
||||
|
||||
/// <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>
|
||||
/// <param name="type">The <see cref="WIN2D_GET_DEVICE_ASSOCIATION_TYPE"/> value describing the returned instance.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(3)]
|
||||
public HRESULT GetDevice(ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasImageInterop*, ICanvasDevice**, WIN2D_GET_DEVICE_ASSOCIATION_TYPE*, int>)this.lpVtbl[3])((ICanvasImageInterop*)Unsafe.AsPointer(ref this), device, type);
|
||||
}
|
||||
|
||||
/// <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="WIN2D_GET_D2D_IMAGE_FLAGS.WIN2D_GET_D2D_IMAGE_FLAGS_READ_DPI_FROM_DEVICE_CONTEXT"/> 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="WIN2D_GET_D2D_IMAGE_FLAGS.WIN2D_GET_D2D_IMAGE_FLAGS_READ_DPI_FROM_DEVICE_CONTEXT"/>,
|
||||
/// <see cref="WIN2D_GET_D2D_IMAGE_FLAGS.WIN2D_GET_D2D_IMAGE_FLAGS_ALWAYS_INSERT_DPI_COMPENSATION"/>
|
||||
/// or <see cref="WIN2D_GET_D2D_IMAGE_FLAGS.WIN2D_GET_D2D_IMAGE_FLAGS_NEVER_INSERT_DPI_COMPENSATION"/>
|
||||
/// </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>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(4)]
|
||||
public HRESULT GetD2DImage(
|
||||
ICanvasDevice* device,
|
||||
ID2D1DeviceContext* deviceContext,
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS flags,
|
||||
float targetDpi,
|
||||
float* realizeDpi,
|
||||
ID2D1Image** ppImage)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasImageInterop*, ICanvasDevice*, ID2D1DeviceContext*, WIN2D_GET_D2D_IMAGE_FLAGS, float, float*, ID2D1Image**, int>)this.lpVtbl[4])(
|
||||
(ICanvasImageInterop*)Unsafe.AsPointer(ref this),
|
||||
device,
|
||||
deviceContext,
|
||||
flags,
|
||||
targetDpi,
|
||||
realizeDpi,
|
||||
ppImage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ComImportAttribute"/> implementation of <see cref="ICanvasImageInterop"/>.
|
||||
/// </summary>
|
||||
[ComImport]
|
||||
[Guid("E042D1F7-F9AD-4479-A713-67627EA31863")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface Interface
|
||||
{
|
||||
/// <inheritdoc cref="ICanvasImageInterop.GetDevice"/>
|
||||
[PreserveSig]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
int GetDevice(ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type);
|
||||
|
||||
/// <inheritdoc cref="ICanvasImageInterop.GetD2DImage"/>
|
||||
[PreserveSig]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
int GetD2DImage(
|
||||
ICanvasDevice* device,
|
||||
ID2D1DeviceContext* deviceContext,
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS flags,
|
||||
float targetDpi,
|
||||
float* realizeDpi,
|
||||
ID2D1Image** ppImage);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649, IDE1006
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// The native WinRT interface for <see cref="global::Microsoft.Graphics.Canvas.ICanvasResourceCreator"/> objects.
|
||||
/// </summary>
|
||||
[Guid("8F6D8AA8-492F-4BC6-B3D0-E7F5EAE84B11")]
|
||||
[NativeTypeName("class ICanvasResourceCreator : IInspectable")]
|
||||
[NativeInheritance("IInspectable")]
|
||||
internal unsafe struct ICanvasResourceCreator
|
||||
{
|
||||
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[Stdcall]<ICanvasResourceCreator*, Guid*, void**, int>)this.lpVtbl[0])((ICanvasResourceCreator*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasResourceCreator*, uint>)this.lpVtbl[1])((ICanvasResourceCreator*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasResourceCreator*, uint>)this.lpVtbl[2])((ICanvasResourceCreator*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649, IDE1006
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// The native WinRT interface for <see cref="global::Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi"/> objects.
|
||||
/// </summary>
|
||||
[Guid("1A75B512-E9FA-49E6-A876-38CAE194013E")]
|
||||
[NativeTypeName("class ICanvasResourceCreatorWithDpi : IInspectable")]
|
||||
[NativeInheritance("IInspectable")]
|
||||
internal unsafe struct ICanvasResourceCreatorWithDpi
|
||||
{
|
||||
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[Stdcall]<ICanvasResourceCreatorWithDpi*, Guid*, void**, int>)this.lpVtbl[0])((ICanvasResourceCreatorWithDpi*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasResourceCreatorWithDpi*, uint>)this.lpVtbl[1])((ICanvasResourceCreatorWithDpi*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasResourceCreatorWithDpi*, uint>)this.lpVtbl[2])((ICanvasResourceCreatorWithDpi*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649, IDE1006
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// An interop wrapper type for Win2D objects (see <see href="https://microsoft.github.io/Win2D/WinUI3/html/Interop.htm"/>).
|
||||
/// </summary>
|
||||
[Guid("5F10688D-EA55-4D55-A3B0-4DDB55C0C20A")]
|
||||
[NativeTypeName("class ICanvasResourceWrapperNative : IUnknown")]
|
||||
[NativeInheritance("IUnknown")]
|
||||
internal unsafe struct ICanvasResourceWrapperNative
|
||||
{
|
||||
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[Stdcall]<ICanvasResourceWrapperNative*, Guid*, void**, int>)this.lpVtbl[0])((ICanvasResourceWrapperNative*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasResourceWrapperNative*, uint>)this.lpVtbl[1])((ICanvasResourceWrapperNative*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasResourceWrapperNative*, uint>)this.lpVtbl[2])((ICanvasResourceWrapperNative*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface provided by various Win2D objects that is able to retrieve the wrapped resource.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(3)]
|
||||
public HRESULT GetNativeResource(ICanvasDevice* device, float dpi, [NativeTypeName("REFIID")] Guid* iid, void** resource)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ICanvasResourceWrapperNative*, ICanvasDevice*, float, Guid*, void**, int>)this.lpVtbl[3])((ICanvasResourceWrapperNative*)Unsafe.AsPointer(ref this), device, dpi, iid, resource);
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649, IDE1006
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// An interface for a COM object that provides access to a pooled <see cref="ID2D1DeviceContext"/> object.
|
||||
/// </summary>
|
||||
[Guid("A0928F38-F7D5-44DD-A5C9-E23D94734BBB")]
|
||||
[NativeTypeName("class ID2D1DeviceContextLease : IUnknown")]
|
||||
[NativeInheritance("IUnknown")]
|
||||
internal unsafe struct ID2D1DeviceContextLease
|
||||
{
|
||||
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[Stdcall]<ID2D1DeviceContextLease*, Guid*, void**, int>)this.lpVtbl[0])((ID2D1DeviceContextLease*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1DeviceContextLease*, uint>)this.lpVtbl[1])((ID2D1DeviceContextLease*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1DeviceContextLease*, uint>)this.lpVtbl[2])((ID2D1DeviceContextLease*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides access to the <see cref="ID2D1DeviceContext"/> object wrapped by the current instance.
|
||||
/// </summary>
|
||||
/// <param name="deviceContext">The resulting <see cref="ID2D1DeviceContext"/> object wrapped by the current instance.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
/// <remarks>The returned <see cref="ID2D1DeviceContext"/> cannot be used once the owning lease has been released.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(3)]
|
||||
public HRESULT GetD2DDeviceContext(ID2D1DeviceContext** deviceContext)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1DeviceContextLease*, ID2D1DeviceContext**, int>)this.lpVtbl[3])((ID2D1DeviceContextLease*)Unsafe.AsPointer(ref this), deviceContext);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649, IDE1006
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// An interface for an object that provides access to pooled <see cref="TerraFX.Interop.DirectX.ID2D1DeviceContext"/> objects.
|
||||
/// </summary>
|
||||
[Guid("454A82A1-F024-40DB-BD5B-8F527FD58AD0")]
|
||||
[NativeTypeName("class ID2D1DeviceContextPool : IUnknown")]
|
||||
[NativeInheritance("IUnknown")]
|
||||
internal unsafe struct ID2D1DeviceContextPool
|
||||
{
|
||||
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[Stdcall]<ID2D1DeviceContextPool*, Guid*, void**, int>)this.lpVtbl[0])((ID2D1DeviceContextPool*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1DeviceContextPool*, uint>)this.lpVtbl[1])((ID2D1DeviceContextPool*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1DeviceContextPool*, uint>)this.lpVtbl[2])((ID2D1DeviceContextPool*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a new <see cref="ID2D1DeviceContextLease"/> object from the current instance.
|
||||
/// </summary>
|
||||
/// <param name="lease">The resulting <see cref="ID2D1DeviceContextLease"/> object to use.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(3)]
|
||||
public HRESULT GetDeviceContextLease(ID2D1DeviceContextLease** lease)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1DeviceContextPool*, ID2D1DeviceContextLease**, int>)this.lpVtbl[3])((ID2D1DeviceContextPool*)Unsafe.AsPointer(ref this), lease);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// Options for fine-tuning the behavior of <see cref="ICanvasImageInterop.Interface.GetD2DImage"/>.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
internal enum WIN2D_GET_D2D_IMAGE_FLAGS : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// No options specified.
|
||||
/// </summary>
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_NONE = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Ignore the <c>targetDpi</c> parameter, read DPI from <c>deviceContext</c> instead.
|
||||
/// </summary>
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_READ_DPI_FROM_DEVICE_CONTEXT = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Ignore the <c>targetDpi</c> parameter, always insert DPI compensation.
|
||||
/// </summary>
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_ALWAYS_INSERT_DPI_COMPENSATION = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Ignore the <c>targetDpi</c> parameter, never insert DPI compensation.
|
||||
/// </summary>
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_NEVER_INSERT_DPI_COMPENSATION = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Do the bare minimum to get back an <c>ID2D1Image</c>, no validation or recursive realization.
|
||||
/// </summary>
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_MINIMAL_REALIZATION = 8,
|
||||
|
||||
/// <summary>
|
||||
/// Allow partially configured effect graphs where some inputs are <see langword="null"/>.
|
||||
/// </summary>
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_ALLOW_NULL_EFFECT_INPUTS = 16,
|
||||
|
||||
/// <summary>
|
||||
/// If an input is invalid, unrealize the effect and set the output image to <see langword="null"/>.
|
||||
/// </summary>
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE = 32,
|
||||
|
||||
/// <summary>
|
||||
/// Ignored.
|
||||
/// </summary>
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_FORCE_DWORD = 0xFFFFFFFF
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// Options for fine-tuning the behavior of <see cref="ICanvasImageInterop.Interface.GetDevice"/>.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
internal enum WIN2D_GET_DEVICE_ASSOCIATION_TYPE : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// No device info is available, callers will handle the returned device with their own logic.
|
||||
/// </summary>
|
||||
WIN2D_GET_DEVICE_ASSOCIATION_TYPE_UNSPECIFIED = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The returned device is the one the image is currently realized on, if any.
|
||||
/// </summary>
|
||||
WIN2D_GET_DEVICE_ASSOCIATION_TYPE_REALIZATION_DEVICE = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The returned device is the one that created the image resource, and cannot change.
|
||||
/// </summary>
|
||||
WIN2D_GET_DEVICE_ASSOCIATION_TYPE_CREATION_DEVICE = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Ignored.
|
||||
/// </summary>
|
||||
WIN2D_GET_DEVICE_ASSOCIATION_TYPE_FORCE_DWORD = 0xFFFFFFFF
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using ABI.Microsoft.Graphics.Canvas.Effects;
|
||||
using TerraFX.Interop;
|
||||
using Windows.Foundation;
|
||||
|
||||
namespace ABI.Microsoft.Graphics.Canvas;
|
||||
|
||||
/// <summary>
|
||||
/// Native APIs from <c>Microsoft.Graphics.Canvas</c> (ie. Win2D).
|
||||
/// </summary>
|
||||
internal static unsafe class Win2D
|
||||
{
|
||||
/// <summary>
|
||||
/// Calculates the bounds for a given <see cref="ICanvasImageInterop"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="resourceCreator">The <see cref="ICanvasResourceCreator"/> object in use.</param>
|
||||
/// <param name="image">The input <see cref="ICanvasImageInterop"/> instance to compute the bounds for.</param>
|
||||
/// <param name="transform">The transform to use (optional).</param>
|
||||
/// <param name="rect">The resulting bounds.</param>
|
||||
/// <returns>The <see cref="TerraFX.Interop.Windows.HRESULT"/> for the operation.</returns>
|
||||
[DllImport("Microsoft.Graphics.Canvas.dll", PreserveSig = true, ExactSpelling = true)]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
public static extern int GetBoundsForICanvasImageInterop(
|
||||
ICanvasResourceCreator* resourceCreator,
|
||||
ICanvasImageInterop* image,
|
||||
[NativeTypeName("Windows::Foundation::Numerics::Matrix3x2 const*")] Matrix3x2* transform,
|
||||
Rect* rect);
|
||||
|
||||
/// <summary>
|
||||
/// Implements support for <see cref="global::Microsoft.Graphics.Canvas.Effects.ICanvasEffect.InvalidateSourceRectangle"/> for an external <see cref="ICanvasImageInterop"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="resourceCreator">The input <see cref="ICanvasResourceCreatorWithDpi"/> instance to use to perform the operation.</param>
|
||||
/// <param name="image">The target <see cref="ICanvasImageInterop"/> instance to execute the operation upon.</param>
|
||||
/// <param name="sourceIndex">The input index to invalidate.</param>
|
||||
/// <param name="invalidRectangle">The rectangle to invalidate.</param>
|
||||
/// <returns>The <see cref="TerraFX.Interop.Windows.HRESULT"/> for the operation.</returns>
|
||||
[DllImport("Microsoft.Graphics.Canvas.dll", PreserveSig = true, ExactSpelling = true)]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
public static extern int InvalidateSourceRectangleForICanvasImageInterop(
|
||||
ICanvasResourceCreatorWithDpi* resourceCreator,
|
||||
ICanvasImageInterop* image,
|
||||
uint sourceIndex,
|
||||
[NativeTypeName("Windows::Foundation::Rect const*")] Rect* invalidRectangle);
|
||||
|
||||
/// <summary>
|
||||
/// Implements support for <see cref="global::Microsoft.Graphics.Canvas.Effects.ICanvasEffect.GetInvalidRectangles"/> for an external <see cref="ICanvasImageInterop"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="resourceCreator">The input <see cref="ICanvasResourceCreatorWithDpi"/> instance to use to perform the operation.</param>
|
||||
/// <param name="image">The target <see cref="ICanvasImageInterop"/> instance to execute the operation upon.</param>
|
||||
/// <param name="valueCount">The resulting length of the COM array returned via <paramref name="valueElements"/>.</param>
|
||||
/// <param name="valueElements">The COM array with the sequence of invalid rectangles for the effect.</param>
|
||||
/// <returns>The <see cref="TerraFX.Interop.Windows.HRESULT"/> for the operation.</returns>
|
||||
[DllImport("Microsoft.Graphics.Canvas.dll", PreserveSig = true, ExactSpelling = true)]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
public static extern int GetInvalidRectanglesForICanvasImageInterop(
|
||||
ICanvasResourceCreatorWithDpi* resourceCreator,
|
||||
ICanvasImageInterop* image,
|
||||
uint* valueCount,
|
||||
Rect** valueElements);
|
||||
|
||||
/// <summary>
|
||||
/// Implements support for <see cref="global::Microsoft.Graphics.Canvas.Effects.ICanvasEffect.GetRequiredSourceRectangle"/> and
|
||||
/// <see cref="global::Microsoft.Graphics.Canvas.Effects.ICanvasEffect.GetRequiredSourceRectangles"/> for an external <see cref="ICanvasImageInterop"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="resourceCreator">The input <see cref="ICanvasResourceCreatorWithDpi"/> instance to use to perform the operation.</param>
|
||||
/// <param name="image">The target <see cref="ICanvasImageInterop"/> instance to execute the operation upon.</param>
|
||||
/// <param name="outputRectangle">The portion of the output image whose inputs are being inspected.</param>
|
||||
/// <param name="sourceEffectCount">The length of the sequence of input effects.</param>
|
||||
/// <param name="sourceEffects">The sequence of input effects whose rectangles are being queries.</param>
|
||||
/// <param name="sourceIndexCount">The length of the sequence of indices for the input effects.</param>
|
||||
/// <param name="sourceIndices">The sequence of indices for the input effects.</param>
|
||||
/// <param name="sourceBoundsCount">The length of the sequence of bounds to consider.</param>
|
||||
/// <param name="sourceBounds">The sequence of bounds to consider in the resulting output.</param>
|
||||
/// <param name="valueCount">The number of elements provided in <paramref name="valueElements"/>.</param>
|
||||
/// <param name="valueElements">The sequence of resulting required rectangles to compute.</param>
|
||||
/// <returns>The <see cref="TerraFX.Interop.Windows.HRESULT"/> for the operation.</returns>
|
||||
[DllImport("Microsoft.Graphics.Canvas.dll", PreserveSig = true, ExactSpelling = true)]
|
||||
[return: NativeTypeName("HRESULT")]
|
||||
public static extern int GetRequiredSourceRectanglesForICanvasImageInterop(
|
||||
ICanvasResourceCreatorWithDpi* resourceCreator,
|
||||
ICanvasImageInterop* image,
|
||||
[NativeTypeName("Windows::Foundation::Rect const*")] Rect* outputRectangle,
|
||||
uint sourceEffectCount,
|
||||
[NativeTypeName("ABI::Microsoft::Graphics::Canvas::Effects::ICanvasEffect* const*")] ICanvasEffect** sourceEffects,
|
||||
uint sourceIndexCount,
|
||||
[NativeTypeName("uint32_t const*")] uint* sourceIndices,
|
||||
uint sourceBoundsCount,
|
||||
[NativeTypeName("Windows::Foundation::Rect const*")] Rect* sourceBounds,
|
||||
uint valueCount,
|
||||
Rect* valueElements);
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Windows.Graphics.Effects;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Buffers;
|
||||
|
||||
/// <summary>
|
||||
/// A fixed buffer type containing 16 <see cref="IGraphicsEffectSource"/> fields.
|
||||
/// </summary>
|
||||
internal struct GraphicsEffectSourceBuffer
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 0.
|
||||
/// </summary>
|
||||
public SourceReference Source0;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 1.
|
||||
/// </summary>
|
||||
public SourceReference Source1;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 2.
|
||||
/// </summary>
|
||||
public SourceReference Source2;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 3.
|
||||
/// </summary>
|
||||
public SourceReference Source3;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 4.
|
||||
/// </summary>
|
||||
public SourceReference Source4;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 5.
|
||||
/// </summary>
|
||||
public SourceReference Source5;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 6.
|
||||
/// </summary>
|
||||
public SourceReference Source6;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 7.
|
||||
/// </summary>
|
||||
public SourceReference Source7;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 8.
|
||||
/// </summary>
|
||||
public SourceReference Source8;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 9.
|
||||
/// </summary>
|
||||
public SourceReference Source9;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 10.
|
||||
/// </summary>
|
||||
public SourceReference Source10;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 11.
|
||||
/// </summary>
|
||||
public SourceReference Source11;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 12.
|
||||
/// </summary>
|
||||
public SourceReference Source12;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 13.
|
||||
/// </summary>
|
||||
public SourceReference Source13;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 14.
|
||||
/// </summary>
|
||||
public SourceReference Source14;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="SourceReference"/> instance at index 15.
|
||||
/// </summary>
|
||||
public SourceReference Source15;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="SourceReference"/> value at a given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the <see cref="SourceReference"/> value to get a reference to.</param>
|
||||
/// <returns>A reference to the <see cref="SourceReference"/> value at a given index.</returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is not a valid index for the current effect.</exception>
|
||||
[UnscopedRef]
|
||||
public ref SourceReference this[int index]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, 16);
|
||||
|
||||
ref SourceReference r0 = ref Unsafe.As<GraphicsEffectSourceBuffer, SourceReference>(ref this);
|
||||
ref SourceReference r1 = ref Unsafe.Add(ref r0, index);
|
||||
|
||||
return ref r1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Buffers;
|
||||
|
||||
/// <summary>
|
||||
/// A fixed buffer type containing 16 <see cref="D2D1ResourceTextureManager"/> fields.
|
||||
/// </summary>
|
||||
internal struct ResourceTextureManagerBuffer
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 0.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager0;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 1.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager1;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 2.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager2;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 3.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager3;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 4.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager4;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 5.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager5;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 6.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager6;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 7.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager7;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 8.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager8;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 9.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager9;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 10.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager10;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 11.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager11;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 12.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager12;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 13.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager13;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 14.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager14;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManager"/> instance at index 15.
|
||||
/// </summary>
|
||||
public D2D1ResourceTextureManager? ResourceTextureManager15;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="D2D1ResourceTextureManager"/> value at a given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the <see cref="D2D1ResourceTextureManager"/> value to get a reference to.</param>
|
||||
/// <returns>A reference to the <see cref="D2D1ResourceTextureManager"/> value at a given index.</returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is not a valid index for the current effect.</exception>
|
||||
[UnscopedRef]
|
||||
public ref D2D1ResourceTextureManager? this[int index]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, 16);
|
||||
|
||||
ref D2D1ResourceTextureManager? r0 = ref Unsafe.As<ResourceTextureManagerBuffer, D2D1ResourceTextureManager?>(ref this);
|
||||
ref D2D1ResourceTextureManager? r1 = ref Unsafe.Add(ref r0, index);
|
||||
|
||||
return ref r1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Uwp.Extensions;
|
||||
using ComputeSharp.D2D1.Uwp.Helpers;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using Windows.Graphics.Effects;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Buffers;
|
||||
|
||||
/// <summary>
|
||||
/// A wrapper type for an input <see cref="IGraphicsEffectSource"/> and its underlying native D2D images.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This type is meant to support these two common operations:
|
||||
/// <list type="bullet">
|
||||
/// <item>Look up a D2D resource from a property of some other D2D interface.</item>
|
||||
/// <item>Get a managed wrapper from a D2D interface.</item>
|
||||
/// </list>
|
||||
/// With this, the generated D2D objects can be associated with each original managed wrapper. Similarly,
|
||||
/// when the other way around is used, this type can also store the generated wrapper for future use.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This gives the following improvements:
|
||||
/// <list type="bullet">
|
||||
/// <item>Improved performance for the common case of repeated calls using the same D2D instance.</item>
|
||||
/// <item>Maintaining a reference to the wrapper avoids it being repeatedly released and recreated.</item>
|
||||
/// </list>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Just like with all other members of an effect, values in this object are considered authoritative when the
|
||||
/// effect is not realized, otherwise they just act as a cache to speedup the reverse managed wrapper lookups.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// For realized effects, <see cref="SourceReference"/> tracks both the <see cref="ID2D1Image"/> resource and its
|
||||
/// <see cref="IGraphicsEffectSource"/> wrapper (and optional <see cref="ID2D1Effect"/> being the DPI compensation effect,
|
||||
/// if one is needed. For unrealized effects, the resource is <see langword="null"/> and only the wrapper part is used.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
internal unsafe struct SourceReference : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ID2D1Image"/> produced by calling <see cref="ICanvasImageInterop.Interface.GetD2DImage"/>
|
||||
/// on the input managed wrapper used as source for the effect (ie. <see cref="graphicsEffectSourceWrapper"/>).
|
||||
/// </summary>
|
||||
private ComPtr<ID2D1Image> d2D1ImageSource;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID2D1Effect"/> for DPI compensation wrapping <see cref="d2D1ImageSource"/>, if needed.
|
||||
/// </summary>
|
||||
private ComPtr<ID2D1Effect> d2D1EffectDpiCompensation;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IGraphicsEffectSource"/> instance being a managed wrapper for the current effect input.
|
||||
/// </summary>
|
||||
private IGraphicsEffectSource? graphicsEffectSourceWrapper;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not this source ference has a DPI compensation effect.
|
||||
/// </summary>
|
||||
public readonly bool HasDpiCompensationEffect
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => this.d2D1EffectDpiCompensation.Get() is not null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ID2D1Effect"/> object for the DPI compensation effect used, if any.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="ID2D1Effect"/> object for the DPI compensation effect used, if any.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly ID2D1Effect* GetDpiCompensationEffect()
|
||||
{
|
||||
return this.d2D1EffectDpiCompensation.Get();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the DPI compensation effet being used,
|
||||
/// </summary>
|
||||
/// <param name="d2D1Effect"></param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetDpiCompensationEffect(ID2D1Effect* d2D1Effect)
|
||||
{
|
||||
this.d2D1EffectDpiCompensation.Dispose();
|
||||
|
||||
if (d2D1Effect is not null)
|
||||
{
|
||||
this.d2D1EffectDpiCompensation = new ComPtr<ID2D1Effect>(d2D1Effect);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IGraphicsEffectSource"/> instance being a managed wrapper for the current effect input.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="IGraphicsEffectSource"/> instance being a managed wrapper for the current effect input.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly IGraphicsEffectSource? GetWrapper()
|
||||
{
|
||||
return this.graphicsEffectSourceWrapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="IGraphicsEffectSource"/> instance being a managed wrapper for the current effect input.
|
||||
/// </summary>
|
||||
/// <param name="wrapper">The <see cref="IGraphicsEffectSource"/> instance being a managed wrapper for the current effect input.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetWrapper(IGraphicsEffectSource? wrapper)
|
||||
{
|
||||
this.d2D1ImageSource.Dispose();
|
||||
|
||||
this.graphicsEffectSourceWrapper = wrapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the wrapper and underlying realized resource for the current source reference.
|
||||
/// </summary>
|
||||
/// <param name="wrapper">The <see cref="IGraphicsEffectSource"/> instance being a managed wrapper for the current effect input.</param>
|
||||
/// <param name="d2D1Image">The underlying relized <see cref="ID2D1Image"/> instance for <paramref name="wrapper"/>.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetWrapperAndResource(IGraphicsEffectSource? wrapper, ID2D1Image* d2D1Image)
|
||||
{
|
||||
this.d2D1ImageSource.Dispose();
|
||||
|
||||
this.d2D1ImageSource = new ComPtr<ID2D1Image>(d2D1Image);
|
||||
this.graphicsEffectSourceWrapper = wrapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or creates an <see cref="IGraphicsEffectSource"/> wrapper for a given <see cref="ID2D1Image"/> object.
|
||||
/// </summary>
|
||||
/// <param name="canvasDevice">The input <see cref="ICanvasDevice"/> object the source effect is realized on.</param>
|
||||
/// <param name="d2D1Image">The input <see cref="ID2D1Image"/> object to get or create a wrapper for.</param>
|
||||
/// <returns>An <see cref="IGraphicsEffectSource"/> wrapper for a given <see cref="ID2D1Image"/> object.</returns>
|
||||
public IGraphicsEffectSource? GetOrCreateWrapper(ICanvasDevice* canvasDevice, ID2D1Image* d2D1Image)
|
||||
{
|
||||
// Check if there already is a matching managed wrapper for the input image
|
||||
if (!this.d2D1ImageSource.Get()->IsSameInstance(d2D1Image))
|
||||
{
|
||||
// If that's not the case, create a new wrapper if the input image is not null
|
||||
if (d2D1Image is not null)
|
||||
{
|
||||
this.graphicsEffectSourceWrapper = ResourceManager.GetOrCreate(
|
||||
device: canvasDevice,
|
||||
resource: (IUnknown*)d2D1Image,
|
||||
dpi: 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.graphicsEffectSourceWrapper = null;
|
||||
}
|
||||
|
||||
this.d2D1ImageSource = new ComPtr<ID2D1Image>(d2D1Image);
|
||||
}
|
||||
|
||||
return this.graphicsEffectSourceWrapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the underlying <see cref="ID2D1Image"/> resource, if needed.
|
||||
/// This is used after a potential re-realization of a lazily bound effect.
|
||||
/// </summary>
|
||||
/// <param name="d2D1Image">The input <see cref="ID2D1Image"/> object.</param>
|
||||
/// <returns>Whether the resource has changed or not.</returns>
|
||||
public bool UpdateResource(ID2D1Image* d2D1Image)
|
||||
{
|
||||
if (d2D1Image->IsSameInstance(this.d2D1ImageSource.Get()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.d2D1ImageSource.Dispose();
|
||||
this.d2D1ImageSource = new ComPtr<ID2D1Image>(d2D1Image);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
this.d2D1ImageSource.Dispose();
|
||||
this.d2D1EffectDpiCompensation.Dispose();
|
||||
this.graphicsEffectSourceWrapper = null;
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using Windows.Foundation;
|
||||
using ICanvasResourceCreator = Microsoft.Graphics.Canvas.ICanvasResourceCreator;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial class CanvasEffect
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public Rect GetBounds(ICanvasResourceCreator resourceCreator)
|
||||
{
|
||||
return GetCanvasImage().GetBounds(resourceCreator);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Rect GetBounds(ICanvasResourceCreator resourceCreator, Matrix3x2 transform)
|
||||
{
|
||||
return GetCanvasImage().GetBounds(resourceCreator, transform);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe int ICanvasImageInterop.Interface.GetDevice(ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type)
|
||||
{
|
||||
using ComPtr<ICanvasImageInterop> canvasImageInterop = default;
|
||||
|
||||
GetCanvasImageInterop(canvasImageInterop.GetAddressOf());
|
||||
|
||||
return canvasImageInterop.Get()->GetDevice(device, type);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe int ICanvasImageInterop.Interface.GetD2DImage(
|
||||
ICanvasDevice* device,
|
||||
ID2D1DeviceContext* deviceContext,
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS flags,
|
||||
float targetDpi,
|
||||
float* realizeDpi,
|
||||
ID2D1Image** ppImage)
|
||||
{
|
||||
using ComPtr<ICanvasImageInterop> canvasImageInterop = default;
|
||||
|
||||
GetCanvasImageInterop(canvasImageInterop.GetAddressOf());
|
||||
|
||||
return canvasImageInterop.Get()->GetD2DImage(device, deviceContext, flags, targetDpi, realizeDpi, ppImage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or creates the current <see cref="ICanvasImage"/> instance.
|
||||
/// </summary>
|
||||
/// <returns>The current <see cref="ICanvasImage"/> instance.</returns>
|
||||
/// <exception cref="ObjectDisposedException">Thrown if the current instance is disposed.</exception>
|
||||
private ICanvasImage GetCanvasImage()
|
||||
{
|
||||
lock (this.lockObject)
|
||||
{
|
||||
default(ObjectDisposedException).ThrowIf(this.isDisposed, this);
|
||||
|
||||
this.canvasImage ??= BuildEffectGraph();
|
||||
|
||||
if (this.isInvalidated)
|
||||
{
|
||||
ConfigureEffectGraph();
|
||||
|
||||
this.isInvalidated = false;
|
||||
}
|
||||
|
||||
return this.canvasImage;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ICanvasImageInterop"/> object currently in use.
|
||||
/// </summary>
|
||||
/// <param name="canvasImageInterop">A pointer to the <see cref="ICanvasImageInterop"/> object currently in use.</param>
|
||||
private void GetCanvasImageInterop(ICanvasImageInterop** canvasImageInterop)
|
||||
{
|
||||
using ComPtr<IUnknown> canvasImageUnknown = default;
|
||||
|
||||
canvasImageUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(GetCanvasImage()));
|
||||
|
||||
canvasImageUnknown.CopyTo(canvasImageInterop).Assert();
|
||||
}
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <summary>
|
||||
/// A base type to implement packaged and easy to use <see cref="ICanvasImage"/>-based effects that can be used with Win2D.
|
||||
/// </summary>
|
||||
public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.Interface
|
||||
{
|
||||
/// <summary>
|
||||
/// Lock object used to synchronize calls to <see cref="ICanvasImageInterop"/> APIs.
|
||||
/// </summary>
|
||||
private readonly object lockObject = new();
|
||||
|
||||
/// <summary>
|
||||
/// The current cached result for <see cref="GetCanvasImage"/>, if available.
|
||||
/// </summary>
|
||||
private ICanvasImage? canvasImage;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the current state has been invalidated (requiring <see cref="ConfigureEffectGraph"/> to be called).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is initially <see langword="true"/> so that <see cref="ConfigureEffectGraph"/> will always be called when
|
||||
/// first creating the image, even if the effect has not bee invalidated. This ensures default parameters are set.
|
||||
/// </remarks>
|
||||
private bool isInvalidated = true;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the effect is disposed.
|
||||
/// </summary>
|
||||
private bool isDisposed;
|
||||
|
||||
/// <summary>
|
||||
/// Builds the effect graph for the current <see cref="CanvasEffect"/> instance, and returns an <see cref="ICanvasImage"/> object
|
||||
/// representing the output node of the graph. This image will then be passed to Win2D to perform the actual drawing, when needed.
|
||||
/// </summary>
|
||||
/// <returns>The resulting <see cref="ICanvasImage"/> object representing the output node of the effect graph.</returns>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This method is called once before the current effect is drawn, and the resulting image is automatically cached and reused.
|
||||
/// It will remain in use until <see cref="InvalidateEffectGraph"/> is called with <see cref="InvalidationType.Creation"/>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If the effect is invalidated with <see cref="InvalidationType.Update"/>, only <see cref="ConfigureEffectGraph"/> will be
|
||||
/// called. As such, derived types should save any effect graph nodes that might need updates into instance fields, for later use.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// For instance, consider a <c>FrostedGlassEffect</c> type deriving from <see cref="CanvasEffect"/>, with this effect graph:
|
||||
/// <code>
|
||||
/// ┌────────┐ ┌──────┐ ┌──────┐ ┌───────┐ ┌────────┐
|
||||
/// │ source ├──►│ blur ├──►│ tint ├──►│ noise ├──►│ output │
|
||||
/// └────────┘ └──────┘ └──────┘ └───────┘ └────────┘
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// In this example, <c>blur</c> is a <see cref="Microsoft.Graphics.Canvas.Effects.GaussianBlurEffect"/> instance, <c>tint</c>
|
||||
/// is a <see cref="Microsoft.Graphics.Canvas.Effects.TintEffect"/>. and <c>noise</c> is some other custom effect. In this case,
|
||||
/// the <see cref="ICanvasImage"/> instance returned by <see cref="BuildEffectGraph"/> will be <c>noise</c>, as that's the output
|
||||
/// node for the effect graph. At the same time, both <c>blur</c> and <c>tint</c> will also need to be saved as instance fields,
|
||||
/// so that <see cref="ConfigureEffectGraph"/> will be able to set properties on them when needed. For instance, the effect might
|
||||
/// expose a property to control the blur amount, as well as the tint color and opacity.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Generally speaking, an implementation of <see cref="BuildEffectGraph"/> will consist of these steps:
|
||||
/// <list type="bullet">
|
||||
/// <item>Create an instance of all necessary nodes in the effect graph.</item>
|
||||
/// <item>Connect the effect nodes as needed to build the connected graph.</item>
|
||||
/// <item>Save all effects that can be configured as instance fields in the effect type.</item>
|
||||
/// <item>Return the <see cref="ICanvasImage"/> instance for the output node of the graph.</item>
|
||||
/// </list>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This method should never be called directly. It is automatically invoked when an <see cref="ICanvasImage"/> is needed.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
protected abstract ICanvasImage BuildEffectGraph();
|
||||
|
||||
/// <summary>
|
||||
/// Configures the current effect graph whenever it is invalidated.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This method is guaranteed to be called after <see cref="BuildEffectGraph"/> has been invoked already. As such, any instance
|
||||
/// fields that are set by <see cref="BuildEffectGraph"/> can be assumed to never be <see langword="null"/> when this method runs.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This method should never be called directly. It is used internally to configure the current <see cref="ICanvasImage"/> instance.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
protected abstract void ConfigureEffectGraph();
|
||||
|
||||
/// <summary>
|
||||
/// Invalidates the last returned result from <see cref="GetCanvasImage"/>.
|
||||
/// </summary>
|
||||
/// <param name="invalidationType">The invalidation type to request.</param>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This method is used to signal when the effect graph should be updated, and it can indicate
|
||||
/// that either the entire graph should be created again (by calling <see cref="GetCanvasImage"/>),
|
||||
/// or whether it simply needs to refresh its internal state (by calling <see cref="ConfigureEffectGraph"/>).
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If <see cref="InvalidateEffectGraph"/> is called with <see cref="InvalidationType.Update"/>, the effect
|
||||
/// graph will only be refreshed the next time the image is actually requested. That is, repeated requests
|
||||
/// for updates do not result in unnecessarily calls to <see cref="ConfigureEffectGraph"/>.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
protected void InvalidateEffectGraph(InvalidationType invalidationType = InvalidationType.Update)
|
||||
{
|
||||
lock (this.lockObject)
|
||||
{
|
||||
// If the effect graph should be created again, dispose the image and throw it away
|
||||
if (invalidationType == InvalidationType.Creation)
|
||||
{
|
||||
this.canvasImage?.Dispose();
|
||||
|
||||
this.canvasImage = null;
|
||||
this.isInvalidated = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, just mark the internal state as not being valid anymore. The next
|
||||
// time the image is requested, the effect graph will be configured if needed.
|
||||
this.isInvalidated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the backing storage for an effect property and checks if it has changed.
|
||||
/// If so, it invalidates the effect graph as well with the requested invalidation type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the property that changed.</typeparam>
|
||||
/// <param name="storage">The storage for the effect property value.</param>
|
||||
/// <param name="value">The new effect property value to set.</param>
|
||||
/// <param name="invalidationType">The invalidation type to request.</param>
|
||||
protected void SetAndInvalidateEffectGraph<T>([NotNullIfNotNull(nameof(value))] ref T storage, T value, InvalidationType invalidationType = InvalidationType.Update)
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(storage, value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
storage = value;
|
||||
|
||||
InvalidateEffectGraph(invalidationType);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes any disposable resources in the current instance.
|
||||
/// </summary>
|
||||
/// <param name="disposing">
|
||||
/// Indicates whether the method was called from <see cref="Dispose()"/> of from a finalizer:
|
||||
/// <list type="bullet">
|
||||
/// <item><see langword="true"/>: the method was called from <see cref="Dispose()"/>.</item>
|
||||
/// <item><see langword="false"/>: the method was called from a finalizer.</item>
|
||||
/// </list>
|
||||
/// </param>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// If implementing a type that derives from <see cref="CanvasEffect"/>, this method can be overridden to add logic to dispose
|
||||
/// any additional state. Managed objects should only be disposed when <paramref name="disposing"/> is <see langword="true"/>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If the derived type does not need a finalizer (ie. if it doesn't wrap any native resources), this method should not be
|
||||
/// called directly. It will be called automatically by <see cref="Dispose()"/>. If the derived type does instead define a
|
||||
/// finalizer, it should call <see cref="Dispose(bool)"/> with a value of <see langword="false"/>. As mentioned above, when
|
||||
/// implementing <see cref="Dispose(bool)"/> in a derived type, managed objects should only be disposed when
|
||||
/// <paramref name="disposing"/> is <see langword="true"/>, otherwise only unmanaged resorces should be disposed.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Though the pattern does support this, it is recommended not to add finalizers in types deriving from <see cref="CanvasEffect"/>.
|
||||
/// Rather, if an effect needs to wrap native resources, it should do so via some same managed wrapper type (such as
|
||||
/// <see cref="System.Runtime.InteropServices.SafeHandle"/>), or some other custom unmanaged resource wrapper type.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <seealso href="https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose"/>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Only take a lock and dispose the image if the method was called explicitly from user code. If instead it was
|
||||
// called from the finalizer, we can make no guarantees on the order of objects being collected, meaning that
|
||||
// the lock itself might have already been collected by the time this code runs, which would lead the lock
|
||||
// statement to throw a NullReferenceException. So if a finalizer is running, just let objects be collected
|
||||
// on their own. This is fine here since there are no unmanaged references to free, but just managed wrappers.
|
||||
lock (this.lockObject)
|
||||
{
|
||||
this.canvasImage?.Dispose();
|
||||
this.canvasImage = null;
|
||||
}
|
||||
}
|
||||
|
||||
this.isDisposed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the invalidation type to request when invoking <see cref="InvalidateEffectGraph"/> and related methods.
|
||||
/// </summary>
|
||||
protected enum InvalidationType
|
||||
{
|
||||
/// <summary>
|
||||
/// Fully invalidates the effect graph, causing it to be created again the next time it is needed.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This will cause the last returned <see cref="ICanvasImage"/> instance to be disposed and discarded,
|
||||
/// and <see cref="BuildEffectGraph"/> to be called again the next time the effect is used for drawing.
|
||||
/// </remarks>
|
||||
Creation,
|
||||
|
||||
/// <summary>
|
||||
/// Invalidates the state of the effect graph, causing it to be configured again the next time it is used.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// This will preserve the last returned <see cref="ICanvasImage"/> instance, if available, and it will only
|
||||
/// mark the internal state as being out of date, resulting in <see cref="ConfigureEffectGraph"/> to be called
|
||||
/// the next time the effect is used for drawing.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This is much less expensive than creating the effect graph again, and should be preferred if possible.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
Update
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// Shared helpers for all types implementing <see cref="IFixedCountList{T}"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of elements in the list.</typeparam>
|
||||
internal static class FixedCountList<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Copies the entire <see cref="IFixedCountList{T}"/> instance to a target array range.
|
||||
/// </summary>
|
||||
/// <param name="list">The input <see cref="IFixedCountList{T}"/> instance.</param>
|
||||
/// <param name="array">The array to copy elements to.</param>
|
||||
/// <param name="index">The initial index within <paramref name="array"/>.</param>
|
||||
public static void CopyTo(IFixedCountList<T> list, T[] array, int index)
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(array);
|
||||
|
||||
Span<T> span = array.AsSpan(index);
|
||||
|
||||
default(ArgumentException).ThrowIf(list.Indices.Length > span.Length, nameof(array));
|
||||
|
||||
foreach (int i in list.Indices)
|
||||
{
|
||||
span[i] = list[i];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the entire <see cref="IFixedCountList{T}"/> instance to a target array range.
|
||||
/// </summary>
|
||||
/// <param name="list">The input <see cref="IFixedCountList{T}"/> instance.</param>
|
||||
/// <param name="array">The array to copy elements to.</param>
|
||||
/// <param name="index">The initial index within <paramref name="array"/>.</param>
|
||||
public static void CopyTo(IFixedCountList<T> list, Array array, int index)
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(array);
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, array.Length);
|
||||
|
||||
int remainingLength = array.Length - index;
|
||||
|
||||
default(ArgumentException).ThrowIf(list.Indices.Length > remainingLength, nameof(array));
|
||||
|
||||
foreach (int i in list.Indices)
|
||||
{
|
||||
array.SetValue(list[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="IEnumerable{T}"/> for an input <see cref="IFixedCountList{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="list">The input <see cref="IFixedCountList{T}"/> instance.</param>
|
||||
/// <returns>An <see cref="IEnumerable{T}"/> instance for <paramref name="list"/>.</returns>
|
||||
public static IEnumerator<T> GetEnumerator(IFixedCountList<T> list)
|
||||
{
|
||||
foreach (int i in list.Indices)
|
||||
{
|
||||
yield return list[i];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches for the specified object and returns the zero-based index of the first occurrence
|
||||
/// within the range of elements in a given <see cref="IFixedCountList{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="list">The input <see cref="IFixedCountList{T}"/> instance.</param>
|
||||
/// <param name="value">
|
||||
/// The object to locate in <paramref name="list"/>. The value can be <see langword="null"/> for reference types.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The zero-based index of the first occurrence of item within <paramref name="list"/>, otherwise -1.
|
||||
/// </returns>
|
||||
public static int IndexOf(IFixedCountList<T> list, T value)
|
||||
{
|
||||
foreach (int i in list.Indices)
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(list[i], value))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// An interface for a list with a fixed collection.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of elements in the list.</typeparam>
|
||||
interface IFixedCountList<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the collection of valid indices for the current effect.
|
||||
/// </summary>
|
||||
ImmutableArray<int> Indices { get; }
|
||||
|
||||
/// <inheritdoc cref="IList{T}.this"/>
|
||||
T this[int index] { get; set; }
|
||||
}
|
||||
@@ -25,11 +25,6 @@
|
||||
<PackageTags>$(PackageTags) uwp winui</PackageTags>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\ComputeSharp\Graphics\Interop\IReferenceTrackedObject.cs" Link="Interop\IReferenceTrackedObject.cs" />
|
||||
<Compile Include="..\ComputeSharp\Graphics\Interop\ReferenceTracker.cs" Link="Interop\ReferenceTracker.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\ComputeSharp.Core.Package\icon.png" Pack="true" PackagePath="\icon.png" Visible="False" />
|
||||
</ItemGroup>
|
||||
@@ -41,4 +36,6 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\ComputeSharp.D2D1.UI\ComputeSharp.D2D1.UI.projitems" Label="Shared" />
|
||||
</Project>
|
||||
@@ -1,79 +0,0 @@
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using Win32 = TerraFX.Interop.Windows.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with extensions for the <see cref="ICanvasDevice"/> type.
|
||||
/// </summary>
|
||||
internal static unsafe class ICanvasDeviceExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the underlying <see cref="ID2D1Device1"/> object from an <see cref="ICanvasDevice"/> object.
|
||||
/// </summary>
|
||||
/// <param name="canvasDevice">The input <see cref="ICanvasDevice"/> object.</param>
|
||||
/// <param name="d2D1Device1">The underlying <see cref="ID2D1Device1"/> object for <paramref name="canvasDevice"/>.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
public static HRESULT GetD2DDevice(this ref ICanvasDevice canvasDevice, ID2D1Device1** d2D1Device1)
|
||||
{
|
||||
using ComPtr<ICanvasResourceWrapperNative> canvasDeviceResourceWrapperNative = default;
|
||||
|
||||
// Get the ICanvasResourceWrapperNative wrapper around the input device
|
||||
canvasDevice.QueryInterface(
|
||||
riid: Win32.__uuidof<ICanvasResourceWrapperNative>(),
|
||||
ppvObject: canvasDeviceResourceWrapperNative.GetVoidAddressOf()).Assert();
|
||||
|
||||
// Get the underlying ID2D1Device1 instance in use
|
||||
HRESULT hresult = canvasDeviceResourceWrapperNative.Get()->GetNativeResource(
|
||||
device: null,
|
||||
dpi: 0,
|
||||
iid: Win32.__uuidof<ID2D1Device1>(),
|
||||
resource: (void**)d2D1Device1);
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a usable <see cref="ID2D1DeviceContext"/> from an input <see cref="ICanvasDevice"/> if one is not available.
|
||||
/// If a new one had to be rented from the pool, it also returns the owning <see cref="ID2D1DeviceContextLease"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="canvasDevice">The input <see cref="ICanvasDevice"/> object.</param>
|
||||
/// <param name="d2D1DeviceContext">The current <see cref="ID2D1DeviceContext"/> object, if available.</param>
|
||||
/// <param name="d2D1DeviceContextEffective">The resulting <see cref="ID2D1DeviceContext"/> instance to use.</param>
|
||||
/// <param name="d2D1DeviceContextLease">The resulting <see cref="ID2D1DeviceContextLease"/> object, if used.</param>
|
||||
/// <remarks>
|
||||
/// When this method returns, <paramref name="d2D1DeviceContextEffective"/> is guaranteed to not be <see langword="null"/>.
|
||||
/// </remarks>
|
||||
public static void GetEffectiveD2DDeviceContextWithOptionalLease(
|
||||
this ref ICanvasDevice canvasDevice,
|
||||
ID2D1DeviceContext* d2D1DeviceContext,
|
||||
ID2D1DeviceContext** d2D1DeviceContextEffective,
|
||||
ID2D1DeviceContextLease** d2D1DeviceContextLease)
|
||||
{
|
||||
// If there is no input device context, just create a new one from the input canvas device
|
||||
if (d2D1DeviceContext is null)
|
||||
{
|
||||
using (ComPtr<ID2D1DeviceContextPool> d2D1DeviceContextPool = default)
|
||||
{
|
||||
// Get the ID2D1DeviceContextPool interface reference
|
||||
canvasDevice.QueryInterface(
|
||||
riid: Win32.__uuidof<ID2D1DeviceContextPool>(),
|
||||
ppvObject: d2D1DeviceContextPool.GetVoidAddressOf()).Assert();
|
||||
|
||||
// Get a new ID2D1DeviceContextLease object from the retrieved pool
|
||||
d2D1DeviceContextPool.Get()->GetDeviceContextLease(d2D1DeviceContextLease).Assert();
|
||||
}
|
||||
|
||||
// Get the underlying device context from the lease (this is much faster than creating a new device context)
|
||||
(*d2D1DeviceContextLease)->GetD2DDeviceContext(d2D1DeviceContextEffective).Assert();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, just use the input device context
|
||||
*d2D1DeviceContextEffective = new ComPtr<ID2D1DeviceContext>(d2D1DeviceContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with extensions for the <see cref="ID2D1DeviceContext"/> type.
|
||||
/// </summary>
|
||||
internal static unsafe class ID2D1DeviceContextExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks whether a given <see cref="ID2D1DeviceContext"/> has an <see cref="ID2D1CommandList"/> as render target.
|
||||
/// </summary>
|
||||
/// <param name="deviceContext">The input <see cref="ID2D1DeviceContext"/> instance to check.</param>
|
||||
/// <returns>Whether the target of <paramref name="deviceContext"/> is an <see cref="ID2D1CommandList"/>.</returns>
|
||||
public static bool HasCommandListTarget(this ref ID2D1DeviceContext deviceContext)
|
||||
{
|
||||
using ComPtr<ID2D1Image> d2D1Image = default;
|
||||
|
||||
// First get the target and check that it is not null
|
||||
deviceContext.GetTarget(d2D1Image.GetAddressOf());
|
||||
|
||||
if (d2D1Image.Get() is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using ComPtr<ID2D1CommandList> d2D1CommandList = default;
|
||||
|
||||
// If there is a target, check if it is an ID2D1CommandList
|
||||
HRESULT hresult = d2D1Image.CopyTo(d2D1CommandList.GetAddressOf());
|
||||
|
||||
// Special case E_NOINTERFACE: this should return false and it's not an error
|
||||
if (hresult == E.E_NOINTERFACE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Throw for any other failure
|
||||
hresult.Assert();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the DPI value from a target <see cref="ID2D1DeviceContext"/> object.
|
||||
/// </summary>
|
||||
/// <param name="deviceContext">The input <see cref="ID2D1DeviceContext"/> instance.</param>
|
||||
/// <returns>The DPIs from <paramref name="deviceContext"/>.</returns>
|
||||
public static float GetDpi(this ref ID2D1DeviceContext deviceContext)
|
||||
{
|
||||
float dpiX;
|
||||
float dpiY;
|
||||
|
||||
deviceContext.GetDpi(&dpiX, &dpiY);
|
||||
|
||||
return dpiX;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="ID2D1Factory1"/> object from a given <see cref="ID2D1DeviceContext"/>.
|
||||
/// </summary>
|
||||
/// <param name="deviceContext">The input <see cref="ID2D1DeviceContext"/> instance.</param>
|
||||
/// <param name="d2D1Factory1">The resulting <see cref="ID2D1Factory1"/> object.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
/// <remarks>
|
||||
/// The <see cref="Interop.D2D1PixelShaderEffect"/> APIs specifically need an <see cref="ID2D1Factory1"/> (as <see cref="ID2D1Factory1.RegisterEffectFromString"/> is used).
|
||||
/// </remarks>
|
||||
public static HRESULT GetFactory1(this ref ID2D1DeviceContext deviceContext, ID2D1Factory1** d2D1Factory1)
|
||||
{
|
||||
using ComPtr<ID2D1Factory> d2D1Factory = default;
|
||||
|
||||
// Get the underlying ID2D1Factory from the input context, which can be used to register effects
|
||||
deviceContext.GetFactory(d2D1Factory.GetAddressOf());
|
||||
|
||||
// QueryInterface for the ID2D1Factory1 object (which should always be present)
|
||||
return d2D1Factory.CopyTo(d2D1Factory1);
|
||||
}
|
||||
}
|
||||
@@ -1,228 +0,0 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with extensions for the <see cref="ID2D1Effect"/> type.
|
||||
/// </summary>
|
||||
internal static unsafe class ID2D1EffectExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the constant buffer of type <typeparamref name="T"/> from a given <see cref="ID2D1Effect"/> object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of shader being used.</typeparam>
|
||||
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
|
||||
/// <returns>The constant buffer of type <typeparamref name="T"/> for <paramref name="d2D1Effect"/>.</returns>
|
||||
public static T GetConstantBuffer<T>(this ref ID2D1Effect d2D1Effect)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
int constantBufferSize = D2D1PixelShader.GetConstantBufferSize<T>();
|
||||
|
||||
// Special cases the constant buffer type being empty. If that's the case, there is no
|
||||
// need to try to retrieve the constant buffer from the underlying effect anyway, and
|
||||
// most importantly, the ID2D1EffectImpl from ComputeSharp.D2D1 will return E_INVALIDARG.
|
||||
if (constantBufferSize == 0)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
byte[] buffer = ArrayPool<byte>.Shared.Rent(constantBufferSize);
|
||||
|
||||
fixed (byte* p = buffer)
|
||||
{
|
||||
// Get the raw constant buffer from the effect
|
||||
d2D1Effect.GetValue(
|
||||
index: D2D1PixelShaderEffectProperty.ConstantBuffer,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BLOB,
|
||||
data: p,
|
||||
dataSize: (uint)constantBufferSize).Assert();
|
||||
}
|
||||
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
shader.InitializeFromDispatchData(buffer.AsSpan(0, constantBufferSize));
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the constant buffer of type <typeparamref name="T"/> from a given <see cref="ID2D1Effect"/> object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of shader being used.</typeparam>
|
||||
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
|
||||
/// <param name="value">The constant buffer value to set.</param>
|
||||
public static void SetConstantBuffer<T>(this ref ID2D1Effect d2D1Effect, in T value)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
// Same as above, simply do nothing for empty types. This case is still handled to
|
||||
// avoid crashing when someone's just setting an empty constant buffer, which is
|
||||
// unnecessary but still valid (eg. a stateless shader). This could be the case if
|
||||
// someone was eg. binding or using some other automated system to set constant buffer.
|
||||
if (D2D1PixelShader.GetConstantBufferSize<T>() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect((ID2D1Effect*)Unsafe.AsPointer(ref d2D1Effect), in value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D2D1TransformMapper{T}"/> instance from a given <see cref="ID2D1Effect"/> object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of shader being used.</typeparam>
|
||||
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
|
||||
/// <returns>The <see cref="D2D1TransformMapper{T}"/> instance for <paramref name="d2D1Effect"/>.</returns>
|
||||
public static D2D1TransformMapper<T>? GetTransformMapper<T>(this ref ID2D1Effect d2D1Effect)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
using ComPtr<ID2D1TransformMapper> d2D1TransformMapper = default;
|
||||
|
||||
// Get the ID2D1TransformMapper object from the effect
|
||||
d2D1Effect.GetValue(
|
||||
index: D2D1PixelShaderEffectProperty.TransformMapper,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_IUNKNOWN,
|
||||
data: (byte*)d2D1TransformMapper.GetAddressOf(),
|
||||
dataSize: (uint)sizeof(void*)).Assert();
|
||||
|
||||
// If there is no transform, just return null (this is the default state)
|
||||
if (d2D1TransformMapper.Get() is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Otherwise, check if it's an internal CCW and retrieve the managed wrapper
|
||||
using ComPtr<ID2D1TransformMapperInternal> d2D1TransformMapperInternal = default;
|
||||
|
||||
d2D1TransformMapper.CopyTo(d2D1TransformMapperInternal.GetAddressOf()).Assert();
|
||||
|
||||
IntPtr handlePtr;
|
||||
|
||||
// Get the underlying GCHandle value
|
||||
d2D1TransformMapperInternal.Get()->GetManagedWrapperHandle((void**)&handlePtr).Assert();
|
||||
|
||||
// Retrieve the managed wrapper from the GCHandle
|
||||
return (D2D1TransformMapper<T>)GCHandle.FromIntPtr(handlePtr).Target!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D2D1ResourceTextureManager"/> instance from a given <see cref="ID2D1Effect"/> object.
|
||||
/// </summary>
|
||||
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
|
||||
/// <param name="source">The current cached source instance.</param>
|
||||
/// <param name="index">The index of the resource texture manager to retrieve.</param>
|
||||
/// <returns>The <see cref="D2D1ResourceTextureManager"/> instance for <paramref name="d2D1Effect"/>.</returns>
|
||||
public static D2D1ResourceTextureManager? GetResourceTextureManager(
|
||||
this ref ID2D1Effect d2D1Effect,
|
||||
D2D1ResourceTextureManager? source,
|
||||
int index)
|
||||
{
|
||||
using ComPtr<ID2D1ResourceTextureManager> d2D1ResourceTextureManager = default;
|
||||
|
||||
// Get the ID2D1ResourceTextureManager object from the effect
|
||||
d2D1Effect.GetValue(
|
||||
index: (uint)(D2D1PixelShaderEffectProperty.ResourceTextureManager0 + index),
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_IUNKNOWN,
|
||||
data: (byte*)d2D1ResourceTextureManager.GetAddressOf(),
|
||||
dataSize: (uint)sizeof(void*)).Assert();
|
||||
|
||||
// If there is no resource texture manager, just return null (this is the default state)
|
||||
if (d2D1ResourceTextureManager.Get() is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Otherwise, the source must not be null and wrapping the same CCW
|
||||
if (source is not null)
|
||||
{
|
||||
using ComPtr<ID2D1ResourceTextureManager> d2D1ResourceTextureManagerSource = default;
|
||||
|
||||
source.GetD2D1ResourceTextureManager(d2D1ResourceTextureManagerSource.GetAddressOf());
|
||||
|
||||
// Check if the instances match, and return the managed wrapper we already have
|
||||
if (d2D1ResourceTextureManager.Get()->IsSameInstance(d2D1ResourceTextureManagerSource.Get()))
|
||||
{
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
// There was no way to retrieve the correct managed wrapper
|
||||
return default(InvalidOperationException).Throw<D2D1ResourceTextureManager?>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D2D1_PROPERTY.D2D1_PROPERTY_CACHED"/> property for a given <see cref="ID2D1Effect"/> object.
|
||||
/// </summary>
|
||||
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
|
||||
/// <returns>The <see cref="D2D1_PROPERTY.D2D1_PROPERTY_CACHED"/> value for <paramref name="d2D1Effect"/>.</returns>
|
||||
public static bool GetCachedProperty(this ref ID2D1Effect d2D1Effect)
|
||||
{
|
||||
int cacheOutput;
|
||||
|
||||
d2D1Effect.GetValue(
|
||||
index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_CACHED,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BOOL,
|
||||
data: (byte*)&cacheOutput,
|
||||
dataSize: sizeof(int)).Assert();
|
||||
|
||||
return cacheOutput != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="D2D1_PROPERTY.D2D1_PROPERTY_CACHED"/> property for a given <see cref="ID2D1Effect"/> object.
|
||||
/// </summary>
|
||||
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
|
||||
/// <param name="value">The property value to set.</param>
|
||||
public static void SetCachedProperty(this ref ID2D1Effect d2D1Effect, bool value)
|
||||
{
|
||||
int cacheOutput = value ? 1 : 0;
|
||||
|
||||
d2D1Effect.SetValue(
|
||||
index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_CACHED,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BOOL,
|
||||
data: (byte*)&cacheOutput,
|
||||
dataSize: sizeof(int)).Assert();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D2D1_PROPERTY.D2D1_PROPERTY_PRECISION"/> property for a given <see cref="ID2D1Effect"/> object.
|
||||
/// </summary>
|
||||
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
|
||||
/// <returns>The <see cref="D2D1_PROPERTY.D2D1_PROPERTY_PRECISION"/> value for <paramref name="d2D1Effect"/>.</returns>
|
||||
public static D2D1_BUFFER_PRECISION GetPrecisionProperty(this ref ID2D1Effect d2D1Effect)
|
||||
{
|
||||
D2D1_BUFFER_PRECISION d2D1BufferPrecision;
|
||||
|
||||
d2D1Effect.GetValue(
|
||||
index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_PRECISION,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN,
|
||||
data: (byte*)&d2D1BufferPrecision,
|
||||
dataSize: sizeof(D2D1_BUFFER_PRECISION)).Assert();
|
||||
|
||||
return d2D1BufferPrecision;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="D2D1_PROPERTY.D2D1_PROPERTY_PRECISION"/> property for a given <see cref="ID2D1Effect"/> object.
|
||||
/// </summary>
|
||||
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
|
||||
/// <param name="value">The property value to set.</param>
|
||||
public static void SetPrecisionProperty(this ref ID2D1Effect d2D1Effect, D2D1_BUFFER_PRECISION value)
|
||||
{
|
||||
d2D1Effect.SetValue(
|
||||
index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_PRECISION,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN,
|
||||
data: (byte*)&value,
|
||||
dataSize: sizeof(D2D1_BUFFER_PRECISION)).Assert();
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using TerraFX.Interop.Windows;
|
||||
using Win32 = TerraFX.Interop.Windows.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Helper methods for working with the <see cref="IUnknown"/> type.
|
||||
/// </summary>
|
||||
internal static unsafe class IUnknownExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks whether two <see cref="IUnknown"/> values have the same underlying COM object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the first value to check.</typeparam>
|
||||
/// <typeparam name="U">The type of the second value to check.</typeparam>
|
||||
/// <param name="left">The first <see cref="IUnknown"/> object to compare.</param>
|
||||
/// <param name="right">The second <see cref="IUnknown"/> object to compare.</param>
|
||||
/// <returns>Whether <paramref name="left"/> and <paramref name="right"/> point to the same COM object.</returns>
|
||||
public static bool IsSameInstance<T, U>(this ref T left, U* right)
|
||||
where T : unmanaged // IUnknown
|
||||
where U : unmanaged // IUnknown
|
||||
{
|
||||
if (Unsafe.AreSame(ref left, ref *(T*)right))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Unsafe.IsNullRef(ref left) || right is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using ComPtr<IUnknown> leftUnknown = default;
|
||||
using ComPtr<IUnknown> rightUnknown = default;
|
||||
|
||||
((IUnknown*)Unsafe.AsPointer(ref left))->QueryInterface(Win32.__uuidof<T>(), leftUnknown.GetVoidAddressOf()).Assert();
|
||||
((IUnknown*)right)->QueryInterface(Win32.__uuidof<T>(), rightUnknown.GetVoidAddressOf()).Assert();
|
||||
|
||||
return leftUnknown.Get() == rightUnknown.Get();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the source <see cref="IUnknown"/> object onto a target <see cref="ComPtr{T}"/> destination.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object being copied.</typeparam>
|
||||
/// <param name="source">The source <see cref="IUnknown"/> object.</param>
|
||||
/// <param name="destination">The destination <see cref="ComPtr{T}"/> location.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation (always <see cref="S.S_OK"/>).</returns>
|
||||
public static HRESULT CopyTo<T>(this ref T source, ref ComPtr<T> destination)
|
||||
where T : unmanaged // IUnknown
|
||||
{
|
||||
// Note: this explicitly needs a temporary copy to avoid issues in case source and destination were
|
||||
// pointers to the same object (which can be the case even if the two pointers are not identical).
|
||||
// To double check, a full check through an IUnknown* cast would be needed, but to avoid the extra
|
||||
// QueryInterface call on both objects, we can just always do one AddRef call which avoids issues in
|
||||
// all cases as well. The situation we need to avoid is that without a temporary copy, releasing the
|
||||
// target object might actually destroy the object, causing the following AddRef call to AV.
|
||||
using ComPtr<T> temporary = new((T*)Unsafe.AsPointer(ref source));
|
||||
|
||||
return temporary.CopyTo(ref destination);
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using TerraFX.Interop.Windows;
|
||||
using TerraFX.Interop.WinRT;
|
||||
using Windows.Graphics.Effects;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A helper type to replicate Win2D's <c>ResourceManager</c> type.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This type provides an entry point to use the Win2D <see cref="ICanvasFactoryNative"/> activation factory.
|
||||
/// </remarks>
|
||||
internal static class ResourceManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or creates an <see cref="IGraphicsEffectSource"/> instance for a native resource.
|
||||
/// </summary>
|
||||
/// <param name="device">The input canvas device (as a marshalled <see cref="Microsoft.Graphics.Canvas.CanvasDevice"/>).</param>
|
||||
/// <param name="resource">The input native resource to create a wrapper for.</param>
|
||||
/// <param name="dpi">The realization DPIs for <paramref name="resource"/></param>
|
||||
/// <returns>The resulting <see cref="IGraphicsEffectSource"/> wrapper instance.</returns>
|
||||
/// <exception cref="Exception">Thrown if the managed wrapper could not be retrieved.</exception>
|
||||
public static unsafe IGraphicsEffectSource GetOrCreate(ICanvasDevice* device, IUnknown* resource, float dpi)
|
||||
{
|
||||
using ComPtr<ICanvasFactoryNative> canvasFactoryNative = default;
|
||||
|
||||
const string activatableClassId = "Microsoft.Graphics.Canvas.CanvasDevice";
|
||||
|
||||
fixed (char* pActivatableClassId = activatableClassId)
|
||||
{
|
||||
HSTRING_HEADER hStringHeaderActivatableClassId;
|
||||
HSTRING hStringActivatableClass;
|
||||
|
||||
// Create a fast-pass HSTRING for "Microsoft.Graphics.Canvas.CanvasDevice"
|
||||
WinRT.WindowsCreateStringReference(
|
||||
sourceString: (ushort*)pActivatableClassId,
|
||||
length: (uint)activatableClassId.Length,
|
||||
hstringHeader: &hStringHeaderActivatableClassId,
|
||||
@string: &hStringActivatableClass).Assert();
|
||||
|
||||
Guid canvasFactoryNativeId = typeof(ICanvasFactoryNative).GUID;
|
||||
|
||||
// Get the activation factory for CanvasDevice
|
||||
WinRT.RoGetActivationFactory(
|
||||
activatableClassId: hStringActivatableClass,
|
||||
iid: &canvasFactoryNativeId,
|
||||
factory: canvasFactoryNative.GetVoidAddressOf()).Assert();
|
||||
}
|
||||
|
||||
using ComPtr<IUnknown> wrapperUnknown = default;
|
||||
|
||||
// Get or create a WinRT wrapper for the resource
|
||||
canvasFactoryNative.Get()->GetOrCreate(
|
||||
device: device,
|
||||
resource: resource,
|
||||
dpi: dpi,
|
||||
wrapper: wrapperUnknown.GetVoidAddressOf()).Assert();
|
||||
|
||||
// Get the runtime-provided RCW for the resulting WinRT wrapper
|
||||
object wrapper = Marshal.GetObjectForIUnknown((IntPtr)wrapperUnknown.Get());
|
||||
|
||||
return (IGraphicsEffectSource)wrapper;
|
||||
}
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.__Internals;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Loaders;
|
||||
|
||||
/// <summary>
|
||||
/// A resource texture index array loader for D2D1 pixel shaders.
|
||||
/// </summary>
|
||||
internal struct D2D1ImmutableArrayResourceTextureDescriptionsLoader : ID2D1ResourceTextureDescriptionsLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// The array of indices for resource textures for the current effect.
|
||||
/// </summary>
|
||||
private ImmutableArray<int> indices;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the resulting array of indices for resource textures for the current effect.
|
||||
/// </summary>
|
||||
/// <returns>An array of indices for resource textures for the current effect.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ImmutableArray<int> GetResultingIndices()
|
||||
{
|
||||
return this.indices;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ID2D1ResourceTextureDescriptionsLoader.LoadResourceTextureDescriptions(ReadOnlySpan<byte> data)
|
||||
{
|
||||
if (data.IsEmpty)
|
||||
{
|
||||
this.indices = ImmutableArray<int>.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadOnlySpan<D2D1ResourceTextureDescription> descriptions = MemoryMarshal.Cast<byte, D2D1ResourceTextureDescription>(data);
|
||||
|
||||
int[] indices = new int[descriptions.Length];
|
||||
|
||||
for (int i = 0; i < descriptions.Length; i++)
|
||||
{
|
||||
indices[i] = descriptions[i].Index;
|
||||
}
|
||||
|
||||
this.indices = Unsafe.As<int[], ImmutableArray<int>>(ref indices);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.__Internals;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Loaders;
|
||||
|
||||
/// <summary>
|
||||
/// A resource texture index bitmask loader for D2D1 pixel shaders.
|
||||
/// </summary>
|
||||
internal struct D2D1IndexBitmaskResourceTextureDescriptionsLoader : ID2D1ResourceTextureDescriptionsLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// The bitmask of indices for resource textures in the target shader.
|
||||
/// </summary>
|
||||
private int indexBitmask;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the resulting bitmask of indices for resource textures in the target shader.
|
||||
/// </summary>
|
||||
/// <returns>A bitmask of indices for resource textures in the target shader.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int GetResultingIndexBitmask()
|
||||
{
|
||||
return this.indexBitmask;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ID2D1ResourceTextureDescriptionsLoader.LoadResourceTextureDescriptions(ReadOnlySpan<byte> data)
|
||||
{
|
||||
int indexBitmask = 0;
|
||||
|
||||
foreach (ref readonly D2D1ResourceTextureDescription description in MemoryMarshal.Cast<byte, D2D1ResourceTextureDescription>(data))
|
||||
{
|
||||
indexBitmask |= 1 << description.Index;
|
||||
}
|
||||
|
||||
this.indexBitmask = indexBitmask;
|
||||
}
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Runtime.InteropServices;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop.Windows;
|
||||
using Windows.Foundation;
|
||||
using ICanvasEffect = Microsoft.Graphics.Canvas.Effects.ICanvasEffect;
|
||||
using ICanvasResourceCreatorWithDpi = Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void InvalidateSourceRectangle(ICanvasResourceCreatorWithDpi resourceCreator, uint sourceIndex, Rect invalidRectangle)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
using ComPtr<ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi> resourceCreatorWithDpi = default;
|
||||
using ComPtr<ICanvasImageInterop> canvasImageInterop = default;
|
||||
|
||||
GetCanvasResourceCreatorAndCanvasImageInteropUnderlyingObjects(
|
||||
resourceCreator,
|
||||
resourceCreatorWithDpi.GetAddressOf(),
|
||||
canvasImageInterop.GetAddressOf());
|
||||
|
||||
Win2D.InvalidateSourceRectangleForICanvasImageInterop(
|
||||
resourceCreator: resourceCreatorWithDpi.Get(),
|
||||
image: canvasImageInterop.Get(),
|
||||
sourceIndex: sourceIndex,
|
||||
invalidRectangle: &invalidRectangle).Assert();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Rect[] GetInvalidRectangles(ICanvasResourceCreatorWithDpi resourceCreator)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
using ComPtr<ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi> resourceCreatorWithDpi = default;
|
||||
using ComPtr<ICanvasImageInterop> canvasImageInterop = default;
|
||||
|
||||
GetCanvasResourceCreatorAndCanvasImageInteropUnderlyingObjects(
|
||||
resourceCreator,
|
||||
resourceCreatorWithDpi.GetAddressOf(),
|
||||
canvasImageInterop.GetAddressOf());
|
||||
|
||||
uint valueCount;
|
||||
Rect* valueElements;
|
||||
|
||||
Win2D.GetInvalidRectanglesForICanvasImageInterop(
|
||||
resourceCreator: resourceCreatorWithDpi.Get(),
|
||||
image: canvasImageInterop.Get(),
|
||||
valueCount: &valueCount,
|
||||
valueElements: &valueElements).Assert();
|
||||
|
||||
try
|
||||
{
|
||||
// Copy the data back from the COM array that Win2D created and returned.
|
||||
// If no items were returned, this will automatically return an empty array.
|
||||
return new Span<Rect>(valueElements, checked((int)valueCount)).ToArray();
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Make sure to release the callee-allocated COM array
|
||||
Marshal.FreeCoTaskMem((IntPtr)valueElements);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Rect GetRequiredSourceRectangle(
|
||||
ICanvasResourceCreatorWithDpi resourceCreator,
|
||||
Rect outputRectangle,
|
||||
ICanvasEffect sourceEffect,
|
||||
uint sourceIndex,
|
||||
Rect sourceBounds)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
using ComPtr<ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi> resourceCreatorWithDpi = default;
|
||||
using ComPtr<ICanvasImageInterop> canvasImageInterop = default;
|
||||
|
||||
GetCanvasResourceCreatorAndCanvasImageInteropUnderlyingObjects(
|
||||
resourceCreator,
|
||||
resourceCreatorWithDpi.GetAddressOf(),
|
||||
canvasImageInterop.GetAddressOf());
|
||||
|
||||
Rect result;
|
||||
|
||||
using ComPtr<IUnknown> canvasEffectUnknown = default;
|
||||
using ComPtr<ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect> canvasEffectAbi = default;
|
||||
|
||||
// Get the ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect object from the input interface
|
||||
canvasEffectUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(sourceEffect));
|
||||
canvasEffectUnknown.CopyTo(canvasEffectAbi.GetAddressOf()).Assert();
|
||||
|
||||
Win2D.GetRequiredSourceRectanglesForICanvasImageInterop(
|
||||
resourceCreator: resourceCreatorWithDpi.Get(),
|
||||
image: canvasImageInterop.Get(),
|
||||
outputRectangle: &outputRectangle,
|
||||
sourceEffectCount: 1,
|
||||
sourceEffects: canvasEffectAbi.GetAddressOf(),
|
||||
sourceIndexCount: 1,
|
||||
sourceIndices: &sourceIndex,
|
||||
sourceBoundsCount: 1,
|
||||
sourceBounds: &sourceBounds,
|
||||
valueCount: 1,
|
||||
valueElements: &result).Assert();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Rect[] GetRequiredSourceRectangles(
|
||||
ICanvasResourceCreatorWithDpi resourceCreator,
|
||||
Rect outputRectangle,
|
||||
ICanvasEffect[] sourceEffects,
|
||||
uint[] sourceIndices,
|
||||
Rect[] sourceBounds)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
using ComPtr<ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi> resourceCreatorWithDpi = default;
|
||||
using ComPtr<ICanvasImageInterop> canvasImageInterop = default;
|
||||
|
||||
GetCanvasResourceCreatorAndCanvasImageInteropUnderlyingObjects(
|
||||
resourceCreator,
|
||||
resourceCreatorWithDpi.GetAddressOf(),
|
||||
canvasImageInterop.GetAddressOf());
|
||||
|
||||
// The array optionally rented from the pool is of IntPtr types to reduce the number of generic
|
||||
// instantiations. This increases the chances of the pooled arrays being shared with other code.
|
||||
IntPtr[]? canvasEffectsAbiArray = null;
|
||||
|
||||
// Create the span and optional array of ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect objects
|
||||
Span<ComPtr<ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect>> canvasEffects = sourceEffects.Length <= 16
|
||||
? stackalloc ComPtr<ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect>[16]
|
||||
: MemoryMarshal.Cast<IntPtr, ComPtr<ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect>>(
|
||||
canvasEffectsAbiArray = ArrayPool<IntPtr>.Shared.Rent(sourceEffects.Length));
|
||||
|
||||
// Clear the span to ensure no false positives are accidentally disposed
|
||||
canvasEffects.Clear();
|
||||
|
||||
try
|
||||
{
|
||||
// Get the underlying ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect object for each input effect
|
||||
for (int i = 0; i < sourceEffects.Length; i++)
|
||||
{
|
||||
using ComPtr<IUnknown> canvasEffectUnknown = default;
|
||||
|
||||
canvasEffectUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(sourceEffects[i]));
|
||||
canvasEffectUnknown.CopyTo(canvasEffects[i].GetAddressOf()).Assert();
|
||||
}
|
||||
|
||||
Rect[] result = new Rect[sourceEffects.Length];
|
||||
|
||||
fixed (ComPtr<ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect>* pCanvasEffects = canvasEffects)
|
||||
fixed (uint* pSourceIndices = sourceIndices)
|
||||
fixed (Rect* pSourceBounds = sourceBounds)
|
||||
fixed (Rect* pResult = result)
|
||||
{
|
||||
Win2D.GetRequiredSourceRectanglesForICanvasImageInterop(
|
||||
resourceCreator: resourceCreatorWithDpi.Get(),
|
||||
image: canvasImageInterop.Get(),
|
||||
outputRectangle: &outputRectangle,
|
||||
sourceEffectCount: (uint)sourceEffects.Length,
|
||||
sourceEffects: (ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect**)pCanvasEffects,
|
||||
sourceIndexCount: (uint)sourceIndices.Length,
|
||||
sourceIndices: pSourceIndices,
|
||||
sourceBoundsCount: (uint)sourceBounds.Length,
|
||||
sourceBounds: pSourceBounds,
|
||||
valueCount: (uint)sourceEffects.Length,
|
||||
valueElements: pResult).Assert();
|
||||
}
|
||||
|
||||
// Only return the array to the pool if no exceptions have been thrown
|
||||
if (canvasEffectsAbiArray is not null)
|
||||
{
|
||||
ArrayPool<IntPtr>.Shared.Return(canvasEffectsAbiArray);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Release all canvas effects that have been retrieved up until the exception
|
||||
foreach (ref ComPtr<ABI.Microsoft.Graphics.Canvas.Effects.ICanvasEffect> canvasEffect in canvasEffects)
|
||||
{
|
||||
canvasEffect.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying <see cref="ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi"/> and <see cref="ICanvasImageInterop"/>
|
||||
/// objects from an input <see cref="ICanvasResourceCreatorWithDpi"/> object and the current <see cref="PixelShaderEffect{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="resourceCreator">The input <see cref="ICanvasResourceCreatorWithDpi"/> object.</param>
|
||||
/// <param name="resourceCreatorWithDpi">The resulting <see cref="ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi"/> object for <paramref name="resourceCreator"/>.</param>
|
||||
/// <param name="canvasImageInterop">The resulting <see cref="ICanvasImageInterop"/> object for the current <see cref="PixelShaderEffect{T}"/> instance.</param>
|
||||
private void GetCanvasResourceCreatorAndCanvasImageInteropUnderlyingObjects(
|
||||
ICanvasResourceCreatorWithDpi resourceCreator,
|
||||
ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi** resourceCreatorWithDpi,
|
||||
ICanvasImageInterop** canvasImageInterop)
|
||||
{
|
||||
using ComPtr<IUnknown> resourceCreatorUnknown = default;
|
||||
|
||||
// Get the ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreatorWithDpi object from the input interface
|
||||
resourceCreatorUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(resourceCreator));
|
||||
resourceCreatorUnknown.CopyTo(resourceCreatorWithDpi).Assert();
|
||||
|
||||
using ComPtr<IUnknown> canvasImageInteropUnknown = default;
|
||||
|
||||
// Get the ICanvasImageInterop object from the current instance
|
||||
canvasImageInteropUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(this));
|
||||
canvasImageInteropUnknown.CopyTo(canvasImageInterop).Assert();
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.Interop;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using TerraFX.Interop.Windows;
|
||||
using Windows.Foundation;
|
||||
using ICanvasResourceCreator = Microsoft.Graphics.Canvas.ICanvasResourceCreator;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public Rect GetBounds(ICanvasResourceCreator resourceCreator)
|
||||
{
|
||||
return GetBounds(resourceCreator, null);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Rect GetBounds(ICanvasResourceCreator resourceCreator, Matrix3x2 transform)
|
||||
{
|
||||
return GetBounds(resourceCreator, &transform);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ICanvasImage.GetBounds(ICanvasResourceCreator, Matrix3x2)"/>
|
||||
private Rect GetBounds(ICanvasResourceCreator resourceCreator, Matrix3x2* transform)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
using ComPtr<IUnknown> resourceCreatorUnknown = default;
|
||||
using ComPtr<ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreator> resourceCreatorAbi = default;
|
||||
|
||||
// Get the ABI.Microsoft.Graphics.Canvas.ICanvasResourceCreator object from the input interface
|
||||
resourceCreatorUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(resourceCreator));
|
||||
resourceCreatorUnknown.CopyTo(resourceCreatorAbi.GetAddressOf()).Assert();
|
||||
|
||||
using ComPtr<IUnknown> canvasImageInteropUnknown = default;
|
||||
using ComPtr<ICanvasImageInterop> canvasImageInterop = default;
|
||||
|
||||
// Get the ICanvasImageInterop object from the current instance
|
||||
canvasImageInteropUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(this));
|
||||
canvasImageInteropUnknown.CopyTo(canvasImageInterop.GetAddressOf()).Assert();
|
||||
|
||||
Rect bounds;
|
||||
|
||||
// Forward the actual logic to Win2D to compute the image bounds (it needs the internal context)
|
||||
Win2D.GetBoundsForICanvasImageInterop(
|
||||
resourceCreator: resourceCreatorAbi.Get(),
|
||||
image: canvasImageInterop.Get(),
|
||||
transform: transform,
|
||||
rect: &bounds).Assert();
|
||||
|
||||
return bounds;
|
||||
}
|
||||
}
|
||||
@@ -1,403 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Interop.Effects;
|
||||
using ComputeSharp.D2D1.Uwp.Extensions;
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using Windows.Graphics.Effects;
|
||||
using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_D2D_IMAGE_FLAGS;
|
||||
using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_DEVICE_ASSOCIATION_TYPE;
|
||||
using Win32 = TerraFX.Interop.Windows.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
int ICanvasImageInterop.Interface.GetDevice(ICanvasDevice** device, WIN2D_GET_DEVICE_ASSOCIATION_TYPE* type)
|
||||
{
|
||||
// Validate all input parameters
|
||||
if (device is null || type is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
// Set parameters to default values
|
||||
*device = null;
|
||||
*type = WIN2D_GET_DEVICE_ASSOCIATION_TYPE_UNSPECIFIED;
|
||||
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().TryGetLease(out bool leaseTaken);
|
||||
|
||||
// Check for disposal
|
||||
if (!leaseTaken)
|
||||
{
|
||||
return RO.RO_E_CLOSED;
|
||||
}
|
||||
|
||||
// Ensure we can take a lock without blocking. We can't access the realization device with no
|
||||
// lock, as that could lead to memory leaks or corruption if GetD2DImage was to manipulate that
|
||||
// field concurrently. We also cannot lock directly, because that would deadlock if someone was
|
||||
// to (incorrectly) try to use the same effect from two different threads. To protect against
|
||||
// that, we try to lock, and just return E_NOT_VALID_STATE if another thread holds the lock. If
|
||||
// this call had GetD2DImage in the stack, that would work fine because locks are recursive.
|
||||
if (!Monitor.TryEnter(this.lockObject))
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
HRESULT hresult;
|
||||
|
||||
try
|
||||
{
|
||||
// Copy the device over to the target
|
||||
hresult = this.canvasDevice.CopyTo(device);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Monitor.Exit(this.lockObject);
|
||||
}
|
||||
|
||||
// Set the association type if the copy was successful
|
||||
if (Win32.SUCCEEDED(hresult))
|
||||
{
|
||||
*type = WIN2D_GET_DEVICE_ASSOCIATION_TYPE_REALIZATION_DEVICE;
|
||||
}
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
int ICanvasImageInterop.Interface.GetD2DImage(
|
||||
ICanvasDevice* device,
|
||||
ID2D1DeviceContext* deviceContext,
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS flags,
|
||||
float targetDpi,
|
||||
float* realizeDpi,
|
||||
ID2D1Image** ppImage)
|
||||
{
|
||||
// The device and resulting image pointers cannot be null
|
||||
if (device is null || ppImage is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
// Set the resulting image to null
|
||||
*ppImage = null;
|
||||
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().TryGetLease(out bool leaseTaken);
|
||||
|
||||
// Check for disposal
|
||||
if (!leaseTaken)
|
||||
{
|
||||
return RO.RO_E_CLOSED;
|
||||
}
|
||||
|
||||
// Check for graph cycles
|
||||
if (Interlocked.CompareExchange(ref this.isInsideGetD2DImage, 1, 0) == 1)
|
||||
{
|
||||
return D2DERR.D2DERR_CYCLIC_GRAPH;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Lock after checking for graph cycles (other public APIs also lock on this object)
|
||||
lock (this.lockObject)
|
||||
{
|
||||
// Process the ReadDpiFromDeviceContext flag (same logic as CanvasEffect::GetD2DImage)
|
||||
if ((flags & WIN2D_GET_D2D_IMAGE_FLAGS_READ_DPI_FROM_DEVICE_CONTEXT) != WIN2D_GET_D2D_IMAGE_FLAGS_NONE)
|
||||
{
|
||||
// If ReadDpiFromDeviceContext is used, the context cannot be null
|
||||
if (deviceContext is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
if (deviceContext->HasCommandListTarget())
|
||||
{
|
||||
// Command lists are DPI dependent, so DPI compensation effects are always needed
|
||||
flags |= WIN2D_GET_D2D_IMAGE_FLAGS_ALWAYS_INSERT_DPI_COMPENSATION;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the effect is not being drawn onto a command list, the DPIs can be read from the device context
|
||||
targetDpi = deviceContext->GetDpi();
|
||||
}
|
||||
|
||||
// ReadDpiFromDeviceContext has been processed, so it can be removed now
|
||||
flags &= ~WIN2D_GET_D2D_IMAGE_FLAGS_READ_DPI_FROM_DEVICE_CONTEXT;
|
||||
}
|
||||
|
||||
using ComPtr<ID2D1Device1> d2D1Device1 = default;
|
||||
|
||||
// Get the underlying ID2D1Device1 instance in use
|
||||
device->GetD2DDevice(d2D1Device1.GetAddressOf()).Assert();
|
||||
|
||||
// Check that the input D2D device is the same instance as the current realization device, if any.
|
||||
// If not and the effect has already been realized, unrealize it and store the new device to use.
|
||||
if (!d2D1Device1.Get()->IsSameInstance(this.d2D1RealizationDevice.Get()))
|
||||
{
|
||||
Unrealize();
|
||||
|
||||
// Store the input realization device and canvas device for future uses
|
||||
d2D1Device1.CopyTo(ref this.d2D1RealizationDevice).Assert();
|
||||
device->CopyTo(ref this.canvasDevice).Assert();
|
||||
}
|
||||
|
||||
// Create the effect, if it doesn't exist already
|
||||
if (this.d2D1Effect.Get() is null)
|
||||
{
|
||||
if (!Realize(flags, targetDpi, deviceContext))
|
||||
{
|
||||
return E.E_FAIL;
|
||||
}
|
||||
}
|
||||
else if (!flags.HasFlag(WIN2D_GET_D2D_IMAGE_FLAGS_MINIMAL_REALIZATION))
|
||||
{
|
||||
// Recurse through the effect graph and ensure all nodes are initialized
|
||||
RefreshInputs(flags, targetDpi, deviceContext);
|
||||
}
|
||||
|
||||
// The realized DPIs are always 0 for pixel shader effects
|
||||
if (realizeDpi is not null)
|
||||
{
|
||||
*realizeDpi = 0;
|
||||
}
|
||||
|
||||
this.d2D1Effect.CopyTo(ppImage).Assert();
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Ensure that reset this flag so that this method can be called again
|
||||
this.isInsideGetD2DImage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unrealizes the currently realized <see cref="ID2D1Effect"/> object.
|
||||
/// </summary>
|
||||
/// <param name="source">The value to set for <see cref="Sources"/>.</param>
|
||||
/// <param name="index">The index of the <see cref="IGraphicsEffectSource"/> source to get or set.</param>
|
||||
private void Unrealize(IGraphicsEffectSource source, int index)
|
||||
{
|
||||
// Unrealize the effect and indicate to the logic to skip the source at the current index.
|
||||
// That is, there is no need to marshal it back to the cache, as we're about to do that here.
|
||||
Unrealize(index);
|
||||
|
||||
// Once the effect is unrealized, also update the cached source managed wrapper
|
||||
Sources.Storage[index].SetWrapper(source);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unrealizes the currently realized <see cref="ID2D1Effect"/> object.
|
||||
/// </summary>
|
||||
private void Unrealize(int? sourceIndexToSkip = null)
|
||||
{
|
||||
// If there is no ID2D1Effect object, there is nothing left to do
|
||||
if (this.d2D1Effect.Get() is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Cache the last update values for the constant buffer, cache output, buffer precision properties, etc.
|
||||
// Note: the resource texture managers are deliberately not read back, as the only supported way to set
|
||||
// those is directly from the current effect instance. As such, they'd all either be the same instances
|
||||
// that are already stored locally, or trying to retrieve them would just throw an exception.
|
||||
this.constantBuffer = this.d2D1Effect.Get()->GetConstantBuffer<T>();
|
||||
this.transformMapper = this.d2D1Effect.Get()->GetTransformMapper<T>();
|
||||
this.cacheOutput = this.d2D1Effect.Get()->GetCachedProperty();
|
||||
this.d2D1BufferPrecision = this.d2D1Effect.Get()->GetPrecisionProperty();
|
||||
|
||||
// Loop over all effect inputs and update the cache back as well
|
||||
for (int i = 0; i < Sources.Count; i++)
|
||||
{
|
||||
// If this index has been explicitly requested to be skipped, just dispose the source reference.
|
||||
// This is the case when the effect is being unrealized, and callers will set this value on their own.
|
||||
if (i == sourceIndexToSkip)
|
||||
{
|
||||
Sources.Storage[i].Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, just get the input, which will automatically update the cached values. The
|
||||
// returned IGraphicsEffectSource managed wrapper is not used here and is safe to ignore.
|
||||
_ = GetD2DInput(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Finally release the effect as well
|
||||
this.d2D1Effect.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Realizes the underlying <see cref="ID2D1Effect"/> for this object.
|
||||
/// </summary>
|
||||
/// <param name="flags">The current flags in use.</param>
|
||||
/// <param name="targetDpi">The target DPI in use.</param>
|
||||
/// <param name="deviceContext">The <see cref="ID2D1DeviceContext"/> instance in use.</param>
|
||||
/// <returns>Whether the effect was realized correctly.</returns>
|
||||
private bool Realize(WIN2D_GET_D2D_IMAGE_FLAGS flags, float targetDpi, ID2D1DeviceContext* deviceContext)
|
||||
{
|
||||
fixed (ID2D1Effect** d2D1Effect = this.d2D1Effect)
|
||||
{
|
||||
Guid effectId = PixelShaderEffect.For<T>.Instance.Id;
|
||||
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContextEffective = default;
|
||||
using ComPtr<ID2D1DeviceContextLease> d2D1DeviceContextLease = default;
|
||||
|
||||
// We need to realize the current effect (ComputeSharp.D2D1's ID2D1Effect), which needs a device context
|
||||
this.canvasDevice.Get()->GetEffectiveD2DDeviceContextWithOptionalLease(
|
||||
d2D1DeviceContext: deviceContext,
|
||||
d2D1DeviceContextEffective: d2D1DeviceContextEffective.GetAddressOf(),
|
||||
d2D1DeviceContextLease: d2D1DeviceContextLease.GetAddressOf());
|
||||
|
||||
// Try to create an instance of the effect in use and store it in the current object
|
||||
HRESULT hresult = d2D1DeviceContextEffective.Get()->CreateEffect(effectId: &effectId, effect: d2D1Effect);
|
||||
|
||||
// Check if creation failed due to the effect not being registered. In that case, register
|
||||
// it and then try again. This is much faster than check whether the effect is registered
|
||||
// manually every time, by enumerating all registered effects for the target device context.
|
||||
// An unregistered effect can also sometimes return E_NOTFOUND, although it's not documented.
|
||||
if (hresult == D2DERR.D2DERR_EFFECT_IS_NOT_REGISTERED ||
|
||||
hresult == E.E_NOTFOUND)
|
||||
{
|
||||
using ComPtr<ID2D1Factory1> d2D1Factory1 = default;
|
||||
|
||||
// Get the ID2D1Factory1 object to register the effect (required by D2D1PixelShaderEffect)
|
||||
d2D1DeviceContextEffective.Get()->GetFactory1(d2D1Factory1.GetAddressOf()).Assert();
|
||||
|
||||
// Register the effect with the factory (pass the same D2D1 draw transform mapper factory that was used before)
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<T>(d2D1Factory1.Get(), out _);
|
||||
|
||||
// Try to create the effect again
|
||||
hresult = d2D1DeviceContextEffective.Get()->CreateEffect(effectId: &effectId, effect: d2D1Effect);
|
||||
}
|
||||
|
||||
// Rethrow any other errors
|
||||
hresult.Assert();
|
||||
}
|
||||
|
||||
// Set the constant buffer for the effect
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(this.d2D1Effect.Get(), in this.constantBuffer);
|
||||
|
||||
// If there is a transform mapper, set it in the effect
|
||||
if (this.transformMapper is not null)
|
||||
{
|
||||
D2D1PixelShaderEffect.SetTransformMapperForD2D1Effect(this.d2D1Effect.Get(), this.transformMapper);
|
||||
}
|
||||
|
||||
// If cache input has been set, forward that to the new effect
|
||||
if (this.cacheOutput)
|
||||
{
|
||||
this.d2D1Effect.Get()->SetCachedProperty(true);
|
||||
}
|
||||
|
||||
// If the buffer precision isn't unknown, forward that as well
|
||||
if (this.d2D1BufferPrecision != D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_UNKNOWN)
|
||||
{
|
||||
this.d2D1Effect.Get()->SetPrecisionProperty(this.d2D1BufferPrecision);
|
||||
}
|
||||
|
||||
// Forward all available sources (the effect is being created now, so no need to validate the underlying resources)
|
||||
for (int i = 0; i < Sources.Count; i++)
|
||||
{
|
||||
if (!SetD2DInput(
|
||||
index: i,
|
||||
value: Sources.Storage[i].GetWrapper(),
|
||||
flags: flags,
|
||||
targetDpi: targetDpi,
|
||||
d2D1DeviceContext: deviceContext))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Set all available resource texture managers (only set those that are not null, as they're all null by default anyway).
|
||||
// The loop only goes over the indices of valid slots for resource textures for the current effect, and ignores the others.
|
||||
foreach (int index in ResourceTextureManagerCollection.Indices)
|
||||
{
|
||||
if (ResourceTextureManagers.Storage[index] is D2D1ResourceTextureManager resourceTextureManager)
|
||||
{
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(this.d2D1Effect.Get(), resourceTextureManager, index);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the draw state for the currently realized effect.
|
||||
/// </summary>
|
||||
/// <param name="flags">The current flags in use.</param>
|
||||
/// <param name="targetDpi">The target DPI in use.</param>
|
||||
/// <param name="deviceContext">The <see cref="ID2D1DeviceContext"/> instance in use.</param>
|
||||
private void RefreshInputs(WIN2D_GET_D2D_IMAGE_FLAGS flags, float targetDpi, ID2D1DeviceContext* deviceContext)
|
||||
{
|
||||
for (int i = 0; i < Sources.Count; i++)
|
||||
{
|
||||
// Retrieve the managed wrapper for the current source
|
||||
IGraphicsEffectSource? source = GetD2DInput(i);
|
||||
|
||||
if (source is null)
|
||||
{
|
||||
// If the source is null and that is not valid here (eg. when drawing), just throw
|
||||
default(InvalidOperationException).ThrowIf((flags & WIN2D_GET_D2D_IMAGE_FLAGS_ALLOW_NULL_EFFECT_INPUTS) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
using ComPtr<IUnknown> canvasImageInteropUnknown = default;
|
||||
using ComPtr<ICanvasImageInterop> canvasImageInterop = default;
|
||||
|
||||
// Get the underlying IUnknown object for the current source
|
||||
canvasImageInteropUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(source));
|
||||
|
||||
// Convert to ICanvasImageInterop (this must always succeed, and throws if it doesn't)
|
||||
canvasImageInteropUnknown.CopyTo(canvasImageInterop.GetAddressOf()).Assert();
|
||||
|
||||
using ComPtr<ID2D1Image> d2D1Image = default;
|
||||
|
||||
float realizedDpi;
|
||||
|
||||
// Invoke GetD2DImage on the underlying object (either a built-in effect or a custom one)
|
||||
HRESULT hresult = canvasImageInterop.Get()->GetD2DImage(
|
||||
device: this.canvasDevice.Get(),
|
||||
deviceContext: deviceContext,
|
||||
flags: flags,
|
||||
targetDpi: targetDpi,
|
||||
realizeDpi: &realizedDpi,
|
||||
ppImage: d2D1Image.GetAddressOf());
|
||||
|
||||
// To match the behavior of ICanvasImageInternal::GetD2DImage in case of failure, check if the flags being used did have the flag
|
||||
// WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE set. If not, and the call failed, then we explicitly throw from the returned HRESULT.
|
||||
if ((flags & WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE)
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
|
||||
bool isDifferentResource = Sources.Storage[i].UpdateResource(d2D1Image.Get());
|
||||
|
||||
bool isDifferentDpi = ApplyDpiCompensation(
|
||||
index: i,
|
||||
d2D1Image: ref *&d2D1Image,
|
||||
inputDpi: realizedDpi,
|
||||
flags: flags,
|
||||
targetDpi: targetDpi,
|
||||
d2D1DeviceContext: deviceContext);
|
||||
|
||||
// If the source or the DPI setting has changed, also update the D2D effect graph
|
||||
if (isDifferentResource || isDifferentDpi)
|
||||
{
|
||||
this.d2D1Effect.Get()->SetInput(index: (uint)i, input: d2D1Image.Get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,361 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.Uwp.Buffers;
|
||||
using ComputeSharp.D2D1.Uwp.Extensions;
|
||||
using ComputeSharp.Interop;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using Windows.Graphics.Effects;
|
||||
using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_D2D_IMAGE_FLAGS;
|
||||
using static ABI.Microsoft.Graphics.Canvas.WIN2D_GET_DEVICE_ASSOCIATION_TYPE;
|
||||
using static TerraFX.Interop.DirectX.D2D1_BORDER_MODE;
|
||||
using static TerraFX.Interop.DirectX.D2D1_DPICOMPENSATION_INTERPOLATION_MODE;
|
||||
using static TerraFX.Interop.DirectX.D2D1_DPICOMPENSATION_PROP;
|
||||
using static TerraFX.Interop.DirectX.D2D1_PROPERTY_TYPE;
|
||||
using Win32 = TerraFX.Interop.Windows.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the marshalled value for <see cref="Sources"/>.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the <see cref="Sources"/> source to get or set.</param>
|
||||
/// <returns>The marshalled value for <see cref="Sources"/>.</returns>
|
||||
private IGraphicsEffectSource? GetSource(int index)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
return this.d2D1Effect.Get() switch
|
||||
{
|
||||
not null => GetD2DInput(index),
|
||||
_ => Sources.Storage[index].GetWrapper()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the marshalled value for <see cref="Sources"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to set for <see cref="Sources"/>.</param>
|
||||
/// <param name="index">The index of the <see cref="IGraphicsEffectSource"/> source to get or set.</param>
|
||||
private void SetSource(IGraphicsEffectSource? value, int index)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
ref SourceReference source = ref Sources.Storage[index];
|
||||
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
{
|
||||
const WIN2D_GET_D2D_IMAGE_FLAGS flags =
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_MINIMAL_REALIZATION |
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_ALLOW_NULL_EFFECT_INPUTS |
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE;
|
||||
|
||||
// The WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE flag is passed, so we just let the effect
|
||||
// unrealize in case of failure and take no other action (including throwing) if that happens.
|
||||
_ = SetD2DInput(index, value, flags, targetDpi: 0.0f, d2D1DeviceContext: null);
|
||||
}
|
||||
else
|
||||
{
|
||||
source.SetWrapper(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks>This method assumes a lock is taken and the effect is already realized.</remarks>
|
||||
/// <inheritdoc cref="GetSource"/>
|
||||
private IGraphicsEffectSource? GetD2DInput(int index)
|
||||
{
|
||||
using ComPtr<ID2D1Image> d2D1Image = default;
|
||||
|
||||
// Get the ID2D1Image input from the effect
|
||||
this.d2D1Effect.Get()->GetInput(
|
||||
index: (uint)index,
|
||||
input: d2D1Image.GetAddressOf());
|
||||
|
||||
ref SourceReference sourceReference = ref Sources.Storage[index];
|
||||
|
||||
// Check whether the input had a DPI compensation effect added to it, and skip it if so
|
||||
if (sourceReference.HasDpiCompensationEffect)
|
||||
{
|
||||
// Since a realized effect is the only source of authority for the effect state, we also
|
||||
// need to check that the actual source is in fact the same that was previous set by the
|
||||
// managed wrapper. If it is, we get the input and return that (ie. the underlying image).
|
||||
// If not, we just return it directly and reset the locally stored DPI compensation effect.
|
||||
if (d2D1Image.Get()->IsSameInstance(sourceReference.GetDpiCompensationEffect()))
|
||||
{
|
||||
sourceReference.GetDpiCompensationEffect()->GetInput(0, d2D1Image.ReleaseAndGetAddressOf());
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceReference.SetDpiCompensationEffect(null);
|
||||
}
|
||||
}
|
||||
|
||||
// Get or create a wrapper for the input image
|
||||
return sourceReference.GetOrCreateWrapper(this.canvasDevice.Get(), d2D1Image.Get());
|
||||
}
|
||||
|
||||
/// <param name="index">The index of the <see cref="IGraphicsEffectSource"/> source to get or set.</param>
|
||||
/// <param name="value">The value to set for <see cref="Sources"/>.</param>
|
||||
/// <param name="flags">The <see cref="WIN2D_GET_D2D_IMAGE_FLAGS"/> flags for <paramref name="value"/>.</param>
|
||||
/// <param name="targetDpi">The target DPI for the realized image, if present.</param>
|
||||
/// <param name="d2D1DeviceContext">The input <see cref="ID2D1DeviceContext"/> object to use, if present.</param>
|
||||
/// <returns>Whether the input was set successfully or not.</returns>
|
||||
/// <remarks>This method assumes a lock is taken and the effect is already realized.</remarks>
|
||||
/// <inheritdoc cref="SetSource"/>
|
||||
private bool SetD2DInput(
|
||||
int index,
|
||||
IGraphicsEffectSource? value,
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS flags,
|
||||
float targetDpi,
|
||||
ID2D1DeviceContext* d2D1DeviceContext)
|
||||
{
|
||||
using ComPtr<ID2D1Image> d2D1Image = default;
|
||||
|
||||
float realizedDpi = 0;
|
||||
|
||||
if (value is not null)
|
||||
{
|
||||
using ComPtr<IUnknown> canvasImageUnknown = default;
|
||||
|
||||
// Get the underlying IUnknown object for the input source
|
||||
canvasImageUnknown.Attach((IUnknown*)Marshal.GetIUnknownForObject(value));
|
||||
|
||||
using ComPtr<ICanvasImageInterop> canvasImageInterop = default;
|
||||
|
||||
// Try to get the ICanvasImageInterop interface from the input source
|
||||
HRESULT hresult = canvasImageUnknown.CopyTo(canvasImageInterop.GetAddressOf());
|
||||
|
||||
if (!Win32.SUCCEEDED(hresult))
|
||||
{
|
||||
// Only potentially handle E_NOINTERFACE, always throw in other cases
|
||||
if (hresult != E.E_NOINTERFACE)
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
|
||||
// If unrealization isn't requested for failures, just throw
|
||||
default(InvalidOperationException).ThrowIf((flags & WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE);
|
||||
|
||||
Unrealize(value, index);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
using ComPtr<ICanvasDevice> sourceCanvasDevice = default;
|
||||
|
||||
WIN2D_GET_DEVICE_ASSOCIATION_TYPE sourceCanvasDeviceType = WIN2D_GET_DEVICE_ASSOCIATION_TYPE_UNSPECIFIED;
|
||||
|
||||
// Get the canvas device the source is realized on, if any, and its association type
|
||||
canvasImageInterop.Get()->GetDevice(sourceCanvasDevice.GetAddressOf(), &sourceCanvasDeviceType).Assert();
|
||||
|
||||
// If the specified source is bound to a creation device, validate that this matches the one we are realized on.
|
||||
// A "creation device" is a canvas device that is used to create the native resources in a given canvas image
|
||||
// implementation, such that the canvas device and the canvas image are bound for the entire lifetime of the
|
||||
// canvas image itself. This applies to eg. CanvasBitmap, which directly wraps some native memory allocated on
|
||||
// a specific device. In these cases, if the associated device doesn't match the one this effect is currently
|
||||
// realized on, that is an error and the source is invalid.
|
||||
//
|
||||
// Otherwise, the device returned here will depend on the specific implementation of this external effect. That is,
|
||||
// it could be null for an unrealized effect, it could be null for a lazily initialized device-bound resource, or it
|
||||
// could also be an already instantiated resource tied to a specific device.
|
||||
//
|
||||
// The only case where the device has to be an exact match is if the device is an owning device for the canvas image.
|
||||
// In all other cases (including when the device is null), we can proceed to resolve the effects graph normally. This
|
||||
// will allow sources to either just work in case the device matches, or unrealize and re-realize themselves on the
|
||||
// new device if they were already realized on a different device (so that things would just work fine if someone was
|
||||
// trying to draw a reused effect after a device lost event, for instance). In the niche scenario where a given source
|
||||
// was some lazily-initialized instance that doesn't allow changing device after that, then the call to Get2D2Image
|
||||
// on that specific source will just fail during the recursive traversal, but that couldn't be checked from here anyway.
|
||||
if (sourceCanvasDeviceType == WIN2D_GET_DEVICE_ASSOCIATION_TYPE_CREATION_DEVICE && !this.canvasDevice.Get()->IsSameInstance(sourceCanvasDevice.Get()))
|
||||
{
|
||||
default(InvalidOperationException).ThrowIf((flags & WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE);
|
||||
|
||||
Unrealize(value, index);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Try to realize the image from the input source (this will recurse through the effect graph)
|
||||
hresult = canvasImageInterop.Get()->GetD2DImage(
|
||||
device: this.canvasDevice.Get(),
|
||||
deviceContext: d2D1DeviceContext,
|
||||
flags: flags,
|
||||
targetDpi: targetDpi,
|
||||
realizeDpi: &realizedDpi,
|
||||
ppImage: d2D1Image.GetAddressOf());
|
||||
|
||||
// Unless requested, a failure to retrieve the image should just bubble up the HRESULT in an exception
|
||||
if ((flags & WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE)
|
||||
{
|
||||
hresult.Assert();
|
||||
}
|
||||
|
||||
// If no realized image is available, unrealize the effect
|
||||
if (d2D1Image.Get() is null)
|
||||
{
|
||||
Unrealize(value, index);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if ((flags & WIN2D_GET_D2D_IMAGE_FLAGS_ALLOW_NULL_EFFECT_INPUTS) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE)
|
||||
{
|
||||
// If the source is null and this is not explicitly allowed, the invocation is not valid
|
||||
default(ArgumentNullException).Throw(nameof(value));
|
||||
}
|
||||
|
||||
// Save the managed wrapper and realized image
|
||||
Sources.Storage[index].SetWrapperAndResource(value, d2D1Image.Get());
|
||||
|
||||
// Handle DPI compensation (the return is ignored here as whether DPI compensation was applied doesn't matter)
|
||||
_ = ApplyDpiCompensation(
|
||||
index: index,
|
||||
d2D1Image: ref *&d2D1Image,
|
||||
inputDpi: realizedDpi,
|
||||
flags: flags,
|
||||
targetDpi: targetDpi,
|
||||
d2D1DeviceContext: d2D1DeviceContext);
|
||||
|
||||
// Set the actual effect input
|
||||
this.d2D1Effect.Get()->SetInput(index: (uint)index, input: d2D1Image.Get());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies a DPI compensation effect onto a realized image, if needed.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the source being processed.</param>
|
||||
/// <param name="d2D1Image">A reference to the realized source (this might be replaced if DPI compensation is added).</param>
|
||||
/// <param name="inputDpi">The input DPU for <paramref name="d2D1Image"/>.</param>
|
||||
/// <param name="flags">The <see cref="WIN2D_GET_D2D_IMAGE_FLAGS"/> flags for <paramref name="d2D1Image"/>.</param>
|
||||
/// <param name="targetDpi">The target DPI for the realized image, if present.</param>
|
||||
/// <param name="d2D1DeviceContext">The input <see cref="ID2D1DeviceContext"/> object to use, if present.</param>
|
||||
/// <returns>Whether the DPI configuration has changed.</returns>
|
||||
private bool ApplyDpiCompensation(
|
||||
int index,
|
||||
ref ComPtr<ID2D1Image> d2D1Image,
|
||||
float inputDpi,
|
||||
WIN2D_GET_D2D_IMAGE_FLAGS flags,
|
||||
float targetDpi,
|
||||
ID2D1DeviceContext* d2D1DeviceContext)
|
||||
{
|
||||
ref SourceReference sourceReference = ref Sources.Storage[index];
|
||||
|
||||
bool isDpiCompensationNeeded;
|
||||
|
||||
// Detemine whether DPI compensation is needed (direct port of Win2D's CanvasEffect::ApplyDpiCompensation)
|
||||
if ((flags & WIN2D_GET_D2D_IMAGE_FLAGS_MINIMAL_REALIZATION) != WIN2D_GET_D2D_IMAGE_FLAGS_NONE)
|
||||
{
|
||||
// In minimal mode, we don't yet know the target DPI. For instance this occurs when setting an
|
||||
// effect as the source of an image brush. We'll fix up later when the brush is drawn to a device
|
||||
// context, at which point the real DPI is known. Since we don't yet know whether to include
|
||||
// compensation, we just preserve the existing state. This avoids repeated recreation during
|
||||
// set-draw-set-draw sequences.
|
||||
isDpiCompensationNeeded = sourceReference.HasDpiCompensationEffect && (inputDpi != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool neverCompensate = (flags & WIN2D_GET_D2D_IMAGE_FLAGS_NEVER_INSERT_DPI_COMPENSATION) != WIN2D_GET_D2D_IMAGE_FLAGS_NONE;
|
||||
bool alwaysCompensate = (flags & WIN2D_GET_D2D_IMAGE_FLAGS_ALWAYS_INSERT_DPI_COMPENSATION) != WIN2D_GET_D2D_IMAGE_FLAGS_NONE;
|
||||
|
||||
// We need DPI compensation if:
|
||||
// - The input has a fixed DPI
|
||||
// - We were not told never to include it
|
||||
// - Either we were told to always include it, or the input DPI is different from the target
|
||||
isDpiCompensationNeeded = (inputDpi != 0) && !neverCompensate && (alwaysCompensate || (inputDpi != targetDpi));
|
||||
|
||||
// Early out if we are already in the right state
|
||||
if (isDpiCompensationNeeded == sourceReference.HasDpiCompensationEffect)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply the determined DPI compensation configuration
|
||||
if (isDpiCompensationNeeded)
|
||||
{
|
||||
using ComPtr<ID2D1Effect> d2D1EffectDpiCompensation = default;
|
||||
|
||||
// Create an ID2D1Effect for the DPI compensation, if there isn't one already
|
||||
if (!sourceReference.HasDpiCompensationEffect)
|
||||
{
|
||||
using (ComPtr<ID2D1DeviceContext> d2D1DeviceContextEffective = default)
|
||||
using (ComPtr<ID2D1DeviceContextLease> d2D1DeviceContextLease = default)
|
||||
{
|
||||
// Just like when realizing the current effect, rent a device context from the pool if one is not available
|
||||
this.canvasDevice.Get()->GetEffectiveD2DDeviceContextWithOptionalLease(
|
||||
d2D1DeviceContext: d2D1DeviceContext,
|
||||
d2D1DeviceContextEffective: d2D1DeviceContextEffective.GetAddressOf(),
|
||||
d2D1DeviceContextLease: d2D1DeviceContextLease.GetAddressOf());
|
||||
|
||||
// Create the DPI compensation effect
|
||||
d2D1DeviceContextEffective.Get()->CreateEffect(
|
||||
effectId: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_D2D1DpiCompensation)),
|
||||
effect: d2D1EffectDpiCompensation.GetAddressOf()).Assert();
|
||||
}
|
||||
|
||||
D2D1_BORDER_MODE d2D1BorderMode = D2D1_BORDER_MODE_HARD;
|
||||
D2D1_DPICOMPENSATION_INTERPOLATION_MODE d2D1DpiCompensationInterpolationMode = D2D1_DPICOMPENSATION_INTERPOLATION_MODE_LINEAR;
|
||||
|
||||
// Set the border mode to hard
|
||||
d2D1EffectDpiCompensation.Get()->SetValue(
|
||||
index: (uint)D2D1_DPICOMPENSATION_PROP_BORDER_MODE,
|
||||
type: D2D1_PROPERTY_TYPE_UNKNOWN,
|
||||
data: (byte*)&d2D1BorderMode,
|
||||
dataSize: sizeof(D2D1_BORDER_MODE)).Assert();
|
||||
|
||||
// Set the interpolation mode to linear
|
||||
d2D1EffectDpiCompensation.Get()->SetValue(
|
||||
index: (uint)D2D1_DPICOMPENSATION_PROP_INTERPOLATION_MODE,
|
||||
type: D2D1_PROPERTY_TYPE_UNKNOWN,
|
||||
data: (byte*)&d2D1DpiCompensationInterpolationMode,
|
||||
dataSize: sizeof(D2D1_DPICOMPENSATION_INTERPOLATION_MODE)).Assert();
|
||||
|
||||
// Store the DPI effect for later use
|
||||
sourceReference.SetDpiCompensationEffect(d2D1EffectDpiCompensation.Get());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just reuse the existing DPI effect otherwise
|
||||
d2D1EffectDpiCompensation.Attach(new ComPtr<ID2D1Effect>(sourceReference.GetDpiCompensationEffect()).Get());
|
||||
}
|
||||
|
||||
// Set the input image as source for the DPI compensation effect
|
||||
sourceReference.GetDpiCompensationEffect()->SetInput(index: (uint)index, input: d2D1Image.Get());
|
||||
|
||||
D2D_VECTOR_2F d2DVectorDpi;
|
||||
d2DVectorDpi.x = inputDpi;
|
||||
d2DVectorDpi.y = inputDpi;
|
||||
|
||||
// Set the DPI setting
|
||||
sourceReference.GetDpiCompensationEffect()->SetValue(
|
||||
index: (uint)D2D1_DPICOMPENSATION_PROP_INPUT_DPI,
|
||||
type: D2D1_PROPERTY_TYPE_UNKNOWN,
|
||||
data: (byte*)&d2DVectorDpi,
|
||||
dataSize: (uint)sizeof(D2D_VECTOR_2F)).Assert();
|
||||
|
||||
// Substitute the input image with the DPI compensation effect
|
||||
d2D1EffectDpiCompensation.CopyTo(ref d2D1Image).Assert();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure the existing effect is released, if present
|
||||
sourceReference.SetDpiCompensationEffect(null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,231 +0,0 @@
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Uwp.Extensions;
|
||||
using ComputeSharp.Interop;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using TerraFX.Interop.DirectX;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the marshalled value for <see cref="CacheOutput"/>.
|
||||
/// </summary>
|
||||
/// <returns>The marshalled value for <see cref="CacheOutput"/>.</returns>
|
||||
private T GetConstantBuffer()
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
return this.d2D1Effect.Get() switch
|
||||
{
|
||||
not null => this.d2D1Effect.Get()->GetConstantBuffer<T>(),
|
||||
_ => this.constantBuffer
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the marshalled value for <see cref="ConstantBuffer"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to set for <see cref="ConstantBuffer"/>.</param>
|
||||
private void SetConstantBuffer(in T value)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
// If the effect is realized, set the property on the underlying ID2D1Effect object
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
{
|
||||
this.d2D1Effect.Get()->SetConstantBuffer(in value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, just store the value locally
|
||||
this.constantBuffer = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the marshalled value for <see cref="TransformMapper"/>.
|
||||
/// </summary>
|
||||
/// <returns>The marshalled value for <see cref="TransformMapper"/>.</returns>
|
||||
private D2D1TransformMapper<T>? GetTransformMapper()
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
return this.d2D1Effect.Get() switch
|
||||
{
|
||||
not null => this.d2D1Effect.Get()->GetTransformMapper<T>(),
|
||||
_ => this.transformMapper
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the marshalled value for <see cref="TransformMapper"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to set for <see cref="TransformMapper"/>.</param>
|
||||
private void SetTransformMapper(D2D1TransformMapper<T> value)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
{
|
||||
D2D1PixelShaderEffect.SetTransformMapperForD2D1Effect(this.d2D1Effect.Get(), value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.transformMapper = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the marshalled value for <see cref="ResourceTextureManagers"/>.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the <see cref="D2D1ResourceTextureManager"/> source to get or set.</param>
|
||||
/// <returns>The marshalled value for <see cref="ResourceTextureManagers"/>.</returns>
|
||||
private D2D1ResourceTextureManager? GetResourceTextureManager(int index)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
D2D1ResourceTextureManager? resourceTextureManager = ResourceTextureManagers.Storage[index];
|
||||
|
||||
return this.d2D1Effect.Get() switch
|
||||
{
|
||||
not null => this.d2D1Effect.Get()->GetResourceTextureManager(resourceTextureManager, index),
|
||||
_ => resourceTextureManager
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the marshalled value for <see cref="ResourceTextureManagers"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to set for <see cref="ResourceTextureManagers"/>.</param>
|
||||
/// <param name="index">The index of the <see cref="D2D1ResourceTextureManager"/> source to get or set.</param>
|
||||
private void SetResourceTextureManager(D2D1ResourceTextureManager value, int index)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
{
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(this.d2D1Effect.Get(), value, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
ResourceTextureManagers.Storage[index] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the marshalled value for <see cref="CacheOutput"/>.
|
||||
/// </summary>
|
||||
/// <returns>The marshalled value for <see cref="CacheOutput"/>.</returns>
|
||||
private bool GetCacheOutput()
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
return this.d2D1Effect.Get() switch
|
||||
{
|
||||
not null => this.d2D1Effect.Get()->GetCachedProperty(),
|
||||
_ => this.cacheOutput
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the marshalled value for <see cref="CacheOutput"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to set for <see cref="CacheOutput"/>.</param>
|
||||
private void SetCacheOutput(bool value)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
{
|
||||
this.d2D1Effect.Get()->SetCachedProperty(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cacheOutput = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the marshalled value for <see cref="BufferPrecision"/>.
|
||||
/// </summary>
|
||||
/// <returns>The marshalled value for <see cref="BufferPrecision"/>.</returns>
|
||||
private CanvasBufferPrecision? GetBufferPrecision()
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
D2D1_BUFFER_PRECISION d2D1BufferPrecision = this.d2D1Effect.Get() switch
|
||||
{
|
||||
not null => this.d2D1Effect.Get()->GetPrecisionProperty(),
|
||||
_ => this.d2D1BufferPrecision
|
||||
};
|
||||
|
||||
// Map from D2D1_BUFFER_PRECISION to CanvasBufferPrecision, and return null for D2D1_BUFFER_PRECISION_UNKNOWN
|
||||
return this.d2D1BufferPrecision switch
|
||||
{
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM => CanvasBufferPrecision.Precision8UIntNormalized,
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB => CanvasBufferPrecision.Precision8UIntNormalizedSrgb,
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_UNORM => CanvasBufferPrecision.Precision16UIntNormalized,
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_FLOAT => CanvasBufferPrecision.Precision16Float,
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_32BPC_FLOAT => CanvasBufferPrecision.Precision32Float,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the marshalled value for <see cref="BufferPrecision"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to set for <see cref="BufferPrecision"/>.</param>
|
||||
private void SetBufferPrecision(CanvasBufferPrecision? value)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
// Map back from CanvasBufferPrecision? to D2D1_BUFFER_PRECISION (null results in D2D1_BUFFER_PRECISION_UNKNOWN)
|
||||
this.d2D1BufferPrecision = value switch
|
||||
{
|
||||
CanvasBufferPrecision.Precision8UIntNormalized => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM,
|
||||
CanvasBufferPrecision.Precision8UIntNormalizedSrgb => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB,
|
||||
CanvasBufferPrecision.Precision16UIntNormalized => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_UNORM,
|
||||
CanvasBufferPrecision.Precision16Float => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_FLOAT,
|
||||
CanvasBufferPrecision.Precision32Float => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_32BPC_FLOAT,
|
||||
_ => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_UNKNOWN
|
||||
};
|
||||
|
||||
// If the effect is realized, set the property on the underlying ID2D1Effect object too
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
{
|
||||
this.d2D1Effect.Get()->SetPrecisionProperty(this.d2D1BufferPrecision);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-251
@@ -1,251 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Shaders.Loaders;
|
||||
using ComputeSharp.D2D1.Uwp.Buffers;
|
||||
using ComputeSharp.D2D1.Uwp.Collections;
|
||||
|
||||
#pragma warning disable CS0618, CS8767
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the collection of <see cref="D2D1ResourceTextureManager"/> objects in a <see cref="PixelShaderEffect{T}"/> instance.
|
||||
/// </summary>
|
||||
public sealed class ResourceTextureManagerCollection : IList<D2D1ResourceTextureManager?>, IReadOnlyList<D2D1ResourceTextureManager?>, IList, IFixedCountList<D2D1ResourceTextureManager?>
|
||||
{
|
||||
/// <summary>
|
||||
/// The bitmask of valid indices for resource texture managers in the current shader type.
|
||||
/// </summary>
|
||||
private static readonly int IndexBitmask = GetIndexBitmask();
|
||||
|
||||
/// <summary>
|
||||
/// The fixed buffer of <see cref="D2D1ResourceTextureManager"/> instances.
|
||||
/// </summary>
|
||||
private ResourceTextureManagerBuffer fixedBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ResourceTextureManagerCollection"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owning <see cref="PixelShaderEffect{T}"/> instance.</param>
|
||||
internal ResourceTextureManagerCollection(PixelShaderEffect<T> owner)
|
||||
{
|
||||
Owner = owner;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int Count => Indices.Length;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="D2D1ResourceTextureManager"/> object at a specified index.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the <see cref="D2D1ResourceTextureManager"/> source to get or set.</param>
|
||||
/// <returns>The <see cref="D2D1ResourceTextureManager"/> object at the specified index.</returns>
|
||||
/// <exception cref="ArgumentNullException">Thrown if the value is set to <see langword="null"/>.</exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is not a valid index for the current effect.</exception>
|
||||
[DisallowNull]
|
||||
public D2D1ResourceTextureManager? this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, 16, nameof(index));
|
||||
default(ArgumentOutOfRangeException).ThrowIf((IndexBitmask & (1 << index)) == 0, nameof(index));
|
||||
|
||||
return Owner.GetResourceTextureManager(index);
|
||||
}
|
||||
set
|
||||
{
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, 16, nameof(index));
|
||||
default(ArgumentOutOfRangeException).ThrowIf((IndexBitmask & (1 << index)) == 0, nameof(index));
|
||||
default(ArgumentNullException).ThrowIfNull(value);
|
||||
|
||||
Owner.SetResourceTextureManager(value, index);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
object? IList.this[int index]
|
||||
{
|
||||
get => this[index];
|
||||
set => this[index] = (D2D1ResourceTextureManager?)value!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of valid resource texture indices for the current effect.
|
||||
/// </summary>
|
||||
internal static ImmutableArray<int> Indices { get; } = GetIndices();
|
||||
|
||||
/// <summary>
|
||||
/// The owning <see cref="PixelShaderEffect{T}"/> instance.
|
||||
/// </summary>
|
||||
internal PixelShaderEffect<T> Owner { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="ResourceTextureManagerBuffer"/> value containing the available <see cref="D2D1ResourceTextureManager"/>-s.
|
||||
/// </summary>
|
||||
internal ref ResourceTextureManagerBuffer Storage => ref this.fixedBuffer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
ImmutableArray<int> IFixedCountList<D2D1ResourceTextureManager?>.Indices => Indices;
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool ICollection<D2D1ResourceTextureManager?>.IsReadOnly => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool IList.IsReadOnly => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool IList.IsFixedSize => true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool ICollection.IsSynchronized => true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
object ICollection.SyncRoot => default(NotSupportedException).Throw<object>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ICollection<D2D1ResourceTextureManager?>.Add(D2D1ResourceTextureManager? item)
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
int IList.Add(object value)
|
||||
{
|
||||
return default(NotSupportedException).Throw<int>();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ICollection<D2D1ResourceTextureManager?>.Clear()
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IList.Clear()
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool ICollection<D2D1ResourceTextureManager?>.Contains(D2D1ResourceTextureManager? item)
|
||||
{
|
||||
return FixedCountList<D2D1ResourceTextureManager?>.IndexOf(this, item) != -1;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool IList.Contains(object value)
|
||||
{
|
||||
return FixedCountList<D2D1ResourceTextureManager?>.IndexOf(this, (D2D1ResourceTextureManager?)value) != -1;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ICollection<D2D1ResourceTextureManager?>.CopyTo(D2D1ResourceTextureManager?[] array, int arrayIndex)
|
||||
{
|
||||
FixedCountList<D2D1ResourceTextureManager?>.CopyTo(this, array, arrayIndex);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ICollection.CopyTo(Array array, int index)
|
||||
{
|
||||
FixedCountList<D2D1ResourceTextureManager?>.CopyTo(this, array, index);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
IEnumerator<D2D1ResourceTextureManager?> IEnumerable<D2D1ResourceTextureManager?>.GetEnumerator()
|
||||
{
|
||||
return FixedCountList<D2D1ResourceTextureManager?>.GetEnumerator(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return FixedCountList<D2D1ResourceTextureManager?>.GetEnumerator(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
int IList<D2D1ResourceTextureManager?>.IndexOf(D2D1ResourceTextureManager? item)
|
||||
{
|
||||
return FixedCountList<D2D1ResourceTextureManager?>.IndexOf(this, item);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
int IList.IndexOf(object value)
|
||||
{
|
||||
return FixedCountList<D2D1ResourceTextureManager?>.IndexOf(this, (D2D1ResourceTextureManager?)value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IList<D2D1ResourceTextureManager?>.Insert(int index, D2D1ResourceTextureManager? item)
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IList.Insert(int index, object value)
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool ICollection<D2D1ResourceTextureManager?>.Remove(D2D1ResourceTextureManager? item)
|
||||
{
|
||||
return default(NotSupportedException).Throw<bool>();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IList.Remove(object value)
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IList<D2D1ResourceTextureManager?>.RemoveAt(int index)
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IList.RemoveAt(int index)
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bitmask of indices for resource textures in the target shader.
|
||||
/// </summary>
|
||||
/// <returns>The bitmask of indices for resource textures in the target shader.</returns>
|
||||
private static int GetIndexBitmask()
|
||||
{
|
||||
D2D1IndexBitmaskResourceTextureDescriptionsLoader bitmaskLoader = default;
|
||||
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
shader.LoadResourceTextureDescriptions(ref bitmaskLoader);
|
||||
|
||||
return bitmaskLoader.GetResultingIndexBitmask();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of valid indices for the current effect.
|
||||
/// </summary>
|
||||
/// <returns>The collection of valid indices for the current effect.</returns>
|
||||
private static ImmutableArray<int> GetIndices()
|
||||
{
|
||||
D2D1ImmutableArrayResourceTextureDescriptionsLoader indicesLoader = default;
|
||||
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
shader.LoadResourceTextureDescriptions(ref indicesLoader);
|
||||
|
||||
return indicesLoader.GetResultingIndices();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,230 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Uwp.Buffers;
|
||||
using ComputeSharp.D2D1.Uwp.Collections;
|
||||
using Windows.Graphics.Effects;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the collection of <see cref="IGraphicsEffectSource"/> sources in a <see cref="PixelShaderEffect{T}"/> instance.
|
||||
/// </summary>
|
||||
public sealed class SourceCollection : IList<IGraphicsEffectSource?>, IReadOnlyList<IGraphicsEffectSource?>, IList, IFixedCountList<IGraphicsEffectSource?>
|
||||
{
|
||||
/// <summary>
|
||||
/// The collection of valid resource texture indices for the current effect.
|
||||
/// </summary>
|
||||
private static readonly ImmutableArray<int> Indices = GetIndices();
|
||||
|
||||
/// <summary>
|
||||
/// The fixed buffer of <see cref="IGraphicsEffectSource"/> instances.
|
||||
/// </summary>
|
||||
private GraphicsEffectSourceBuffer fixedBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="SourceCollection"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owning <see cref="PixelShaderEffect{T}"/> instance.</param>
|
||||
internal SourceCollection(PixelShaderEffect<T> owner)
|
||||
{
|
||||
Owner = owner;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int Count
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => D2D1PixelShader.GetInputCount<T>();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IGraphicsEffectSource? this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, D2D1PixelShader.GetInputCount<T>(), nameof(index));
|
||||
|
||||
return Owner.GetSource(index);
|
||||
}
|
||||
set
|
||||
{
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, D2D1PixelShader.GetInputCount<T>(), nameof(index));
|
||||
|
||||
Owner.SetSource(value, index);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
object? IList.this[int index]
|
||||
{
|
||||
get => this[index];
|
||||
set => this[index] = (IGraphicsEffectSource?)value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The owning <see cref="PixelShaderEffect{T}"/> instance.
|
||||
/// </summary>
|
||||
internal PixelShaderEffect<T> Owner { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="GraphicsEffectSourceBuffer"/> value containing the available <see cref="IGraphicsEffectSource"/>-s.
|
||||
/// </summary>
|
||||
internal ref GraphicsEffectSourceBuffer Storage => ref this.fixedBuffer;
|
||||
|
||||
/// <inheritdoc/>
|
||||
ImmutableArray<int> IFixedCountList<IGraphicsEffectSource?>.Indices => Indices;
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool ICollection<IGraphicsEffectSource?>.IsReadOnly => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool IList.IsReadOnly => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool IList.IsFixedSize => true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool ICollection.IsSynchronized => true;
|
||||
|
||||
/// <inheritdoc/>
|
||||
object ICollection.SyncRoot => default(NotSupportedException).Throw<object>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ICollection<IGraphicsEffectSource?>.Add(IGraphicsEffectSource? item)
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
int IList.Add(object value)
|
||||
{
|
||||
return default(NotSupportedException).Throw<int>();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ICollection<IGraphicsEffectSource?>.Clear()
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IList.Clear()
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool ICollection<IGraphicsEffectSource?>.Contains(IGraphicsEffectSource? item)
|
||||
{
|
||||
return FixedCountList<IGraphicsEffectSource?>.IndexOf(this, item) != -1;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool IList.Contains(object value)
|
||||
{
|
||||
return FixedCountList<IGraphicsEffectSource?>.IndexOf(this, (IGraphicsEffectSource?)value) != -1;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ICollection<IGraphicsEffectSource?>.CopyTo(IGraphicsEffectSource?[] array, int arrayIndex)
|
||||
{
|
||||
FixedCountList<IGraphicsEffectSource?>.CopyTo(this, array, arrayIndex);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ICollection.CopyTo(Array array, int index)
|
||||
{
|
||||
FixedCountList<IGraphicsEffectSource?>.CopyTo(this, array, index);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
IEnumerator<IGraphicsEffectSource?> IEnumerable<IGraphicsEffectSource?>.GetEnumerator()
|
||||
{
|
||||
return FixedCountList<IGraphicsEffectSource?>.GetEnumerator(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return FixedCountList<IGraphicsEffectSource?>.GetEnumerator(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
int IList<IGraphicsEffectSource?>.IndexOf(IGraphicsEffectSource? item)
|
||||
{
|
||||
return FixedCountList<IGraphicsEffectSource?>.IndexOf(this, item);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
int IList.IndexOf(object value)
|
||||
{
|
||||
return FixedCountList<IGraphicsEffectSource?>.IndexOf(this, (IGraphicsEffectSource?)value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IList<IGraphicsEffectSource?>.Insert(int index, IGraphicsEffectSource? item)
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IList.Insert(int index, object value)
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool ICollection<IGraphicsEffectSource?>.Remove(IGraphicsEffectSource? item)
|
||||
{
|
||||
return default(NotSupportedException).Throw<bool>();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IList.Remove(object value)
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IList<IGraphicsEffectSource?>.RemoveAt(int index)
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IList.RemoveAt(int index)
|
||||
{
|
||||
default(NotSupportedException).Throw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of valid indices for the current effect.
|
||||
/// </summary>
|
||||
/// <returns>The collection of valid indices for the current effect.</returns>
|
||||
private static ImmutableArray<int> GetIndices()
|
||||
{
|
||||
int inputCount = D2D1PixelShader.GetInputCount<T>();
|
||||
|
||||
if (inputCount == 0)
|
||||
{
|
||||
return ImmutableArray<int>.Empty;
|
||||
}
|
||||
|
||||
int[] indices = new int[inputCount];
|
||||
|
||||
for (int i = 0; i < indices.Length; i++)
|
||||
{
|
||||
indices[i] = i;
|
||||
}
|
||||
|
||||
return Unsafe.As<int[], ImmutableArray<int>>(ref indices);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the current <typeparamref name="T"/> value in use.
|
||||
/// </summary>
|
||||
public T ConstantBuffer
|
||||
{
|
||||
get => GetConstantBuffer();
|
||||
set => SetConstantBuffer(in value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="D2D1TransformMapper{T}"/> instance to use for the effect, if any.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentNullException">Thrown if the value is set to <see langword="null"/>.</exception>
|
||||
[DisallowNull]
|
||||
public D2D1TransformMapper<T>? TransformMapper
|
||||
{
|
||||
get => GetTransformMapper();
|
||||
set => SetTransformMapper(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool CacheOutput
|
||||
{
|
||||
get => GetCacheOutput();
|
||||
set => SetCacheOutput(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public CanvasBufferPrecision? BufferPrecision
|
||||
{
|
||||
get => GetBufferPrecision();
|
||||
set => SetBufferPrecision(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string? Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="SourceCollection"/> object associated with the current instance.
|
||||
/// </summary>
|
||||
public SourceCollection Sources { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ResourceTextureManagerCollection"/> object associated with the current instance.
|
||||
/// </summary>
|
||||
public ResourceTextureManagerCollection ResourceTextureManagers { get; }
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using ComputeSharp.Interop;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Releases unmanaged resources and performs other cleanup operations.
|
||||
/// </summary>
|
||||
~PixelShaderEffect()
|
||||
{
|
||||
this.referenceTracker.Dispose();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
{
|
||||
this.referenceTracker.Dispose();
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IReferenceTrackedObject.GetReferenceTracker"/>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal ref ReferenceTracker GetReferenceTracker()
|
||||
{
|
||||
return ref this.referenceTracker;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
ref ReferenceTracker IReferenceTrackedObject.GetReferenceTracker()
|
||||
{
|
||||
return ref this.referenceTracker;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IReferenceTrackedObject.DangerousOnDispose()
|
||||
{
|
||||
this.canvasDevice.Dispose();
|
||||
this.d2D1RealizationDevice.Dispose();
|
||||
this.d2D1Effect.Dispose();
|
||||
|
||||
// Also release all native resources for the used sources.
|
||||
// The transform mapper and resource texture managers don't
|
||||
// need to be disposed, as those could be shared between effects.
|
||||
for (int i = 0; i < Sources.Count; i++)
|
||||
{
|
||||
Sources.Storage[i].Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.Interop;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
using Microsoft.Graphics.Canvas.Effects;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp;
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="ICanvasEffect"/> 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, ICanvasEffect, ICanvasImageInterop.Interface
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ReferenceTracker"/> value for the current instance.
|
||||
/// </summary>
|
||||
private ReferenceTracker referenceTracker;
|
||||
|
||||
/// <summary>
|
||||
/// Lock object used to synchronize calls to <see cref="ICanvasImageInterop"/> APIs.
|
||||
/// </summary>
|
||||
private readonly object lockObject = new();
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
|
||||
/// <summary>
|
||||
/// The current device the effect is realized on, if one is available (this is the underlying COM object for <see cref="CanvasDevice"/>).
|
||||
/// </summary>
|
||||
private ComPtr<ICanvasDevice> canvasDevice;
|
||||
|
||||
/// <summary>
|
||||
/// The underlying D2D1 device the effect is realized on, if one is available (this is the D2D device backing <see cref="canvasDevice"/>).
|
||||
/// </summary>
|
||||
private ComPtr<ID2D1Device1> d2D1RealizationDevice;
|
||||
|
||||
/// <summary>
|
||||
/// The current realized <see cref="ID2D1Effect"/>, if one is available.
|
||||
/// </summary>
|
||||
private ComPtr<ID2D1Effect> d2D1Effect;
|
||||
|
||||
/// <summary>
|
||||
/// The backing field for <see cref="ConstantBuffer"/>.
|
||||
/// </summary>
|
||||
private T constantBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// The backing field for <see cref="TransformMapper"/>.
|
||||
/// </summary>
|
||||
private D2D1TransformMapper<T>? transformMapper;
|
||||
|
||||
/// <summary>
|
||||
/// The backing field for <see cref="CacheOutput"/>.
|
||||
/// </summary>
|
||||
private bool cacheOutput;
|
||||
|
||||
/// <summary>
|
||||
/// The backing field for <see cref="BufferPrecision"/>.
|
||||
/// </summary>
|
||||
private D2D1_BUFFER_PRECISION d2D1BufferPrecision;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="PixelShaderEffect{T}"/> instance.
|
||||
/// </summary>
|
||||
public PixelShaderEffect()
|
||||
{
|
||||
this.referenceTracker = new ReferenceTracker(this);
|
||||
|
||||
Sources = new SourceCollection(this);
|
||||
ResourceTextureManagers = new ResourceTextureManagerCollection(this);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする