Update built-in affine transform mappers
このコミットが含まれているのは:
1 親
b4f8f497c4
コミット
079a3de5b6
5ファイル変更
+67
-113
検索条件に一致するファイルはありません
@@ -65,28 +65,28 @@ public static class D2D1TransformMapperFactory<T>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="ID2D1TransformMapperFactory{T}"/> instance for an affine transform.
|
||||
/// Creates an <see cref="D2D1TransformMapper{T}"/> instance for an affine transform.
|
||||
/// </summary>
|
||||
/// <param name="matrix">The fixed transformation matrix to use.</param>
|
||||
/// <returns>The resulting <see cref="ID2D1TransformMapperFactory{T}"/> instance for an affine transform.</returns>
|
||||
public static ID2D1TransformMapperFactory<T> Transform(Matrix3x2 matrix)
|
||||
/// <returns>The resulting <see cref="D2D1TransformMapper{T}"/> instance for an affine transform.</returns>
|
||||
public static D2D1TransformMapper<T> Transform(Matrix3x2 matrix)
|
||||
{
|
||||
return new D2D1AffineTransformMapperFactory.For<T> { ParametersAccessor = new D2D1AffineTransformMapperFactory.For<T>.ConstantMatrix { Amount = matrix } };
|
||||
return new D2D1AffineTransformMapper<T>.ConstantMatrix { Amount = matrix };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="ID2D1TransformMapperFactory{T}"/> instance for an affine transform.
|
||||
/// Creates an <see cref="D2D1TransformMapper{T}"/> instance for an affine transform.
|
||||
/// </summary>
|
||||
/// <param name="accessor">The input <see cref="Accessor{TResult}"/> instance to retrieve the transformation matrix to use.</param>
|
||||
/// <returns>The resulting <see cref="ID2D1TransformMapperFactory{T}"/> instance for an affine transform.</returns>
|
||||
public static ID2D1TransformMapperFactory<T> Transform(Accessor<Matrix3x2> accessor)
|
||||
/// <returns>The resulting <see cref="D2D1TransformMapper{T}"/> instance for an affine transform.</returns>
|
||||
public static D2D1TransformMapper<T> Transform(Accessor<Matrix3x2> accessor)
|
||||
{
|
||||
if (accessor is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(accessor), "The input D2D1TransformMapperFactory<T>.Accessor<Matrix3x2> object cannot be null.");
|
||||
}
|
||||
|
||||
return new D2D1AffineTransformMapperFactory.For<T> { ParametersAccessor = new D2D1AffineTransformMapperFactory.For<T>.DynamicMatrix { Accessor = accessor } };
|
||||
return new D2D1AffineTransformMapper<T>.DynamicMatrix { Accessor = accessor };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Factories.Abstract;
|
||||
|
||||
/// <summary>
|
||||
/// A base type for a transform mapper factory to be used in a D2D1 pixel shader effect.
|
||||
/// </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>
|
||||
/// <typeparam name="TTransformMapper">The type of concrete transform mapper to produce from this factory.</typeparam>
|
||||
internal abstract class D2D1TransformMapperFactory<T, TParameters, TTransformMapper> : ID2D1TransformMapperFactory<T>
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
where TParameters : unmanaged
|
||||
where TTransformMapper : D2D1TransformMapper<T, TParameters>, new()
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
ID2D1TransformMapper<T> ID2D1TransformMapperFactory<T>.Create()
|
||||
{
|
||||
return new TTransformMapper { ParametersAccessor = ParametersAccessor };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1TransformMapperParametersAccessor{T, TParameters}"/> instance to use to retrieve parameters for the transform mapper.
|
||||
/// </summary>
|
||||
public required D2D1TransformMapperParametersAccessor<T, TParameters> ParametersAccessor { get; init; }
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Factories.Abstract;
|
||||
|
||||
/// <summary>
|
||||
/// A base type for an accessor of parameters to be used in D2D1 transform mapping implementations.
|
||||
/// </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 D2D1TransformMapperParametersAccessor<T, TParameters>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the parameters to be used by the transform mapper.
|
||||
/// </summary>
|
||||
/// <param name="shader">The input D2D1 pixel shader being executed on the current effect (this can be used to retrieve shader properties).</param>
|
||||
/// <returns>The resulting parameters to be used by the transform mapper.</returns>
|
||||
public abstract TParameters Get(in T shader);
|
||||
}
|
||||
+54
-60
@@ -8,19 +8,19 @@ using ComputeSharp.D2D1.Shaders.Interop.Helpers;
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Factories;
|
||||
|
||||
/// <summary>
|
||||
/// A container for shader-specific affine transform mapper factory.
|
||||
/// Shared helpers for <see cref="D2D1AffineTransformMapper{T}"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This non-generic type is used so that <see cref="Transform"/> and <see cref="SubtractAndClampToMaxIfOverflow"/> are not recompiled for each generic type instantiation.
|
||||
/// </remarks>
|
||||
internal sealed class D2D1AffineTransformMapperFactory
|
||||
file static class D2D1AffineTransformMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// Transforms a target rectangle using a given transform matrix.
|
||||
/// </summary>
|
||||
/// <param name="matrix">The transform matrix to use.</param>
|
||||
/// <param name="rectangle">The rectangle to transform.</param>
|
||||
private static void Transform(in Matrix3x2 matrix, ref Rectangle64 rectangle)
|
||||
public static void Transform(in Matrix3x2 matrix, ref Rectangle64 rectangle)
|
||||
{
|
||||
// Get the rectangle corners
|
||||
Point64 topLeft = new(rectangle.Left, rectangle.Top);
|
||||
@@ -60,7 +60,7 @@ internal sealed class D2D1AffineTransformMapperFactory
|
||||
/// <param name="y">The value to subtract.</param>
|
||||
/// <returns>The result of the subtraction, clamped to <see cref="long.MaxValue"/>.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static long SubtractAndClampToMaxIfOverflow(long x, long y)
|
||||
public static long SubtractAndClampToMaxIfOverflow(long x, long y)
|
||||
{
|
||||
long z = unchecked(x - y);
|
||||
|
||||
@@ -73,74 +73,68 @@ internal sealed class D2D1AffineTransformMapperFactory
|
||||
|
||||
return z;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="D2D1TransformMapper{T, TParameters}"/> implementation for an affine transform.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader associated to the transform mapper.</typeparam>
|
||||
internal abstract class D2D1AffineTransformMapper<T> : D2D1TransformMapper<T, Matrix3x2>
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected sealed override void TransformInputToOutput(in Matrix3x2 parameters, ref Rectangle64 rectangle)
|
||||
{
|
||||
D2D1AffineTransformMapper.Transform(in parameters, ref rectangle);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected sealed override void TransformOutputToInput(in Matrix3x2 parameters, ref Rectangle64 rectangle)
|
||||
{
|
||||
if (!Matrix3x2.Invert(parameters, out Matrix3x2 matrix))
|
||||
{
|
||||
static void Throw()
|
||||
{
|
||||
throw new ArgumentException("The input transform matrix can't be inverted, so it can't be used for a transform mapper.");
|
||||
}
|
||||
|
||||
Throw();
|
||||
}
|
||||
|
||||
D2D1AffineTransformMapper.Transform(in matrix, ref rectangle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="D2D1TransformMapperFactory{T, TParameters, TTransformMapper}"/> implementation for an affine transform.
|
||||
/// A <see cref="D2D1AffineTransformMapper{T}"/> implementation for a constant affine transform matrix.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader associated to the transform mapper.</typeparam>
|
||||
public sealed class For<T> : D2D1TransformMapperFactory<T, Matrix3x2, For<T>.TransformMapper>
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
public sealed class ConstantMatrix : D2D1AffineTransformMapper<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="D2D1TransformMapperParametersAccessor{T, TParameters}"/> implementation for a constant affine transform matrix.
|
||||
/// Gets the fixed affine transform matrix.
|
||||
/// </summary>
|
||||
public sealed class ConstantMatrix : D2D1TransformMapperParametersAccessor<T, Matrix3x2>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the fixed affine transform matrix.
|
||||
/// </summary>
|
||||
public required Matrix3x2 Amount { get; init; }
|
||||
public required Matrix3x2 Amount { get; init; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override Matrix3x2 Get(in T shader)
|
||||
{
|
||||
return Amount;
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
protected override Matrix3x2 GetParameters(D2D1DrawInfoUpdateContext<T> drawInfoUpdateContext)
|
||||
{
|
||||
return Amount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="D2D1AffineTransformMapper{T}"/> implementation for a dynamic affine transform matrix.
|
||||
/// </summary>
|
||||
public sealed class DynamicMatrix : D2D1AffineTransformMapper<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="D2D1TransformMapperParametersAccessor{T, TParameters}"/> implementation for a dynamic affine transform matrix.
|
||||
/// Gets the <see cref="D2D1TransformMapperFactory{T}.Accessor{TResult}"/> instance to get the dynamic affine transform matrix.
|
||||
/// </summary>
|
||||
public sealed class DynamicMatrix : D2D1TransformMapperParametersAccessor<T, Matrix3x2>
|
||||
public required D2D1TransformMapperFactory<T>.Accessor<Matrix3x2> Accessor { get; init; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override Matrix3x2 GetParameters(D2D1DrawInfoUpdateContext<T> drawInfoUpdateContext)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D2D1TransformMapperFactory{T}.Accessor{TResult}"/> instance to get the dynamic affine transform matrix.
|
||||
/// </summary>
|
||||
public required D2D1TransformMapperFactory<T>.Accessor<Matrix3x2> Accessor { get; init; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override Matrix3x2 Get(in T shader)
|
||||
{
|
||||
return Accessor(in shader);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="D2D1TransformMapper{T, TParameters}"/> implementation for an affine transform.
|
||||
/// </summary>
|
||||
public sealed class TransformMapper : D2D1TransformMapper<T, Matrix3x2>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
protected override void TransformInputToOutput(in Matrix3x2 parameters, ref Rectangle64 rectangle)
|
||||
{
|
||||
Transform(in parameters, ref rectangle);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void TransformOutputToInput(in Matrix3x2 parameters, ref Rectangle64 rectangle)
|
||||
{
|
||||
if (!Matrix3x2.Invert(parameters, out Matrix3x2 matrix))
|
||||
{
|
||||
static void Throw()
|
||||
{
|
||||
throw new ArgumentException("The input transform matrix can't be inverted, so it can't be used for a transform mapper.");
|
||||
}
|
||||
|
||||
Throw();
|
||||
}
|
||||
|
||||
Transform(in matrix, ref rectangle);
|
||||
}
|
||||
return Accessor(drawInfoUpdateContext.GetConstantBuffer());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ using ComputeSharp.D2D1.Shaders.Interop.Helpers;
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Factories;
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="D2D1TransformMapperFactory{T, TParameters, TTransformMapper}"/> implementation for an inflate transform.
|
||||
/// A custom <see cref="D2D1TransformMapper{T, TParameters}"/> implementation for an inflate transform.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader associated to the transform mapper.</typeparam>
|
||||
internal abstract class D2D1InflateTransformMapper<T> : D2D1TransformMapper<T, (int Left, int Top, int Right, int Bottom)>
|
||||
@@ -24,7 +24,7 @@ internal abstract class D2D1InflateTransformMapper<T> : D2D1TransformMapper<T, (
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="D2D1TransformMapperParametersAccessor{T, TParameters}"/> implementation for a constant inflate amount.
|
||||
/// A <see cref="D2D1InflateTransformMapper{T}"/> implementation for a constant inflate amount.
|
||||
/// </summary>
|
||||
public sealed class ConstantAmount : D2D1InflateTransformMapper<T>
|
||||
{
|
||||
@@ -41,7 +41,7 @@ internal abstract class D2D1InflateTransformMapper<T> : D2D1TransformMapper<T, (
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="D2D1TransformMapperParametersAccessor{T, TParameters}"/> implementation for a constant inflate LTRB amount.
|
||||
/// A <see cref="D2D1TransformMapper{T, TParameters}"/> implementation for a constant inflate LTRB amount.
|
||||
/// </summary>
|
||||
public sealed class ConstantLeftTopRightBottomAmount : D2D1InflateTransformMapper<T>
|
||||
{
|
||||
@@ -73,7 +73,7 @@ internal abstract class D2D1InflateTransformMapper<T> : D2D1TransformMapper<T, (
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="D2D1TransformMapperParametersAccessor{T, TParameters}"/> implementation for a dynamic inflate amount.
|
||||
/// A <see cref="D2D1TransformMapper{T, TParameters}"/> implementation for a dynamic inflate amount.
|
||||
/// </summary>
|
||||
public sealed class DynamicAmount : D2D1InflateTransformMapper<T>
|
||||
{
|
||||
@@ -92,7 +92,7 @@ internal abstract class D2D1InflateTransformMapper<T> : D2D1TransformMapper<T, (
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="D2D1TransformMapperParametersAccessor{T, TParameters}"/> implementation for a dynamic inflate LTRB amount.
|
||||
/// A <see cref="D2D1TransformMapper{T, TParameters}"/> implementation for a dynamic inflate LTRB amount.
|
||||
/// </summary>
|
||||
public sealed class DynamicLeftTopRightBottomAmount : D2D1InflateTransformMapper<T>
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする