Browse Source

Use Marshal.AllocHGlobal to allocate frame buffer

pull/8417/head
Lobster Uberlord 4 years ago
parent
commit
37a1a5553d
  1. 10
      src/Web/Avalonia.Web.Blazor/BlazorSkiaRasterSurface.cs

10
src/Web/Avalonia.Web.Blazor/BlazorSkiaRasterSurface.cs

@ -65,26 +65,22 @@ namespace Avalonia.Web.Blazor
private readonly struct FramebufferData
{
private readonly byte[]? _data;
private readonly GCHandle _dataHandle;
public PixelSize Size { get; }
public int RowBytes { get; }
public IntPtr Address => _dataHandle.AddrOfPinnedObject();
public IntPtr Address { get; }
public FramebufferData(int width, int height, int bytesPerPixel)
{
Size = new PixelSize(width, height);
RowBytes = width * bytesPerPixel;
_data = new byte[width * height * bytesPerPixel];
_dataHandle = GCHandle.Alloc(_data, GCHandleType.Pinned);
Address = Marshal.AllocHGlobal(width * height * bytesPerPixel);
}
public void Dispose()
{
_dataHandle.Free();
Marshal.FreeHGlobal(Address);
}
}
}

Loading…
Cancel
Save