From d02f8f3a9f100f4da34a641b663014a3bce345b2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 11 Aug 2022 22:53:24 +0200 Subject: [PATCH] Update code to use new COM interface binding ttypes --- .../Interop/D2D1ResourceTextureManager.cs | 68 ++++++++++--------- .../ID2D1ResourceTextureManager.cs | 2 + .../ID2D1ResourceTextureManagerInternal.cs | 4 +- ...tureManager.ID2D1ResourceTextureManager.cs | 24 +------ ...ger.ID2D1ResourceTextureManagerInternal.cs | 14 +--- .../ResourceTextureManager.cs | 51 +------------- 6 files changed, 47 insertions(+), 116 deletions(-) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureManager.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureManager.cs index de94028c..1927e19c 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureManager.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureManager.cs @@ -81,17 +81,21 @@ public static unsafe class D2D1ResourceTextureManager } /// - /// + /// Initializes a given ID2D1ResourceTextureManager instance. /// - /// - /// - /// - /// - /// - /// - /// - /// - /// + /// A pointer to the ID2D1ResourceTextureManager instance to use. + /// The resource id for the resource to create. + /// The extents of the resource to create. + /// The buffer precision for the resource to create. + /// The channel depth for the resource to create. + /// The filter for the resource to create. + /// The extend modes for the resource to create. + /// The data to load in the resource to create. + /// The strides for the data supplied for the resource to create. + /// + /// Depending on internal state, might immediately create the resource + /// texture, or it might buffer the data internally and then create the resource texture at a later time. + /// public static void Initialize( void* resourceTextureManager, Guid resourceId, @@ -118,25 +122,25 @@ public static unsafe class D2D1ResourceTextureManager d2D1ResourceTextureProperties.filter = (D2D1_FILTER)filter; d2D1ResourceTextureProperties.extendModes = (D2D1_EXTEND_MODE*)pExtendModes; - _ = ((delegate* unmanaged[Stdcall])(*(void***)resourceTextureManager)[3])( - resourceTextureManager, - &resourceId, - &d2D1ResourceTextureProperties, - pData, - pStrides, - (uint)data.Length); + // TODO: validate + _ = ((ID2D1ResourceTextureManager*)resourceTextureManager)->Initialize( + resourceId: &resourceId, + resourceTextureProperties: &d2D1ResourceTextureProperties, + data: pData, + strides: pStrides, + dataSize: (uint)data.Length); } } /// - /// + /// Updates the data in a given ID2D1ResourceTextureManager instance. /// - /// - /// - /// - /// - /// - /// + /// A pointer to the ID2D1ResourceTextureManager instance to use. + /// The "left" extent of the updates if specified (if empty, the entire texture is updated). + /// The "right" extent of the updates if specified (if empty, 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. public static void Update( void* resourceTextureManager, ReadOnlySpan minimumExtents, @@ -152,14 +156,14 @@ public static unsafe class D2D1ResourceTextureManager fixed (uint* pStrides = strides) fixed (byte* pData = data) { - _ = ((delegate* unmanaged[Stdcall])(*(void***)resourceTextureManager)[4])( - resourceTextureManager, - pMinimumExtents, - pMaximumExtents, - pStrides, - dimensions, - pData, - (uint)data.Length); + // TODO: validate + _ = ((ID2D1ResourceTextureManager*)resourceTextureManager)->Update( + minimumExtents: pMinimumExtents, + maximumExtents: pMaximumExtents, + strides: pStrides, + dimensions: dimensions, + data: pData, + dataCount: (uint)data.Length); } } } diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManager.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManager.cs index e7abbbba..da7d07fd 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManager.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManager.cs @@ -4,6 +4,8 @@ using System.Runtime.InteropServices; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +#pragma warning disable CS0649 + namespace ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers; /// diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManagerInternal.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManagerInternal.cs index f6115fc9..fb9635fb 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManagerInternal.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ID2D1ResourceTextureManagerInternal.cs @@ -4,6 +4,8 @@ using System.Runtime.InteropServices; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +#pragma warning disable CS0649 + namespace ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers; /// @@ -14,7 +16,7 @@ internal unsafe struct ID2D1ResourceTextureManagerInternal /// /// Gets the for ID2D1ResourceTextureManagerInternal (5CBB1024-8EA1-4689-81BF-8AD190B5EF5D). /// - private static ref readonly Guid Guid + public static ref readonly Guid Guid { get { diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ResourceTextureManager.ID2D1ResourceTextureManager.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ResourceTextureManager.ID2D1ResourceTextureManager.cs index 896bc334..364574c7 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ResourceTextureManager.ID2D1ResourceTextureManager.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ResourceTextureManager.ID2D1ResourceTextureManager.cs @@ -85,17 +85,7 @@ partial struct ResourceTextureManager return @this->Release(); } - /// - /// 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. - /// - /// The current ID2D1ResourceTextureManager instance. - /// 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. + /// [UnmanagedCallersOnly] public static int Initialize( ResourceTextureManager* @this, @@ -175,17 +165,7 @@ partial struct ResourceTextureManager return 0; } - /// - /// Updates the specific resource texture inside the specific range or box using the supplied data. - /// - /// The current ID2D1ResourceTextureManager instance. - /// 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. + /// [UnmanagedCallersOnly] public static int Update( ResourceTextureManager* @this, diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ResourceTextureManager.ID2D1ResourceTextureManagerInternal.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ResourceTextureManager.ID2D1ResourceTextureManagerInternal.cs index 462ca410..1ace7736 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ResourceTextureManager.ID2D1ResourceTextureManagerInternal.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ResourceTextureManager.ID2D1ResourceTextureManagerInternal.cs @@ -78,12 +78,7 @@ partial struct ResourceTextureManager return @this->Release(); } - /// - /// Sets the for the current ID2D1ResourceTextureManagerInternal instance. - /// - /// The current ID2D1ResourceTextureManagerInternal instance. - /// The input for the manager. - /// An for the operation. + /// [UnmanagedCallersOnly] public static int SetEffectContext(ResourceTextureManager* @this, ID2D1EffectContext* effectContext) { @@ -110,12 +105,7 @@ partial struct ResourceTextureManager return S.S_FALSE; } - /// - /// Gets the instance held by the manager. - /// - /// The current ID2D1ResourceTextureManagerInternal instance. - /// The resulting instance. - /// An for the operation. + /// [UnmanagedCallersOnly] public static int GetResourceTexture(ResourceTextureManager* @this, ID2D1ResourceTexture** resourceTexture) { diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ResourceTextureManager.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ResourceTextureManager.cs index 39f766cd..d5bdbfd3 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ResourceTextureManager.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/ResourceManagers/ResourceTextureManager.cs @@ -17,53 +17,6 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers; /// internal unsafe partial struct ResourceTextureManager { - /// - /// Gets the for ID2D1ResourceTextureManager (3C4FC7E4-A419-46CA-B5F6-66EB4FF18D64). - /// - private static ref readonly Guid IID_ID2D1ResourceTextureManager - { - 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)); - } - } - - /// - /// Gets the for ID2D1ResourceTextureManagerInternal (5CBB1024-8EA1-4689-81BF-8AD190B5EF5D). - /// - private static ref readonly Guid IID_ID2D1ResourceTextureManagerInternal - { - 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)); - } - } - /// [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate int QueryInterfaceDelegate(ResourceTextureManager* @this, Guid* riid, void** ppvObject); @@ -231,7 +184,7 @@ internal unsafe partial struct ResourceTextureManager // ID2D1ResourceTextureManager if (riid->Equals(Windows.__uuidof()) || - riid->Equals(IID_ID2D1ResourceTextureManager)) + riid->Equals(ID2D1ResourceTextureManager.Guid)) { _ = Interlocked.Increment(ref this.referenceCount); @@ -241,7 +194,7 @@ internal unsafe partial struct ResourceTextureManager } // ID2D1ResourceTextureManagerInternal - if (riid->Equals(IID_ID2D1ResourceTextureManagerInternal)) + if (riid->Equals(ID2D1ResourceTextureManagerInternal.Guid)) { _ = Interlocked.Increment(ref this.referenceCount);