Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ public SKXamlCanvas()
Initialize();
}

partial void DoUnloaded() =>
partial void DoUnloaded()
{
FreeBitmap();
FreePixels();
}

private void DoInvalidate()
{
Expand Down Expand Up @@ -83,8 +86,21 @@ private SKImageInfo CreateBitmap(out SKSizeI unscaledSize, out float dpi)
var size = CreateSize(out unscaledSize, out dpi);
var info = new SKImageInfo(size.Width, size.Height, SKColorType.Bgra8888, SKAlphaType.Premul);

if (pixels == null || pixelWidth != info.Width || pixelHeight != info.Height)
{
FreePixels();

pixels = new byte[info.BytesSize];
pixelsHandle = GCHandle.Alloc(pixels, GCHandleType.Pinned);

pixelWidth = info.Width;
pixelHeight = info.Height;
}

if (bitmap?.PixelWidth != info.Width || bitmap?.PixelHeight != info.Height)
{
FreeBitmap();
}

if (bitmap == null && info.Width > 0 && info.Height > 0)
{
Expand All @@ -101,28 +117,18 @@ private SKImageInfo CreateBitmap(out SKSizeI unscaledSize, out float dpi)
Background = brush;
}

if (pixels == null || pixelWidth != info.Width || pixelHeight != info.Height)
{
FreeBitmap();

pixels = new byte[info.BytesSize];
pixelsHandle = GCHandle.Alloc(pixels, GCHandleType.Pinned);

pixelWidth = info.Width;
pixelHeight = info.Height;
}

return info;
}

private void FreeBitmap()
private void FreePixels()
{
if (pixels != null)
{
pixelsHandle.Free();
pixels = null;
bitmap = null;
}
}

private void FreeBitmap() => _bitmap = null;
}
}
Loading