Pārlūkot izejas kodu

Render child visual nodes explicitly.

Render them in DeferredRenderer rather than in VisualNode.
Steven Kirk 9 gadi atpakaļ
vecāks
revīzija
34227686d4

+ 22 - 1
src/Avalonia.Visuals/Rendering/DeferredRenderer.cs

@@ -6,6 +6,7 @@ using Avalonia.Rendering.SceneGraph;
 using Avalonia.Threading;
 using Avalonia.VisualTree;
 using System.Collections.Generic;
+using System.Collections.Concurrent;
 
 namespace Avalonia.Rendering
 {
@@ -68,6 +69,26 @@ namespace Avalonia.Rendering
         {
         }
 
+        private void Render(IDrawingContextImpl context, IVisualNode node, Rect clipBounds)
+        {
+            clipBounds = node.Bounds.Intersect(clipBounds);
+
+            if (!clipBounds.IsEmpty)
+            {
+                node.Render(context);
+
+                foreach (var child in node.Children)
+                {
+                    var visualChild = child as IVisualNode;
+
+                    if (visualChild != null)
+                    {
+                        Render(context, visualChild, clipBounds);
+                    }
+                }
+            }
+        }
+
         private void RenderFps(IDrawingContextImpl context)
         {
             var now = _stopwatch.Elapsed;
@@ -141,7 +162,7 @@ namespace Avalonia.Rendering
 
                     using (var context = _renderTarget.CreateDrawingContext())
                     {
-                        _scene.Root.Render(context);
+                        Render(context, _scene.Root, new Rect(_root.ClientSize));
 
                         if (DrawFps)
                         {

+ 0 - 5
src/Avalonia.Visuals/Rendering/SceneGraph/IGeometryNode.cs

@@ -10,11 +10,6 @@ namespace Avalonia.Rendering.SceneGraph
     /// </summary>
     public interface IGeometryNode : ISceneNode
     {
-        /// <summary>
-        /// Gets the bounds of the node in global coordinates.
-        /// </summary>
-        Rect Bounds { get; }
-
         /// <summary>
         /// Hit test the geometry in this node.
         /// </summary>

+ 2 - 0
src/Avalonia.Visuals/Rendering/SceneGraph/ISceneNode.cs

@@ -11,6 +11,8 @@ namespace Avalonia.Rendering.SceneGraph
     /// </summary>
     public interface ISceneNode
     {
+        Rect Bounds { get; }
+
         /// <summary>
         /// Renders the node to a drawing context.
         /// </summary>

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

@@ -13,6 +13,8 @@ namespace Avalonia.Rendering.SceneGraph
     /// </summary>
     public class VisualNode : IVisualNode
     {
+        private Rect? _bounds;
+        
         /// <summary>
         /// Initializes a new instance of the <see cref="VisualNode"/> class.
         /// </summary>
@@ -42,6 +44,9 @@ namespace Avalonia.Rendering.SceneGraph
         /// <inheritdoc/>
         public Matrix Transform { get; set; }
 
+        // TODO: Calculate real bounds.
+        public Rect Bounds => ClipBounds;
+
         /// <inheritdoc/>
         public Rect ClipBounds { get; set; }
 
@@ -125,7 +130,10 @@ namespace Avalonia.Rendering.SceneGraph
 
             foreach (var child in Children)
             {
-                child.Render(context);
+                if (!(child is IVisualNode))
+                {
+                    child.Render(context);
+                }
             }
 
             if (ClipToBounds)