More code refactoring

このコミットが含まれているのは:
Sergio Pedri committed 2022-12-22 10:56:03 -08:00
1 親 1c2ff9a2ef
コミット a32fc9ec64
5ファイル変更
+203 -131

検索条件に一致するファイルはありません

+22
ファイルの表示
@@ -0,0 +1,22 @@
using System;
using System.Numerics;
using Microsoft.Graphics.Canvas;
using Windows.Foundation;
namespace ComputeSharp.D2D1.Uwp;
/// <inheritdoc/>
partial class PixelShaderEffect<T>
{
/// <inheritdoc/>
Rect ICanvasImage.GetBounds(ICanvasResourceCreator resourceCreator)
{
throw new NotSupportedException();
}
/// <inheritdoc/>
Rect ICanvasImage.GetBounds(ICanvasResourceCreator resourceCreator, Matrix3x2 transform)
{
throw new NotSupportedException();
}
}
+2 -2
ファイルの表示
@@ -248,7 +248,7 @@ unsafe partial class PixelShaderEffect<T>
// TODO: port base CanvasEffect::Realize logic
// Also set the current constants for the effect
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in this.Value, this.d2D1Effect.Get());
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(Value, this.d2D1Effect.Get());
}
/// <summary>
@@ -259,7 +259,7 @@ unsafe partial class PixelShaderEffect<T>
/// <param name="deviceContext">The <see cref="ID2D1DeviceContext"/> instance in use.</param>
private void RefreshInputs(CanvasImageGetD2DImageFlags flags, float targetDpi, ID2D1DeviceContext* deviceContext)
{
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in this.Value, this.d2D1Effect.Get());
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(Value, this.d2D1Effect.Get());
// TODO
}
+108
ファイルの表示
@@ -0,0 +1,108 @@
using ComputeSharp.D2D1.Uwp.Extensions;
using ComputeSharp.Interop;
using Microsoft.Graphics.Canvas;
using TerraFX.Interop.DirectX;
namespace ComputeSharp.D2D1.Uwp;
/// <inheritdoc/>
unsafe partial class PixelShaderEffect<T>
{
/// <summary>
/// Gets the marshalled value for <see cref="CacheOutput"/>.
/// </summary>
/// <returns>The marshalled value for <see cref="CacheOutput"/>.</returns>
private bool GetCacheOutput()
{
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
lock (this.lockObject)
{
// If the effect is realized, get the latest value from it
if (this.d2D1Effect.Get() is not null)
{
this.cacheOutput = this.d2D1Effect.Get()->GetCachedProperty();
}
return this.cacheOutput;
}
}
/// <summary>
/// Sets the marshalled value for <see cref="CacheOutput"/>.
/// </summary>
/// <param name="value">The value to set for <see cref="CacheOutput"/>.</param>
private void SetCacheOutput(bool value)
{
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
lock (this.lockObject)
{
this.cacheOutput = value;
// If the effect is realized, set the property on the underlying ID2D1Effect object too
if (this.d2D1Effect.Get() is not null)
{
this.d2D1Effect.Get()->SetCachedProperty(value);
}
}
}
/// <summary>
/// Gets the marshalled value for <see cref="BufferPrecision"/>.
/// </summary>
/// <returns>The marshalled value for <see cref="BufferPrecision"/>.</returns>
private CanvasBufferPrecision? GetBufferPrecision()
{
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
lock (this.lockObject)
{
// If the effect is realized, get the latest value from it
if (this.d2D1Effect.Get() is not null)
{
this.d2D1BufferPrecision = this.d2D1Effect.Get()->GetPrecisionProperty();
}
// 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
};
}
}
/// <summary>
/// Sets the marshalled value for <see cref="BufferPrecision"/>.
/// </summary>
/// <param name="value">The value to set for <see cref="BufferPrecision"/>.</param>
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);
}
}
}
}
+71
ファイルの表示
@@ -0,0 +1,71 @@
using System;
using ComputeSharp.D2D1.Interop.Effects;
using Microsoft.Graphics.Canvas;
using Windows.Graphics.Effects;
namespace ComputeSharp.D2D1.Uwp;
/// <inheritdoc/>
partial class PixelShaderEffect<T>
{
/// <summary>
/// Configures the <see cref="ID2D1TransformMapperFactory{T}"/> to use for effects of type <typeparamref name="T"/>.
/// </summary>
/// <param name="d2D1DrawTransformMapperFactory">The factory of <see cref="ID2D1TransformMapper{T}"/> instances to use for each created effect.</param>
/// <exception cref="InvalidOperationException">Thrown if initialization is attempted with a mismatched transform factory.</exception>
/// <remarks>
/// <para>Initialization can only be done once, and is shared across all effects of type <typeparamref name="T"/>.</para>
/// <para>Initializing an effect is not necessary before using it: if no transform has been set, the default one will be used.</para>
/// </remarks>
public static void ConfigureD2D1TransformMapperFactory(ID2D1TransformMapperFactory<T>? d2D1DrawTransformMapperFactory)
{
PixelShaderEffect.For<T>.Initialize(d2D1DrawTransformMapperFactory);
}
/// <summary>
/// Gets or sets the current <typeparamref name="T"/> value in use.
/// </summary>
public T Value { get; set; }
/// <summary>
/// Gets the <see cref="SourceCollection"/> object associated with the current instance.
/// </summary>
public SourceCollection Sources { get; } = new();
/// <summary>
/// Gets or sets a value indicating whether to enable caching the output from drawing this effect.
/// </summary>
public bool CacheOutput
{
get => GetCacheOutput();
set => SetCacheOutput(value);
}
/// <summary>
/// Gets or sets the precision to use for intermediate buffers when drawing this effect.
/// </summary>
/// <remarks>If <see langword="null"/>, the default precision for effects will be used.</remarks>
public CanvasBufferPrecision? BufferPrecision
{
get => GetBufferPrecision();
set => SetBufferPrecision(value);
}
/// <summary>
/// Represents the collection of <see cref="IGraphicsEffectSource"/> sources in a <see cref="PixelShaderEffect{T}"/> instance.
/// </summary>
public sealed class SourceCollection
{
/// <summary>
/// Gets or sets the <see cref="IGraphicsEffectSource"/> source at a specified index.
/// </summary>
/// <param name="index">The index of the <see cref="IGraphicsEffectSource"/> source to get or set.</param>
/// <returns>The <see cref="IGraphicsEffectSource"/> source at the specified index.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is not a valid index for the current effect.</exception>
public IGraphicsEffectSource this[int index]
{
get => null!;
set { }
}
}
}
-129
ファイルの表示
@@ -1,11 +1,6 @@
using System;
using System.Numerics;
using ABI.Microsoft.Graphics.Canvas;
using ComputeSharp.D2D1.Interop.Effects;
using ComputeSharp.D2D1.Uwp.Extensions;
using ComputeSharp.Interop;
using Microsoft.Graphics.Canvas;
using Windows.Foundation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
@@ -57,128 +52,4 @@ public sealed partial class PixelShaderEffect<T> : IReferenceTrackedObject, ICan
/// The backing field for <see cref="BufferPrecision"/>.
/// </summary>
private D2D1_BUFFER_PRECISION d2D1BufferPrecision;
/// <summary>
/// The current <typeparamref name="T"/> value in use.
/// </summary>
public T Value;
/// <summary>
/// Configures the <see cref="ID2D1TransformMapperFactory{T}"/> to use for effects of type <typeparamref name="T"/>.
/// </summary>
/// <param name="d2D1DrawTransformMapperFactory">The factory of <see cref="ID2D1TransformMapper{T}"/> instances to use for each created effect.</param>
/// <exception cref="InvalidOperationException">Thrown if initialization is attempted with a mismatched transform factory.</exception>
/// <remarks>
/// <para>Initialization can only be done once, and is shared across all effects of type <typeparamref name="T"/>.</para>
/// <para>Initializing an effect is not necessary before using it: if no transform has been set, the default one will be used.</para>
/// </remarks>
public static void ConfigureD2D1TransformMapperFactory(ID2D1TransformMapperFactory<T>? d2D1DrawTransformMapperFactory)
{
PixelShaderEffect.For<T>.Initialize(d2D1DrawTransformMapperFactory);
}
/// <summary>
/// Gets or sets a value indicating whether to enable caching the output from drawing this effect.
/// </summary>
public unsafe bool CacheOutput
{
get
{
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
lock (this.lockObject)
{
// If the effect is realized, get the latest value from it
if (this.d2D1Effect.Get() is not null)
{
this.cacheOutput = this.d2D1Effect.Get()->GetCachedProperty();
}
return this.cacheOutput;
}
}
set
{
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
lock (this.lockObject)
{
this.cacheOutput = value;
// If the effect is realized, set the property on the underlying ID2D1Effect object too
if (this.d2D1Effect.Get() is not null)
{
this.d2D1Effect.Get()->SetCachedProperty(value);
}
}
}
}
/// <summary>
/// Gets or sets the precision to use for intermediate buffers when drawing this effect.
/// </summary>
/// <remarks>If <see langword="null"/>, the default precision for effects will be used.</remarks>
public unsafe CanvasBufferPrecision? BufferPrecision
{
get
{
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
lock (this.lockObject)
{
// If the effect is realized, get the latest value from it
if (this.d2D1Effect.Get() is not null)
{
this.d2D1BufferPrecision = this.d2D1Effect.Get()->GetPrecisionProperty();
}
// 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
};
}
}
set
{
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);
}
}
}
}
/// <inheritdoc/>
Rect ICanvasImage.GetBounds(ICanvasResourceCreator resourceCreator)
{
throw new NotSupportedException();
}
/// <inheritdoc/>
Rect ICanvasImage.GetBounds(ICanvasResourceCreator resourceCreator, Matrix3x2 transform)
{
throw new NotSupportedException();
}
}