using System.Diagnostics.CodeAnalysis;
using ABI.Microsoft.Graphics.Canvas;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.Interop;
using ComputeSharp.Win32;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
namespace ComputeSharp.D2D1.WinUI;
///
/// A custom implementation powered by a supplied shader type.
///
/// The type of shader to use to render frames.
public sealed partial class PixelShaderEffect : IReferenceTrackedObject, ICanvasEffect, ICanvasImageInterop.Interface
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor
{
///
/// The value for the current instance.
///
private ReferenceTracker referenceTracker;
///
/// Lock object used to synchronize calls to APIs.
///
private readonly object lockObject = new();
///
/// Flag to track whether a given call is recursively invoked by , to avoid graph cycles.
///
private volatile int isInsideGetD2DImage;
///
/// The current device the effect is realized on, if one is available (this is the underlying COM object for ).
///
private ComPtr canvasDevice;
///
/// The underlying D2D1 device the effect is realized on, if one is available (this is the D2D device backing ).
///
private ComPtr d2D1RealizationDevice;
///
/// The current realized , if one is available.
///
private ComPtr d2D1Effect;
///
/// The backing field for .
///
private T constantBuffer;
///
/// The backing field for .
///
private D2D1DrawTransformMapper? transformMapper;
///
/// The backing field for .
///
private bool cacheOutput;
///
/// The backing field for .
///
private D2D1_BUFFER_PRECISION d2D1BufferPrecision;
///
/// Creates a new instance.
///
// Workaround for trimming bug in custom COM/WinRT components with CsWinRT. Without manually preserving metadata for
// these types, using them will throw an InvalidCastException (see https://github.com/microsoft/CsWinRT/issues/1319).
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ICanvasImageInterop.Interface))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ICanvasImageInterop.Interface.Vftbl))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ICanvasFactoryNative.Interface))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ICanvasFactoryNative.Interface.Vftbl))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ICanvasEffectFactoryNative.Interface))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ICanvasEffectFactoryNative.Interface.Vftbl))]
public PixelShaderEffect()
{
using ReferenceTracker.Lease _0 = ReferenceTracker.Create(this, out this.referenceTracker);
Sources = new SourceCollection(this);
ResourceTextureManagers = new ResourceTextureManagerCollection(this);
}
}