diff --git a/src/ComputeSharp.D2D1.UI/CanvasEffectInvalidationType.cs b/src/ComputeSharp.D2D1.UI/CanvasEffectInvalidationType.cs index 00b24c07..aef4f100 100644 --- a/src/ComputeSharp.D2D1.UI/CanvasEffectInvalidationType.cs +++ b/src/ComputeSharp.D2D1.UI/CanvasEffectInvalidationType.cs @@ -1,5 +1,7 @@ +#if !D2D1_UWINUI_SOURCE_GENERATOR using ABI.Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas; +#endif #if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; diff --git a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.Execute.cs b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.Execute.cs index d298b1b5..1ac2abf1 100644 --- a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.Execute.cs +++ b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.Execute.cs @@ -41,6 +41,23 @@ partial class CanvasEffectPropertyGenerator return node.Parent?.IsTypeDeclarationWithOrPotentiallyWithBaseTypes() == true; } + /// + /// Gets the invalidation type to use for the generated effect property. + /// + /// The instance for the processed attribute. + /// The resulting to use for the generated property. + public static CanvasEffectInvalidationType GetCanvasEffectInvalidationType(AttributeData attributeData) + { + if (attributeData.ConstructorArguments is [{ Kind: TypedConstantKind.Enum, Value: byte enumValue }]) + { + return (CanvasEffectInvalidationType)enumValue; + } + + // No constructor parameter, or an invalid one. In this case we either just use the default + // invalidation mode, or let the analyzer emit a diagnostic to let the user know. + return CanvasEffectInvalidationType.Update; + } + /// /// Checks whether the generated code has to directly reference the old property value. /// @@ -101,7 +118,7 @@ partial class CanvasEffectPropertyGenerator On{{propertyInfo.PropertyName}}Changed(value); On{{propertyInfo.PropertyName}}Changed(oldValue, value); - InvalidateEffectGraph(default); + InvalidateEffectGraph(global::ComputeSharp.D2D1.WinUI.CanvasEffectInvalidationType.{{propertyInfo.InvalidationType}}); } } """, isMultiline: true); diff --git a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.cs b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.cs index 8332fcaf..d0d24d96 100644 --- a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.cs +++ b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/CanvasEffectPropertyGenerator.cs @@ -41,6 +41,7 @@ public sealed partial class CanvasEffectPropertyGenerator : IIncrementalGenerato string typeNameWithNullabilityAnnotations = propertySymbol.Type.GetFullyQualifiedNameWithNullabilityAnnotations(); bool isOldPropertyValueDirectlyReferenced = Execute.IsOldPropertyValueDirectlyReferenced(propertySymbol); + CanvasEffectInvalidationType invalidationType = Execute.GetCanvasEffectInvalidationType(context.Attributes[0]); // We're using IsValueType here and not IsReferenceType to also cover unconstrained type parameter cases. // This will cover both reference types as well T when the constraints are not struct or unmanaged. @@ -57,7 +58,8 @@ public sealed partial class CanvasEffectPropertyGenerator : IIncrementalGenerato PropertyName: propertySymbol.Name, TypeNameWithNullabilityAnnotations: typeNameWithNullabilityAnnotations, IsOldPropertyValueDirectlyReferenced: isOldPropertyValueDirectlyReferenced, - IsReferenceTypeOrUnconstraindTypeParameter: isReferenceTypeOrUnconstraindTypeParameter); + IsReferenceTypeOrUnconstraindTypeParameter: isReferenceTypeOrUnconstraindTypeParameter, + InvalidationType: invalidationType); }) .Where(static item => item is not null)!; diff --git a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/ComputeSharp.D2D1.WinUI.SourceGenerators.csproj b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/ComputeSharp.D2D1.WinUI.SourceGenerators.csproj index 8d807603..8003250d 100644 --- a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/ComputeSharp.D2D1.WinUI.SourceGenerators.csproj +++ b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/ComputeSharp.D2D1.WinUI.SourceGenerators.csproj @@ -1,6 +1,13 @@ netstandard2.0 + $(DefineConstants);D2D1_UWINUI_SOURCE_GENERATOR + + + + + + $(NoWarn);CS1574 @@ -12,6 +19,11 @@ + + + + + diff --git a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/Models/CanvasEffectPropertyInfo.cs b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/Models/CanvasEffectPropertyInfo.cs index 98ab84ae..7deb91a6 100644 --- a/src/ComputeSharp.D2D1.WinUI.SourceGenerators/Models/CanvasEffectPropertyInfo.cs +++ b/src/ComputeSharp.D2D1.WinUI.SourceGenerators/Models/CanvasEffectPropertyInfo.cs @@ -10,9 +10,11 @@ namespace ComputeSharp.D2D1.WinUI.SourceGenerators.Models; /// The generated property name. /// Whether the old property value is being directly referenced. /// Indicates whether the property is of a reference type or an unconstrained type parameter. +/// The invalidation type to request. internal sealed record CanvasEffectPropertyInfo( HierarchyInfo Hierarchy, string PropertyName, string TypeNameWithNullabilityAnnotations, bool IsOldPropertyValueDirectlyReferenced, - bool IsReferenceTypeOrUnconstraindTypeParameter); + bool IsReferenceTypeOrUnconstraindTypeParameter, + CanvasEffectInvalidationType InvalidationType);