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
Notes: sideshowbarker 2024-07-19 00:12:14 +09:00
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)

View file

@ -89,6 +89,7 @@ enum RotationDirection {
class Bitmap : public RefCounted<Bitmap> {
public:
static RefPtr<Bitmap> create(BitmapFormat, const IntSize&);
static RefPtr<Bitmap> create_shareable(BitmapFormat, const IntSize&);
static RefPtr<Bitmap> create_purgeable(BitmapFormat, const IntSize&);
static RefPtr<Bitmap> create_wrapper(BitmapFormat, const IntSize&, size_t pitch, void*);
static RefPtr<Bitmap> load_from_file(const StringView& path);