|
|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
|