1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 23:15:07 +00:00

LibGfx: Add Gfx::Bitmap::create_shareable(format, size)

This helper allocates a shbuf and returns it wrapped in a Bitmap.
This commit is contained in:
Andreas Kling 2021-01-02 16:23:04 +01:00
parent fd08c93ef5
commit 0bc8d58c3b
2 changed files with 14 additions and 0 deletions

View file

@ -98,6 +98,19 @@ RefPtr<Bitmap> Bitmap::create_purgeable(BitmapFormat format, const IntSize& size
return adopt(*new Bitmap(format, size, Purgeable::Yes, backing_store.value()));
}
RefPtr<Bitmap> Bitmap::create_shareable(BitmapFormat format, const IntSize& size)
{
if (size_would_overflow(format, size))
return nullptr;
const auto pitch = minimum_pitch(size.width(), format);
const auto data_size = size_in_bytes(pitch, size.height());
auto shared_buffer = SharedBuffer::create_with_size(data_size);
if (!shared_buffer)
return nullptr;
return adopt(*new Bitmap(format, shared_buffer.release_nonnull(), size, Vector<RGBA32>()));
}
Bitmap::Bitmap(BitmapFormat format, const IntSize& size, Purgeable purgeable, const BackingStore& backing_store)
: m_size(size)
, m_data(backing_store.data)