Add ID2D1TransformMapperProxy type
このコミットが含まれているのは:
1 親
69d4ba3094
コミット
df103b871f
3ファイル変更
+341
-1
検索条件に一致するファイルはありません
@@ -406,7 +406,7 @@ public sealed unsafe class D2D1ResourceTextureManager : ICustomQueryInterface
|
||||
fixed (Guid* pIid = &iid)
|
||||
fixed (IntPtr* pPpv = &ppv)
|
||||
{
|
||||
int hresult = this.d2D1ResourceManagerImpl.Get()->QueryInterface(pIid, (void**)pPpv);
|
||||
int hresult = this.d2D1ResourceManagerImpl.CopyTo(pIid, (void**)pPpv);
|
||||
|
||||
GC.KeepAlive(this);
|
||||
|
||||
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.Interop.Effects;
|
||||
using TerraFX.Interop.Windows;
|
||||
#if !NET6_0_OR_GREATER
|
||||
using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial struct ID2D1TransformMapperProxy
|
||||
{
|
||||
#if !NET6_0_OR_GREATER
|
||||
/// <inheritdoc cref="IUnknown.QueryInterface"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate int QueryInterfaceDelegate(ID2D1TransformMapperProxy* @this, Guid* riid, void** ppvObject);
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate uint AddRefDelegate(ID2D1TransformMapperProxy* @this);
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate uint ReleaseDelegate(ID2D1TransformMapperProxy* @this);
|
||||
|
||||
/// <inheritdoc cref="ID2D1TransformMapper.MapInputRectsToOutputRect"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate int MapInputRectsToOutputRectDelegate(
|
||||
ID2D1TransformMapperProxy* @this,
|
||||
ID2D1DrawInfoUpdateContext* d2D1DrawInfoUpdateContext,
|
||||
RECT* inputRects,
|
||||
RECT* inputOpaqueSubRects,
|
||||
uint inputRectCount,
|
||||
RECT* outputRect,
|
||||
RECT* outputOpaqueSubRect);
|
||||
|
||||
/// <inheritdoc cref="ID2D1TransformMapper.MapOutputRectToInputRects"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate int MapOutputRectToInputRectsDelegate(
|
||||
ID2D1TransformMapperProxy* @this,
|
||||
RECT* outputRect,
|
||||
RECT* inputRects,
|
||||
uint inputRectsCount);
|
||||
|
||||
/// <inheritdoc cref="ID2D1TransformMapper.MapInvalidRect"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate int MapInvalidRectDelegate(
|
||||
ID2D1TransformMapperProxy* @this,
|
||||
uint inputIndex,
|
||||
RECT invalidInputRect,
|
||||
RECT* invalidOutputRect);
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="QueryInterfaceDelegate"/> instance wrapping <see cref="QueryInterface(Guid*, void**)"/>.
|
||||
/// </summary>
|
||||
private static readonly QueryInterfaceDelegate QueryInterfaceWrapper = QueryInterface;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="AddRefDelegate"/> instance wrapping <see cref="AddRef()"/>.
|
||||
/// </summary>
|
||||
private static readonly AddRefDelegate AddRefWrapper = AddRef;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="ReleaseDelegate"/> instance wrapping <see cref="Release()"/>.
|
||||
/// </summary>
|
||||
private static readonly ReleaseDelegate ReleaseWrapper = Release;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="MapInputRectsToOutputRectDelegate"/> instance wrapping <see cref="MapInputRectsToOutputRect"/>.
|
||||
/// </summary>
|
||||
private static readonly MapInputRectsToOutputRectDelegate MapInputRectsToOutputRectWrapper = MapInputRectsToOutputRect;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="MapOutputRectToInputRectsDelegate"/> instance wrapping <see cref="MapOutputRectToInputRects"/>.
|
||||
/// </summary>
|
||||
private static readonly MapOutputRectToInputRectsDelegate MapOutputRectToInputRectsWrapper = MapOutputRectToInputRects;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="MapInvalidRectDelegate"/> instance wrapping <see cref="MapInvalidRect"/>.
|
||||
/// </summary>
|
||||
private static readonly MapInvalidRectDelegate MapInvalidRectWrapper = MapInvalidRect;
|
||||
#endif
|
||||
|
||||
/// <inheritdoc cref="QueryInterface(Guid*, void**)"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int QueryInterface(ID2D1TransformMapperProxy* @this, Guid* riid, void** ppvObject)
|
||||
{
|
||||
return @this->QueryInterface(riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="AddRef()"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static uint AddRef(ID2D1TransformMapperProxy* @this)
|
||||
{
|
||||
return @this->AddRef();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Release()"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static uint Release(ID2D1TransformMapperProxy* @this)
|
||||
{
|
||||
return @this->Release();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1TransformMapper.MapInputRectsToOutputRect"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int MapInputRectsToOutputRect(
|
||||
ID2D1TransformMapperProxy* @this,
|
||||
ID2D1DrawInfoUpdateContext* d2D1DrawInfoUpdateContext,
|
||||
RECT* inputRects,
|
||||
RECT* inputOpaqueSubRects,
|
||||
uint inputRectCount,
|
||||
RECT* outputRect,
|
||||
RECT* outputOpaqueSubRect)
|
||||
{
|
||||
Span<Rectangle> inputs = stackalloc Rectangle[8].Slice(0, (int)inputRectCount);
|
||||
Span<Rectangle> opaqueInputs = stackalloc Rectangle[8].Slice(0, (int)inputRectCount);
|
||||
|
||||
for (int i = 0; i < (int)inputRectCount; i++)
|
||||
{
|
||||
inputs[i] = inputRects[i].ToRectangle();
|
||||
opaqueInputs[i] = inputOpaqueSubRects[i].ToRectangle();
|
||||
}
|
||||
|
||||
Rectangle output;
|
||||
Rectangle opaqueOutput;
|
||||
|
||||
// Invoke MapInputsToOutput and handle exceptions so they don't cross the ABI boundary
|
||||
try
|
||||
{
|
||||
Unsafe.As<ID2D1TransformMapperInterop>(@this->transformMapperHandle.Target!).MapInputsToOutput(
|
||||
d2D1DrawInfoUpdateContext,
|
||||
inputs,
|
||||
opaqueInputs,
|
||||
out output,
|
||||
out opaqueOutput);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return e.HResult;
|
||||
}
|
||||
|
||||
*outputRect = output.ToRECT();
|
||||
*outputOpaqueSubRect = opaqueOutput.ToRECT();
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1TransformMapper.MapOutputRectToInputRects"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int MapOutputRectToInputRects(
|
||||
ID2D1TransformMapperProxy* @this,
|
||||
RECT* outputRect,
|
||||
RECT* inputRects,
|
||||
uint inputRectsCount)
|
||||
{
|
||||
Rectangle output = outputRect->ToRectangle();
|
||||
Span<Rectangle> inputs = stackalloc Rectangle[8].Slice(0, (int)inputRectsCount);
|
||||
|
||||
for (int i = 0; i < (int)inputRectsCount; i++)
|
||||
{
|
||||
inputs[i] = inputRects[i].ToRectangle();
|
||||
}
|
||||
|
||||
// Handle exceptions, as mentioned above
|
||||
try
|
||||
{
|
||||
Unsafe.As<ID2D1TransformMapperInterop>(@this->transformMapperHandle.Target!).MapOutputToInputs(in output, inputs);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return e.HResult;
|
||||
}
|
||||
|
||||
for (int i = 0; i < (int)inputRectsCount; i++)
|
||||
{
|
||||
inputRects[i] = inputs[i].ToRECT();
|
||||
}
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1TransformMapper.MapInvalidRect"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int MapInvalidRect(
|
||||
ID2D1TransformMapperProxy* @this,
|
||||
uint inputIndex,
|
||||
RECT invalidInputRect,
|
||||
RECT* invalidOutputRect)
|
||||
{
|
||||
Rectangle invalidInput = invalidInputRect.ToRectangle();
|
||||
Rectangle invalidOutput;
|
||||
|
||||
// Handle exceptions once again
|
||||
try
|
||||
{
|
||||
Unsafe.As<ID2D1TransformMapperInterop>(@this->transformMapperHandle.Target!).MapInvalidOutput((int)inputIndex, invalidInput, out invalidOutput);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return e.HResult;
|
||||
}
|
||||
|
||||
*invalidOutputRect = invalidOutput.ToRECT();
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using ComputeSharp.D2D1.Interop.Effects;
|
||||
using TerraFX.Interop.Windows;
|
||||
#if NET6_0_OR_GREATER
|
||||
using RuntimeHelpers = System.Runtime.CompilerServices.RuntimeHelpers;
|
||||
#else
|
||||
using RuntimeHelpers = ComputeSharp.D2D1.NetStandard.System.Runtime.CompilerServices.RuntimeHelpers;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
|
||||
|
||||
/// <summary>
|
||||
/// An implementation of the <see cref="ID2D1TransformMapper"/> interface wrapping <see cref="ID2D1TransformMapperInterop"/>.
|
||||
/// </summary>
|
||||
internal unsafe partial struct ID2D1TransformMapperProxy
|
||||
{
|
||||
/// <summary>
|
||||
/// The shared method table pointer for all <see cref="ID2D1TransformMapper"/> instances.
|
||||
/// </summary>
|
||||
private static readonly void** Vtbl = InitVtbl();
|
||||
|
||||
/// <summary>
|
||||
/// Builds the custom method table pointer for <see cref="ID2D1TransformMapper"/>.
|
||||
/// </summary>
|
||||
/// <returns>The method table pointer for <see cref="ID2D1TransformMapper"/>.</returns>
|
||||
private static void** InitVtbl()
|
||||
{
|
||||
void** lpVtbl = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ID2D1TransformMapperProxy), sizeof(void*) * 6);
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
lpVtbl[0] = (delegate* unmanaged<ID2D1TransformMapperProxy*, Guid*, void**, int>)&QueryInterface;
|
||||
lpVtbl[1] = (delegate* unmanaged<ID2D1TransformMapperProxy*, uint>)&AddRef;
|
||||
lpVtbl[2] = (delegate* unmanaged<ID2D1TransformMapperProxy*, uint>)&Release;
|
||||
lpVtbl[3] = (delegate* unmanaged<ID2D1TransformMapperProxy*, ID2D1DrawInfoUpdateContext*, RECT*, RECT*, uint, RECT*, RECT*, int>)&MapInputRectsToOutputRect;
|
||||
lpVtbl[4] = (delegate* unmanaged<ID2D1TransformMapperProxy*, RECT*, RECT*, uint, int>)&MapOutputRectToInputRects;
|
||||
lpVtbl[5] = (delegate* unmanaged<ID2D1TransformMapperProxy*, uint, RECT, RECT*, int>)&MapInvalidRect;
|
||||
#else
|
||||
lpVtbl[0] = (void*)Marshal.GetFunctionPointerForDelegate(QueryInterfaceWrapper);
|
||||
lpVtbl[1] = (void*)Marshal.GetFunctionPointerForDelegate(AddRefWrapper);
|
||||
lpVtbl[2] = (void*)Marshal.GetFunctionPointerForDelegate(ReleaseWrapper);
|
||||
lpVtbl[3] = (void*)Marshal.GetFunctionPointerForDelegate(MapInputRectsToOutputRectWrapper);
|
||||
lpVtbl[4] = (void*)Marshal.GetFunctionPointerForDelegate(MapOutputRectToInputRectsWrapper);
|
||||
lpVtbl[5] = (void*)Marshal.GetFunctionPointerForDelegate(MapInvalidRectWrapper);
|
||||
#endif
|
||||
|
||||
return lpVtbl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The vtable pointer for the current instance.
|
||||
/// </summary>
|
||||
private void** lpVtbl;
|
||||
|
||||
/// <summary>
|
||||
/// The current reference count for the object (from <see cref="IUnknown"/>).
|
||||
/// </summary>
|
||||
private volatile int referenceCount;
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="GCHandle"/> to the wrapped <see cref="ID2D1TransformMapperInterop"/> instance.
|
||||
/// </summary>
|
||||
private GCHandle transformMapperHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The factory method for <see cref="ID2D1TransformMapperProxy"/> instances.
|
||||
/// </summary>
|
||||
/// <param name="transformMapper">The input <see cref="ID2D1TransformMapperInterop"/> instance to wrap.</param>
|
||||
/// <param name="d2D1TransformMapperProxy">The resulting <see cref="ID2D1TransformMapperProxy"/> instance.</param>
|
||||
public static void Factory(
|
||||
ID2D1TransformMapperInterop transformMapper,
|
||||
ID2D1TransformMapperProxy** d2D1TransformMapperProxy)
|
||||
{
|
||||
ID2D1TransformMapperProxy* @this = (ID2D1TransformMapperProxy*)NativeMemory.Alloc((nuint)sizeof(ID2D1TransformMapperProxy));
|
||||
|
||||
@this->lpVtbl = Vtbl;
|
||||
@this->referenceCount = 1;
|
||||
@this->transformMapperHandle = GCHandle.Alloc(transformMapper);
|
||||
|
||||
*d2D1TransformMapperProxy = @this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.QueryInterface"/>
|
||||
public int QueryInterface(Guid* riid, void** ppvObject)
|
||||
{
|
||||
if (ppvObject is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
if (riid->Equals(Windows.__uuidof<IUnknown>()) ||
|
||||
riid->Equals(ID2D1TransformMapper.Guid))
|
||||
{
|
||||
_ = Interlocked.Increment(ref this.referenceCount);
|
||||
|
||||
*ppvObject = Unsafe.AsPointer(ref this);
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
*ppvObject = null;
|
||||
|
||||
return E.E_NOINTERFACE;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
public uint AddRef()
|
||||
{
|
||||
return (uint)Interlocked.Increment(ref this.referenceCount);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
public uint Release()
|
||||
{
|
||||
uint referenceCount = (uint)Interlocked.Decrement(ref this.referenceCount);
|
||||
|
||||
if (referenceCount == 0)
|
||||
{
|
||||
this.transformMapperHandle.Free();
|
||||
|
||||
NativeMemory.Free(Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
return referenceCount;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする