Browse Source

Merge pull request #40 from ncarrillo/feat-cairo-rtb

Implemented RenderTargetBitmap support for Cairo
pull/58/head
Steven Kirk 11 years ago
parent
commit
e340d70b03
  1. 5
      Cairo/Perspex.Cairo/CairoPlatform.cs
  2. 2
      Cairo/Perspex.Cairo/Media/DrawingContext.cs
  3. 2
      Cairo/Perspex.Cairo/Media/Imaging/BitmapImpl.cs
  4. 33
      Cairo/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs
  5. 1
      Cairo/Perspex.Cairo/Perspex.Cairo.csproj
  6. 8
      Cairo/Perspex.Cairo/Renderer.cs
  7. 8
      Perspex.SceneGraph/Media/Imaging/RenderTargetBitmap.cs
  8. 4
      Perspex.SceneGraph/Platform/IRenderTargetBitmapImpl.cs
  9. BIN
      TestFiles/Cairo/Controls/Border/Border_1px_Border.expected.png
  10. BIN
      TestFiles/Cairo/Controls/Border/Border_2px_Border.expected.png
  11. BIN
      TestFiles/Cairo/Controls/Border/Border_Bottom_Aligns_Content.expected.png
  12. BIN
      TestFiles/Cairo/Controls/Border/Border_Brush_Offsets_Content.expected.png
  13. BIN
      TestFiles/Cairo/Controls/Border/Border_Centers_Content_Horizontally.expected.png
  14. BIN
      TestFiles/Cairo/Controls/Border/Border_Centers_Content_Vertically.expected.png
  15. BIN
      TestFiles/Cairo/Controls/Border/Border_Fill.expected.png
  16. BIN
      TestFiles/Cairo/Controls/Border/Border_Left_Aligns_Content.expected.png
  17. BIN
      TestFiles/Cairo/Controls/Border/Border_Margin_Offsets_Content.expected.png
  18. BIN
      TestFiles/Cairo/Controls/Border/Border_Nested_Rotate.expected.png
  19. BIN
      TestFiles/Cairo/Controls/Border/Border_Padding_Offsets_Content.expected.png
  20. BIN
      TestFiles/Cairo/Controls/Border/Border_Right_Aligns_Content.expected.png
  21. BIN
      TestFiles/Cairo/Controls/Border/Border_Stretches_Content_Horizontally.expected.png
  22. BIN
      TestFiles/Cairo/Controls/Border/Border_Stretches_Content_Vertically.expected.png
  23. BIN
      TestFiles/Cairo/Controls/Border/Border_Top_Aligns_Content.expected.png
  24. BIN
      TestFiles/Cairo/Controls/Image/Image_Stretch_Fill.expected.png
  25. BIN
      TestFiles/Cairo/Controls/Image/Image_Stretch_None.expected.png
  26. BIN
      TestFiles/Cairo/Controls/Image/Image_Stretch_Uniform.expected.png
  27. BIN
      TestFiles/Cairo/Controls/Image/Image_Stretch_UniformToFill.expected.png
  28. BIN
      TestFiles/Cairo/Controls/Image/test.png
  29. BIN
      TestFiles/Cairo/Shapes/Ellipse/Circle_1px_Stroke.expected.png
  30. BIN
      TestFiles/Cairo/Shapes/Path/Path_100px_Triangle_Centered.expected.png
  31. BIN
      TestFiles/Cairo/Shapes/Path/Path_Expander_With_Border.expected.png
  32. BIN
      TestFiles/Cairo/Shapes/Path/Path_Tick_Scaled.expected.png
  33. BIN
      TestFiles/Cairo/Shapes/Rectangle/Rectangle_1px_Stroke.expected.png
  34. BIN
      TestFiles/Cairo/Shapes/Rectangle/Rectangle_2px_Stroke.expected.png
  35. BIN
      TestFiles/Cairo/Shapes/Rectangle/Rectangle_Stroke_Fill.expected.png
  36. 7
      Windows/Perspex.Direct2D1/Media/Imaging/RenderTargetBitmapImpl.cs

