Add EffectGraph APIs to register anonymous nodes

このコミットが含まれているのは:
Sergio Pedri committed 2023-04-30 16:02:31 +02:00
1 親 596187aeaa
コミット 4db990d03b
2ファイル変更
+85 -1

検索条件に一致するファイルはありません

+56
ファイルの表示
@@ -55,6 +55,34 @@ partial class CanvasEffect
return Unsafe.As<T>(canvasImage);
}
/// <summary>
/// Registers an <see cref="ICanvasImage"/> object in the effect graph.
/// </summary>
/// <param name="canvasImage">The <see cref="ICanvasImage"/> object to register in the effect graph.</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="canvasImage"/> is <see langword="null"/>.</exception>
/// <exception cref="InvalidOperationException">Thrown if the effect graph does not support modifications at this time.</exception>
/// <remarks>
/// <para><inheritdoc cref="RegisterNode{T}(EffectNode{T}, T)" path="/remarks/node()"/></para>
/// <para>
/// This method can be used when <paramref name="canvasImage"/> doesn't need to be retrieved from <see cref="ConfigureEffectGraph"/>, 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.
/// </para>
/// <para>
/// If performing lookups on <paramref name="canvasImage"/> is required, use the <see cref="RegisterNode{T}(EffectNode{T}, T)"/> overload.
/// </para>
/// </remarks>
public void RegisterNode(ICanvasImage canvasImage)
{
default(ArgumentNullException).ThrowIfNull(canvasImage);
default(InvalidOperationException).ThrowIf(!this.owner.isBuildingEffectGraph);
// 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<ICanvasImage> instance) just to hold the anonymous effects that may be registered. This way,
// the same dictionary can be reused for all kinds of effect nodes instead. Anonymous effects are generally a nicher scenario.
_ = this.owner.transformNodes.TryAdd(new object(), canvasImage);
}
/// <summary>
/// Registers an <see cref="ICanvasImage"/> object in the effect graph, associated with a given <see cref="EffectNode{T}"/> instance.
/// </summary>
@@ -83,6 +111,34 @@ partial class CanvasEffect
}
}
/// <summary>
/// Registers an <see cref="ICanvasImage"/> object in the effect graph, and marks it as the output node for the effect graph being built.
/// </summary>
/// <remarks>
/// <para><inheritdoc cref="RegisterNode{T}(EffectNode{T}, T)" path="/remarks/node()"/></para>
/// <para>
/// This method can be used when <paramref name="canvasImage"/> doesn't need to be retrieved from <see cref="ConfigureEffectGraph"/>, 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.
/// </para>
/// <para>
/// If performing lookups on <paramref name="canvasImage"/> is required, use the <see cref="RegisterAndSetOutputNode{T}(EffectNode{T}, T)"/> overload.
/// </para>
/// </remarks>
/// <inheritdoc cref="RegisterNode(ICanvasImage)"/>
public void RegisterAndSetOutputNode(ICanvasImage canvasImage)
{
default(ArgumentNullException).ThrowIfNull(canvasImage);
default(InvalidOperationException).ThrowIf(!this.owner.isBuildingEffectGraph);
default(InvalidOperationException).ThrowIf(this.owner.canvasImage is not null);
// Register the anonymous effect node with a dummy object, same as above
_ = this.owner.transformNodes.TryAdd(new object(), canvasImage);
// Store the anonymous output node for later use
this.owner.canvasImage = canvasImage;
}
/// <summary>
/// Registers an <see cref="ICanvasImage"/> object in the effect graph, associated with a given <see cref="EffectNode{T}"/> instance.
/// Additionally, it also marks the input <see cref="ICanvasImage"/> object as the output node for the effect graph being built.