Browse Source

Merge pull request #11235 from AvaloniaUI/feature/rtb-copypixels

Use SKBitmap-backed bitmap for RenderTargetBitmap
pull/11247/head
Max Katz 4 years ago
committed by GitHub
parent
commit
556de33b04
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs
  2. 11
      src/Skia/Avalonia.Skia/PlatformRenderInterface.cs
  3. 31
      src/Skia/Avalonia.Skia/RenderTargetBitmapImpl.cs
  4. 2
      src/Skia/Avalonia.Skia/WriteableBitmapImpl.cs

8
src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs

@ -9,7 +9,7 @@ namespace Avalonia.Media.Imaging
/// <summary>
/// A bitmap that holds the rendering of a <see cref="Visual"/>.
/// </summary>
public class RenderTargetBitmap : Bitmap, IDisposable
public class RenderTargetBitmap : Bitmap
{
/// <summary>
/// Initializes a new instance of the <see cref="RenderTargetBitmap"/> class.
@ -68,5 +68,11 @@ namespace Avalonia.Media.Imaging
platform.Clear(Colors.Transparent);
return new PlatformDrawingContext(platform);
}
public override void Dispose()
{
PlatformImpl.Dispose();
base.Dispose();
}
}
}

11
src/Skia/Avalonia.Skia/PlatformRenderInterface.cs

@ -191,16 +191,7 @@ namespace Avalonia.Skia
throw new ArgumentException("Height can't be less than 1", nameof(size));
}
var createInfo = new SurfaceRenderTarget.CreateInfo
{
Width = size.Width,
Height = size.Height,
Dpi = dpi,
DisableTextLcdRendering = false,
DisableManualFbo = true,
};
return new SurfaceRenderTarget(createInfo);
return new RenderTargetBitmapImpl(size, dpi);
}
/// <inheritdoc />

31
src/Skia/Avalonia.Skia/RenderTargetBitmapImpl.cs

@ -0,0 +1,31 @@
using System.IO;
using Avalonia.Controls.Platform.Surfaces;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using SkiaSharp;
namespace Avalonia.Skia;
internal class RenderTargetBitmapImpl : WriteableBitmapImpl,
IRenderTargetBitmapImpl,
IFramebufferPlatformSurface
{
private readonly FramebufferRenderTarget _renderTarget;
public RenderTargetBitmapImpl(PixelSize size, Vector dpi) : base(size, dpi,
SKImageInfo.PlatformColorType == SKColorType.Rgba8888 ? PixelFormats.Rgba8888 : PixelFormat.Bgra8888,
AlphaFormat.Premul)
{
_renderTarget = new FramebufferRenderTarget(this);
}
public IDrawingContextImpl CreateDrawingContext() => _renderTarget.CreateDrawingContext();
public bool IsCorrupted => false;
public override void Dispose()
{
_renderTarget.Dispose();
base.Dispose();
}
}

2
src/Skia/Avalonia.Skia/WriteableBitmapImpl.cs

@ -131,7 +131,7 @@ namespace Avalonia.Skia
}
/// <inheritdoc />
public void Dispose()
public virtual void Dispose()
{
_bitmap.Dispose();
}

Loading…
Cancel
Save