Unify D2D1 effect and transform type implementation
このコミットが含まれているのは:
1 親
edc06630c3
コミット
4adb73fe02
4ファイル変更
+272
-305
検索条件に一致するファイルはありません
+110
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1Interop.Tests.Helpers;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial struct PixelShaderEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The implementation for <see cref="ID2D1DrawTransform"/>.
|
||||
/// </summary>
|
||||
private unsafe static class ID2D1DrawTransformMethods
|
||||
{
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.QueryInterface"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int QueryInterface(PixelShaderEffect* @this, Guid* riid, void** ppvObject)
|
||||
{
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
return @this->QueryInterface(riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.AddRef"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static uint AddRef(PixelShaderEffect* @this)
|
||||
{
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
return @this->AddRef();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.Release"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static uint Release(PixelShaderEffect* @this)
|
||||
{
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
return @this->Release();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.GetInputCount"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static uint GetInputCount(PixelShaderEffect* @this)
|
||||
{
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
return (uint)@this->numberOfInputs;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.MapOutputRectToInputRects"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int MapOutputRectToInputRects(PixelShaderEffect* @this, RECT* outputRect, RECT* inputRects, uint inputRectsCount)
|
||||
{
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
if (inputRectsCount != 1)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
inputRects[0] = *outputRect;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.MapInputRectsToOutputRect"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int MapInputRectsToOutputRect(PixelShaderEffect* @this, RECT* inputRects, RECT* inputOpaqueSubRects, uint inputRectCount, RECT* outputRect, RECT* outputOpaqueSubRect)
|
||||
{
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
if (inputRectCount != 1)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
*outputRect = inputRects[0];
|
||||
|
||||
@this->inputRect = inputRects[0];
|
||||
|
||||
*outputOpaqueSubRect = default;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.MapInvalidRect"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int MapInvalidRect(PixelShaderEffect* @this, uint inputIndex, RECT invalidInputRect, RECT* invalidOutputRect)
|
||||
{
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
*invalidOutputRect = @this->inputRect;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.SetDrawInfo"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int SetDrawInfo(PixelShaderEffect* @this, ID2D1DrawInfo* drawInfo)
|
||||
{
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
@this->d2D1DrawInfo = drawInfo;
|
||||
|
||||
return drawInfo->SetPixelShader(&@this->shaderId);
|
||||
}
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1Interop.Tests.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A simple <see cref="ID2D1EffectImpl"/> and <see cref="ID2D1DrawTransform"/> implementation for a given pixel shader.
|
||||
/// </summary>
|
||||
internal unsafe partial struct PixelShaderEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The implementation for <see cref="ID2D1EffectImpl"/>.
|
||||
/// </summary>
|
||||
private static class ID2D1EffectImplMethods
|
||||
{
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.QueryInterface"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int QueryInterface(PixelShaderEffect* @this, Guid* riid, void** ppvObject)
|
||||
{
|
||||
return @this->QueryInterface(riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.AddRef"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static uint AddRef(PixelShaderEffect* @this)
|
||||
{
|
||||
return @this->AddRef();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.Release"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static uint Release(PixelShaderEffect* @this)
|
||||
{
|
||||
return @this->Release();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.Initialize"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int Initialize(PixelShaderEffect* @this, ID2D1EffectContext* effectContext, ID2D1TransformGraph* transformGraph)
|
||||
{
|
||||
int hresult = effectContext->LoadPixelShader(
|
||||
shaderId: &@this->shaderId,
|
||||
shaderBuffer: @this->bytecode,
|
||||
shaderBufferCount: (uint)@this->bytecodeSize);
|
||||
|
||||
if (Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
hresult = transformGraph->SetSingleTransformNode((ID2D1TransformNode*)&@this->lpVtblForID2D1DrawTransform);
|
||||
}
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.PrepareForRender"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int PrepareForRender(PixelShaderEffect* @this, D2D1_CHANGE_TYPE changeType)
|
||||
{
|
||||
if (@this->constantBuffer is not null)
|
||||
{
|
||||
return @this->d2D1DrawInfo->SetPixelShaderConstantBuffer(
|
||||
buffer: @this->constantBuffer,
|
||||
bufferCount: (uint)@this->constantBufferSize);
|
||||
}
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.SetGraph"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int SetGraph(PixelShaderEffect* @this, ID2D1TransformGraph* transformGraph)
|
||||
{
|
||||
return E.E_NOTIMPL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,202 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1Interop.Tests.Helpers;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial struct PixelShaderEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple <see cref="ID2D1DrawTransform"/> implementation.
|
||||
/// </summary>
|
||||
private unsafe struct PixelShaderTransform
|
||||
{
|
||||
/// <summary>
|
||||
/// The shared vtable pointer for <see cref="PixelShaderTransform"/> instances.
|
||||
/// </summary>
|
||||
private static readonly void** Vtbl = InitVtbl();
|
||||
|
||||
/// <summary>
|
||||
/// Setups the vtable pointer for <see cref="PixelShaderTransform"/>.
|
||||
/// </summary>
|
||||
/// <returns>The initialized vtable pointer for <see cref="PixelShaderTransform"/>.</returns>
|
||||
private static void** InitVtbl()
|
||||
{
|
||||
void** lpVtbl = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(PixelShaderTransform), sizeof(void*) * 8);
|
||||
|
||||
lpVtbl[0] = (delegate* unmanaged<PixelShaderTransform*, Guid*, void**, int>)&QueryInterface;
|
||||
lpVtbl[1] = (delegate* unmanaged<PixelShaderTransform*, uint>)&AddRef;
|
||||
lpVtbl[2] = (delegate* unmanaged<PixelShaderTransform*, uint>)&Release;
|
||||
lpVtbl[3] = (delegate* unmanaged<PixelShaderTransform*, uint>)&GetInputCount;
|
||||
lpVtbl[4] = (delegate* unmanaged<PixelShaderTransform*, RECT*, RECT*, uint, int>)&MapOutputRectToInputRects;
|
||||
lpVtbl[5] = (delegate* unmanaged<PixelShaderTransform*, RECT*, RECT*, uint, RECT*, RECT*, int>)&MapInputRectsToOutputRect;
|
||||
lpVtbl[6] = (delegate* unmanaged<PixelShaderTransform*, uint, RECT, RECT*, int>)&MapInvalidRect;
|
||||
lpVtbl[7] = (delegate* unmanaged<PixelShaderTransform*, ID2D1DrawInfo*, int>)&SetDrawInfo;
|
||||
|
||||
return lpVtbl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The vtable pointer for the current instance.
|
||||
/// </summary>
|
||||
private void** lpVtbl;
|
||||
|
||||
/// <summary>
|
||||
/// The current reference count for the object (from <c>IUnknown</c>).
|
||||
/// </summary>
|
||||
private volatile int referenceCount;
|
||||
|
||||
/// <summary>
|
||||
/// The current input rectangle.
|
||||
/// </summary>
|
||||
private RECT inputRect;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID2D1DrawInfo"/> instance currently in use.
|
||||
/// </summary>
|
||||
private ID2D1DrawInfo* d2D1DrawInfo;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Guid"/> for the shader.
|
||||
/// </summary>
|
||||
private Guid shaderId;
|
||||
|
||||
/// <summary>
|
||||
/// The number of inputs for the shader.
|
||||
/// </summary>
|
||||
private int numberOfInputs;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ID2D1DrawInfo"/> instance currently in use.
|
||||
/// </summary>
|
||||
public ID2D1DrawInfo* D2D1DrawInfo => this.d2D1DrawInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Creates and initializes a new <see cref="PixelShaderTransform"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="shaderId">The <see cref="Guid"/> for the shader.</param>
|
||||
/// <param name="numberOfInpputs">The number of inputs for the shader.</param>
|
||||
/// <returns>A new <see cref="PixelShaderTransform"/> instance.</returns>
|
||||
public static PixelShaderTransform* Create(Guid shaderId, int numberOfInpputs)
|
||||
{
|
||||
PixelShaderTransform* @this = (PixelShaderTransform*)NativeMemory.Alloc((nuint)sizeof(PixelShaderTransform));
|
||||
|
||||
@this->lpVtbl = Vtbl;
|
||||
@this->referenceCount = 1;
|
||||
@this->inputRect = default;
|
||||
@this->d2D1DrawInfo = null;
|
||||
@this->shaderId = shaderId;
|
||||
@this->numberOfInputs = numberOfInpputs;
|
||||
|
||||
return @this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.QueryInterface"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int QueryInterface(PixelShaderTransform* @this, Guid* riid, void** ppvObject)
|
||||
{
|
||||
if (ppvObject is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
if (riid->Equals(Windows.__uuidof<IUnknown>()) ||
|
||||
riid->Equals(Windows.__uuidof<ID2D1TransformNode>()) ||
|
||||
riid->Equals(Windows.__uuidof<ID2D1Transform>()) ||
|
||||
riid->Equals(Windows.__uuidof<ID2D1DrawTransform>()))
|
||||
{
|
||||
_ = Interlocked.Increment(ref @this->referenceCount);
|
||||
|
||||
*ppvObject = @this;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
*ppvObject = null;
|
||||
|
||||
return E.E_NOINTERFACE;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.AddRef"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static uint AddRef(PixelShaderTransform* @this)
|
||||
{
|
||||
return (uint)Interlocked.Increment(ref @this->referenceCount);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.Release"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static uint Release(PixelShaderTransform* @this)
|
||||
{
|
||||
uint referenceCount = (uint)Interlocked.Decrement(ref @this->referenceCount);
|
||||
|
||||
if (referenceCount == 0)
|
||||
{
|
||||
NativeMemory.Free(@this);
|
||||
}
|
||||
|
||||
return referenceCount;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.GetInputCount"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static uint GetInputCount(PixelShaderTransform* @this)
|
||||
{
|
||||
return (uint)@this->numberOfInputs;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.MapOutputRectToInputRects"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int MapOutputRectToInputRects(PixelShaderTransform* @this, RECT* outputRect, RECT* inputRects, uint inputRectsCount)
|
||||
{
|
||||
if (inputRectsCount != 1)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
inputRects[0] = *outputRect;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.MapInputRectsToOutputRect"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int MapInputRectsToOutputRect(PixelShaderTransform* @this, RECT* inputRects, RECT* inputOpaqueSubRects, uint inputRectCount, RECT* outputRect, RECT* outputOpaqueSubRect)
|
||||
{
|
||||
if (inputRectCount != 1)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
*outputRect = inputRects[0];
|
||||
|
||||
@this->inputRect = inputRects[0];
|
||||
|
||||
*outputOpaqueSubRect = default;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.MapInvalidRect"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int MapInvalidRect(PixelShaderTransform* @this, uint inputIndex, RECT invalidInputRect, RECT* invalidOutputRect)
|
||||
{
|
||||
*invalidOutputRect = @this->inputRect;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.SetDrawInfo"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int SetDrawInfo(PixelShaderTransform* @this, ID2D1DrawInfo* drawInfo)
|
||||
{
|
||||
@this->d2D1DrawInfo = drawInfo;
|
||||
|
||||
return drawInfo->SetPixelShader(&@this->shaderId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,18 @@ using TerraFX.Interop.Windows;
|
||||
namespace ComputeSharp.D2D1Interop.Tests.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A simple <see cref="ID2D1EffectImpl"/> implementation for a given pixel shader.
|
||||
/// A simple <see cref="ID2D1EffectImpl"/> and <see cref="ID2D1DrawTransform"/> implementation for a given pixel shader.
|
||||
/// </summary>
|
||||
internal unsafe partial struct PixelShaderEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// A wrapper for an effect factory.
|
||||
/// </summary>
|
||||
/// <param name="effectImpl">The resulting effect factory.</param>
|
||||
/// <returns>The <c>HRESULT</c> for the operation.</returns>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
private delegate int FactoryDelegate(IUnknown** effectImpl);
|
||||
|
||||
/// <summary>
|
||||
/// A generic pixel shader implementation.
|
||||
/// </summary>
|
||||
@@ -83,43 +91,59 @@ internal unsafe partial struct PixelShaderEffect
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The shared vtable pointer for <see cref="PixelShaderEffect"/> instances.
|
||||
/// The shared vtable pointer for <see cref="PixelShaderEffect"/> instance, for <see cref="ID2D1EffectImplMethods"/>.
|
||||
/// </summary>
|
||||
private static readonly void** Vtbl = InitVtbl();
|
||||
private static readonly void** VtblForID2D1EffectImpl;
|
||||
|
||||
/// <summary>
|
||||
/// Setups the vtable pointer for <see cref="PixelShaderEffect"/>.
|
||||
/// The shared vtable pointer for <see cref="PixelShaderEffect"/> instance, for <see cref="ID2D1DrawTransform"/>.
|
||||
/// </summary>
|
||||
/// <returns>The initialized vtable pointer for <see cref="PixelShaderEffect"/>.</returns>
|
||||
private static void** InitVtbl()
|
||||
private static readonly void** VtblForID2D1DrawTransform;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the shared state for <see cref="PixelShaderEffect"/>.
|
||||
/// </summary>
|
||||
static PixelShaderEffect()
|
||||
{
|
||||
void** lpVtbl = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(PixelShaderEffect), sizeof(void*) * 6);
|
||||
void** lpVtbl = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(PixelShaderEffect), sizeof(void*) * 14);
|
||||
|
||||
lpVtbl[0] = (delegate* unmanaged<PixelShaderEffect*, Guid*, void**, int>)&QueryInterface;
|
||||
lpVtbl[1] = (delegate* unmanaged<PixelShaderEffect*, uint>)&AddRef;
|
||||
lpVtbl[2] = (delegate* unmanaged<PixelShaderEffect*, uint>)&Release;
|
||||
lpVtbl[3] = (delegate* unmanaged<PixelShaderEffect*, ID2D1EffectContext*, ID2D1TransformGraph*, int>)&Initialize;
|
||||
lpVtbl[4] = (delegate* unmanaged<PixelShaderEffect*, D2D1_CHANGE_TYPE, int>)&PrepareForRender;
|
||||
lpVtbl[5] = (delegate* unmanaged<PixelShaderEffect*, ID2D1TransformGraph*, int>)&SetGraph;
|
||||
// ID2D1EffectImpl
|
||||
lpVtbl[0] = (delegate* unmanaged<PixelShaderEffect*, Guid*, void**, int>)&ID2D1EffectImplMethods.QueryInterface;
|
||||
lpVtbl[1] = (delegate* unmanaged<PixelShaderEffect*, uint>)&ID2D1EffectImplMethods.AddRef;
|
||||
lpVtbl[2] = (delegate* unmanaged<PixelShaderEffect*, uint>)&ID2D1EffectImplMethods.Release;
|
||||
lpVtbl[3] = (delegate* unmanaged<PixelShaderEffect*, ID2D1EffectContext*, ID2D1TransformGraph*, int>)&ID2D1EffectImplMethods.Initialize;
|
||||
lpVtbl[4] = (delegate* unmanaged<PixelShaderEffect*, D2D1_CHANGE_TYPE, int>)&ID2D1EffectImplMethods.PrepareForRender;
|
||||
lpVtbl[5] = (delegate* unmanaged<PixelShaderEffect*, ID2D1TransformGraph*, int>)&ID2D1EffectImplMethods.SetGraph;
|
||||
|
||||
return lpVtbl;
|
||||
// ID2D1DrawTransform
|
||||
lpVtbl[6 + 0] = (delegate* unmanaged<PixelShaderEffect*, Guid*, void**, int>)&ID2D1DrawTransformMethods.QueryInterface;
|
||||
lpVtbl[6 + 1] = (delegate* unmanaged<PixelShaderEffect*, uint>)&ID2D1DrawTransformMethods.AddRef;
|
||||
lpVtbl[6 + 2] = (delegate* unmanaged<PixelShaderEffect*, uint>)&ID2D1DrawTransformMethods.Release;
|
||||
lpVtbl[6 + 3] = (delegate* unmanaged<PixelShaderEffect*, uint>)&ID2D1DrawTransformMethods.GetInputCount;
|
||||
lpVtbl[6 + 4] = (delegate* unmanaged<PixelShaderEffect*, RECT*, RECT*, uint, int>)&ID2D1DrawTransformMethods.MapOutputRectToInputRects;
|
||||
lpVtbl[6 + 5] = (delegate* unmanaged<PixelShaderEffect*, RECT*, RECT*, uint, RECT*, RECT*, int>)&ID2D1DrawTransformMethods.MapInputRectsToOutputRect;
|
||||
lpVtbl[6 + 6] = (delegate* unmanaged<PixelShaderEffect*, uint, RECT, RECT*, int>)&ID2D1DrawTransformMethods.MapInvalidRect;
|
||||
lpVtbl[6 + 7] = (delegate* unmanaged<PixelShaderEffect*, ID2D1DrawInfo*, int>)&ID2D1DrawTransformMethods.SetDrawInfo;
|
||||
|
||||
VtblForID2D1EffectImpl = lpVtbl;
|
||||
VtblForID2D1DrawTransform = &lpVtbl[6];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The vtable pointer for the current instance.
|
||||
/// The vtable pointer for the current instance, for <see cref="ID2D1Effect"/>.
|
||||
/// </summary>
|
||||
private void** lpVtbl;
|
||||
private void** lpVtblForID2D1EffectImpl;
|
||||
|
||||
/// <summary>
|
||||
/// The vtable pointer for the current instance, for <see cref="ID2D1DrawTransform"/>.
|
||||
/// </summary>
|
||||
private void** lpVtblForID2D1DrawTransform;
|
||||
|
||||
/// <summary>
|
||||
/// The current reference count for the object (from <c>IUnknown</c>).
|
||||
/// </summary>
|
||||
private volatile int referenceCount;
|
||||
|
||||
/// <summary>
|
||||
/// The linked <see cref="PixelShaderTransform"/> instance currently in use.
|
||||
/// </summary>
|
||||
private PixelShaderTransform* pixelShaderTransform;
|
||||
|
||||
/// <summary>
|
||||
/// The constant buffer data, if set.
|
||||
/// </summary>
|
||||
@@ -151,29 +175,14 @@ internal unsafe partial struct PixelShaderEffect
|
||||
private int numberOfInputs;
|
||||
|
||||
/// <summary>
|
||||
/// Creates and initializes a new <see cref="PixelShaderEffect"/> instance.
|
||||
/// The current input rectangle.
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="PixelShaderEffect"/> instance.</returns>
|
||||
private static PixelShaderEffect* Create()
|
||||
{
|
||||
PixelShaderEffect* @this = (PixelShaderEffect*)NativeMemory.Alloc((nuint)sizeof(PixelShaderEffect));
|
||||
|
||||
@this->lpVtbl = Vtbl;
|
||||
@this->referenceCount = 1;
|
||||
@this->pixelShaderTransform = null;
|
||||
@this->constantBuffer = null;
|
||||
@this->constantBufferSize = 0;
|
||||
|
||||
return @this;
|
||||
}
|
||||
private RECT inputRect;
|
||||
|
||||
/// <summary>
|
||||
/// A wrapper for an effect factory.
|
||||
/// The <see cref="ID2D1DrawInfo"/> instance currently in use.
|
||||
/// </summary>
|
||||
/// <param name="effectImpl">The resulting effect factory.</param>
|
||||
/// <returns>The <c>HRESULT</c> for the operation.</returns>
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
private delegate int FactoryDelegate(IUnknown** effectImpl);
|
||||
private ID2D1DrawInfo* d2D1DrawInfo;
|
||||
|
||||
/// <summary>
|
||||
/// The factory method for <see cref="ID2D1Factory2.RegisterEffectFromString"/>.
|
||||
@@ -182,20 +191,23 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// <param name="bytecode">The shader bytecode.</param>
|
||||
/// <param name="effectImpl">The resulting effect instance.</param>
|
||||
/// <param name="bytecodeSize">The size of <paramref name="bytecode"/>.</param>
|
||||
/// <param name="numberOfInpputs">The number of inputs for the shader.</param>
|
||||
/// <param name="numberOfInputs">The number of inputs for the shader.</param>
|
||||
/// <returns>This always returns <c>0</c>.</returns>
|
||||
private static int Factory(Guid shaderId, byte* bytecode, int bytecodeSize, int numberOfInpputs, IUnknown** effectImpl)
|
||||
private static int Factory(Guid shaderId, byte* bytecode, int bytecodeSize, int numberOfInputs, IUnknown** effectImpl)
|
||||
{
|
||||
PixelShaderEffect* pixelShaderEffect = Create();
|
||||
PixelShaderTransform* pixelShaderTransform = PixelShaderTransform.Create(shaderId, numberOfInpputs);
|
||||
PixelShaderEffect* @this = (PixelShaderEffect*)NativeMemory.Alloc((nuint)sizeof(PixelShaderEffect));
|
||||
|
||||
pixelShaderEffect->pixelShaderTransform = pixelShaderTransform;
|
||||
pixelShaderEffect->shaderId = shaderId;
|
||||
pixelShaderEffect->bytecode = bytecode;
|
||||
pixelShaderEffect->bytecodeSize = bytecodeSize;
|
||||
pixelShaderEffect->numberOfInputs = numberOfInpputs;
|
||||
*@this = default;
|
||||
|
||||
*effectImpl = (IUnknown*)pixelShaderEffect;
|
||||
@this->lpVtblForID2D1EffectImpl = VtblForID2D1EffectImpl;
|
||||
@this->lpVtblForID2D1DrawTransform = VtblForID2D1DrawTransform;
|
||||
@this->referenceCount = 1;
|
||||
@this->shaderId = shaderId;
|
||||
@this->bytecode = bytecode;
|
||||
@this->bytecodeSize = bytecodeSize;
|
||||
@this->numberOfInputs = numberOfInputs;
|
||||
|
||||
*effectImpl = (IUnknown*)@this;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
@@ -244,20 +256,32 @@ internal unsafe partial struct PixelShaderEffect
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.QueryInterface"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int QueryInterface(PixelShaderEffect* @this, Guid* riid, void** ppvObject)
|
||||
private int QueryInterface(Guid* riid, void** ppvObject)
|
||||
{
|
||||
if (ppvObject is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
// ID2D1EffectImpl
|
||||
if (riid->Equals(Windows.__uuidof<IUnknown>()) ||
|
||||
riid->Equals(Windows.__uuidof<ID2D1EffectImpl>()))
|
||||
{
|
||||
_ = Interlocked.Increment(ref @this->referenceCount);
|
||||
_ = Interlocked.Increment(ref this.referenceCount);
|
||||
|
||||
*ppvObject = @this;
|
||||
*ppvObject = Unsafe.AsPointer(ref this);
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
// ID2D1DrawTransform
|
||||
if (riid->Equals(Windows.__uuidof<ID2D1TransformNode>()) ||
|
||||
riid->Equals(Windows.__uuidof<ID2D1Transform>()) ||
|
||||
riid->Equals(Windows.__uuidof<ID2D1DrawTransform>()))
|
||||
{
|
||||
_ = Interlocked.Increment(ref this.referenceCount);
|
||||
|
||||
*ppvObject = (void**)Unsafe.AsPointer(ref this) + 1;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
@@ -268,68 +292,26 @@ internal unsafe partial struct PixelShaderEffect
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.AddRef"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static uint AddRef(PixelShaderEffect* @this)
|
||||
private uint AddRef()
|
||||
{
|
||||
return (uint)Interlocked.Increment(ref @this->referenceCount);
|
||||
return (uint)Interlocked.Increment(ref this.referenceCount);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.Release"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static uint Release(PixelShaderEffect* @this)
|
||||
private uint Release()
|
||||
{
|
||||
uint referenceCount = (uint)Interlocked.Decrement(ref @this->referenceCount);
|
||||
uint referenceCount = (uint)Interlocked.Decrement(ref this.referenceCount);
|
||||
|
||||
if (referenceCount == 0)
|
||||
{
|
||||
((IUnknown*)@this->pixelShaderTransform)->Release();
|
||||
|
||||
if (@this->constantBuffer is not null)
|
||||
if (this.constantBuffer is not null)
|
||||
{
|
||||
NativeMemory.Free(@this->constantBuffer);
|
||||
NativeMemory.Free(this.constantBuffer);
|
||||
}
|
||||
|
||||
NativeMemory.Free(@this);
|
||||
NativeMemory.Free(Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
return referenceCount;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.Initialize"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int Initialize(PixelShaderEffect* @this, ID2D1EffectContext* effectContext, ID2D1TransformGraph* transformGraph)
|
||||
{
|
||||
int hresult = effectContext->LoadPixelShader(
|
||||
shaderId: &@this->shaderId,
|
||||
shaderBuffer: @this->bytecode,
|
||||
shaderBufferCount: (uint)@this->bytecodeSize);
|
||||
|
||||
if (Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
hresult = transformGraph->SetSingleTransformNode((ID2D1TransformNode*)@this->pixelShaderTransform);
|
||||
}
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.PrepareForRender"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int PrepareForRender(PixelShaderEffect* @this, D2D1_CHANGE_TYPE changeType)
|
||||
{
|
||||
if (@this->constantBuffer is not null)
|
||||
{
|
||||
return @this->pixelShaderTransform->D2D1DrawInfo->SetPixelShaderConstantBuffer(
|
||||
buffer: @this->constantBuffer,
|
||||
bufferCount: (uint)@this->constantBufferSize);
|
||||
}
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.SetGraph"/>
|
||||
[UnmanagedCallersOnly]
|
||||
private static int SetGraph(PixelShaderEffect* @this, ID2D1TransformGraph* transformGraph)
|
||||
{
|
||||
return E.E_NOTIMPL;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする