From f039cdbb82ad6e191afdfecadf84a8d5fd807a2b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 4 Sep 2022 23:36:54 +0200 Subject: [PATCH] Add public D2D1TransformMapperFactory type --- .../Interop/D2D1TransformMapperFactory{T}.cs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapperFactory{T}.cs diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapperFactory{T}.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapperFactory{T}.cs new file mode 100644 index 00000000..0796e88f --- /dev/null +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1TransformMapperFactory{T}.cs @@ -0,0 +1,62 @@ +using ComputeSharp.D2D1.Shaders.Interop.Factories; + +namespace ComputeSharp.D2D1; + +/// +/// Provides built-in transform mapper factories for common transform mapping operations. +/// +/// The type of D2D1 pixel shader associated to the transform mapper. +public static class D2D1TransformMapperFactory + where T : unmanaged, ID2D1PixelShader +{ + /// + /// Creates an instance for an inflate transform. + /// + /// The fixed inflate amount to use (applies to all edges of the input area). + /// The resulting instance for an inflate transform. + public static ID2D1TransformMapperFactory Inflate(int amount) + { + return new D2D1InflateTransformMapperFactory { Parameters = new D2D1InflateTransformMapperFactory.FixedAmount { Amount = amount } }; + } + + /// + /// Creates an instance for an inflate transform. + /// + /// The fixed left inflate amount to use. + /// The fixed top inflate amount to use. + /// The fixed right inflate amount to use. + /// The fixed bottom inflate amount to use. + /// The resulting instance for an inflate transform. + public static ID2D1TransformMapperFactory Inflate(int left, int top, int right, int bottom) + { + return new D2D1InflateTransformMapperFactory { Parameters = new D2D1InflateTransformMapperFactory.FixedLeftTopRightBottomAmount { Left = left, Top = top, Right = right, Bottom = bottom } }; + } + + /// + /// Creates an instance for an inflate transform. + /// + /// The input instance to retrieve the inflate amount to use (applies to all edges of the input area). + /// The resulting instance for an inflate transform. + public static ID2D1TransformMapperFactory Inflate(Accessor accessor) + { + return new D2D1InflateTransformMapperFactory { Parameters = new D2D1InflateTransformMapperFactory.DynamicAmount { Accessor = accessor } }; + } + + /// + /// Creates an instance for an inflate transform. + /// + /// The input instance to retrieve the inflate amount to use. + /// The resulting instance for an inflate transform. + public static ID2D1TransformMapperFactory Inflate(Accessor<(int Left, int Top, int Right, int Bottom)> accessor) + { + return new D2D1InflateTransformMapperFactory { Parameters = new D2D1InflateTransformMapperFactory.DynamicLeftTopRightBottomAmount { Accessor = accessor } }; + } + + /// + /// An accessor of parameters to be used in D2D1 transform mapping implementations. + /// + /// The type of parameters that the transform mapper will use. + /// The input D2D1 pixel shader being executed on the current effect (this can be used to retrieve shader properties). + /// The resulting parameters to be used by the transform mapper. + public delegate TResult Accessor(in T shader); +}