diff --git a/src/ComputeSharp.D2D1/Interfaces/ID2D1TransformMapperFactory{T}.cs b/src/ComputeSharp.D2D1/Interfaces/ID2D1TransformMapperFactory{T}.cs deleted file mode 100644 index a5b122ea..00000000 --- a/src/ComputeSharp.D2D1/Interfaces/ID2D1TransformMapperFactory{T}.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace ComputeSharp.D2D1; - -/// -/// An acting as a factory for instances. -/// -/// The type of shader this factory creates transform mapper instances for. -public interface ID2D1TransformMapperFactory - where T : unmanaged, ID2D1PixelShader -{ - /// - /// Creates a new instance for a given shader. - /// - /// A new instance for the input shader. - ID2D1TransformMapper Create(); -} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Interfaces/ID2D1TransformMapper{T}.cs b/src/ComputeSharp.D2D1/Interfaces/ID2D1TransformMapper{T}.cs deleted file mode 100644 index 7d4ae285..00000000 --- a/src/ComputeSharp.D2D1/Interfaces/ID2D1TransformMapper{T}.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Drawing; - -namespace ComputeSharp.D2D1; - -/// -/// An providing support for custom, stateful draw transform mappings for shaders. -/// -public interface ID2D1TransformMapper - where T : unmanaged, ID2D1PixelShader -{ - /// - /// - /// Allows a transform to state how it would map a a set of sample rectangles on its input to an output rectangle. - /// - /// - /// This is effectively the inverse mapping of . - /// - /// - /// The input D2D1 pixel shader being executed on the current effect (this can be used to retrieve shader properties). - /// The input rectangles to be mapped to the output rectangle. This parameter is always equal to the input bounds. - /// The input rectangles to be mapped to the opaque output rectangle. - /// The output rectangle that maps to the corresponding input rectangle. - /// The output rectangle that maps to the corresponding opaque input rectangle. - /// - /// - /// Unlike and , this method is explicitly called by the renderer at - /// a determined place in its rendering algorithm. The transform implementation may change its state based on the input rectangles - /// and use this information to control its rendering information. This method is always called before the - /// and methods. - /// - /// - /// For more info, see . - /// - /// - void MapInputsToOutput( - in T shader, - ReadOnlySpan inputs, - ReadOnlySpan opaqueInputs, - out Rectangle output, - out Rectangle opaqueOutput); - - /// - /// Allows a transform to state how it would map a rectangle requested on its output to a set of sample rectangles on its input. - /// - /// The output rectangle from which the inputs must be mapped. - /// The corresponding set of inputs. The inputs will directly correspond to the transform inputs. - /// - /// - /// The transform implementation must regard this method as purely functional. It can base the mapped input and output rectangles on its - /// current state as specified by the encapsulating effect properties. However, it must not change its own state in response to this method - /// being invoked. The Direct2D renderer implementation reserves the right to call this method at any time and in any sequence. - /// - /// - /// For more info, see . - /// - /// - void MapOutputToInputs(in Rectangle output, Span inputs); - - /// - /// Sets the input rectangles for this rendering pass into the transform. - /// - /// The index of the input rectangle. - /// The invalid input rectangle. - /// The output rectangle to which the input rectangle must be mapped. - /// - /// - /// The transform implementation must regard this method as purely functional. The transform implementation can base the mapped input rectangle on - /// the transform implementation's current state as specified by the encapsulating effect properties. But the transform implementation can't change - /// its own state in response to a call to . Direct2D can call this method at any time - /// and in any sequence following a call to . - /// - /// - /// For more info, see . - /// - /// - void MapInvalidOutput(int inputIndex, Rectangle invalidInput, out Rectangle invalidOutput); -} \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/D2D1TransformMapper.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/D2D1TransformMapper.cs deleted file mode 100644 index f13dc1ac..00000000 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/D2D1TransformMapper.cs +++ /dev/null @@ -1,133 +0,0 @@ -using System; -using System.Drawing; -using System.Runtime.CompilerServices; - -#pragma warning disable CS0618 - -namespace ComputeSharp.D2D1.Interop.Effects; - -/// -/// A base type to support non-generic uses. -/// -internal abstract class D2D1TransformMapper -{ - /// - /// The buffer with the serialized shader dispatch data, if any. - /// The input rectangles to be mapped to the output rectangle. This parameter is always equal to the input bounds. - /// The input rectangles to be mapped to the opaque output rectangle. - /// The output rectangle that maps to the corresponding input rectangle. - /// The output rectangle that maps to the corresponding opaque input rectangle. - public abstract void MapInputsToOutput( - ReadOnlySpan buffer, - ReadOnlySpan inputs, - ReadOnlySpan opaqueInputs, - out Rectangle output, - out Rectangle opaqueOutput); - - /// - /// The output rectangle from which the inputs must be mapped. - /// The corresponding set of inputs. The inputs will directly correspond to the transform inputs. - public abstract void MapOutputToInputs(in Rectangle output, Span inputs); - - /// - /// The index of the input rectangle. - /// The invalid input rectangle. - /// The output rectangle to which the input rectangle must be mapped. - public abstract void MapInvalidOutput(int inputIndex, Rectangle invalidInput, out Rectangle invalidOutput); - - /// - /// A generic implementation for a specific shader type. - /// - /// The target shader type. - public sealed class For : D2D1TransformMapper - where T : unmanaged, ID2D1PixelShader - { - /// - /// The instance to use. - /// - private readonly ID2D1TransformMapper transformMapper; - - /// - /// Creates a new instance with the specified parameters. - /// - /// The instance to use. - private For(ID2D1TransformMapper transformMapper) - { - this.transformMapper = transformMapper; - } - - /// - /// Creates a new instance for a given transform mapper, if there is one. - /// - /// The instance to usse, if there is one. - /// A new instance wrapping , or . - public static D2D1TransformMapper? Get(ID2D1TransformMapper? transformMapper) - { - if (transformMapper is null) - { - return null; - } - - // If one of the built-in transform mapper factories from D2D1TransformMapperFactory was used, - // the returned ID2D1TransformMapper instance will already inherit from D2D1TransformMapper. - // If that's the case, that object can be returned directly, saving one allocation and avoiding - // an extra interface stub dispatch call every time one of the transform mapping APIs is called. - if (transformMapper is D2D1TransformMapper d2D1TransformMapper) - { - return d2D1TransformMapper; - } - - return new For(transformMapper); - } - - /// - public override void MapInputsToOutput(ReadOnlySpan buffer, ReadOnlySpan inputs, ReadOnlySpan opaqueInputs, out Rectangle output, out Rectangle opaqueOutput) - { - Unsafe.SkipInit(out T shader); - - shader.InitializeFromDispatchData(buffer); - - this.transformMapper.MapInputsToOutput(in shader, inputs, opaqueInputs, out output, out opaqueOutput); - } - - /// - public override void MapOutputToInputs(in Rectangle output, Span inputs) - { - this.transformMapper.MapOutputToInputs(in output, inputs); - } - - /// - public override void MapInvalidOutput(int inputIndex, Rectangle invalidInput, out Rectangle invalidOutput) - { - this.transformMapper.MapInvalidOutput(inputIndex, invalidInput, out invalidOutput); - } - } - - /// - /// A generic implementation for a mapper with a parameterless constructor. - /// - /// The type of D2D1 pixel shader to register. - /// The type of implementation to register. - public sealed class FactoryOf : ID2D1TransformMapperFactory - where T : unmanaged, ID2D1PixelShader - where TMapper : class, ID2D1TransformMapper, new() - { - /// - /// Creates a new instance. - /// - private FactoryOf() - { - } - - /// - /// Gets the shared instance for a given transform mapper. - /// - public static FactoryOf Instance { get; } = new(); - - /// - public ID2D1TransformMapper Create() - { - return new TMapper(); - } - } -} \ No newline at end of file