From 4591de830c0b83e37d5e5296562d401b8a34fce4 Mon Sep 17 00:00:00 2001 From: Simeon Cran Date: Thu, 7 Jan 2021 14:38:36 -0800 Subject: [PATCH] Show gradient brushes in DGML. Animated gradient brushes are expensive to render. This change allows us to see the gradient brushes in the DGML graph representation, and colors the animated ones in a very obvious red color. --- .../CompositionObjectDgmlSerializer.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/source/UIDataCodeGen/Serialization/CompositionObjectDgmlSerializer.cs b/source/UIDataCodeGen/Serialization/CompositionObjectDgmlSerializer.cs index 31e1fe65..5aea4f5a 100644 --- a/source/UIDataCodeGen/Serialization/CompositionObjectDgmlSerializer.cs +++ b/source/UIDataCodeGen/Serialization/CompositionObjectDgmlSerializer.cs @@ -26,6 +26,8 @@ sealed class CompositionObjectDgmlSerializer static readonly Category CategoryEffectBrush = new Category("EffectBrush", Colors.LightGray); static readonly Category CategoryEllipse = new Category("Ellipse", Colors.DarkGoldenrod); static readonly Category CategoryEllipseAnimated = new Category("AnimatedEllipse", "Animated Ellipse", Colors.Goldenrod); + static readonly Category CategoryGradientBrush = new Category("GradientBrush", Colors.Orange); + static readonly Category CategoryGradientBrushAnimated = new Category("AnimatedGradientBrush", Colors.Red); static readonly Category CategoryLayerVisual = new Category("LayerVisual", Colors.DarkRed); static readonly Category CategoryLayerVisualAnimated = new Category("AnimatedLayerVisual", "Animated LayerVisual", Colors.Crimson); static readonly Category CategoryPath = new Category("Path", Colors.DarkOrange); @@ -292,11 +294,9 @@ internal void Initialize(CompositionObjectDgmlSerializer owner) case CompositionObjectType.CompositionColorBrush: case CompositionObjectType.CompositionColorGradientStop: case CompositionObjectType.CompositionEllipseGeometry: - case CompositionObjectType.CompositionLinearGradientBrush: case CompositionObjectType.CompositionGeometricClip: case CompositionObjectType.CompositionPathGeometry: case CompositionObjectType.CompositionPropertySet: - case CompositionObjectType.CompositionRadialGradientBrush: case CompositionObjectType.CompositionRectangleGeometry: case CompositionObjectType.CompositionRoundedRectangleGeometry: case CompositionObjectType.CompositionViewBox: @@ -340,6 +340,10 @@ internal void Initialize(CompositionObjectDgmlSerializer owner) case CompositionObjectType.SpriteVisual: Category = CategorySpriteVisual; break; + case CompositionObjectType.CompositionLinearGradientBrush: + case CompositionObjectType.CompositionRadialGradientBrush: + Category = GetCategory((CompositionGradientBrush)obj); + break; default: throw new InvalidOperationException(); } @@ -394,6 +398,14 @@ static Category GetCategory(CompositionSpriteShape shape) _ => throw new InvalidOperationException(), }; } + + static Category GetCategory(CompositionGradientBrush brush) + { + var isAnimated = brush.Animators.Any() || brush.Properties.Animators.Any() || + brush.ColorStops.Any(cs => cs.Animators.Any() || cs.Properties.Animators.Any()); + + return isAnimated ? CategoryGradientBrushAnimated : CategoryGradientBrush; + } } sealed class GroupNode