Propagate the 'InvalidationType' parameter

このコミットが含まれているのは:
Sergio Pedri committed 2024-10-17 21:41:03 -07:00
1 親 44959ce417
コミット 3f4d59e981
5ファイル変更
+38 -3

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

+2
ファイルの表示
@@ -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;
+18 -1
ファイルの表示
@@ -41,6 +41,23 @@ partial class CanvasEffectPropertyGenerator
return node.Parent?.IsTypeDeclarationWithOrPotentiallyWithBaseTypes<ClassDeclarationSyntax>() == true;
}
/// <summary>
/// Gets the invalidation type to use for the generated effect property.
/// </summary>
/// <param name="attributeData">The <see cref="AttributeData"/> instance for the processed attribute.</param>
/// <returns>The resulting <see cref="CanvasEffectInvalidationType"/> to use for the generated property.</returns>
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;
}
/// <summary>
/// Checks whether the generated code has to directly reference the old property value.
/// </summary>
@@ -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);
+3 -1
ファイルの表示
@@ -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)!;
@@ -1,6 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DefineConstants>$(DefineConstants);D2D1_UWINUI_SOURCE_GENERATOR</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<!-- Ignore warnings for unresolved XML cref attributes (for imported types, same as in the D3D12 generator) -->
<NoWarn>$(NoWarn);CS1574</NoWarn>
</PropertyGroup>
<ItemGroup>
@@ -12,6 +19,11 @@
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
</ItemGroup>
<!-- ComputeSharp.D2D1.WinUI APIs -->
<ItemGroup>
<Compile Include="..\ComputeSharp.D2D1.UI\CanvasEffectInvalidationType.cs" Link="ComputeSharp.D2D1.WinUI\CanvasEffectInvalidationType.cs" />
</ItemGroup>
<!-- Shared project with common helpers -->
<Import Project="..\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems" Label="Shared" />
</Project>
+3 -1
ファイルの表示
@@ -10,9 +10,11 @@ namespace ComputeSharp.D2D1.WinUI.SourceGenerators.Models;
/// <param name="PropertyName">The generated property name.</param>
/// <param name="IsOldPropertyValueDirectlyReferenced">Whether the old property value is being directly referenced.</param>
/// <param name="IsReferenceTypeOrUnconstraindTypeParameter">Indicates whether the property is of a reference type or an unconstrained type parameter.</param>
/// <param name="InvalidationType">The invalidation type to request.</param>
internal sealed record CanvasEffectPropertyInfo(
HierarchyInfo Hierarchy,
string PropertyName,
string TypeNameWithNullabilityAnnotations,
bool IsOldPropertyValueDirectlyReferenced,
bool IsReferenceTypeOrUnconstraindTypeParameter);
bool IsReferenceTypeOrUnconstraindTypeParameter,
CanvasEffectInvalidationType InvalidationType);