using ComputeSharp.D2D1.Interop; #if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Extensions; #else using ComputeSharp.D2D1.WinUI.Extensions; #endif using ComputeSharp.Interop; using Microsoft.Graphics.Canvas; using TerraFX.Interop.DirectX; #if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; #else namespace ComputeSharp.D2D1.WinUI; #endif /// unsafe partial class PixelShaderEffect { /// /// Gets the marshalled value for . /// /// The marshalled value for . private T GetConstantBuffer() { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); lock (this.lockObject) { return this.d2D1Effect.Get() switch { not null => this.d2D1Effect.Get()->GetConstantBuffer(), _ => this.constantBuffer }; } } /// /// Sets the marshalled value for . /// /// The value to set for . private void SetConstantBuffer(in T value) { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); lock (this.lockObject) { // If the effect is realized, set the property on the underlying ID2D1Effect object if (this.d2D1Effect.Get() is not null) { this.d2D1Effect.Get()->SetConstantBuffer(in value); } else { // Otherwise, just store the value locally this.constantBuffer = value; } } } /// /// Gets the marshalled value for . /// /// The marshalled value for . private D2D1TransformMapper? GetTransformMapper() { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); lock (this.lockObject) { return this.d2D1Effect.Get() switch { not null => this.d2D1Effect.Get()->GetTransformMapper(), _ => this.transformMapper }; } } /// /// Sets the marshalled value for . /// /// The value to set for . private void SetTransformMapper(D2D1TransformMapper value) { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); lock (this.lockObject) { if (this.d2D1Effect.Get() is not null) { D2D1PixelShaderEffect.SetTransformMapperForD2D1Effect(this.d2D1Effect.Get(), value); } else { this.transformMapper = value; } } } /// /// Gets the marshalled value for . /// /// The index of the source to get or set. /// The marshalled value for . private D2D1ResourceTextureManager? GetResourceTextureManager(int index) { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); lock (this.lockObject) { D2D1ResourceTextureManager? resourceTextureManager = ResourceTextureManagers.Storage[index]; return this.d2D1Effect.Get() switch { not null => this.d2D1Effect.Get()->GetResourceTextureManager(resourceTextureManager, index), _ => resourceTextureManager }; } } /// /// Sets the marshalled value for . /// /// The value to set for . /// The index of the source to get or set. private void SetResourceTextureManager(D2D1ResourceTextureManager value, int index) { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); lock (this.lockObject) { if (this.d2D1Effect.Get() is not null) { D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(this.d2D1Effect.Get(), value, index); } else { ResourceTextureManagers.Storage[index] = value; } } } /// /// Gets the marshalled value for . /// /// The marshalled value for . private bool GetCacheOutput() { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); lock (this.lockObject) { return this.d2D1Effect.Get() switch { not null => this.d2D1Effect.Get()->GetCachedProperty(), _ => this.cacheOutput }; } } /// /// Sets the marshalled value for . /// /// The value to set for . private void SetCacheOutput(bool value) { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); lock (this.lockObject) { if (this.d2D1Effect.Get() is not null) { this.d2D1Effect.Get()->SetCachedProperty(value); } else { this.cacheOutput = value; } } } /// /// Gets the marshalled value for . /// /// The marshalled value for . private CanvasBufferPrecision? GetBufferPrecision() { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); lock (this.lockObject) { D2D1_BUFFER_PRECISION d2D1BufferPrecision = this.d2D1Effect.Get() switch { not null => this.d2D1Effect.Get()->GetPrecisionProperty(), _ => this.d2D1BufferPrecision }; // Map from D2D1_BUFFER_PRECISION to CanvasBufferPrecision, and return null for D2D1_BUFFER_PRECISION_UNKNOWN return this.d2D1BufferPrecision switch { D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM => CanvasBufferPrecision.Precision8UIntNormalized, D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB => CanvasBufferPrecision.Precision8UIntNormalizedSrgb, D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_UNORM => CanvasBufferPrecision.Precision16UIntNormalized, D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_FLOAT => CanvasBufferPrecision.Precision16Float, D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_32BPC_FLOAT => CanvasBufferPrecision.Precision32Float, _ => null }; } } /// /// Sets the marshalled value for . /// /// The value to set for . private void SetBufferPrecision(CanvasBufferPrecision? value) { using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease(); lock (this.lockObject) { // Map back from CanvasBufferPrecision? to D2D1_BUFFER_PRECISION (null results in D2D1_BUFFER_PRECISION_UNKNOWN) this.d2D1BufferPrecision = value switch { CanvasBufferPrecision.Precision8UIntNormalized => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM, CanvasBufferPrecision.Precision8UIntNormalizedSrgb => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB, CanvasBufferPrecision.Precision16UIntNormalized => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_UNORM, CanvasBufferPrecision.Precision16Float => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_FLOAT, CanvasBufferPrecision.Precision32Float => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_32BPC_FLOAT, _ => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_UNKNOWN }; // If the effect is realized, set the property on the underlying ID2D1Effect object too if (this.d2D1Effect.Get() is not null) { this.d2D1Effect.Get()->SetPrecisionProperty(this.d2D1BufferPrecision); } } } }