Browse Source

Send paint and resize notifications to renderer.

scenegraph-after-breakage
Steven Kirk 9 years ago
parent
commit
ad73e7f8e8
  1. 12
      src/Avalonia.Controls/TopLevel.cs
  2. 3
      src/Avalonia.Controls/WindowBase.cs
  3. 9
      src/Avalonia.Visuals/Rendering/DeferredRenderer.cs
  4. 35
      src/Avalonia.Visuals/Rendering/IRenderer.cs
  5. 12
      src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs
  6. 2
      src/Windows/Avalonia.Win32/WindowImpl.cs

12
src/Avalonia.Controls/TopLevel.cs

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

3
src/Avalonia.Controls/WindowBase.cs

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

9
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. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System; using System;
using System.Diagnostics;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Rendering.SceneGraph; using Avalonia.Rendering.SceneGraph;
@ -101,10 +100,12 @@ namespace Avalonia.Rendering
return _scene.HitTest(p, filter); 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) Size IVisualBrushRenderer.GetRenderTargetSize(IVisualBrush brush)

35
src/Avalonia.Visuals/Rendering/IRenderer.cs

@ -7,13 +7,46 @@ using System.Collections.Generic;
namespace Avalonia.Rendering namespace Avalonia.Rendering
{ {
/// <summary>
/// Defines the interface for a renderer.
/// </summary>
public interface IRenderer : IDisposable public interface IRenderer : IDisposable
{ {
/// <summary>
/// Gets or sets a value indicating whether the renderer should draw an FPS counter.
/// </summary>
bool DrawFps { get; set; } 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; } 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); 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); 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);
} }
} }

12
src/Avalonia.Visuals/Rendering/ImmediateRenderer.cs

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

2
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -575,7 +575,7 @@ namespace Avalonia.Win32
UnmanagedMethods.RECT r; UnmanagedMethods.RECT r;
UnmanagedMethods.GetUpdateRect(_hwnd, out r, false); UnmanagedMethods.GetUpdateRect(_hwnd, out r, false);
var f = Scaling; 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); UnmanagedMethods.EndPaint(_hwnd, ref ps);
} }

Loading…
Cancel
Save