From 7f80a7270f3143ed50f50eda04a98a4b936707d7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 11 Aug 2022 22:42:04 +0200 Subject: [PATCH] Add bindings for internal COM interfaces --- .../ID2D1ResourceTextureManager.cs | 99 +++++++++++++++++++ .../ID2D1ResourceTextureManagerInternal.cs | 70 +++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManager.cs create mode 100644 src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManagerInternal.cs diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManager.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManager.cs new file mode 100644 index 00000000..e7abbbba --- /dev/null +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManager.cs @@ -0,0 +1,99 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; + +namespace ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers; + +/// +/// The resource texture manager type to use with built-in effects. +/// +internal unsafe struct ID2D1ResourceTextureManager +{ + /// + /// Gets the for ID2D1ResourceTextureManager (3C4FC7E4-A419-46CA-B5F6-66EB4FF18D64). + /// + public static ref readonly Guid Guid + { + get + { + ReadOnlySpan data = new byte[] { + 0x3C, 0x4F, 0xC7, 0xE4, 0xA4, + 0x19, 0x46, + 0xCA, 0xB5, + 0xF6, 0x66, + 0xEB, + 0x4F, + 0xF1, + 0x8D, + 0x64 + }; + + return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); + } + } + + /// + /// The vtable for the current instance. + /// + private readonly void** lpVtbl; + + /// + /// Creates or finds the given resource texture, depending on whether a resource id is specified. + /// It also optionally initializes the texture with the specified data. + /// + /// An optional pointer to the unique id that identifies the resource texture. + /// The properties used to create the resource texture. + /// The optional data to be loaded into the resource texture. + /// An optional pointer to the stride to advance through the resource texture, according to dimension. + /// The size, in bytes, of the data. + /// An for the operation. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Initialize( + Guid* resourceId, + D2D1_RESOURCE_TEXTURE_PROPERTIES* resourceTextureProperties, + byte* data, + uint* strides, + uint dataSize) + { + return + ((delegate* unmanaged[Stdcall])this.lpVtbl[3])( + (ID2D1ResourceTextureManager*)Unsafe.AsPointer(ref this), + resourceId, + resourceTextureProperties, + data, + strides, + dataSize); + } + + /// + /// Updates the specific resource texture inside the specific range or box using the supplied data. + /// + /// The "left" extent of the updates if specified. If , the entire texture is updated. + /// The "right" extent of the updates if specified. If , the entire texture is updated. + /// The stride to advance through the input data, according to dimension. + /// The number of dimensions in the resource texture. This must match the number used to load the texture. + /// The data to be placed into the resource texture. + /// The size of the data buffer to be used to update the resource texture. + /// An for the operation. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int Update( + uint* minimumExtents, + uint* maximumExtents, + uint* strides, + uint dimensions, + byte* data, + uint dataCount) + { + return + ((delegate* unmanaged[Stdcall])this.lpVtbl[4])( + (ID2D1ResourceTextureManager*)Unsafe.AsPointer(ref this), + minimumExtents, + maximumExtents, + strides, + dimensions, + data, + dataCount); + } +} diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManagerInternal.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManagerInternal.cs new file mode 100644 index 00000000..f6115fc9 --- /dev/null +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManagerInternal.cs @@ -0,0 +1,70 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; + +namespace ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers; + +/// +/// The internal resource texture manager type to use with built-in effects. +/// +internal unsafe struct ID2D1ResourceTextureManagerInternal +{ + /// + /// Gets the for ID2D1ResourceTextureManagerInternal (5CBB1024-8EA1-4689-81BF-8AD190B5EF5D). + /// + private static ref readonly Guid Guid + { + get + { + ReadOnlySpan data = new byte[] { + 0x5C, 0xBB, 0x10, 0x24, + 0x8E, 0xA1, + 0x46, 0x89, + 0x81, 0xBF, + 0x8A, + 0xD1, + 0x90, + 0xB5, + 0xEF, + 0x5D + }; + + return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); + } + } + + /// + /// The vtable for the current instance. + /// + private readonly void** lpVtbl; + + /// + /// Sets the for the current ID2D1ResourceTextureManagerInternal instance. + /// + /// The input for the manager. + /// An for the operation. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int SetEffectContext(ID2D1EffectContext* effectContext) + { + return + ((delegate* unmanaged[Stdcall])this.lpVtbl[3])( + (ID2D1ResourceTextureManagerInternal*)Unsafe.AsPointer(ref this), + effectContext); + } + + /// + /// Gets the instance held by the manager. + /// + /// The resulting instance. + /// An for the operation. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int GetResourceTexture(ID2D1ResourceTexture** resourceTexture) + { + return + ((delegate* unmanaged[Stdcall])this.lpVtbl[4])( + (ID2D1ResourceTextureManagerInternal*)Unsafe.AsPointer(ref this), + resourceTexture); + } +}