diff --git a/Cairo/Perspex.Cairo/CairoPlatform.cs b/Cairo/Perspex.Cairo/CairoPlatform.cs
index 8e0a09ce04..e280a5038e 100644
--- a/Cairo/Perspex.Cairo/CairoPlatform.cs
+++ b/Cairo/Perspex.Cairo/CairoPlatform.cs
@@ -38,7 +38,7 @@ namespace Perspex.Cairo
//return new BitmapImpl(imagingFactory, width, height);
}
- public IRenderer CreateRenderer(IntPtr handle, double width, double height)
+ public IRenderer CreateRenderer(IPlatformHandle handle, double width, double height)
{
return new Renderer(handle, width, height);
}
diff --git a/Cairo/Perspex.Cairo/Renderer.cs b/Cairo/Perspex.Cairo/Renderer.cs
index eea2ec56d3..17d9fa60ce 100644
--- a/Cairo/Perspex.Cairo/Renderer.cs
+++ b/Cairo/Perspex.Cairo/Renderer.cs
@@ -7,29 +7,31 @@
namespace Perspex.Cairo
{
using System;
- using Perspex.Platform;
- using Splat;
- using global::Cairo;
using System.Runtime.InteropServices;
+ using global::Cairo;
using Perspex.Cairo.Media;
+ using Perspex.Platform;
using Matrix = Perspex.Matrix;
+ ///
+ /// A cairo renderer.
+ ///
public class Renderer : IRenderer
{
///
/// The handle of the window to draw to.
///
- private IntPtr hwnd;
+ private IPlatformHandle handle;
///
/// Initializes a new instance of the class.
///
- /// The window handle.
+ /// The window handle.
/// The width of the window.
/// The height of the window.
- public Renderer(IntPtr hwnd, double width, double height)
+ public Renderer(IPlatformHandle handle, double width, double height)
{
- this.hwnd = hwnd;
+ this.handle = handle;
}
///
@@ -38,7 +40,7 @@ namespace Perspex.Cairo
/// The visual to render.
public void Render(IVisual visual)
{
- using (var surface = new Win32Surface(GetDC(this.hwnd)))
+ using (var surface = CreateSurface(this.handle))
using (DrawingContext context = new DrawingContext(surface))
{
this.Render(visual, context);
@@ -52,11 +54,32 @@ namespace Perspex.Cairo
/// The new height.
public void Resize(int width, int height)
{
+ // Don't need to do anything here as we create a new Win32Surface on each render.
}
[DllImport("user32.dll")]
private static extern IntPtr GetDC(IntPtr hWnd);
+ ///
+ /// Creates a cairo surface that targets a platform-specific resource.
+ ///
+ /// The platform-specific handle.
+ /// A surface.
+ private static Surface CreateSurface(IPlatformHandle handle)
+ {
+ switch (handle.HandleDescriptor)
+ {
+ case "HWND":
+ return new Win32Surface(GetDC(handle.Handle));
+ case "HDC":
+ return new Win32Surface(handle.Handle);
+ default:
+ throw new NotSupportedException(string.Format(
+ "Don't know how to create a Cairo renderer from a '{0}' handle",
+ handle.HandleDescriptor));
+ }
+ }
+
///
/// Renders the specified visual.
///