5
Cairo/Perspex.Cairo/CairoPlatform.cs

@ -27,8 +27,7 @@ namespace Perspex.Cairo
public IBitmapImpl CreateBitmap(int width, int height)
{
throw new NotImplementedException();
////return new BitmapImpl(imagingFactory, width, height);
return new BitmapImpl(new ImageSurface(Format.Argb32, width, height));
}
public IFormattedTextImpl CreateFormattedText(
@ -49,7 +48,7 @@ namespace Perspex.Cairo
public IRenderTargetBitmapImpl CreateRenderTargetBitmap(int width, int height)
{
throw new NotImplementedException();
return new RenderTargetBitmapImpl(new ImageSurface(Format.Argb32, width, height));
}
public IStreamGeometryImpl CreateStreamGeometry()

2
Cairo/Perspex.Cairo/Media/DrawingContext.cs

@ -70,7 +70,7 @@ namespace Perspex.Cairo.Media
{
this.context.Dispose();
if (this.surface != null)
if (this.surface is Cairo.Win32Surface)
{
this.surface.Dispose();
}

2
Cairo/Perspex.Cairo/Media/Imaging/BitmapImpl.cs

@ -35,7 +35,7 @@ namespace Perspex.Cairo.Media.Imaging
public void Save(string fileName)
{
throw new NotImplementedException();
this.Surface.WriteToPng(fileName);
}
}
}

33
Cairo/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs

@ -0,0 +1,33 @@
// -----------------------------------------------------------------------
// <copyright file="RenderTargetBitmapImpl.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Cairo.Media.Imaging
{
using System;
using Perspex.Platform;
using Cairo = global::Cairo;
public class RenderTargetBitmapImpl : BitmapImpl, IRenderTargetBitmapImpl
{
public RenderTargetBitmapImpl(
Cairo.ImageSurface surface)
: base(surface)
{
}
public void Dispose()
{
this.Surface.Dispose();
}
public void Render(IVisual visual)
{
Renderer renderer = new Renderer(this.Surface);
renderer.Render(visual, new PlatformHandle(IntPtr.Zero, "RTB"));
}
}
}

1
Cairo/Perspex.Cairo/Perspex.Cairo.csproj

@ -70,6 +70,7 @@
<Compile Include="Media\DrawingContext.cs" />
<Compile Include="Media\FormattedTextImpl.cs" />
<Compile Include="Media\Imaging\BitmapImpl.cs" />
<Compile Include="Media\Imaging\RenderTargetBitmapImpl.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Renderer.cs" />
<Compile Include="CairoExtensions.cs" />

8
Cairo/Perspex.Cairo/Renderer.cs

@ -30,6 +30,12 @@ namespace Perspex.Cairo
{
}
private ImageSurface surface;
public Renderer(ImageSurface surface)
{
this.surface = surface;
}
/// <summary>
/// Resizes the renderer.
/// </summary>
@ -51,6 +57,8 @@ namespace Perspex.Cairo
{
case "HWND":
return new DrawingContext(new Win32Surface(GetDC(handle.Handle)));
case "RTB":
return new DrawingContext(this.surface);
case "HDC":
return new DrawingContext(new Win32Surface(handle.Handle));
case "GdkWindow":

8
Perspex.SceneGraph/Media/Imaging/RenderTargetBitmap.cs

@ -8,8 +8,9 @@ namespace Perspex.Media.Imaging
{
using Perspex.Platform;
using Splat;
using System;
public class RenderTargetBitmap : Bitmap
public class RenderTargetBitmap : Bitmap, IDisposable
{
public RenderTargetBitmap(int width, int height)
: base(CreateImpl(width, height))
@ -31,5 +32,10 @@ namespace Perspex.Media.Imaging
IPlatformRenderInterface factory = Locator.Current.GetService<IPlatformRenderInterface>();
return factory.CreateRenderTargetBitmap(width, height);
}
public void Dispose()
{
this.PlatformImpl.Dispose();
}
}
}

