1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:18:14 +00:00

LibGfx: restructure Bitmap ctor to expect an alloc'd backing store

Moves Bitmap backing store creation to the static create() methods.
This backing store is then passed into the Bitmap constructor. This
allows us correctly return nullptr from create() in the event that
memory allocation fails.
This commit is contained in:
Peter Nelson 2020-09-12 17:17:50 +01:00 committed by Andreas Kling
parent 06eea59a65
commit d366e996dd
2 changed files with 49 additions and 20 deletions

View file

@ -79,6 +79,8 @@ static StorageFormat determine_storage_format(BitmapFormat format)
}
}
struct BackingStore;
enum RotationDirection {
Left,
Right
@ -192,7 +194,8 @@ public:
void set_mmap_name(const StringView&);
size_t size_in_bytes() const { return m_pitch * m_size.height(); }
static constexpr size_t size_in_bytes(size_t pitch, int height) { return pitch * height; }
size_t size_in_bytes() const { return size_in_bytes(m_pitch, height()); }
Color palette_color(u8 index) const { return Color::from_rgba(m_palette[index]); }
void set_palette_color(u8 index, Color color) { m_palette[index] = color.value(); }
@ -223,10 +226,12 @@ private:
No,
Yes
};
Bitmap(BitmapFormat, const IntSize&, Purgeable);
Bitmap(BitmapFormat, const IntSize&, Purgeable, const BackingStore&);
Bitmap(BitmapFormat, const IntSize&, size_t pitch, void*);
Bitmap(BitmapFormat, NonnullRefPtr<SharedBuffer>&&, const IntSize&, const Vector<RGBA32>& palette);
static Optional<BackingStore> allocate_backing_store(BitmapFormat, const IntSize&, Purgeable);
void allocate_palette_from_format(BitmapFormat, const Vector<RGBA32>& source_palette);
IntSize m_size;