Add ID2D1EffectContextExtensions type and polyfills

このコミットが含まれているのは:
Sergio Pedri committed 2022-08-15 15:01:18 +02:00
1 親 e04887a3e6
コミット bdd4839f55
6ファイル変更
+245

検索条件に一致するファイルはありません

+66
ファイルの表示
@@ -0,0 +1,66 @@
using System;
using System.Runtime.CompilerServices;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
namespace ComputeSharp.D2D1.Shaders.Interop.Extensions;
/// <summary>
/// Extensions for the <see cref="ID2D1Multithread"/> type.
/// </summary>
internal static class ID2D1EffectContextExtensions
{
/// <summary>
/// Gets an <see cref="ID2D1Multithread"/> from an input <see cref="ID2D1EffectContext"/> object.
/// </summary>
/// <param name="effectContext">The input <see cref="ID2D1EffectContext"/> instance.</param>
/// <param name="multithread">The resulting <see cref="ID2D1Multithread"/> object.</param>
/// <returns>The <see cref="HRESULT"/> for the operation</returns>
/// <remarks>
/// <para>
/// The <see cref="ID2D1EffectContext"/> 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 <see cref="ID2D1EffectImpl"/>. To avoid issues, it is necessary to lock with the same lock
/// used by D2D when using any public API on <see cref="ID2D1EffectContext"/> from other callsites.
/// The same goes for any type out of <c>d2d1effectauthor.h</c>, such as <see cref="ID2D1ResourceTexture"/>.
/// </para>
/// <para>
/// To lock, the <see cref="ID2D1Multithread"/> object can be used. To retrieve this, a <see cref="ID2D1Factory"/>
/// instance is needed. This cannot be retrieved directly from an <see cref="ID2D1EffectContext"/>, but this
/// can be used to create any <see cref="ID2D1Effect"/> instance (such as a flood effect, which is fairly cheap).
/// From that, <see cref="IUnknown.QueryInterface"/> can be used to get an <see cref="ID2D1Image"/> object.
/// The fact <see cref="ID2D1Effect"/> implements this interface is mentioned in the <see cref="ID2D1Image"/> docs,
/// see <see href="https://docs.microsoft.com/en-us/windows/desktop/api/d2d1_1/nf-d2d1_1-id2d1effect-getoutput"/>.
/// </para>
/// <para>
/// From the <see cref="ID2D1Image"/>, an <see cref="ID2D1Factory"/> can be retrieved. Finally, this can
/// be cast to <see cref="ID2D1Multithread"/>, which can then be kept and used to synchronize later calls.
/// </para>
/// </remarks>
public static unsafe int GetD2D1Multithread(this ref ID2D1EffectContext effectContext, ID2D1Multithread** multithread)
{
using ComPtr<ID2D1Effect> 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<ID2D1Image> d2D1Image = default;
hresult = floodEffect.CopyTo(d2D1Image.GetAddressOf());
if (Windows.SUCCEEDED(hresult))
{
using ComPtr<ID2D1Factory> d2D1Factory = default;
d2D1Image.Get()->GetFactory(d2D1Factory.GetAddressOf());
hresult = d2D1Factory.CopyTo(multithread);
}
}
return hresult;
}
}
+20
ファイルの表示
@@ -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;
}
}
+55
ファイルの表示
@@ -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;
/// <inheritdoc cref="IUnknown.QueryInterface" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(0)]
public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject)
{
return ((delegate* unmanaged[Stdcall]<ID2D1Image*, Guid*, void**, int>)(lpVtbl[0]))((ID2D1Image*)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]<ID2D1Image*, uint>)(lpVtbl[1]))((ID2D1Image*)Unsafe.AsPointer(ref this));
}
/// <inheritdoc cref="IUnknown.Release" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(2)]
[return: NativeTypeName("ULONG")]
public uint Release()
{
return ((delegate* unmanaged[Stdcall]<ID2D1Image*, uint>)(lpVtbl[2]))((ID2D1Image*)Unsafe.AsPointer(ref this));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(3)]
public void GetFactory(ID2D1Factory** factory)
{
((delegate* unmanaged[Stdcall]<ID2D1Image*, ID2D1Factory**, void>)(lpVtbl[3]))((ID2D1Image*)Unsafe.AsPointer(ref this), factory);
}
}
}
+62
ファイルの表示
@@ -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;
/// <inheritdoc cref="IUnknown.QueryInterface" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(0)]
public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject)
{
return ((delegate* unmanaged[Stdcall]<ID2D1Multithread*, Guid*, void**, int>)(lpVtbl[0]))((ID2D1Multithread*)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]<ID2D1Multithread*, uint>)(lpVtbl[1]))((ID2D1Multithread*)Unsafe.AsPointer(ref this));
}
/// <inheritdoc cref="IUnknown.Release" />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(2)]
[return: NativeTypeName("ULONG")]
public uint Release()
{
return ((delegate* unmanaged[Stdcall]<ID2D1Multithread*, uint>)(lpVtbl[2]))((ID2D1Multithread*)Unsafe.AsPointer(ref this));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(4)]
public void Enter()
{
((delegate* unmanaged[Stdcall]<ID2D1Multithread*, void>)(lpVtbl[4]))((ID2D1Multithread*)Unsafe.AsPointer(ref this));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(5)]
public void Leave()
{
((delegate* unmanaged[Stdcall]<ID2D1Multithread*, void>)(lpVtbl[5]))((ID2D1Multithread*)Unsafe.AsPointer(ref this));
}
}
}
+38
ファイルの表示
@@ -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<byte> data = new byte[] {
0x20, 0x3C, 0xC2, 0x61,
0x69, 0xAE,
0x8E, 0x4D,
0x94,
0xCF,
0x50,
0x07,
0x8D,
0xF6,
0x38,
0xF2
};
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
}
}
}
}
+4
ファイルの表示
@@ -25,13 +25,17 @@
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\ID2D1Transform.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\ID2D1TransformGraph.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\ID2D1TransformNode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effects\CLSID.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1\D2D1_EXTEND_MODE.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1\ID2D1Factory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1\ID2D1Image.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\D2D1_CHANNEL_DEPTH.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\D2D1_BUFFER_PRECISION.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\D2D1_PROPERTY_TYPE.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\ID2D1DeviceContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\ID2D1Effect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\ID2D1Factory1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\ID2D1Multithread.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcommon\D3D_INCLUDE_TYPE.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcommon\D3D_SHADER_MACRO.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3d11shader\D3D11_SHADER_DESC.cs" />