diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Extensions/ID2D1EffectContextExtensions.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Extensions/ID2D1EffectContextExtensions.cs new file mode 100644 index 00000000..17b5dde6 --- /dev/null +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Extensions/ID2D1EffectContextExtensions.cs @@ -0,0 +1,66 @@ +using System; +using System.Runtime.CompilerServices; +using TerraFX.Interop.DirectX; +using TerraFX.Interop.Windows; + +namespace ComputeSharp.D2D1.Shaders.Interop.Extensions; + +/// +/// Extensions for the type. +/// +internal static class ID2D1EffectContextExtensions +{ + /// + /// Gets an from an input object. + /// + /// The input instance. + /// The resulting object. + /// The for the operation + /// + /// + /// The object is not thread-safe, so it cannot be used concurrently + /// when outside of a scenario where D2D has explicitly called into user code (eg. in the public APIs + /// from . To avoid issues, it is necessary to lock with the same lock + /// used by D2D when using any public API on from other callsites. + /// The same goes for any type out of d2d1effectauthor.h, such as . + /// + /// + /// To lock, the object can be used. To retrieve this, a + /// instance is needed. This cannot be retrieved directly from an , but this + /// can be used to create any instance (such as a flood effect, which is fairly cheap). + /// From that, can be used to get an object. + /// The fact implements this interface is mentioned in the docs, + /// see . + /// + /// + /// From the , an can be retrieved. Finally, this can + /// be cast to , which can then be kept and used to synchronize later calls. + /// + /// + public static unsafe int GetD2D1Multithread(this ref ID2D1EffectContext effectContext, ID2D1Multithread** multithread) + { + using ComPtr floodEffect = default; + + int hresult = effectContext.CreateEffect( + effectId: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_D2D1Flood)), + effect: (void**)floodEffect.GetAddressOf()); + + if (Windows.SUCCEEDED(hresult)) + { + using ComPtr d2D1Image = default; + + hresult = floodEffect.CopyTo(d2D1Image.GetAddressOf()); + + if (Windows.SUCCEEDED(hresult)) + { + using ComPtr d2D1Factory = default; + + d2D1Image.Get()->GetFactory(d2D1Factory.GetAddressOf()); + + hresult = d2D1Factory.CopyTo(multithread); + } + } + + return hresult; + } +} diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1/ID2D1Factory.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1/ID2D1Factory.cs new file mode 100644 index 00000000..e690fd2f --- /dev/null +++ b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1/ID2D1Factory.cs @@ -0,0 +1,20 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from um/d2d1.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +using System; +using System.Runtime.InteropServices; + +#pragma warning disable CS0649 + +namespace TerraFX.Interop.DirectX +{ + [Guid("06152247-6F50-465A-9245-118BFD3B6007")] + [NativeTypeName("struct ID2D1Factory : IUnknown")] + [NativeInheritance("IUnknown")] + internal unsafe partial struct ID2D1Factory + { + public void** lpVtbl; + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1/ID2D1Image.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1/ID2D1Image.cs new file mode 100644 index 00000000..bfa830c6 --- /dev/null +++ b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1/ID2D1Image.cs @@ -0,0 +1,55 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from um/d2d1.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using TerraFX.Interop.Windows; + +#pragma warning disable CS0649 + +namespace TerraFX.Interop.DirectX +{ + [Guid("65019F75-8DA2-497C-B32C-DFA34E48EDE6")] + [NativeTypeName("struct ID2D1Image : ID2D1Resource")] + [NativeInheritance("ID2D1Resource")] + internal unsafe partial struct ID2D1Image + { + public void** lpVtbl; + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(0)] + public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject) + { + return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((ID2D1Image*)Unsafe.AsPointer(ref this), riid, ppvObject); + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(1)] + [return: NativeTypeName("ULONG")] + public uint AddRef() + { + return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((ID2D1Image*)Unsafe.AsPointer(ref this)); + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(2)] + [return: NativeTypeName("ULONG")] + public uint Release() + { + return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((ID2D1Image*)Unsafe.AsPointer(ref this)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(3)] + public void GetFactory(ID2D1Factory** factory) + { + ((delegate* unmanaged[Stdcall])(lpVtbl[3]))((ID2D1Image*)Unsafe.AsPointer(ref this), factory); + } + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_1/ID2D1Multithread.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_1/ID2D1Multithread.cs new file mode 100644 index 00000000..93cc3351 --- /dev/null +++ b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1_1/ID2D1Multithread.cs @@ -0,0 +1,62 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from um/d2d1_1.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using TerraFX.Interop.Windows; + +#pragma warning disable CS0649 + +namespace TerraFX.Interop.DirectX +{ + [Guid("31E6E7BC-E0FF-4D46-8C64-A0A8C41C15D3")] + [NativeTypeName("struct ID2D1Multithread : IUnknown")] + [NativeInheritance("IUnknown")] + internal unsafe partial struct ID2D1Multithread + { + public void** lpVtbl; + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(0)] + public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject) + { + return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((ID2D1Multithread*)Unsafe.AsPointer(ref this), riid, ppvObject); + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(1)] + [return: NativeTypeName("ULONG")] + public uint AddRef() + { + return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((ID2D1Multithread*)Unsafe.AsPointer(ref this)); + } + + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(2)] + [return: NativeTypeName("ULONG")] + public uint Release() + { + return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((ID2D1Multithread*)Unsafe.AsPointer(ref this)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(4)] + public void Enter() + { + ((delegate* unmanaged[Stdcall])(lpVtbl[4]))((ID2D1Multithread*)Unsafe.AsPointer(ref this)); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [VtblIndex(5)] + public void Leave() + { + ((delegate* unmanaged[Stdcall])(lpVtbl[5]))((ID2D1Multithread*)Unsafe.AsPointer(ref this)); + } + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effects/CLSID.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effects/CLSID.cs new file mode 100644 index 00000000..e63a48c6 --- /dev/null +++ b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effects/CLSID.cs @@ -0,0 +1,38 @@ +// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. + +// Ported from um/d2d1effects.h in the Windows SDK for Windows 10.0.22000.0 +// Original source is Copyright © Microsoft. All rights reserved. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace TerraFX.Interop.Windows +{ + internal static partial class CLSID + { + [NativeTypeName("const GUID")] + public static ref readonly Guid CLSID_D2D1Flood + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + ReadOnlySpan data = new byte[] { + 0x20, 0x3C, 0xC2, 0x61, + 0x69, 0xAE, + 0x8E, 0x4D, + 0x94, + 0xCF, + 0x50, + 0x07, + 0x8D, + 0xF6, + 0x38, + 0xF2 + }; + + return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); + } + } + } +} \ No newline at end of file diff --git a/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems b/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems index 154db186..f607566b 100644 --- a/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems +++ b/src/TerraFX.Interop.Windows.D2D1/TerraFX.Interop.Windows.D2D1.projitems @@ -25,13 +25,17 @@ + + + +