Browse Source

Moved xplat parts of IRenderManager to extension methods

pull/228/head
Nikita Tsukanov 11 years ago
parent
commit
57b31abe9a
  1. 1
      src/Gtk/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs
  2. 1
      src/Gtk/Perspex.Cairo/Media/TileBrushes.cs
  3. 13
      src/Gtk/Perspex.Cairo/Renderer.cs
  4. 14
      src/Perspex.SceneGraph/Platform/IRenderer.cs
  5. 73
      src/Perspex.SceneGraph/Rendering/RendererBase.cs
  6. 1
      src/Windows/Perspex.Direct2D1/Media/Imaging/RenderTargetBitmapImpl.cs
  7. 1
      src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs
  8. 8
      src/Windows/Perspex.Direct2D1/Renderer.cs

1
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
{

1
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
{

13
src/Gtk/Perspex.Cairo/Renderer.cs

@ -15,7 +15,7 @@ namespace Perspex.Cairo
/// <summary>
/// A cairo renderer.
/// </summary>
public class Renderer : RendererBase
public class Renderer : IRenderer
{
private readonly Surface _surface;
private Gdk.Window _window;
@ -40,7 +40,7 @@ namespace Perspex.Cairo
/// </summary>
/// <param name="width">The new width.</param>
/// <param name="height">The new height.</param>
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
/// </summary>
/// <param name="handle">The platform-specific handle.</param>
/// <returns>A surface wrapped in an <see cref="IDrawingContext"/>.</returns>
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();

14
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
{
/// <summary>
/// Gets the number of times <see cref="Render"/> has been called.
/// Creates an <see cref="IDrawingContext"/> for a rendering session.
/// </summary>
int RenderCount { get; }
/// <summary>
/// Renders the specified visual.
/// </summary>
/// <param name="visual">The visual to render.</param>
/// <param name="handle">An optional platform-specific handle.</param>
void Render(IVisual visual, IPlatformHandle handle);
/// <param name="handle">The handle to use to create the context.</param>
/// <returns>An <see cref="IDrawingContext"/>.</returns>
IDrawingContext CreateDrawingContext(IPlatformHandle target);
/// <summary>
/// Resizes the rendered viewport.

73
src/Perspex.SceneGraph/Rendering/RendererBase.cs

@ -14,61 +14,74 @@ namespace Perspex.Rendering
/// <remarks>
/// This class provides implements the platform-independent parts of <see cref="IRenderer"/>.
/// </remarks>
public abstract class RendererBase : IRenderer
public static class RendererMixin
{
/// <summary>
/// Gets the number of times <see cref="Render(IVisual, IPlatformHandle)"/> has been called.
/// Renders the specified visual.
/// </summary>
public int RenderCount
/// <param name="renderer">IRenderer instance</param>
/// <param name="visual">The visual to render.</param>
/// <param name="target">An optional platform-specific handle.</param>
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();
/// <summary>
/// Renders the specified visual.
/// </summary>
/// <param name="renderer">IRenderer instance</param>
/// <param name="target">An optional platform-specific handle.</param>
/// <param name="visual">The visual to render.</param>
/// <param name="handle">An optional platform-specific handle.</param>
public virtual void Render(IVisual visual, IPlatformHandle handle)
/// <param name="translation">The current translation.</param>
/// <param name="transform">The current transform.</param>
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);
}
/// <summary>
/// Renders the specified visual with the specified transform and clip.
/// </summary>
/// <param name="renderer">IRenderer instance</param>
/// <param name="target">An optional platform-specific handle.</param>
/// <param name="visual">The visual to render.</param>
/// <param name="handle">An optional platform-specific handle.</param>
/// <param name="transform">The transform.</param>
/// <param name="clip">An optional clip rectangle.</param>
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);
}
/// <summary>
/// Resizes the rendered viewport.
/// Renders the specified visual.
/// </summary>
/// <param name="width">The new width.</param>
/// <param name="height">The new height.</param>
public abstract void Resize(int width, int height);
/// <param name="visual">The visual to render.</param>
///
/// <param name="context">The drawing context.</param>
public static void Render(this IDrawingContext context, IVisual visual)
{
context.Render(visual, Matrix.Identity);
}
/// <summary>
/// When overriden by a derived class creates an <see cref="IDrawingContext"/> for a
/// rendering session.
/// Renders the specified visual with the specified transform and clip.
/// </summary>
/// <param name="handle">The handle to use to create the context.</param>
/// <returns>An <see cref="IDrawingContext"/>.</returns>
protected abstract IDrawingContext CreateDrawingContext(IPlatformHandle handle);
/// <param name="visual">The visual to render.</param>
/// <param name="context">The drawing context.</param>
/// <param name="transform">The transform.</param>
/// <param name="clip">An optional clip rectangle.</param>
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);
}
}
/// <summary>
/// Renders the specified visual.
/// </summary>
@ -76,7 +89,7 @@ namespace Perspex.Rendering
/// <param name="context">The drawing context.</param>
/// <param name="translation">The current translation.</param>
/// <param name="transform">The current transform.</param>
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);
}
}
}

1
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;

1
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

8
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
{
/// <summary>
/// The render target.
@ -77,7 +77,7 @@ namespace Perspex.Direct2D1
/// </summary>
/// <param name="width">The new width.</param>
/// <param name="height">The new height.</param>
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
/// </summary>
/// <param name="handle">The platform handle. Unused.</param>
/// <returns>An <see cref="IDrawingContext"/>.</returns>
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();
}

Loading…
Cancel
Save