From ad73e7f8e8825ca952b16a12d7b70fac6a07b1ea Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 28 Feb 2017 21:46:09 +0100 Subject: [PATCH] Send paint and resize notifications to renderer. --- src/Avalonia.Controls/TopLevel.cs | 12 +++++-- src/Avalonia.Controls/WindowBase.cs | 3 +- .../Rendering/DeferredRenderer.cs | 9 ++--- src/Avalonia.Visuals/Rendering/IRenderer.cs | 35 ++++++++++++++++++- .../Rendering/ImmediateRenderer.cs | 12 ++++--- src/Windows/Avalonia.Win32/WindowImpl.cs | 2 +- 6 files changed, 59 insertions(+), 14 deletions(-) diff --git a/src/Avalonia.Controls/TopLevel.cs b/src/Avalonia.Controls/TopLevel.cs index cf40254d45..d67d6ca08f 100644 --- a/src/Avalonia.Controls/TopLevel.cs +++ b/src/Avalonia.Controls/TopLevel.cs @@ -97,7 +97,7 @@ namespace Avalonia.Controls PlatformImpl.Closed = HandleClosed; PlatformImpl.Input = HandleInput; - PlatformImpl.Paint = Renderer != null ? (Action)Renderer.Render : null; + PlatformImpl.Paint = HandlePaint; PlatformImpl.Resized = HandleResized; PlatformImpl.ScalingChanged = HandleScalingChanged; @@ -212,6 +212,14 @@ namespace Avalonia.Controls return PlatformImpl.PointToScreen(p); } + /// + /// Handles a paint notification from . + /// + /// The dirty area. + protected virtual void HandlePaint(Rect rect) + { + Renderer?.Paint(rect); + } /// /// Handles a resize notification from . @@ -223,7 +231,7 @@ namespace Avalonia.Controls Width = clientSize.Width; Height = clientSize.Height; LayoutManager.Instance.ExecuteLayoutPass(); - PlatformImpl.Invalidate(new Rect(clientSize)); + Renderer?.Resized(clientSize); } /// diff --git a/src/Avalonia.Controls/WindowBase.cs b/src/Avalonia.Controls/WindowBase.cs index ac6eea8641..6830e30781 100644 --- a/src/Avalonia.Controls/WindowBase.cs +++ b/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); } /// diff --git a/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs b/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs index e6cf53918e..f223e7cdd8 100644 --- a/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs +++ b/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) diff --git a/src/Avalonia.Visuals/Rendering/IRenderer.cs b/src/Avalonia.Visuals/Rendering/IRenderer.cs index d370a59c62..8d2fc3a0c1 100644 --- a/src/Avalonia.Visuals/Rendering/IRenderer.cs +++ b/src/Avalonia.Visuals/Rendering/IRenderer.cs @@ -7,13 +7,46 @@ using System.Collections.Generic; namespace Avalonia.Rendering { + /// + /// Defines the interface for a renderer. + /// public interface IRenderer : IDisposable { + /// + /// Gets or sets a value indicating whether the renderer should draw an FPS counter. + /// bool DrawFps { get; set; } + + /// + /// Gets or sets a value indicating whether the renderer should a visual representation + /// of its dirty rectangles. + /// bool DrawDirtyRects { get; set; } + /// + /// Mark a visual as dirty and needing re-rendering. + /// + /// The visual. void AddDirty(IVisual visual); + + /// + /// Hit tests a location to find the visuals at the specified point. + /// + /// The point, in client coordinates. + /// An optional filter. + /// The visuals at the specified point, topmost first. IEnumerable HitTest(Point p, Func filter); - void Render(Rect rect); + + /// + /// Called when a resize notification is received by the control being rendered. + /// + /// The new size of the window. + void Resized(Size size); + + /// + /// Called when a paint notification is received by the control being rendered. + /// + /// The dirty rectangle. + void Paint(Rect rect); } } \ No newline at end of file diff --git a/src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs b/src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs index da95645571..a316b5d457 100644 --- a/src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs +++ b/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(); diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index ffa2979e00..0000b5c0a9 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/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); }