From f0e398960d7e7bab414c4b8b78e8def346e3a78e Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 7 May 2017 22:18:18 +0200 Subject: [PATCH] Made some classes internal and added docs. --- src/Avalonia.Visuals/Rendering/DirtyRects.cs | 33 ++++++++++++++++++- .../Rendering/DirtyVisuals.cs | 31 +++++++++++++++++ .../Rendering/DisplayDirtyRect.cs | 30 +++++++++++++++-- .../Rendering/DisplayDirtyRects.cs | 23 +++++++++++-- .../Rendering/SceneGraph/SceneLayer.cs | 10 +++--- 5 files changed, 116 insertions(+), 11 deletions(-) diff --git a/src/Avalonia.Visuals/Rendering/DirtyRects.cs b/src/Avalonia.Visuals/Rendering/DirtyRects.cs index cbfe164202..473d002c76 100644 --- a/src/Avalonia.Visuals/Rendering/DirtyRects.cs +++ b/src/Avalonia.Visuals/Rendering/DirtyRects.cs @@ -7,12 +7,28 @@ using System.Collections.Generic; namespace Avalonia.Rendering { - public class DirtyRects : IEnumerable + /// + /// Tracks dirty rectangles. + /// + internal class DirtyRects : IEnumerable { private List _rects = new List(); public bool IsEmpty => _rects.Count == 0; + /// + /// Adds a dirty rectangle, extending an existing dirty rectangle if it intersects. + /// + /// The dirt rectangle. + /// + /// We probably want to do this more intellegently because: + /// - Adding e.g. the top left quarter of a scene and the bottom left quarter of a scene + /// will cause the whole scene to be invalidated if they overlap by a single pixel + /// - Adding two adjacent rectangles that don't overlap will not cause them to be + /// coalesced + /// - It only coaleces the first intersecting rectangle found - one needs to + /// call at the end of the draw cycle to coalesce the rest. + /// public void Add(Rect rect) { if (!rect.IsEmpty) @@ -32,6 +48,12 @@ namespace Avalonia.Rendering } } + /// + /// Works around our flimsy dirt-rect coalescing algorithm. + /// + /// + /// See the comments in . + /// public void Coalesce() { for (var i = _rects.Count - 1; i >= 0; --i) @@ -51,7 +73,16 @@ namespace Avalonia.Rendering } } + /// + /// Gets the dirty rectangles. + /// + /// A collection of dirty rectangles public IEnumerator GetEnumerator() => _rects.GetEnumerator(); + + /// + /// Gets the dirty rectangles. + /// + /// A collection of dirty rectangles IEnumerator IEnumerable.GetEnumerator() => _rects.GetEnumerator(); } } diff --git a/src/Avalonia.Visuals/Rendering/DirtyVisuals.cs b/src/Avalonia.Visuals/Rendering/DirtyVisuals.cs index ab320e62a5..f14f5bc912 100644 --- a/src/Avalonia.Visuals/Rendering/DirtyVisuals.cs +++ b/src/Avalonia.Visuals/Rendering/DirtyVisuals.cs @@ -5,13 +5,28 @@ using Avalonia.VisualTree; namespace Avalonia.Rendering { + /// + /// Stores a list of dirty visuals for an . + /// + /// + /// This class stores the dirty visuals for a scene, ordered by their distance to the root + /// visual. TODO: We probably want to put an upper limit on the number of visuals that can be + /// stored and if we reach that limit, assume all visuals are dirty. + /// internal class DirtyVisuals : IEnumerable { private SortedDictionary> _inner = new SortedDictionary>(); private Dictionary _index = new Dictionary(); + /// + /// Gets the number of dirty visuals. + /// public int Count => _index.Count; + /// + /// Adds a visual to the dirty list. + /// + /// The dirty visual. public void Add(IVisual visual) { var distance = visual.CalculateDistanceFromAncestor(visual.VisualRoot); @@ -40,12 +55,20 @@ namespace Avalonia.Rendering _index.Add(visual, distance); } + /// + /// Clears the list. + /// public void Clear() { _inner.Clear(); _index.Clear(); } + /// + /// Removes a visual from the dirty list. + /// + /// The visual. + /// True if the visual was present in the list; otherwise false. public bool Remove(IVisual visual) { int distance; @@ -60,6 +83,10 @@ namespace Avalonia.Rendering return false; } + /// + /// Gets the dirty visuals, in ascending order of distance to their root. + /// + /// A collection of visuals. public IEnumerator GetEnumerator() { foreach (var i in _inner) @@ -71,6 +98,10 @@ namespace Avalonia.Rendering } } + /// + /// Gets the dirty visuals, in ascending order of distance to their root. + /// + /// A collection of visuals. IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } diff --git a/src/Avalonia.Visuals/Rendering/DisplayDirtyRect.cs b/src/Avalonia.Visuals/Rendering/DisplayDirtyRect.cs index cde5690585..03b8e95825 100644 --- a/src/Avalonia.Visuals/Rendering/DisplayDirtyRect.cs +++ b/src/Avalonia.Visuals/Rendering/DisplayDirtyRect.cs @@ -2,23 +2,47 @@ namespace Avalonia.Rendering { - public class DisplayDirtyRect + /// + /// Holds the state for a dirty rect rendered when is set. + /// + internal class DisplayDirtyRect { public static readonly TimeSpan TimeToLive = TimeSpan.FromMilliseconds(250); + /// + /// Initializes a new instance of the class. + /// + /// The dirt rect. public DisplayDirtyRect(Rect rect) { Rect = rect; - ResetAge(); + ResetLifetime(); } + /// + /// Gets the bounds of the dirty rectangle. + /// public Rect Rect { get; } + + /// + /// Gets the time at which the rectangle was made dirty. + /// public DateTimeOffset Born { get; private set; } + + /// + /// Gets the time at which the rectagle should no longer be displayed. + /// public DateTimeOffset Dies { get; private set; } + /// + /// Gets the opacity at which to display the dirty rectangle. + /// public double Opacity => (Dies - DateTimeOffset.UtcNow).TotalMilliseconds / TimeToLive.TotalMilliseconds; - public void ResetAge() + /// + /// Resets the rectangle's lifetime. + /// + public void ResetLifetime() { Born = DateTimeOffset.UtcNow; Dies = Born + TimeToLive; diff --git a/src/Avalonia.Visuals/Rendering/DisplayDirtyRects.cs b/src/Avalonia.Visuals/Rendering/DisplayDirtyRects.cs index 769cae64a2..2ffc1b4118 100644 --- a/src/Avalonia.Visuals/Rendering/DisplayDirtyRects.cs +++ b/src/Avalonia.Visuals/Rendering/DisplayDirtyRects.cs @@ -4,17 +4,24 @@ using System.Collections.Generic; namespace Avalonia.Rendering { - public class DisplayDirtyRects : IEnumerable + /// + /// Holds a collection of objects and manages their aging. + /// + internal class DisplayDirtyRects : IEnumerable { private List _inner = new List(); + /// + /// Adds new new dirty rect to the collection. + /// + /// public void Add(Rect rect) { foreach (var r in _inner) { if (r.Rect == rect) { - r.ResetAge(); + r.ResetLifetime(); return; } } @@ -22,6 +29,9 @@ namespace Avalonia.Rendering _inner.Add(new DisplayDirtyRect(rect)); } + /// + /// Removes dirty rects one they are no longer active. + /// public void Tick() { var now = DateTimeOffset.UtcNow; @@ -37,7 +47,16 @@ namespace Avalonia.Rendering } } + /// + /// Gets the dirty rects. + /// + /// A collection of objects. public IEnumerator GetEnumerator() => _inner.GetEnumerator(); + + /// + /// Gets the dirty rects. + /// + /// A collection of objects. IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/SceneLayer.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/SceneLayer.cs index c17fbb08c9..77ad96a222 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/SceneLayer.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/SceneLayer.cs @@ -42,11 +42,6 @@ namespace Avalonia.Rendering.SceneGraph /// public IVisual LayerRoot { get; } - /// - /// Gets the dirty rectangles for the layer. - /// - public DirtyRects Dirty { get; } - /// /// Gets the distance of the layer root from the root of the scene. /// @@ -71,5 +66,10 @@ namespace Avalonia.Rendering.SceneGraph /// Gets the layer's geometry clip. /// public IGeometryImpl GeometryClip { get; set; } + + /// + /// Gets the dirty rectangles for the layer. + /// + internal DirtyRects Dirty { get; } } }