diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Factories/Abstract/D2D1TransformMapper{T, TParameters}.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Factories/Abstract/D2D1TransformMapper{T, TParameters}.cs index 55293655..b4cd8702 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Factories/Abstract/D2D1TransformMapper{T, TParameters}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Factories/Abstract/D2D1TransformMapper{T, TParameters}.cs @@ -1,6 +1,7 @@ using System; using System.Drawing; using System.Runtime.CompilerServices; +using ComputeSharp.D2D1.Shaders.Interop.Helpers; namespace ComputeSharp.D2D1.Shaders.Interop.Factories.Abstract; diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Factories/D2D1InflateTransformMapperFactory.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Factories/D2D1InflateTransformMapperFactory.cs new file mode 100644 index 00000000..314736dd --- /dev/null +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Factories/D2D1InflateTransformMapperFactory.cs @@ -0,0 +1,109 @@ +using ComputeSharp.D2D1.Shaders.Interop.Factories.Abstract; +using ComputeSharp.D2D1.Shaders.Interop.Helpers; + +namespace ComputeSharp.D2D1.Shaders.Interop.Factories; + +/// +/// A custom implementation for an inflate transform. +/// +/// The type of D2D1 pixel shader associated to the transform mapper. +internal sealed class D2D1InflateTransformMapperFactory : D2D1TransformMapperFactory, (int, int, int, int), D2D1InflateTransformMapperFactory.TransformMapper> + where T : unmanaged, ID2D1PixelShader +{ + /// + /// A implementation for a fixed inflate amount. + /// + public sealed class FixedAmount : D2D1TransformMapperParametersAccessor + { + /// + /// Gets the fixed inflate amount. + /// + public int Amount { get; init; } + + /// + public override (int, int, int, int) Get(in T shader) + { + return (Amount, Amount, Amount, Amount); + } + } + + /// + /// A implementation for a fixed inflate LTRB amount. + /// + public sealed class FixedLeftTopRightBottomAmount : D2D1TransformMapperParametersAccessor + { + /// + /// The fixed left inflate amount. + /// + public int Left { get; init; } + + /// + /// The fixed top inflate amount. + /// + public int Top { get; init; } + + /// + /// The fixed right inflate amount. + /// + public int Right { get; init; } + + /// + /// The fixed bottom inflate amount. + /// + public int Bottom { get; init; } + + /// + public override (int, int, int, int) Get(in T shader) + { + return (Left, Top, Right, Bottom); + } + } + + /// + /// A implementation for a dynamic inflate amount. + /// + public sealed class DynamicAmount : D2D1TransformMapperParametersAccessor + { + public D2D1TransformMapperFactory.Accessor? Accessor { get; init; } + + /// + public override (int, int, int, int) Get(in T shader) + { + int amount = Accessor!(in shader); + + return (amount, amount, amount, amount); + } + } + + /// + /// A implementation for a dynamic inflate LTRB amount. + /// + public sealed class DynamicLeftTopRightBottomAmount : D2D1TransformMapperParametersAccessor + { + public D2D1TransformMapperFactory.Accessor<(int, int, int, int)>? Accessor { get; init; } + + /// + public override (int, int, int, int) Get(in T shader) + { + return Accessor!(in shader); + } + } + + /// + /// A custom implementation for an inflate transform. + /// + public sealed class TransformMapper : D2D1TransformMapper + { + /// + protected override void TransformInputToOutput((int Left, int Top, int Right, int Bottom) parameters, ref Rectangle64 rectangle) + { + rectangle.Inflate(parameters.Left, parameters.Top, parameters.Right, parameters.Bottom); + } + + /// + protected override void TransformOutputToInput((int Left, int Top, int Right, int Bottom) parameters, ref Rectangle64 rectangle) + { + rectangle.Inflate(parameters.Left, parameters.Top, parameters.Right, parameters.Bottom); + } + } +} \ No newline at end of file