Jelajahi Sumber

Merge pull request #3816 from AvaloniaUI/revert-3775-pool-deferred-renderer-state

Revert "Collection pooling for DeferredRenderer"
Dariusz Komosiński 5 tahun lalu
induk
melakukan
78b19e095f

+ 4 - 13
src/Avalonia.Visuals/Rendering/SceneGraph/Scene.cs

@@ -12,7 +12,7 @@ namespace Avalonia.Rendering.SceneGraph
     /// </summary>
     public class Scene : IDisposable
     {
-        private readonly Dictionary<IVisual, IVisualNode> _index;
+        private Dictionary<IVisual, IVisualNode> _index;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="Scene"/> class.
@@ -83,7 +83,7 @@ namespace Avalonia.Rendering.SceneGraph
         /// <returns>The cloned scene.</returns>
         public Scene CloneScene()
         {
-            var index = new Dictionary<IVisual, IVisualNode>(_index.Count);
+            var index = new Dictionary<IVisual, IVisualNode>();
             var root = Clone((VisualNode)Root, null, index);
 
             var result = new Scene(root, index, Layers.Clone(), Generation + 1)
@@ -162,18 +162,9 @@ namespace Avalonia.Rendering.SceneGraph
 
             index.Add(result.Visual, result);
 
-            int childCount = source.Children.Count;
-
-            if (childCount > 0)
+            foreach (var child in source.Children)
             {
-                Span<IVisualNode> children = result.AddChildrenSpan(childCount);
-
-                for (var i = 0; i < childCount; i++)
-                {
-                    var child = source.Children[i];
-
-                    children[i] = Clone((VisualNode)child, result, index);
-                }
+                result.AddChild(Clone((VisualNode)child, result, index));
             }
 
             return result;

+ 4 - 16
src/Avalonia.Visuals/Rendering/SceneGraph/SceneLayers.cs

@@ -11,28 +11,16 @@ namespace Avalonia.Rendering.SceneGraph
     public class SceneLayers : IEnumerable<SceneLayer>
     {
         private readonly IVisual _root;
-        private readonly List<SceneLayer> _inner;
-        private readonly Dictionary<IVisual, SceneLayer> _index;
+        private readonly List<SceneLayer> _inner = new List<SceneLayer>();
+        private readonly Dictionary<IVisual, SceneLayer> _index = new Dictionary<IVisual, SceneLayer>();
 
         /// <summary>
         /// Initializes a new instance of the <see cref="SceneLayers"/> class.
         /// </summary>
         /// <param name="root">The scene's root visual.</param>
-        public SceneLayers(IVisual root) : this(root, 0)
-        {
-        }
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="SceneLayers"/> class.
-        /// </summary>
-        /// <param name="root">The scene's root visual.</param>
-        /// <param name="capacity">Initial layer capacity.</param>
-        public SceneLayers(IVisual root, int capacity)
+        public SceneLayers(IVisual root)
         {
             _root = root;
-
-            _inner = new List<SceneLayer>(capacity);
-            _index = new Dictionary<IVisual, SceneLayer>(capacity);
         }
 
         /// <summary>
@@ -96,7 +84,7 @@ namespace Avalonia.Rendering.SceneGraph
         /// <returns>The cloned layers.</returns>
         public SceneLayers Clone()
         {
-            var result = new SceneLayers(_root, Count);
+            var result = new SceneLayers(_root);
 
             foreach (var src in _inner)
             {

+ 9 - 34
src/Avalonia.Visuals/Rendering/SceneGraph/VisualNode.cs

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Reactive.Disposables;
-using Avalonia.Collections.Pooled;
 using Avalonia.Media;
 using Avalonia.Platform;
 using Avalonia.Utilities;
@@ -20,8 +19,8 @@ namespace Avalonia.Rendering.SceneGraph
 
         private Rect? _bounds;
         private double _opacity;
-        private PooledList<IVisualNode> _children;
-        private PooledList<IRef<IDrawOperation>> _drawOperations;
+        private List<IVisualNode> _children;
+        private List<IRef<IDrawOperation>> _drawOperations;
         private IRef<IDisposable> _drawOperationsRefCounter;
         private bool _drawOperationsCloned;
         private Matrix transformRestore;
@@ -350,18 +349,6 @@ namespace Avalonia.Rendering.SceneGraph
             context.Transform = transformRestore;
         }
 
-        /// <summary>
-        /// Inserts default constructed children into collection and returns a span for the newly created range.
-        /// </summary>
-        /// <param name="count">Count of children that will be added.</param>
-        /// <returns></returns>
-        internal Span<IVisualNode> AddChildrenSpan(int count)
-        {
-            EnsureChildrenCreated(count);
-
-            return _children.AddSpan(count);
-        }
-
         private Rect CalculateBounds()
         {
             var result = new Rect();
@@ -375,11 +362,11 @@ namespace Avalonia.Rendering.SceneGraph
             return result;
         }
 
-        private void EnsureChildrenCreated(int capacity = 0)
+        private void EnsureChildrenCreated()
         {
             if (_children == null)
             {
-                _children = new PooledList<IVisualNode>(capacity);
+                _children = new List<IVisualNode>();
             }
         }
 
@@ -390,21 +377,13 @@ namespace Avalonia.Rendering.SceneGraph
         {
             if (_drawOperations == null)
             {
-                _drawOperations = new PooledList<IRef<IDrawOperation>>();
+                _drawOperations = new List<IRef<IDrawOperation>>();
                 _drawOperationsRefCounter = RefCountable.Create(CreateDisposeDrawOperations(_drawOperations));
                 _drawOperationsCloned = false;
             }
             else if (_drawOperationsCloned)
             {
-                var oldDrawOperations = _drawOperations;
-
-                _drawOperations = new PooledList<IRef<IDrawOperation>>(oldDrawOperations.Count);
-
-                foreach (var drawOperation in oldDrawOperations)
-                {
-                    _drawOperations.Add(drawOperation.Clone());
-                }
-
+                _drawOperations = new List<IRef<IDrawOperation>>(_drawOperations.Select(op => op.Clone()));
                 _drawOperationsRefCounter.Dispose();
                 _drawOperationsRefCounter = RefCountable.Create(CreateDisposeDrawOperations(_drawOperations));
                 _drawOperationsCloned = false;
@@ -418,16 +397,14 @@ namespace Avalonia.Rendering.SceneGraph
         /// </summary>
         /// <param name="drawOperations">Draw operations that need to be disposed.</param>
         /// <returns>Disposable for given draw operations.</returns>
-        private static IDisposable CreateDisposeDrawOperations(PooledList<IRef<IDrawOperation>> drawOperations)
+        private static IDisposable CreateDisposeDrawOperations(List<IRef<IDrawOperation>> drawOperations)
         {
-            return Disposable.Create(drawOperations, operations =>
+            return Disposable.Create(() =>
             {
-                foreach (var operation in operations)
+                foreach (var operation in drawOperations)
                 {
                     operation.Dispose();
                 }
-
-                operations.Dispose();
             });
         }
 
@@ -437,8 +414,6 @@ namespace Avalonia.Rendering.SceneGraph
         {
             _drawOperationsRefCounter?.Dispose();
 
-            _children?.Dispose();
-
             Disposed = true;
         }
     }