LibDraw: Add GraphicsBitmap::to_shareable_bitmap()

This function returns the bitmap itself if it's already backed by a
SharedBuffer object, otherwise it creates a shareable copy of itself
and returns that.
This commit is contained in:
Andreas Kling 2019-12-08 17:07:44 +01:00
commit 183ee5847c
Notes: sideshowbarker 2024-07-19 10:55:19 +09:00
2 changed files with 18 additions and 2 deletions

View file

@ -77,6 +77,16 @@ GraphicsBitmap::GraphicsBitmap(Format format, NonnullRefPtr<SharedBuffer>&& shar
ASSERT(format != Format::Indexed8);
}
NonnullRefPtr<GraphicsBitmap> GraphicsBitmap::to_shareable_bitmap() const
{
if (m_shared_buffer)
return *this;
auto buffer = SharedBuffer::create_with_size(size_in_bytes());
auto bitmap = GraphicsBitmap::create_with_shared_buffer(m_format, *buffer, m_size);
memcpy(buffer->data(), scanline(0), size_in_bytes());
return bitmap;
}
GraphicsBitmap::~GraphicsBitmap()
{
if (m_needs_munmap) {