Update built-in inflate transform mappers
このコミットが含まれているのは:
1 親
3870a6181e
コミット
b4f8f497c4
3ファイル変更
+88
-98
検索条件に一致するファイルはありません
@@ -12,56 +12,56 @@ public static class D2D1TransformMapperFactory<T>
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an <see cref="ID2D1TransformMapperFactory{T}"/> instance for an inflate transform.
|
||||
/// Creates an <see cref="D2D1TransformMapper{T}"/> instance for an inflate transform.
|
||||
/// </summary>
|
||||
/// <param name="amount">The fixed inflate amount to use (applies to all edges of the input area).</param>
|
||||
/// <returns>The resulting <see cref="ID2D1TransformMapperFactory{T}"/> instance for an inflate transform.</returns>
|
||||
public static ID2D1TransformMapperFactory<T> Inflate(int amount)
|
||||
/// <returns>The resulting <see cref="D2D1TransformMapper{T}"/> instance for an inflate transform.</returns>
|
||||
public static D2D1TransformMapper<T> Inflate(int amount)
|
||||
{
|
||||
return new D2D1InflateTransformMapperFactory<T> { ParametersAccessor = new D2D1InflateTransformMapperFactory<T>.ConstantAmount { Amount = amount } };
|
||||
return new D2D1InflateTransformMapper<T>.ConstantAmount { Amount = amount };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="ID2D1TransformMapperFactory{T}"/> instance for an inflate transform.
|
||||
/// Creates an <see cref="D2D1TransformMapper{T}"/> instance for an inflate transform.
|
||||
/// </summary>
|
||||
/// <param name="left">The fixed left inflate amount to use.</param>
|
||||
/// <param name="top">The fixed top inflate amount to use.</param>
|
||||
/// <param name="right">The fixed right inflate amount to use.</param>
|
||||
/// <param name="bottom">The fixed bottom inflate amount to use.</param>
|
||||
/// <returns>The resulting <see cref="ID2D1TransformMapperFactory{T}"/> instance for an inflate transform.</returns>
|
||||
public static ID2D1TransformMapperFactory<T> Inflate(int left, int top, int right, int bottom)
|
||||
/// <returns>The resulting <see cref="D2D1TransformMapper{T}"/> instance for an inflate transform.</returns>
|
||||
public static D2D1TransformMapper<T> Inflate(int left, int top, int right, int bottom)
|
||||
{
|
||||
return new D2D1InflateTransformMapperFactory<T> { ParametersAccessor = new D2D1InflateTransformMapperFactory<T>.ConstantLeftTopRightBottomAmount { Left = left, Top = top, Right = right, Bottom = bottom } };
|
||||
return new D2D1InflateTransformMapper<T>.ConstantLeftTopRightBottomAmount { Left = left, Top = top, Right = right, Bottom = bottom };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="ID2D1TransformMapperFactory{T}"/> instance for an inflate transform.
|
||||
/// Creates an <see cref="D2D1TransformMapper{T}"/> instance for an inflate transform.
|
||||
/// </summary>
|
||||
/// <param name="accessor">The input <see cref="Accessor{TResult}"/> instance to retrieve the inflate amount to use (applies to all edges of the input area).</param>
|
||||
/// <returns>The resulting <see cref="ID2D1TransformMapperFactory{T}"/> instance for an inflate transform.</returns>
|
||||
public static ID2D1TransformMapperFactory<T> Inflate(Accessor<int> accessor)
|
||||
/// <returns>The resulting <see cref="D2D1TransformMapper{T}"/> instance for an inflate transform.</returns>
|
||||
public static D2D1TransformMapper<T> Inflate(Accessor<int> accessor)
|
||||
{
|
||||
if (accessor is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(accessor), "The input D2D1TransformMapperFactory<T>.Accessor<int> object cannot be null.");
|
||||
}
|
||||
|
||||
return new D2D1InflateTransformMapperFactory<T> { ParametersAccessor = new D2D1InflateTransformMapperFactory<T>.DynamicAmount { Accessor = accessor } };
|
||||
return new D2D1InflateTransformMapper<T>.DynamicAmount { Accessor = accessor };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="ID2D1TransformMapperFactory{T}"/> instance for an inflate transform.
|
||||
/// Creates an <see cref="D2D1TransformMapper{T}"/> instance for an inflate transform.
|
||||
/// </summary>
|
||||
/// <param name="accessor">The input <see cref="Accessor{TResult}"/> instance to retrieve the inflate amount to use.</param>
|
||||
/// <returns>The resulting <see cref="ID2D1TransformMapperFactory{T}"/> instance for an inflate transform.</returns>
|
||||
public static ID2D1TransformMapperFactory<T> Inflate(Accessor<(int Left, int Top, int Right, int Bottom)> accessor)
|
||||
/// <returns>The resulting <see cref="D2D1TransformMapper{T}"/> instance for an inflate transform.</returns>
|
||||
public static D2D1TransformMapper<T> Inflate(Accessor<(int Left, int Top, int Right, int Bottom)> accessor)
|
||||
{
|
||||
if (accessor is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(accessor), "The input D2D1TransformMapperFactory<T>.Accessor<(int Left, int Top, int Right, int Bottom)> object cannot be null.");
|
||||
}
|
||||
|
||||
return new D2D1InflateTransformMapperFactory<T> { ParametersAccessor = new D2D1InflateTransformMapperFactory<T>.DynamicLeftTopRightBottomAmount { Accessor = accessor } };
|
||||
return new D2D1InflateTransformMapper<T>.DynamicLeftTopRightBottomAmount { Accessor = accessor };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+49
-53
@@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Interop.Effects;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Helpers;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Factories.Abstract;
|
||||
|
||||
/// <summary>
|
||||
@@ -13,7 +11,7 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Factories.Abstract;
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader associated to the transform mapper.</typeparam>
|
||||
/// <typeparam name="TParameters">The type of parameters that the transform mapper will use.</typeparam>
|
||||
internal abstract class D2D1TransformMapper<T, TParameters> : D2D1TransformMapper, ID2D1TransformMapper<T>
|
||||
internal abstract class D2D1TransformMapper<T, TParameters> : D2D1TransformMapper<T>
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
where TParameters : unmanaged
|
||||
{
|
||||
@@ -22,57 +20,15 @@ internal abstract class D2D1TransformMapper<T, TParameters> : D2D1TransformMappe
|
||||
/// </summary>
|
||||
private TParameters parameters;
|
||||
|
||||
/// <inheritdoc cref="D2D1TransformMapperFactory{T, TParameters, TTransformMapper}.ParametersAccessor"/>
|
||||
public D2D1TransformMapperParametersAccessor<T, TParameters>? ParametersAccessor { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Transforms an input rectangle to an output rectangle.
|
||||
/// </summary>
|
||||
/// <param name="parameters">The parameters to be used to inform the transformation.</param>
|
||||
/// <param name="rectangle">The input rectangle to transform to output.</param>
|
||||
protected abstract void TransformInputToOutput(in TParameters parameters, ref Rectangle64 rectangle);
|
||||
|
||||
/// <summary>
|
||||
/// Transforms an output rectangle to an input rectangle.
|
||||
/// </summary>
|
||||
/// <param name="parameters">The parameters to be used to inform the transformation.</param>
|
||||
/// <param name="rectangle">The output rectangle to transform to input.</param>
|
||||
protected abstract void TransformOutputToInput(in TParameters parameters, ref Rectangle64 rectangle);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void MapInputsToOutput(ReadOnlySpan<byte> buffer, ReadOnlySpan<Rectangle> inputs, ReadOnlySpan<Rectangle> opaqueInputs, out Rectangle output, out Rectangle opaqueOutput)
|
||||
public override void MapInputsToOutput(
|
||||
D2D1DrawInfoUpdateContext<T> drawInfoUpdateContext,
|
||||
ReadOnlySpan<Rectangle> inputs,
|
||||
ReadOnlySpan<Rectangle> opaqueInputs,
|
||||
out Rectangle output,
|
||||
out Rectangle opaqueOutput)
|
||||
{
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
shader.InitializeFromDispatchData(buffer);
|
||||
|
||||
MapInputsToOutput(in shader, inputs, opaqueInputs, out output, out opaqueOutput);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void MapOutputToInputs(in Rectangle output, Span<Rectangle> inputs)
|
||||
{
|
||||
Rectangle64 output64 = Rectangle64.FromRectangle(output);
|
||||
|
||||
TransformOutputToInput(in this.parameters, ref output64);
|
||||
|
||||
inputs.Fill(output64.ToRectangleWithD2D1LogicallyInfiniteClamping());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void MapInvalidOutput(int inputIndex, Rectangle invalidInput, out Rectangle invalidOutput)
|
||||
{
|
||||
Rectangle64 output64 = Rectangle64.FromRectangle(invalidInput);
|
||||
|
||||
TransformInputToOutput(in this.parameters, ref output64);
|
||||
|
||||
invalidOutput = output64.ToRectangleWithD2D1LogicallyInfiniteClamping();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void MapInputsToOutput(in T shader, ReadOnlySpan<Rectangle> inputs, ReadOnlySpan<Rectangle> opaqueInputs, out Rectangle output, out Rectangle opaqueOutput)
|
||||
{
|
||||
this.parameters = ParametersAccessor!.Get(in shader);
|
||||
this.parameters = GetParameters(drawInfoUpdateContext);
|
||||
|
||||
if (inputs.IsEmpty)
|
||||
{
|
||||
@@ -96,4 +52,44 @@ internal abstract class D2D1TransformMapper<T, TParameters> : D2D1TransformMappe
|
||||
opaqueOutput = Rectangle.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void MapOutputToInputs(in Rectangle output, Span<Rectangle> inputs)
|
||||
{
|
||||
Rectangle64 output64 = Rectangle64.FromRectangle(output);
|
||||
|
||||
TransformOutputToInput(in this.parameters, ref output64);
|
||||
|
||||
inputs.Fill(output64.ToRectangleWithD2D1LogicallyInfiniteClamping());
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void MapInvalidOutput(int inputIndex, Rectangle invalidInput, out Rectangle invalidOutput)
|
||||
{
|
||||
Rectangle64 output64 = Rectangle64.FromRectangle(invalidInput);
|
||||
|
||||
TransformInputToOutput(in this.parameters, ref output64);
|
||||
|
||||
invalidOutput = output64.ToRectangleWithD2D1LogicallyInfiniteClamping();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <typeparamref name="TParameters"/> values for the current transform mapper.
|
||||
/// </summary>
|
||||
/// <param name="drawInfoUpdateContext">The input <see cref="D2D1DrawInfoUpdateContext{T}"/> value, which can be used to access and modify shader data.</param>
|
||||
protected abstract TParameters GetParameters(D2D1DrawInfoUpdateContext<T> drawInfoUpdateContext);
|
||||
|
||||
/// <summary>
|
||||
/// Transforms an input rectangle to an output rectangle.
|
||||
/// </summary>
|
||||
/// <param name="parameters">The parameters to be used to inform the transformation.</param>
|
||||
/// <param name="rectangle">The input rectangle to transform to output.</param>
|
||||
protected abstract void TransformInputToOutput(in TParameters parameters, ref Rectangle64 rectangle);
|
||||
|
||||
/// <summary>
|
||||
/// Transforms an output rectangle to an input rectangle.
|
||||
/// </summary>
|
||||
/// <param name="parameters">The parameters to be used to inform the transformation.</param>
|
||||
/// <param name="rectangle">The output rectangle to transform to input.</param>
|
||||
protected abstract void TransformOutputToInput(in TParameters parameters, ref Rectangle64 rectangle);
|
||||
}
|
||||
+23
-29
@@ -8,13 +8,25 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Factories;
|
||||
/// A custom <see cref="D2D1TransformMapperFactory{T, TParameters, TTransformMapper}"/> implementation for an inflate transform.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader associated to the transform mapper.</typeparam>
|
||||
internal sealed class D2D1InflateTransformMapperFactory<T> : D2D1TransformMapperFactory<T, (int, int, int, int), D2D1InflateTransformMapperFactory<T>.TransformMapper>
|
||||
internal abstract class D2D1InflateTransformMapper<T> : D2D1TransformMapper<T, (int Left, int Top, int Right, int Bottom)>
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected sealed override void TransformInputToOutput(in (int Left, int Top, int Right, int Bottom) parameters, ref Rectangle64 rectangle)
|
||||
{
|
||||
rectangle.Inflate(parameters.Left, parameters.Top, parameters.Right, parameters.Bottom);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected sealed override void TransformOutputToInput(in (int Left, int Top, int Right, int Bottom) parameters, ref Rectangle64 rectangle)
|
||||
{
|
||||
rectangle.Inflate(parameters.Left, parameters.Top, parameters.Right, parameters.Bottom);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="D2D1TransformMapperParametersAccessor{T, TParameters}"/> implementation for a constant inflate amount.
|
||||
/// </summary>
|
||||
public sealed class ConstantAmount : D2D1TransformMapperParametersAccessor<T, (int, int, int, int)>
|
||||
public sealed class ConstantAmount : D2D1InflateTransformMapper<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the fixed inflate amount.
|
||||
@@ -22,7 +34,7 @@ internal sealed class D2D1InflateTransformMapperFactory<T> : D2D1TransformMapper
|
||||
public required int Amount { get; init; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (int, int, int, int) Get(in T shader)
|
||||
protected override (int Left, int Top, int Right, int Bottom) GetParameters(D2D1DrawInfoUpdateContext<T> drawInfoUpdateContext)
|
||||
{
|
||||
return (Amount, Amount, Amount, Amount);
|
||||
}
|
||||
@@ -31,7 +43,7 @@ internal sealed class D2D1InflateTransformMapperFactory<T> : D2D1TransformMapper
|
||||
/// <summary>
|
||||
/// A <see cref="D2D1TransformMapperParametersAccessor{T, TParameters}"/> implementation for a constant inflate LTRB amount.
|
||||
/// </summary>
|
||||
public sealed class ConstantLeftTopRightBottomAmount : D2D1TransformMapperParametersAccessor<T, (int, int, int, int)>
|
||||
public sealed class ConstantLeftTopRightBottomAmount : D2D1InflateTransformMapper<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The constant left inflate amount.
|
||||
@@ -54,7 +66,7 @@ internal sealed class D2D1InflateTransformMapperFactory<T> : D2D1TransformMapper
|
||||
public required int Bottom { get; init; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (int, int, int, int) Get(in T shader)
|
||||
protected override (int Left, int Top, int Right, int Bottom) GetParameters(D2D1DrawInfoUpdateContext<T> drawInfoUpdateContext)
|
||||
{
|
||||
return (Left, Top, Right, Bottom);
|
||||
}
|
||||
@@ -63,7 +75,7 @@ internal sealed class D2D1InflateTransformMapperFactory<T> : D2D1TransformMapper
|
||||
/// <summary>
|
||||
/// A <see cref="D2D1TransformMapperParametersAccessor{T, TParameters}"/> implementation for a dynamic inflate amount.
|
||||
/// </summary>
|
||||
public sealed class DynamicAmount : D2D1TransformMapperParametersAccessor<T, (int, int, int, int)>
|
||||
public sealed class DynamicAmount : D2D1InflateTransformMapper<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D2D1TransformMapperFactory{T}.Accessor{TResult}"/> instance to get the dynamic inflate amount.
|
||||
@@ -71,9 +83,9 @@ internal sealed class D2D1InflateTransformMapperFactory<T> : D2D1TransformMapper
|
||||
public required D2D1TransformMapperFactory<T>.Accessor<int> Accessor { get; init; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (int, int, int, int) Get(in T shader)
|
||||
protected override (int Left, int Top, int Right, int Bottom) GetParameters(D2D1DrawInfoUpdateContext<T> drawInfoUpdateContext)
|
||||
{
|
||||
int amount = Accessor!(in shader);
|
||||
int amount = Accessor(drawInfoUpdateContext.GetConstantBuffer());
|
||||
|
||||
return (amount, amount, amount, amount);
|
||||
}
|
||||
@@ -82,7 +94,7 @@ internal sealed class D2D1InflateTransformMapperFactory<T> : D2D1TransformMapper
|
||||
/// <summary>
|
||||
/// A <see cref="D2D1TransformMapperParametersAccessor{T, TParameters}"/> implementation for a dynamic inflate LTRB amount.
|
||||
/// </summary>
|
||||
public sealed class DynamicLeftTopRightBottomAmount : D2D1TransformMapperParametersAccessor<T, (int, int, int, int)>
|
||||
public sealed class DynamicLeftTopRightBottomAmount : D2D1InflateTransformMapper<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D2D1TransformMapperFactory{T}.Accessor{TResult}"/> instance to get the dynamic inflate LTRB amount.
|
||||
@@ -90,27 +102,9 @@ internal sealed class D2D1InflateTransformMapperFactory<T> : D2D1TransformMapper
|
||||
public required D2D1TransformMapperFactory<T>.Accessor<(int, int, int, int)> Accessor { get; init; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override (int, int, int, int) Get(in T shader)
|
||||
protected override (int Left, int Top, int Right, int Bottom) GetParameters(D2D1DrawInfoUpdateContext<T> drawInfoUpdateContext)
|
||||
{
|
||||
return Accessor!(in shader);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="D2D1TransformMapper{T, TParameters}"/> implementation for an inflate transform.
|
||||
/// </summary>
|
||||
public sealed class TransformMapper : D2D1TransformMapper<T, (int Left, int Top, int Right, int Bottom)>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void TransformInputToOutput(in (int Left, int Top, int Right, int Bottom) parameters, ref Rectangle64 rectangle)
|
||||
{
|
||||
rectangle.Inflate(parameters.Left, parameters.Top, parameters.Right, parameters.Bottom);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void TransformOutputToInput(in (int Left, int Top, int Right, int Bottom) parameters, ref Rectangle64 rectangle)
|
||||
{
|
||||
rectangle.Inflate(parameters.Left, parameters.Top, parameters.Right, parameters.Bottom);
|
||||
return Accessor(drawInfoUpdateContext.GetConstantBuffer());
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする