From 5e94c4b3ad1056db1252bd41ff18b4bd4f5be95d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 28 May 2022 13:55:33 +0200 Subject: [PATCH] Add missing ID2D1DrawInfo::AddRef calls --- ...ixelShaderEffect.ID2D1DrawTransformMethods.cs | 9 +++++++++ .../Shaders/Interop/Effects/PixelShaderEffect.cs | 5 +++++ .../DirectX/um/d2d1effectauthor/ID2D1DrawInfo.cs | 16 ++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs index f5d73715..4b9995ff 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs @@ -321,6 +321,15 @@ partial struct PixelShaderEffect { @this = (PixelShaderEffect*)&((void**)@this)[-1]; + // Free the previous ID2D1DrawInfo object, if present + if (@this->d2D1DrawInfo is not null) + { + _ = @this->d2D1DrawInfo->Release(); + } + + // Store the new ID2D1DrawInfo object + _ = drawInfo->AddRef(); + @this->d2D1DrawInfo = drawInfo; // Set the pixel shader for the effect diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs index 6524b34e..fb99a9e7 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs @@ -374,6 +374,11 @@ internal unsafe partial struct PixelShaderEffect this.d2D1TransformMapperHandle.Free(); + if (this.d2D1DrawInfo is not null) + { + _ = this.d2D1DrawInfo->Release(); + } + NativeMemory.Free(Unsafe.AsPointer(ref this)); } diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/ID2D1DrawInfo.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/ID2D1DrawInfo.cs index bd4d7036..f1412941 100644 --- a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/ID2D1DrawInfo.cs +++ b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/ID2D1DrawInfo.cs @@ -20,6 +20,22 @@ namespace TerraFX.Interop.DirectX { public void** lpVtbl; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(1)] + [return: NativeTypeName("ULONG")] + public uint AddRef() + { + return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IUnknown*)Unsafe.AsPointer(ref this)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(2)] + [return: NativeTypeName("ULONG")] + public uint Release() + { + return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IUnknown*)Unsafe.AsPointer(ref this)); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] [VtblIndex(3)] public HRESULT SetInputDescription([NativeTypeName("UINT32")] uint inputIndex, D2D1_INPUT_DESCRIPTION inputDescription)