diff --git a/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs b/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs index e77dd9d1ab..4921e9b756 100644 --- a/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs +++ b/src/Avalonia.Base/Media/Imaging/RenderTargetBitmap.cs @@ -9,7 +9,7 @@ namespace Avalonia.Media.Imaging /// /// A bitmap that holds the rendering of a . /// - public class RenderTargetBitmap : Bitmap, IDisposable + public class RenderTargetBitmap : Bitmap { /// /// Initializes a new instance of the 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(); + } } } diff --git a/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs b/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs index b486f8ad42..9e912db797 100644 --- a/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs +++ b/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); } /// diff --git a/src/Skia/Avalonia.Skia/RenderTargetBitmapImpl.cs b/src/Skia/Avalonia.Skia/RenderTargetBitmapImpl.cs new file mode 100644 index 0000000000..e20755b4e2 --- /dev/null +++ b/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(); + } +} \ No newline at end of file diff --git a/src/Skia/Avalonia.Skia/WriteableBitmapImpl.cs b/src/Skia/Avalonia.Skia/WriteableBitmapImpl.cs index 8ea7434c23..38df7b2933 100644 --- a/src/Skia/Avalonia.Skia/WriteableBitmapImpl.cs +++ b/src/Skia/Avalonia.Skia/WriteableBitmapImpl.cs @@ -131,7 +131,7 @@ namespace Avalonia.Skia } /// - public void Dispose() + public virtual void Dispose() { _bitmap.Dispose(); }