using System;
using System.Runtime.InteropServices;
using ABI.Microsoft.Graphics.Canvas;
using ComputeSharp.D2D1.Extensions;
#if WINDOWS_UWP
using ComputeSharp.D2D1.Uwp.Extensions;
using ComputeSharp.D2D1.Uwp.Helpers;
#else
using ComputeSharp.D2D1.WinUI.Extensions;
using ComputeSharp.D2D1.WinUI.Helpers;
#endif
using TerraFX.Interop;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using TerraFX.Interop.WinRT;
#if WINDOWS_UWP
namespace ComputeSharp.D2D1.Uwp;
#else
namespace ComputeSharp.D2D1.WinUI;
#endif
///
unsafe partial class PixelShaderEffect
{
///
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
[return: NativeTypeName("HRESULT")]
private delegate int CreateWrapperDelegate(ICanvasDevice* device, ID2D1Effect* resource, float dpi, IInspectable** wrapper);
///
/// A cached instance wrapping .
///
private static readonly CreateWrapperDelegate CreateWrapperWrapper = CreateWrapper;
///
/// Creates a new instance for an input D2D effect and marshals it as an wrapper.
///
///
///
///
///
/// This method always returns (any exceptions will be marshalled by the delegate stub).
private static int CreateWrapper(ICanvasDevice* device, ID2D1Effect* resource, float dpi, IInspectable** wrapper)
{
PixelShaderEffect @this = new();
@this.InitializeFromNativeResource(device, resource);
RcwMarshaller.GetNativeObject(@this, wrapper);
return S.S_OK;
}
///
/// Initializes a instance from an external realized D2D1 effect.
///
///
///
private void InitializeFromNativeResource(ICanvasDevice* device, ID2D1Effect* resource)
{
using ComPtr d2D1Device1 = default;
// Get the underlying ID2D1Device1 instance for the input device
device->GetD2DDevice(d2D1Device1.GetAddressOf()).Assert();
// Initialize the effect state
device->CopyTo(ref this.canvasDevice).Assert();
d2D1Device1.CopyTo(ref this.d2D1RealizationDevice).Assert();
resource->CopyTo(ref this.d2D1Effect).Assert();
}
}