From a544636358baf5eb1c42b2c8302bc5e0cfbdc2e3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 19 May 2024 13:30:27 +0200 Subject: [PATCH] Rename nested 'CanvasEffect' types --- .../Backend/PixelShaderEffect.cs | 6 +- .../Shaders/PixelShaderEffect.cs | 6 +- .../Runners/D2D1ContouredLayersRunner.cs | 6 +- .../CanvasEffect.EffectGraph.cs | 80 +++++----- .../CanvasEffect.Interop.cs | 10 +- src/ComputeSharp.D2D1.WinUI/CanvasEffect.cs | 26 ++-- .../Tests/CanvasEffectTests.cs | 146 +++++++++--------- .../Tests/ShadersTests.cs | 6 +- 8 files changed, 143 insertions(+), 143 deletions(-) diff --git a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs index efdfd577..614804c2 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs +++ b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/PixelShaderEffect.cs @@ -63,16 +63,16 @@ internal abstract class PixelShaderEffect : CanvasEffect /// /// The node in use. /// - private static readonly EffectNode> Effect = new(); + private static readonly CanvasEffectNode> Effect = new(); /// - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { effectGraph.RegisterOutputNode(Effect, new PixelShaderEffect()); } /// - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { effectGraph.GetNode(Effect).ConstantBuffer = factory(ElapsedTime, ScreenWidth, ScreenHeight); } diff --git a/samples/ComputeSharp.SwapChain.WinUI/Shaders/PixelShaderEffect.cs b/samples/ComputeSharp.SwapChain.WinUI/Shaders/PixelShaderEffect.cs index a6ad7b84..f4dcf177 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Shaders/PixelShaderEffect.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/Shaders/PixelShaderEffect.cs @@ -63,16 +63,16 @@ public abstract class PixelShaderEffect : CanvasEffect /// /// The node in use. /// - private static readonly EffectNode> Effect = new(); + private static readonly CanvasEffectNode> Effect = new(); /// - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { effectGraph.RegisterOutputNode(Effect, new PixelShaderEffect()); } /// - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { effectGraph.GetNode(Effect).ConstantBuffer = factory(ElapsedTime, ScreenWidth, ScreenHeight); } diff --git a/samples/ComputeSharp.SwapChain.WinUI/Shaders/Runners/D2D1ContouredLayersRunner.cs b/samples/ComputeSharp.SwapChain.WinUI/Shaders/Runners/D2D1ContouredLayersRunner.cs index 54fb3a3c..a49c6659 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/Shaders/Runners/D2D1ContouredLayersRunner.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/Shaders/Runners/D2D1ContouredLayersRunner.cs @@ -16,10 +16,10 @@ public sealed class D2D1ContouredLayersEffect : PixelShaderEffect /// /// The reusable node to use to render frames. /// - private static readonly EffectNode> PixelShaderEffect = new(); + private static readonly CanvasEffectNode> PixelShaderEffect = new(); /// - protected override unsafe void BuildEffectGraph(EffectGraph effectGraph) + protected override unsafe void BuildEffectGraph(CanvasEffectGraph effectGraph) { string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png"); @@ -56,7 +56,7 @@ public sealed class D2D1ContouredLayersEffect : PixelShaderEffect } /// - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { effectGraph.GetNode(PixelShaderEffect).ConstantBuffer = new ContouredLayers((float)ElapsedTime.TotalSeconds, new int2(ScreenWidth, ScreenHeight)); } diff --git a/src/ComputeSharp.D2D1.WinUI/CanvasEffect.EffectGraph.cs b/src/ComputeSharp.D2D1.WinUI/CanvasEffect.EffectGraph.cs index 628e0894..42f45112 100644 --- a/src/ComputeSharp.D2D1.WinUI/CanvasEffect.EffectGraph.cs +++ b/src/ComputeSharp.D2D1.WinUI/CanvasEffect.EffectGraph.cs @@ -10,7 +10,7 @@ partial class CanvasEffect /// /// An object representing an effect graph being built or configured. /// - protected readonly ref struct EffectGraph + protected readonly ref struct CanvasEffectGraph { /// /// The owning instance. @@ -18,10 +18,10 @@ partial class CanvasEffect private readonly CanvasEffect owner; /// - /// Creates a new instance with the specified parameters. + /// Creates a new instance with the specified parameters. /// /// The owning instance. - internal EffectGraph(CanvasEffect owner) + internal CanvasEffectGraph(CanvasEffect owner) { this.owner = owner; } @@ -29,12 +29,12 @@ partial class CanvasEffect /// /// Gets a previously registered object associated with a given effect graph node. /// - /// The instance to use to lookup the object to retrieve. + /// The instance to use to lookup the object to retrieve. /// The object associated with in the effect graph. /// Thrown if is . /// Thrown if is not currently registered in the effect graph. - /// Thrown if the current instance is not valid. - public ICanvasImage GetNode(IEffectNode effectNode) + /// Thrown if the current instance is not valid. + public ICanvasImage GetNode(ICanvasEffectNode effectNode) { default(ArgumentNullException).ThrowIfNull(effectNode); default(InvalidOperationException).ThrowIf(this.owner is null); @@ -53,12 +53,12 @@ partial class CanvasEffect /// Gets a previously registered object (an instance) associated with a given effect graph node. /// /// The type of object to retrieve. - /// The instance to use to lookup the object to retrieve. + /// The instance to use to lookup the object to retrieve. /// The object associated with in the effect graph. /// Thrown if is . /// Thrown if is not currently registered in the effect graph. - /// Thrown if the current instance is not valid. - public T GetNode(IEffectNode effectNode) + /// Thrown if the current instance is not valid. + public T GetNode(ICanvasEffectNode effectNode) where T : class, ICanvasImage { default(ArgumentNullException).ThrowIfNull(effectNode); @@ -81,24 +81,24 @@ partial class CanvasEffect /// The object to register in the effect graph. /// Thrown if is . /// - /// Thrown if the current instance is not valid or if the effect graph does not support modifications at this time. + /// Thrown if the current instance is not valid or if the effect graph does not support modifications at this time. /// /// - /// + /// /// /// This method can be used when doesn't need to be retrieved from , ie. /// when it has no properties that the current effect instance will need to mutate over it. Using this method still allows the effect to /// correctly track the image ownership, so that it can be disposed when the current effect instance is disposed. /// /// - /// If performing lookups on is required, use the overload. + /// If performing lookups on is required, use the overload. /// /// public void RegisterNode(ICanvasImage canvasImage) { default(ArgumentNullException).ThrowIfNull(canvasImage); default(InvalidOperationException).ThrowIf(this.owner is null); - default(InvalidOperationException).ThrowIf(this.owner.invalidationType != InvalidationType.Creation, "The effect graph cannot be modified after its creation."); + default(InvalidOperationException).ThrowIf(this.owner.invalidationType != CanvasEffectInvalidationType.Creation, "The effect graph cannot be modified after its creation."); // Use a new dummy object as key to register the anonymous effect node. This is cheaper than having to maintain a different // data structure (eg. a HashSet instance) just to hold the anonymous effects that may be registered. This way, @@ -107,27 +107,27 @@ partial class CanvasEffect } /// - /// Registers an object in the effect graph, associated with a given instance. + /// Registers an object in the effect graph, associated with a given instance. /// /// The type of object to register. - /// The instance to use to register . + /// The instance to use to register . /// The object to register in the effect graph. /// Thrown if or are . /// - /// Thrown if the current instance is not valid or if the effect graph does not support modifications at this time. + /// Thrown if the current instance is not valid or if the effect graph does not support modifications at this time. /// /// Thrown if is already registered in the effect graph. /// - /// This method can only be called from an value being passed to . If this + /// This method can only be called from an value being passed to . If this /// method is called from within , it will fail, as the effect graph cannot be mutated from there. /// - public void RegisterNode(EffectNode effectNode, T canvasImage) + public void RegisterNode(CanvasEffectNode effectNode, T canvasImage) where T : class, ICanvasImage { default(ArgumentNullException).ThrowIfNull(effectNode); default(ArgumentNullException).ThrowIfNull(canvasImage); default(InvalidOperationException).ThrowIf(this.owner is null); - default(InvalidOperationException).ThrowIf(this.owner.invalidationType != InvalidationType.Creation, "The effect graph cannot be modified after its creation."); + default(InvalidOperationException).ThrowIf(this.owner.invalidationType != CanvasEffectInvalidationType.Creation, "The effect graph cannot be modified after its creation."); // Try to add the new canvas image associated with the input effect node marker. // This must not have been previously added from another RegisterNode call. @@ -141,14 +141,14 @@ partial class CanvasEffect /// Registers an object in the effect graph, and marks it as the output node for the effect graph being built. /// /// - /// + /// /// /// This method can be used when doesn't need to be retrieved from , ie. /// when it has no properties that the current effect instance will need to mutate over it. Using this method still allows the effect to /// correctly track the image ownership, so that it can be disposed when the current effect instance is disposed. /// /// - /// If performing lookups on is required, use the overload. + /// If performing lookups on is required, use the overload. /// /// /// @@ -156,7 +156,7 @@ partial class CanvasEffect { default(ArgumentNullException).ThrowIfNull(canvasImage); default(InvalidOperationException).ThrowIf(this.owner is null); - default(InvalidOperationException).ThrowIf(this.owner.invalidationType != InvalidationType.Creation, "The effect graph cannot be modified after its creation."); + default(InvalidOperationException).ThrowIf(this.owner.invalidationType != CanvasEffectInvalidationType.Creation, "The effect graph cannot be modified after its creation."); // Register the anonymous effect node with a dummy object, same as above _ = this.owner.transformNodes.TryAdd(new object(), canvasImage); @@ -166,17 +166,17 @@ partial class CanvasEffect } /// - /// Registers an object in the effect graph, associated with a given instance. + /// Registers an object in the effect graph, associated with a given instance. /// Additionally, it also marks the input object as the output node for the effect graph being built. /// /// - public void RegisterOutputNode(EffectNode effectNode, T canvasImage) + public void RegisterOutputNode(CanvasEffectNode effectNode, T canvasImage) where T : class, ICanvasImage { default(ArgumentNullException).ThrowIfNull(effectNode); default(ArgumentNullException).ThrowIfNull(canvasImage); default(InvalidOperationException).ThrowIf(this.owner is null); - default(InvalidOperationException).ThrowIf(this.owner.invalidationType != InvalidationType.Creation, "The effect graph cannot be modified after its creation."); + default(InvalidOperationException).ThrowIf(this.owner.invalidationType != CanvasEffectInvalidationType.Creation, "The effect graph cannot be modified after its creation."); // Try to add the output node as in the method above (but with an extra check before doing so) if (!this.owner.transformNodes.TryAdd(effectNode, canvasImage)) @@ -189,18 +189,18 @@ partial class CanvasEffect } /// - /// Sets a previously registered instance as the output node for the effect graph. + /// Sets a previously registered instance as the output node for the effect graph. /// - /// The instance to set as output node for the effect graph. + /// The instance to set as output node for the effect graph. /// Thrown if is . - /// Thrown if the current instance is not valid. + /// Thrown if the current instance is not valid. /// Thrown if is not registered in the effect graph. /// /// This method can be called from both and . It can be used for /// efficiently changing the output node of a graph, without having to rebuild it. For instance, this can be used for effects that /// have multiple paths that can be taken for their inputs, depending on the value of some property describing the effect behavior. /// - public void SetOutputNode(IEffectNode effectNode) + public void SetOutputNode(ICanvasEffectNode effectNode) { default(ArgumentNullException).ThrowIfNull(effectNode); default(InvalidOperationException).ThrowIf(this.owner is null); @@ -217,39 +217,39 @@ partial class CanvasEffect } /// - /// A marker interface for an effect node that was registered from an value. + /// A marker interface for an effect node that was registered from an value. /// /// /// - /// This interface allows using and in more scenarios, + /// This interface allows using and in more scenarios, /// including where the concrete type of the image being used (eg. to set the output node) is not known (or needed) by the caller. /// /// - /// This interface only implemented by and it's not meant to be implemented by external types. + /// This interface only implemented by and it's not meant to be implemented by external types. /// /// - protected interface IEffectNode; + protected interface ICanvasEffectNode; /// - /// A marker interface for a generic effect node that was registered from an value. + /// A marker interface for a generic effect node that was registered from an value. /// /// The covariant type of associated with the current effect node. /// /// - /// This interface allows using and in more scenarios, - /// including with ternary expressions returning multiple concrete instances with a common image type. + /// This interface allows using and in more scenarios, + /// including with ternary expressions returning multiple concrete instances with a common image type. /// /// - /// This interface only implemented by and it's not meant to be implemented by external types. + /// This interface only implemented by and it's not meant to be implemented by external types. /// /// - protected interface IEffectNode : IEffectNode + protected interface ICanvasEffectNode : ICanvasEffectNode where T : ICanvasImage; /// - /// A marker type for an effect node that can be registered and retrieved from an value. + /// A marker type for an effect node that can be registered and retrieved from an value. /// /// The type of associated with the current effect node. - protected sealed class EffectNode : IEffectNode + protected sealed class CanvasEffectNode : ICanvasEffectNode where T : class, ICanvasImage; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1.WinUI/CanvasEffect.Interop.cs b/src/ComputeSharp.D2D1.WinUI/CanvasEffect.Interop.cs index 25dee559..623abca5 100644 --- a/src/ComputeSharp.D2D1.WinUI/CanvasEffect.Interop.cs +++ b/src/ComputeSharp.D2D1.WinUI/CanvasEffect.Interop.cs @@ -65,21 +65,21 @@ partial class CanvasEffect default(ObjectDisposedException).ThrowIf(this.isDisposed, this); // Build the effect graph (the output node might not have been set yet) - if (this.invalidationType == InvalidationType.Creation) + if (this.invalidationType == CanvasEffectInvalidationType.Creation) { DisposeEffectGraph(); - BuildEffectGraph(new EffectGraph(this)); + BuildEffectGraph(new CanvasEffectGraph(this)); // We successfully got past the effect graph creation, so update the current // invalidation state. This ensures that even if the configuration failed, the // next time the effect is drawn again the graph won't be created again too. - this.invalidationType = InvalidationType.Update; + this.invalidationType = CanvasEffectInvalidationType.Update; } // Configure the effect graph, if the effect is invalidated - if (this.invalidationType == InvalidationType.Update) + if (this.invalidationType == CanvasEffectInvalidationType.Update) { - ConfigureEffectGraph(new EffectGraph(this)); + ConfigureEffectGraph(new CanvasEffectGraph(this)); // The effect graph is now ready to go: no further work will be done before drawing // unless it is explicitly invalidated again, using either creation or update mode. diff --git a/src/ComputeSharp.D2D1.WinUI/CanvasEffect.cs b/src/ComputeSharp.D2D1.WinUI/CanvasEffect.cs index e08c903b..7b754277 100644 --- a/src/ComputeSharp.D2D1.WinUI/CanvasEffect.cs +++ b/src/ComputeSharp.D2D1.WinUI/CanvasEffect.cs @@ -27,7 +27,7 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I /// /// Indicates the current invalidation state for the effect graph (which controls the logic in ). /// - private InvalidationType invalidationType = InvalidationType.Creation; + private CanvasEffectInvalidationType invalidationType = CanvasEffectInvalidationType.Creation; /// /// Indicates whether the effect is disposed. @@ -38,14 +38,14 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I /// Builds the effect graph for the current instance, and configures all effect nodes, as well as the output /// node for the graph. That instance will then be passed to Win2D to perform the actual drawing, when needed. /// - /// The input value to use to build the effect graph. + /// The input value to use to build the effect graph. /// /// /// This method is called once before the current effect is drawn, and the resulting image is automatically cached and reused. - /// It will remain in use until is called with . + /// It will remain in use until is called with . /// /// - /// If the effect is invalidated with , only will be + /// If the effect is invalidated with , only will be /// called. As such, derived types should save any effect graph nodes that might need updates into instance fields, for later use. /// /// @@ -73,19 +73,19 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I /// /// /// - /// For convenience, it is recommended to store all necessary objects in + /// For convenience, it is recommended to store all necessary objects in /// fields, so they can easily be accessed from and . /// /// /// This method should never be called directly. It is automatically invoked when an effect graph is needed. /// /// - protected abstract void BuildEffectGraph(EffectGraph effectGraph); + protected abstract void BuildEffectGraph(CanvasEffectGraph effectGraph); /// /// Configures the current effect graph whenever it is invalidated. /// - /// The input value to use to configure the effect graph. + /// The input value to use to configure the effect graph. /// /// /// This method is guaranteed to be called after has been invoked already. As such, any instance @@ -95,7 +95,7 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I /// This method should never be called directly. It is used internally to configure the current effect graph. /// /// - protected abstract void ConfigureEffectGraph(EffectGraph effectGraph); + protected abstract void ConfigureEffectGraph(CanvasEffectGraph effectGraph); /// /// Invalidates the last returned result from . @@ -108,12 +108,12 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I /// or whether it simply needs to refresh its internal state (by calling ). /// /// - /// If is called with , the effect + /// If is called with , the effect /// graph will only be refreshed the next time the image is actually requested. That is, repeated requests /// for updates do not result in unnecessarily calls to . /// /// - protected void InvalidateEffectGraph(InvalidationType invalidationType = InvalidationType.Update) + protected void InvalidateEffectGraph(CanvasEffectInvalidationType invalidationType = CanvasEffectInvalidationType.Update) { lock (this.transformNodes) { @@ -123,7 +123,7 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I // The new invalidation type is always set to the maximum between the current one and // the requested one. This means that eg. if the current invalidation type is creation, // and a property only needing an update is set, the creation request will persist. - this.invalidationType = (InvalidationType)Math.Max((byte)this.invalidationType, (byte)invalidationType); + this.invalidationType = (CanvasEffectInvalidationType)Math.Max((byte)this.invalidationType, (byte)invalidationType); } } @@ -135,7 +135,7 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I /// The storage for the effect property value. /// The new effect property value to set. /// The invalidation type to request. - protected void SetAndInvalidateEffectGraph([NotNullIfNotNull(nameof(value))] ref T storage, T value, InvalidationType invalidationType = InvalidationType.Update) + protected void SetAndInvalidateEffectGraph([NotNullIfNotNull(nameof(value))] ref T storage, T value, CanvasEffectInvalidationType invalidationType = CanvasEffectInvalidationType.Update) { if (EqualityComparer.Default.Equals(storage, value)) { @@ -205,7 +205,7 @@ public abstract partial class CanvasEffect : ICanvasImage, ICanvasImageInterop.I /// /// Indicates the invalidation type to request when invoking and related methods. /// - protected enum InvalidationType : byte + protected enum CanvasEffectInvalidationType : byte { /// /// Invalidates the state of the effect graph, causing it to be configured again the next time it is used. diff --git a/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/CanvasEffectTests.cs b/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/CanvasEffectTests.cs index ed224f3e..9b34fb4f 100644 --- a/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/CanvasEffectTests.cs +++ b/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/CanvasEffectTests.cs @@ -383,7 +383,7 @@ public partial class CanvasEffectTests private sealed class EffectWithNoInputs : CanvasEffect { - private static readonly EffectNode> Effect = new(); + private static readonly CanvasEffectNode> Effect = new(); private int value; @@ -396,7 +396,7 @@ public partial class CanvasEffectTests public int ValueWithReload { get => this.value; - set => SetAndInvalidateEffectGraph(ref this.value, value, InvalidationType.Creation); + set => SetAndInvalidateEffectGraph(ref this.value, value, CanvasEffectInvalidationType.Creation); } public int NumberOfBuildEffectGraphCalls { get; private set; } @@ -405,21 +405,21 @@ public partial class CanvasEffectTests public int NumberOfDisposeCalls { get; private set; } - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { NumberOfBuildEffectGraphCalls++; effectGraph.RegisterOutputNode(Effect, new PixelShaderEffect()); } - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { NumberOfConfigureEffectGraphCalls++; effectGraph.GetNode(Effect).ConstantBuffer = new ShaderWithNoInputs(this.value); // Also test the non-generic overload - Assert.IsTrue(effectGraph.GetNode((IEffectNode)Effect) is PixelShaderEffect); + Assert.IsTrue(effectGraph.GetNode((ICanvasEffectNode)Effect) is PixelShaderEffect); } protected override void Dispose(bool disposing) @@ -434,17 +434,17 @@ public partial class CanvasEffectTests { public bool WasConfigureEffectGraphCalled { get; private set; } - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { - effectGraph.RegisterOutputNode(new EffectNode(), new ColorSourceEffect()); - effectGraph.RegisterOutputNode(new EffectNode(), new ColorSourceEffect()); + effectGraph.RegisterOutputNode(new CanvasEffectNode(), new ColorSourceEffect()); + effectGraph.RegisterOutputNode(new CanvasEffectNode(), new ColorSourceEffect()); } - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { WasConfigureEffectGraphCalled = true; - effectGraph.SetOutputNode(new EffectNode()); + effectGraph.SetOutputNode(new CanvasEffectNode()); } } @@ -452,14 +452,14 @@ public partial class CanvasEffectTests { public bool WasConfigureEffectGraphCalled { get; private set; } - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { effectGraph.RegisterNode(new ColorSourceEffect()); - effectGraph.RegisterNode(new EffectNode(), new ColorSourceEffect()); - effectGraph.RegisterNode(new EffectNode(), new ColorSourceEffect()); + effectGraph.RegisterNode(new CanvasEffectNode(), new ColorSourceEffect()); + effectGraph.RegisterNode(new CanvasEffectNode(), new ColorSourceEffect()); } - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { WasConfigureEffectGraphCalled = true; } @@ -467,15 +467,15 @@ public partial class CanvasEffectTests private sealed class EffectRegisteringNodesMultipleTimes1 : CanvasEffect { - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { - EffectNode node = new(); + CanvasEffectNode node = new(); effectGraph.RegisterNode(node, new ColorSourceEffect()); effectGraph.RegisterOutputNode(node, new ColorSourceEffect()); } - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { Assert.Fail(); } @@ -483,16 +483,16 @@ public partial class CanvasEffectTests private sealed class EffectRegisteringNodesMultipleTimes2 : CanvasEffect { - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { - EffectNode node = new(); + CanvasEffectNode node = new(); effectGraph.RegisterNode(node, new ColorSourceEffect()); effectGraph.RegisterNode(node, new ColorSourceEffect()); - effectGraph.RegisterOutputNode(new EffectNode(), new ColorSourceEffect()); + effectGraph.RegisterOutputNode(new CanvasEffectNode(), new ColorSourceEffect()); } - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { Assert.Fail(); } @@ -500,63 +500,63 @@ public partial class CanvasEffectTests private sealed class EffectRegisteringNullObjects : CanvasEffect { - protected override unsafe void BuildEffectGraph(EffectGraph effectGraph) + protected override unsafe void BuildEffectGraph(CanvasEffectGraph effectGraph) { // Verify that if the effect graph is invalid, arguments are validated first - _ = Assert.ThrowsException(() => default(EffectGraph).RegisterNode(null!)); - _ = Assert.ThrowsException(() => default(EffectGraph).RegisterNode(null!, new ColorSourceEffect())); - _ = Assert.ThrowsException(() => default(EffectGraph).RegisterNode(new EffectNode(), null!)); - _ = Assert.ThrowsException(() => default(EffectGraph).RegisterNode(null!, (ColorSourceEffect?)null!)); - _ = Assert.ThrowsException(() => default(EffectGraph).RegisterOutputNode(null!)); - _ = Assert.ThrowsException(() => default(EffectGraph).RegisterOutputNode(null!, new ColorSourceEffect())); - _ = Assert.ThrowsException(() => default(EffectGraph).RegisterOutputNode(new EffectNode(), null!)); - _ = Assert.ThrowsException(() => default(EffectGraph).RegisterOutputNode(null!, (ColorSourceEffect)null!)); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).RegisterNode(null!)); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).RegisterNode(null!, new ColorSourceEffect())); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).RegisterNode(new CanvasEffectNode(), null!)); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).RegisterNode(null!, (ColorSourceEffect?)null!)); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).RegisterOutputNode(null!)); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).RegisterOutputNode(null!, new ColorSourceEffect())); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).RegisterOutputNode(new CanvasEffectNode(), null!)); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).RegisterOutputNode(null!, (ColorSourceEffect)null!)); void* ptr = &effectGraph; - _ = Assert.ThrowsException(() => (*(EffectGraph*)ptr).RegisterNode(null!)); - _ = Assert.ThrowsException(() => (*(EffectGraph*)ptr).RegisterNode(null!, new ColorSourceEffect())); - _ = Assert.ThrowsException(() => (*(EffectGraph*)ptr).RegisterNode(new EffectNode(), null!)); - _ = Assert.ThrowsException(() => (*(EffectGraph*)ptr).RegisterNode(null!, (ColorSourceEffect?)null!)); - _ = Assert.ThrowsException(() => (*(EffectGraph*)ptr).RegisterOutputNode(null!)); - _ = Assert.ThrowsException(() => (*(EffectGraph*)ptr).RegisterOutputNode(null!, new ColorSourceEffect())); - _ = Assert.ThrowsException(() => (*(EffectGraph*)ptr).RegisterOutputNode(new EffectNode(), null!)); - _ = Assert.ThrowsException(() => (*(EffectGraph*)ptr).RegisterOutputNode(null!, (ColorSourceEffect)null!)); + _ = Assert.ThrowsException(() => (*(CanvasEffectGraph*)ptr).RegisterNode(null!)); + _ = Assert.ThrowsException(() => (*(CanvasEffectGraph*)ptr).RegisterNode(null!, new ColorSourceEffect())); + _ = Assert.ThrowsException(() => (*(CanvasEffectGraph*)ptr).RegisterNode(new CanvasEffectNode(), null!)); + _ = Assert.ThrowsException(() => (*(CanvasEffectGraph*)ptr).RegisterNode(null!, (ColorSourceEffect?)null!)); + _ = Assert.ThrowsException(() => (*(CanvasEffectGraph*)ptr).RegisterOutputNode(null!)); + _ = Assert.ThrowsException(() => (*(CanvasEffectGraph*)ptr).RegisterOutputNode(null!, new ColorSourceEffect())); + _ = Assert.ThrowsException(() => (*(CanvasEffectGraph*)ptr).RegisterOutputNode(new CanvasEffectNode(), null!)); + _ = Assert.ThrowsException(() => (*(CanvasEffectGraph*)ptr).RegisterOutputNode(null!, (ColorSourceEffect)null!)); - effectGraph.RegisterOutputNode(new EffectNode(), new ColorSourceEffect()); + effectGraph.RegisterOutputNode(new CanvasEffectNode(), new ColorSourceEffect()); } - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { } } private sealed class EffectConfiguringGraphIncorrectly : CanvasEffect { - private static readonly EffectNode EffectNode1 = new(); - private static readonly EffectNode EffectNode2 = new(); - private static readonly EffectNode EffectNode3 = new(); + private static readonly CanvasEffectNode EffectNode1 = new(); + private static readonly CanvasEffectNode EffectNode2 = new(); + private static readonly CanvasEffectNode EffectNode3 = new(); #pragma warning disable CA2213 private readonly ColorSourceEffect effect1 = new(); private readonly ColorSourceEffect effect2 = new(); private readonly ColorSourceEffect effect3 = new(); #pragma warning restore CA2213 - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { effectGraph.RegisterNode(EffectNode1, this.effect1); effectGraph.RegisterNode(EffectNode2, this.effect2); effectGraph.RegisterOutputNode(EffectNode3, this.effect3); } - protected override unsafe void ConfigureEffectGraph(EffectGraph effectGraph) + protected override unsafe void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { void* ptr = &effectGraph; - _ = Assert.ThrowsException(() => (*(EffectGraph*)ptr).GetNode((EffectNode)null!)); - _ = Assert.ThrowsException(() => (*(EffectGraph*)ptr).GetNode(new EffectNode())); - _ = Assert.ThrowsException(() => (*(EffectGraph*)ptr).RegisterNode(new EffectNode(), new ColorSourceEffect())); - _ = Assert.ThrowsException(() => (*(EffectGraph*)ptr).RegisterOutputNode(new EffectNode(), new ColorSourceEffect())); + _ = Assert.ThrowsException(() => (*(CanvasEffectGraph*)ptr).GetNode((CanvasEffectNode)null!)); + _ = Assert.ThrowsException(() => (*(CanvasEffectGraph*)ptr).GetNode(new CanvasEffectNode())); + _ = Assert.ThrowsException(() => (*(CanvasEffectGraph*)ptr).RegisterNode(new CanvasEffectNode(), new ColorSourceEffect())); + _ = Assert.ThrowsException(() => (*(CanvasEffectGraph*)ptr).RegisterOutputNode(new CanvasEffectNode(), new ColorSourceEffect())); Assert.AreSame(effectGraph.GetNode(EffectNode1), this.effect1); Assert.AreSame(effectGraph.GetNode(EffectNode2), this.effect2); @@ -566,47 +566,47 @@ public partial class CanvasEffectTests private sealed class EffectOnlyUsingAnonymousNodes : CanvasEffect { - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { effectGraph.RegisterNode(new ColorSourceEffect()); effectGraph.RegisterNode(new ColorSourceEffect()); effectGraph.RegisterOutputNode(new ColorSourceEffect()); } - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { } } private sealed class EffectUsingEffectGraphInInvalidState : CanvasEffect { - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { - _ = Assert.ThrowsException(() => default(EffectGraph).RegisterNode(new ColorSourceEffect())); - _ = Assert.ThrowsException(() => default(EffectGraph).RegisterNode(new EffectNode(), new ColorSourceEffect())); - _ = Assert.ThrowsException(() => default(EffectGraph).RegisterOutputNode(new ColorSourceEffect())); - _ = Assert.ThrowsException(() => default(EffectGraph).RegisterOutputNode(new EffectNode(), new ColorSourceEffect())); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).RegisterNode(new ColorSourceEffect())); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).RegisterNode(new CanvasEffectNode(), new ColorSourceEffect())); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).RegisterOutputNode(new ColorSourceEffect())); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).RegisterOutputNode(new CanvasEffectNode(), new ColorSourceEffect())); - effectGraph.RegisterOutputNode(new EffectNode(), new ColorSourceEffect()); + effectGraph.RegisterOutputNode(new CanvasEffectNode(), new ColorSourceEffect()); } - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { - _ = Assert.ThrowsException(() => default(EffectGraph).GetNode(new EffectNode())); + _ = Assert.ThrowsException(() => default(CanvasEffectGraph).GetNode(new CanvasEffectNode())); } } private sealed class PixelShaderSwitchEffect : CanvasEffect { - private static readonly EffectNode> HelloWorldNode = new(); - private static readonly EffectNode> ColorfulInfinityNode = new(); - private static readonly EffectNode> FractalTilingNode = new(); - private static readonly EffectNode> OctagramsNode = new(); - private static readonly EffectNode> ProteanCloudsNode = new(); + private static readonly CanvasEffectNode> HelloWorldNode = new(); + private static readonly CanvasEffectNode> ColorfulInfinityNode = new(); + private static readonly CanvasEffectNode> FractalTilingNode = new(); + private static readonly CanvasEffectNode> OctagramsNode = new(); + private static readonly CanvasEffectNode> ProteanCloudsNode = new(); private int step; - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { effectGraph.RegisterNode(HelloWorldNode, new PixelShaderEffect { ConstantBuffer = new HelloWorld(0, new int2(1280, 720)) }); effectGraph.RegisterNode(ColorfulInfinityNode, new PixelShaderEffect { ConstantBuffer = new ColorfulInfinity(0, new int2(1280, 720)) }); @@ -616,7 +616,7 @@ public partial class CanvasEffectTests effectGraph.SetOutputNode(HelloWorldNode); } - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { switch (this.step++) { @@ -640,24 +640,24 @@ public partial class CanvasEffectTests private sealed class EffectTestingDisposal : CanvasEffect { - private static readonly EffectNode EffectNode1 = new(); - private static readonly EffectNode EffectNode2 = new(); - private static readonly EffectNode EffectNode3 = new(); + private static readonly CanvasEffectNode EffectNode1 = new(); + private static readonly CanvasEffectNode EffectNode2 = new(); + private static readonly CanvasEffectNode EffectNode3 = new(); public readonly List Effects1 = []; public readonly List Effects2 = []; public readonly List Effects3 = []; public void InvalidateCreation() { - InvalidateEffectGraph(InvalidationType.Creation); + InvalidateEffectGraph(CanvasEffectInvalidationType.Creation); } public void InvalidateUpdate() { - InvalidateEffectGraph(InvalidationType.Update); + InvalidateEffectGraph(CanvasEffectInvalidationType.Update); } - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { this.Effects1.Add(new DummyCanvasImageTrackingDisposal()); this.Effects2.Add(new DummyCanvasImageTrackingDisposal()); @@ -668,7 +668,7 @@ public partial class CanvasEffectTests effectGraph.RegisterOutputNode(EffectNode3, this.Effects3[^1]); } - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { } } diff --git a/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/ShadersTests.cs b/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/ShadersTests.cs index d68a5eaf..756726ea 100644 --- a/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/ShadersTests.cs +++ b/tests/ComputeSharp.D2D1.WinUI.Tests/Tests/ShadersTests.cs @@ -113,7 +113,7 @@ public class ShadersTests private sealed class TestCanvasEffect : CanvasEffect where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { - private static readonly EffectNode> Effect = new(); + private static readonly CanvasEffectNode> Effect = new(); private T constantBuffer; @@ -123,12 +123,12 @@ public class ShadersTests set => SetAndInvalidateEffectGraph(ref this.constantBuffer, value); } - protected override void BuildEffectGraph(EffectGraph effectGraph) + protected override void BuildEffectGraph(CanvasEffectGraph effectGraph) { effectGraph.RegisterOutputNode(Effect, new PixelShaderEffect()); } - protected override void ConfigureEffectGraph(EffectGraph effectGraph) + protected override void ConfigureEffectGraph(CanvasEffectGraph effectGraph) { effectGraph.GetNode(Effect).ConstantBuffer = this.constantBuffer; }