Browse Source

Send paint and resize notifications to renderer.

Steven Kirk 8 years ago
parent
commit
ad73e7f8e8

+ 10 - 2
src/Avalonia.Controls/TopLevel.cs

@@ -97,7 +97,7 @@ namespace Avalonia.Controls
 
             PlatformImpl.Closed = HandleClosed;
             PlatformImpl.Input = HandleInput;
-            PlatformImpl.Paint = Renderer != null ? (Action<Rect>)Renderer.Render : null;
+            PlatformImpl.Paint = HandlePaint;
             PlatformImpl.Resized = HandleResized;
             PlatformImpl.ScalingChanged = HandleScalingChanged;
             
@@ -212,6 +212,14 @@ namespace Avalonia.Controls
             return PlatformImpl.PointToScreen(p);
         }
 
+        /// <summary>
+        /// Handles a paint notification from <see cref="ITopLevelImpl.Resized"/>.
+        /// </summary>
+        /// <param name="rect">The dirty area.</param>
+        protected virtual void HandlePaint(Rect rect)
+        {
+            Renderer?.Paint(rect);
+        }
 
         /// <summary>
         /// Handles a resize notification from <see cref="ITopLevelImpl.Resized"/>.
@@ -223,7 +231,7 @@ namespace Avalonia.Controls
             Width = clientSize.Width;
             Height = clientSize.Height;
             LayoutManager.Instance.ExecuteLayoutPass();
-            PlatformImpl.Invalidate(new Rect(clientSize));
+            Renderer?.Resized(clientSize);
         }
 
         /// <summary>

+ 1 - 2
src/Avalonia.Controls/WindowBase.cs

@@ -139,8 +139,7 @@ namespace Avalonia.Controls
             }
             ClientSize = clientSize;
             LayoutManager.Instance.ExecuteLayoutPass();
-            PlatformImpl.Invalidate(new Rect(clientSize));
-
+            Renderer?.Resized(clientSize);
         }
 
         /// <summary>

+ 5 - 4
src/Avalonia.Visuals/Rendering/DeferredRenderer.cs

@@ -2,7 +2,6 @@
 // Licensed under the MIT license. See licence.md file in the project root for full license information.
 
 using System;
-using System.Diagnostics;
 using Avalonia.Media;
 using Avalonia.Platform;
 using Avalonia.Rendering.SceneGraph;
@@ -101,10 +100,12 @@ namespace Avalonia.Rendering
             return _scene.HitTest(p, filter);
         }
 
-        public void Render(Rect rect)
+        public void Paint(Rect rect)
+        {
+        }
+
+        public void Resized(Size size)
         {
-            UpdateScene();
-            Render(_scene);
         }
 
         Size IVisualBrushRenderer.GetRenderTargetSize(IVisualBrush brush)

+ 34 - 1
src/Avalonia.Visuals/Rendering/IRenderer.cs

@@ -7,13 +7,46 @@ using System.Collections.Generic;
 
 namespace Avalonia.Rendering
 {
+    /// <summary>
+    /// Defines the interface for a renderer.
+    /// </summary>
     public interface IRenderer : IDisposable
     {
+        /// <summary>
+        /// Gets or sets a value indicating whether the renderer should draw an FPS counter.
+        /// </summary>
         bool DrawFps { get; set; }
+
+        /// <summary>
+        /// Gets or sets a value indicating whether the renderer should a visual representation
+        /// of its dirty rectangles.
+        /// </summary>
         bool DrawDirtyRects { get; set; }
 
+        /// <summary>
+        /// Mark a visual as dirty and needing re-rendering.
+        /// </summary>
+        /// <param name="visual">The visual.</param>
         void AddDirty(IVisual visual);
+
+        /// <summary>
+        /// Hit tests a location to find the visuals at the specified point.
+        /// </summary>
+        /// <param name="p">The point, in client coordinates.</param>
+        /// <param name="filter">An optional filter.</param>
+        /// <returns>The visuals at the specified point, topmost first.</returns>
         IEnumerable<IVisual> HitTest(Point p, Func<IVisual, bool> filter);
-        void Render(Rect rect);
+
+        /// <summary>
+        /// Called when a resize notification is received by the control being rendered.
+        /// </summary>
+        /// <param name="size">The new size of the window.</param>
+        void Resized(Size size);
+
+        /// <summary>
+        /// Called when a paint notification is received by the control being rendered.
+        /// </summary>
+        /// <param name="rect">The dirty rectangle.</param>
+        void Paint(Rect rect);
     }
 }

+ 8 - 4
src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs

@@ -40,6 +40,14 @@ namespace Avalonia.Rendering
         public bool DrawFps { get; set; }
         public bool DrawDirtyRects { get; set; }
 
+        public void Paint(Rect rect)
+        {
+        }
+
+        public void Resized(Size size)
+        {
+        }
+
         public static void Render(IVisual visual, IRenderTarget target)
         {
             using (var renderer = new ImmediateRenderer(visual))
@@ -75,10 +83,6 @@ namespace Avalonia.Rendering
             return HitTest(_root, p, filter);
         }
 
-        public void Render(Rect rect)
-        {
-        }
-
         Size IVisualBrushRenderer.GetRenderTargetSize(IVisualBrush brush)
         {
             (brush.Visual as IVisualBrushInitialize)?.EnsureInitialized();

+ 1 - 1
src/Windows/Avalonia.Win32/WindowImpl.cs

@@ -575,7 +575,7 @@ namespace Avalonia.Win32
                         UnmanagedMethods.RECT r;
                         UnmanagedMethods.GetUpdateRect(_hwnd, out r, false);
                         var f = Scaling;
-                        //Paint?.Invoke(new Rect(r.left / f, r.top / f, (r.right - r.left) / f, (r.bottom - r.top) / f));
+                        Paint?.Invoke(new Rect(r.left / f, r.top / f, (r.right - r.left) / f, (r.bottom - r.top) / f));
                         UnmanagedMethods.EndPaint(_hwnd, ref ps);
                     }