using System; using System.Runtime.InteropServices; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; #if !NET6_0_OR_GREATER using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute; #endif namespace ComputeSharp.D2D1.Interop.Effects; /// /// A simple and implementation for a given pixel shader. /// internal unsafe partial struct PixelShaderEffect { /// /// The implementation for . /// private static class ID2D1EffectImplMethods { #if !NET6_0_OR_GREATER /// [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate int InitializeDelegate(PixelShaderEffect* @this, ID2D1EffectContext* effectContext, ID2D1TransformGraph* transformGraph); /// [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate int PrepareForRenderDelegate(PixelShaderEffect* @this, D2D1_CHANGE_TYPE changeType); /// [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate int SetGraphDelegate(PixelShaderEffect* @this, ID2D1TransformGraph* transformGraph); /// /// A cached instance wrapping . /// public static readonly QueryInterfaceDelegate QueryInterfaceWrapper = QueryInterface; /// /// A cached instance wrapping . /// public static readonly AddRefDelegate AddRefWrapper = AddRef; /// /// A cached instance wrapping . /// public static readonly ReleaseDelegate ReleaseWrapper = Release; /// /// A cached instance wrapping . /// public static readonly InitializeDelegate InitializeWrapper = Initialize; /// /// A cached instance wrapping . /// public static readonly PrepareForRenderDelegate PrepareForRenderWrapper = PrepareForRender; /// /// A cached instance wrapping . /// public static readonly SetGraphDelegate SetGraphWrapper = SetGraph; #endif /// [UnmanagedCallersOnly] public static int QueryInterface(PixelShaderEffect* @this, Guid* riid, void** ppvObject) { return @this->QueryInterface(riid, ppvObject); } /// [UnmanagedCallersOnly] public static uint AddRef(PixelShaderEffect* @this) { return @this->AddRef(); } /// [UnmanagedCallersOnly] public static uint Release(PixelShaderEffect* @this) { return @this->Release(); } /// [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; } /// [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; } /// [UnmanagedCallersOnly] public static int SetGraph(PixelShaderEffect* @this, ID2D1TransformGraph* transformGraph) { return E.E_NOTIMPL; } } }