diff --git a/src/Gtk/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs b/src/Gtk/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs
index db35a22775..e35780773a 100644
--- a/src/Gtk/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs
+++ b/src/Gtk/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs
@@ -3,6 +3,7 @@
using System;
using Perspex.Platform;
+using Perspex.Rendering;
namespace Perspex.Cairo.Media.Imaging
{
diff --git a/src/Gtk/Perspex.Cairo/Media/TileBrushes.cs b/src/Gtk/Perspex.Cairo/Media/TileBrushes.cs
index e08565785a..761efc2220 100644
--- a/src/Gtk/Perspex.Cairo/Media/TileBrushes.cs
+++ b/src/Gtk/Perspex.Cairo/Media/TileBrushes.cs
@@ -7,6 +7,7 @@ using Perspex.Cairo.Media.Imaging;
using Perspex.Layout;
using Perspex.Media;
using Perspex.Platform;
+using Perspex.Rendering;
namespace Perspex.Cairo.Media
{
diff --git a/src/Gtk/Perspex.Cairo/Renderer.cs b/src/Gtk/Perspex.Cairo/Renderer.cs
index 13bb63445f..a99da669f7 100644
--- a/src/Gtk/Perspex.Cairo/Renderer.cs
+++ b/src/Gtk/Perspex.Cairo/Renderer.cs
@@ -15,7 +15,7 @@ namespace Perspex.Cairo
///
/// A cairo renderer.
///
- public class Renderer : RendererBase
+ public class Renderer : IRenderer
{
private readonly Surface _surface;
private Gdk.Window _window;
@@ -40,7 +40,7 @@ namespace Perspex.Cairo
///
/// The new width.
/// The new height.
- public override void Resize(int width, int height)
+ public void Resize(int width, int height)
{
// Don't need to do anything here.
}
@@ -51,7 +51,7 @@ namespace Perspex.Cairo
///
/// The platform-specific handle.
/// A surface wrapped in an .
- protected override IDrawingContext CreateDrawingContext(IPlatformHandle handle)
+ public IDrawingContext CreateDrawingContext(IPlatformHandle handle)
{
switch (handle.HandleDescriptor)
{
@@ -68,11 +68,8 @@ namespace Perspex.Cairo
handle.HandleDescriptor));
}
}
-
- [DllImport("user32.dll")]
- private static extern IntPtr GetDC(IntPtr hwnd);
-
- public override void Dispose()
+
+ public void Dispose()
{
if (_surface != null)
_surface.Dispose();
diff --git a/src/Perspex.SceneGraph/Platform/IRenderer.cs b/src/Perspex.SceneGraph/Platform/IRenderer.cs
index e1e0f31e21..a19593406b 100644
--- a/src/Perspex.SceneGraph/Platform/IRenderer.cs
+++ b/src/Perspex.SceneGraph/Platform/IRenderer.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
+using Perspex.Media;
namespace Perspex.Platform
{
@@ -17,16 +18,11 @@ namespace Perspex.Platform
public interface IRenderer : IDisposable
{
///
- /// Gets the number of times has been called.
+ /// Creates an for a rendering session.
///
- int RenderCount { get; }
-
- ///
- /// Renders the specified visual.
- ///
- /// The visual to render.
- /// An optional platform-specific handle.
- void Render(IVisual visual, IPlatformHandle handle);
+ /// The handle to use to create the context.
+ /// An .
+ IDrawingContext CreateDrawingContext(IPlatformHandle target);
///
/// Resizes the rendered viewport.
diff --git a/src/Perspex.SceneGraph/Rendering/RendererBase.cs b/src/Perspex.SceneGraph/Rendering/RendererBase.cs
index 26e74dc6ad..4f9440eb4d 100644
--- a/src/Perspex.SceneGraph/Rendering/RendererBase.cs
+++ b/src/Perspex.SceneGraph/Rendering/RendererBase.cs
@@ -14,61 +14,74 @@ namespace Perspex.Rendering
///
/// This class provides implements the platform-independent parts of .
///
- public abstract class RendererBase : IRenderer
+ public static class RendererMixin
{
///
- /// Gets the number of times has been called.
+ /// Renders the specified visual.
///
- public int RenderCount
+ /// IRenderer instance
+ /// The visual to render.
+ /// An optional platform-specific handle.
+ public static void Render(this IRenderer renderer, IVisual visual, IPlatformHandle target)
{
- get;
- private set;
+ using (var ctx = renderer.CreateDrawingContext(target))
+ ctx.Render(visual);
}
- public abstract void Dispose();
-
///
/// Renders the specified visual.
///
+ /// IRenderer instance
+ /// An optional platform-specific handle.
/// The visual to render.
- /// An optional platform-specific handle.
- public virtual void Render(IVisual visual, IPlatformHandle handle)
+ /// The current translation.
+ /// The current transform.
+ public static void Render(this IRenderer renderer, IVisual visual, IPlatformHandle target, Matrix translation, Matrix transform)
{
- Render(visual, handle, Matrix.Identity);
- ++RenderCount;
+ using (var ctx = renderer.CreateDrawingContext(target))
+ ctx.Render(visual, translation, transform);
}
///
/// Renders the specified visual with the specified transform and clip.
///
+ /// IRenderer instance
+ /// An optional platform-specific handle.
/// The visual to render.
- /// An optional platform-specific handle.
/// The transform.
/// An optional clip rectangle.
- public virtual void Render(IVisual visual, IPlatformHandle handle, Matrix transform, Rect? clip = null)
+ public static void Render(this IRenderer renderer, IVisual visual, IPlatformHandle target, Matrix transform, Rect? clip = null)
{
- using (var context = CreateDrawingContext(handle))
- using (clip.HasValue ? context.PushClip(clip.Value) : null)
- {
- Render(visual, context, Matrix.Identity, transform);
- }
+ using (var context = renderer.CreateDrawingContext(target))
+ context.Render(visual, transform, clip);
}
///
- /// Resizes the rendered viewport.
+ /// Renders the specified visual.
///
- /// The new width.
- /// The new height.
- public abstract void Resize(int width, int height);
+ /// The visual to render.
+ ///
+ /// The drawing context.
+ public static void Render(this IDrawingContext context, IVisual visual)
+ {
+ context.Render(visual, Matrix.Identity);
+ }
///
- /// When overriden by a derived class creates an for a
- /// rendering session.
+ /// Renders the specified visual with the specified transform and clip.
///
- /// The handle to use to create the context.
- /// An .
- protected abstract IDrawingContext CreateDrawingContext(IPlatformHandle handle);
-
+ /// The visual to render.
+ /// The drawing context.
+ /// The transform.
+ /// An optional clip rectangle.
+ public static void Render(this IDrawingContext context, IVisual visual, Matrix transform, Rect? clip = null)
+ {
+ using (clip.HasValue ? context.PushClip(clip.Value) : null)
+ {
+ context.Render(visual, Matrix.Identity, transform);
+ }
+ }
+
///
/// Renders the specified visual.
///
@@ -76,7 +89,7 @@ namespace Perspex.Rendering
/// The drawing context.
/// The current translation.
/// The current transform.
- protected virtual void Render(IVisual visual, IDrawingContext context, Matrix translation, Matrix transform)
+ public static void Render(this IDrawingContext context, IVisual visual, Matrix translation, Matrix transform)
{
var opacity = visual.Opacity;
@@ -108,7 +121,7 @@ namespace Perspex.Rendering
foreach (var child in visual.VisualChildren.OrderBy(x => x.ZIndex))
{
- Render(child, context, translation, transform);
+ context.Render(child, translation, transform);
}
}
}
diff --git a/src/Windows/Perspex.Direct2D1/Media/Imaging/RenderTargetBitmapImpl.cs b/src/Windows/Perspex.Direct2D1/Media/Imaging/RenderTargetBitmapImpl.cs
index 51f7a71cca..16cda058ce 100644
--- a/src/Windows/Perspex.Direct2D1/Media/Imaging/RenderTargetBitmapImpl.cs
+++ b/src/Windows/Perspex.Direct2D1/Media/Imaging/RenderTargetBitmapImpl.cs
@@ -3,6 +3,7 @@
using System;
using Perspex.Platform;
+using Perspex.Rendering;
using SharpDX.Direct2D1;
using SharpDX.WIC;
diff --git a/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs b/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs
index bc049e7ca3..0acb5e07dc 100644
--- a/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs
+++ b/src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs
@@ -4,6 +4,7 @@
using System;
using Perspex.Layout;
using Perspex.Media;
+using Perspex.Rendering;
using SharpDX.Direct2D1;
namespace Perspex.Direct2D1.Media
diff --git a/src/Windows/Perspex.Direct2D1/Renderer.cs b/src/Windows/Perspex.Direct2D1/Renderer.cs
index b112dfea65..607270ed69 100644
--- a/src/Windows/Perspex.Direct2D1/Renderer.cs
+++ b/src/Windows/Perspex.Direct2D1/Renderer.cs
@@ -12,7 +12,7 @@ using DwFactory = SharpDX.DirectWrite.Factory;
namespace Perspex.Direct2D1
{
- public class Renderer : RendererBase
+ public class Renderer : IRenderer
{
///
/// The render target.
@@ -77,7 +77,7 @@ namespace Perspex.Direct2D1
///
/// The new width.
/// The new height.
- public override void Resize(int width, int height)
+ public void Resize(int width, int height)
{
WindowRenderTarget window = _renderTarget as WindowRenderTarget;
@@ -96,12 +96,12 @@ namespace Perspex.Direct2D1
///
/// The platform handle. Unused.
/// An .
- protected override IDrawingContext CreateDrawingContext(IPlatformHandle handle)
+ public IDrawingContext CreateDrawingContext(IPlatformHandle handle)
{
return new DrawingContext(_renderTarget, DirectWriteFactory);
}
- public override void Dispose()
+ public void Dispose()
{
_renderTarget.Dispose();
}