4
Perspex.SceneGraph/Platform/IRenderTargetBitmapImpl.cs

@ -4,9 +4,11 @@
// </copyright>
// -----------------------------------------------------------------------
using System;
namespace Perspex.Platform
{
public interface IRenderTargetBitmapImpl : IBitmapImpl
public interface IRenderTargetBitmapImpl : IBitmapImpl, IDisposable
{
void Render(IVisual visual);
}

BIN
TestFiles/Cairo/Controls/Border/Border_1px_Border.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 B

BIN
TestFiles/Cairo/Controls/Border/Border_2px_Border.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 B

BIN
TestFiles/Cairo/Controls/Border/Border_Bottom_Aligns_Content.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 797 B

BIN
TestFiles/Cairo/Controls/Border/Border_Brush_Offsets_Content.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 B

BIN
TestFiles/Cairo/Controls/Border/Border_Centers_Content_Horizontally.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 830 B

BIN
TestFiles/Cairo/Controls/Border/Border_Centers_Content_Vertically.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 B

BIN
TestFiles/Cairo/Controls/Border/Border_Fill.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 601 B

BIN
TestFiles/Cairo/Controls/Border/Border_Left_Aligns_Content.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 838 B

BIN
TestFiles/Cairo/Controls/Border/Border_Margin_Offsets_Content.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

BIN
TestFiles/Cairo/Controls/Border/Border_Nested_Rotate.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
TestFiles/Cairo/Controls/Border/Border_Padding_Offsets_Content.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

BIN
TestFiles/Cairo/Controls/Border/Border_Right_Aligns_Content.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 B

BIN
TestFiles/Cairo/Controls/Border/Border_Stretches_Content_Horizontally.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

BIN
TestFiles/Cairo/Controls/Border/Border_Stretches_Content_Vertically.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

BIN
TestFiles/Cairo/Controls/Border/Border_Top_Aligns_Content.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 801 B

BIN
TestFiles/Cairo/Controls/Image/Image_Stretch_Fill.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

BIN
TestFiles/Cairo/Controls/Image/Image_Stretch_None.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
TestFiles/Cairo/Controls/Image/Image_Stretch_Uniform.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
TestFiles/Cairo/Controls/Image/Image_Stretch_UniformToFill.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

BIN
TestFiles/Cairo/Controls/Image/test.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
TestFiles/Cairo/Shapes/Ellipse/Circle_1px_Stroke.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
TestFiles/Cairo/Shapes/Path/Path_100px_Triangle_Centered.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
TestFiles/Cairo/Shapes/Path/Path_Expander_With_Border.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
TestFiles/Cairo/Shapes/Path/Path_Tick_Scaled.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

BIN
TestFiles/Cairo/Shapes/Rectangle/Rectangle_1px_Stroke.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 628 B

BIN
TestFiles/Cairo/Shapes/Rectangle/Rectangle_2px_Stroke.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

BIN
TestFiles/Cairo/Shapes/Rectangle/Rectangle_Stroke_Fill.expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

7
Windows/Perspex.Direct2D1/Media/Imaging/RenderTargetBitmapImpl.cs

@ -11,7 +11,7 @@ namespace Perspex.Direct2D1.Media
using SharpDX.Direct2D1;
using SharpDX.WIC;
public class RenderTargetBitmapImpl : BitmapImpl, IRenderTargetBitmapImpl
public class RenderTargetBitmapImpl : BitmapImpl, IRenderTargetBitmapImpl, IDisposable
{
private WicRenderTarget target;
@ -32,6 +32,11 @@ namespace Perspex.Direct2D1.Media
});
}
public void Dispose()
{
// TODO:
}
public void Render(IVisual visual)
{
Renderer renderer = new Renderer(this.target);

Loading…
Cancel
Save