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 System;
using Perspex.Platform; using Perspex.Platform;
using Perspex.Rendering;
namespace Perspex.Cairo.Media.Imaging 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.Layout;
using Perspex.Media; using Perspex.Media;
using Perspex.Platform; using Perspex.Platform;
using Perspex.Rendering;
namespace Perspex.Cairo.Media namespace Perspex.Cairo.Media
{ {

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

@ -15,7 +15,7 @@ namespace Perspex.Cairo
/// <summary> /// <summary>
/// A cairo renderer. /// A cairo renderer.
/// </summary> /// </summary>
public class Renderer : RendererBase public class Renderer : IRenderer
{ {
private readonly Surface _surface; private readonly Surface _surface;
private Gdk.Window _window; private Gdk.Window _window;
@ -40,7 +40,7 @@ namespace Perspex.Cairo
/// </summary> /// </summary>
/// <param name="width">The new width.</param> /// <param name="width">The new width.</param>
/// <param name="height">The new height.</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. // Don't need to do anything here.
} }
@ -51,7 +51,7 @@ namespace Perspex.Cairo
/// </summary> /// </summary>
/// <param name="handle">The platform-specific handle.</param> /// <param name="handle">The platform-specific handle.</param>
/// <returns>A surface wrapped in an <see cref="IDrawingContext"/>.</returns> /// <returns>A surface wrapped in an <see cref="IDrawingContext"/>.</returns>
protected override IDrawingContext CreateDrawingContext(IPlatformHandle handle) public IDrawingContext CreateDrawingContext(IPlatformHandle handle)
{ {
switch (handle.HandleDescriptor) switch (handle.HandleDescriptor)
{ {
@ -68,11 +68,8 @@ namespace Perspex.Cairo
handle.HandleDescriptor)); handle.HandleDescriptor));
} }
} }
[DllImport("user32.dll")] public void Dispose()
private static extern IntPtr GetDC(IntPtr hwnd);
public override void Dispose()
{ {
if (_surface != null) if (_surface != null)
_surface.Dispose(); _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. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System; using System;
using Perspex.Media;
namespace Perspex.Platform namespace Perspex.Platform
{ {
@ -17,16 +18,11 @@ namespace Perspex.Platform
public interface IRenderer : IDisposable public interface IRenderer : IDisposable
{ {
/// <summary> /// <summary>
/// Gets the number of times <see cref="Render"/> has been called. /// Creates an <see cref="IDrawingContext"/> for a rendering session.
/// </summary> /// </summary>
int RenderCount { get; } /// <param name="handle">The handle to use to create the context.</param>
/// <returns>An <see cref="IDrawingContext"/>.</returns>
/// <summary> IDrawingContext CreateDrawingContext(IPlatformHandle target);
/// 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);
/// <summary> /// <summary>
/// Resizes the rendered viewport. /// Resizes the rendered viewport.

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

@ -14,61 +14,74 @@ namespace Perspex.Rendering
/// <remarks> /// <remarks>
/// This class provides implements the platform-independent parts of <see cref="IRenderer"/>. /// This class provides implements the platform-independent parts of <see cref="IRenderer"/>.
/// </remarks> /// </remarks>
public abstract class RendererBase : IRenderer public static class RendererMixin
{ {
/// <summary> /// <summary>
/// Gets the number of times <see cref="Render(IVisual, IPlatformHandle)"/> has been called. /// Renders the specified visual.
/// </summary> /// </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; using (var ctx = renderer.CreateDrawingContext(target))
private set; ctx.Render(visual);
} }
public abstract void Dispose();
/// <summary> /// <summary>
/// Renders the specified visual. /// Renders the specified visual.
/// </summary> /// </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="visual">The visual to render.</param>
/// <param name="handle">An optional platform-specific handle.</param> /// <param name="translation">The current translation.</param>
public virtual void Render(IVisual visual, IPlatformHandle handle) /// <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); using (var ctx = renderer.CreateDrawingContext(target))
++RenderCount; ctx.Render(visual, translation, transform);
} }
/// <summary> /// <summary>
/// Renders the specified visual with the specified transform and clip. /// Renders the specified visual with the specified transform and clip.
/// </summary> /// </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="visual">The visual to render.</param>
/// <param name="handle">An optional platform-specific handle.</param>
/// <param name="transform">The transform.</param> /// <param name="transform">The transform.</param>
/// <param name="clip">An optional clip rectangle.</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 (var context = renderer.CreateDrawingContext(target))
using (clip.HasValue ? context.PushClip(clip.Value) : null) context.Render(visual, transform, clip);
{
Render(visual, context, Matrix.Identity, transform);
}
} }
/// <summary> /// <summary>
/// Resizes the rendered viewport. /// Renders the specified visual.
/// </summary> /// </summary>
/// <param name="width">The new width.</param> /// <param name="visual">The visual to render.</param>
/// <param name="height">The new height.</param> ///
public abstract void Resize(int width, int height); /// <param name="context">The drawing context.</param>
public static void Render(this IDrawingContext context, IVisual visual)
{
context.Render(visual, Matrix.Identity);
}
/// <summary> /// <summary>
/// When overriden by a derived class creates an <see cref="IDrawingContext"/> for a /// Renders the specified visual with the specified transform and clip.
/// rendering session.
/// </summary> /// </summary>
/// <param name="handle">The handle to use to create the context.</param> /// <param name="visual">The visual to render.</param>
/// <returns>An <see cref="IDrawingContext"/>.</returns> /// <param name="context">The drawing context.</param>
protected abstract IDrawingContext CreateDrawingContext(IPlatformHandle handle); /// <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> /// <summary>
/// Renders the specified visual. /// Renders the specified visual.
/// </summary> /// </summary>
@ -76,7 +89,7 @@ namespace Perspex.Rendering
/// <param name="context">The drawing context.</param> /// <param name="context">The drawing context.</param>
/// <param name="translation">The current translation.</param> /// <param name="translation">The current translation.</param>
/// <param name="transform">The current transform.</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; var opacity = visual.Opacity;
@ -108,7 +121,7 @@ namespace Perspex.Rendering
foreach (var child in visual.VisualChildren.OrderBy(x => x.ZIndex)) 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 System;
using Perspex.Platform; using Perspex.Platform;
using Perspex.Rendering;
using SharpDX.Direct2D1; using SharpDX.Direct2D1;
using SharpDX.WIC; using SharpDX.WIC;

1
src/Windows/Perspex.Direct2D1/Media/VisualBrushImpl.cs

@ -4,6 +4,7 @@
using System; using System;
using Perspex.Layout; using Perspex.Layout;
using Perspex.Media; using Perspex.Media;
using Perspex.Rendering;
using SharpDX.Direct2D1; using SharpDX.Direct2D1;
namespace Perspex.Direct2D1.Media namespace Perspex.Direct2D1.Media

8
src/Windows/Perspex.Direct2D1/Renderer.cs

@ -12,7 +12,7 @@ using DwFactory = SharpDX.DirectWrite.Factory;
namespace Perspex.Direct2D1 namespace Perspex.Direct2D1
{ {
public class Renderer : RendererBase public class Renderer : IRenderer
{ {
/// <summary> /// <summary>
/// The render target. /// The render target.
@ -77,7 +77,7 @@ namespace Perspex.Direct2D1
/// </summary> /// </summary>
/// <param name="width">The new width.</param> /// <param name="width">The new width.</param>
/// <param name="height">The new height.</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; WindowRenderTarget window = _renderTarget as WindowRenderTarget;
@ -96,12 +96,12 @@ namespace Perspex.Direct2D1
/// </summary> /// </summary>
/// <param name="handle">The platform handle. Unused.</param> /// <param name="handle">The platform handle. Unused.</param>
/// <returns>An <see cref="IDrawingContext"/>.</returns> /// <returns>An <see cref="IDrawingContext"/>.</returns>
protected override IDrawingContext CreateDrawingContext(IPlatformHandle handle) public IDrawingContext CreateDrawingContext(IPlatformHandle handle)
{ {
return new DrawingContext(_renderTarget, DirectWriteFactory); return new DrawingContext(_renderTarget, DirectWriteFactory);
} }
public override void Dispose() public void Dispose()
{ {
_renderTarget.Dispose(); _renderTarget.Dispose();
} }

Loading…
Cancel
Save