diff options
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r-- | Userland/Libraries/LibGfx/Bitmap.cpp | 21 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Bitmap.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/ShareableBitmap.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/ShareableBitmap.h | 3 |
4 files changed, 11 insertions, 20 deletions
diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index 5d3e85edd5..4c75417700 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -533,17 +533,12 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::cropped(Gfx::IntRect crop) const return new_bitmap.release_nonnull(); } -RefPtr<Bitmap> Bitmap::to_bitmap_backed_by_anonymous_buffer() const +ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::to_bitmap_backed_by_anonymous_buffer() const { if (m_buffer.is_valid()) - return *this; - auto buffer_or_error = Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(size_in_bytes(), PAGE_SIZE)); - if (buffer_or_error.is_error()) - return nullptr; - auto bitmap_or_error = Bitmap::try_create_with_anonymous_buffer(m_format, buffer_or_error.release_value(), size(), scale(), palette_to_vector()); - if (bitmap_or_error.is_error()) - return nullptr; - auto bitmap = bitmap_or_error.release_value(); + return NonnullRefPtr { *this }; + auto buffer = TRY(Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(size_in_bytes(), PAGE_SIZE))); + auto bitmap = TRY(Bitmap::try_create_with_anonymous_buffer(m_format, move(buffer), size(), scale(), palette_to_vector())); memcpy(bitmap->scanline(0), scanline(0), size_in_bytes()); return bitmap; } @@ -612,12 +607,12 @@ void Bitmap::set_volatile() return true; } -ShareableBitmap Bitmap::to_shareable_bitmap() const +Gfx::ShareableBitmap Bitmap::to_shareable_bitmap() const { - auto bitmap = to_bitmap_backed_by_anonymous_buffer(); - if (!bitmap) + auto bitmap_or_error = to_bitmap_backed_by_anonymous_buffer(); + if (bitmap_or_error.is_error()) return {}; - return ShareableBitmap(*bitmap); + return Gfx::ShareableBitmap { bitmap_or_error.release_value_but_fixme_should_propagate_errors(), Gfx::ShareableBitmap::ConstructWithKnownGoodBitmap }; } ErrorOr<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, IntSize const& size, int scale_factor) diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h index 28e6333b02..528cc74b98 100644 --- a/Userland/Libraries/LibGfx/Bitmap.h +++ b/Userland/Libraries/LibGfx/Bitmap.h @@ -116,7 +116,7 @@ public: ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled(int sx, int sy) const; ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled(float sx, float sy) const; ErrorOr<NonnullRefPtr<Gfx::Bitmap>> cropped(Gfx::IntRect) const; - [[nodiscard]] RefPtr<Bitmap> to_bitmap_backed_by_anonymous_buffer() const; + ErrorOr<NonnullRefPtr<Gfx::Bitmap>> to_bitmap_backed_by_anonymous_buffer() const; [[nodiscard]] ByteBuffer serialize_to_byte_buffer() const; [[nodiscard]] ShareableBitmap to_shareable_bitmap() const; diff --git a/Userland/Libraries/LibGfx/ShareableBitmap.cpp b/Userland/Libraries/LibGfx/ShareableBitmap.cpp index 1b598dec53..44d1de68d5 100644 --- a/Userland/Libraries/LibGfx/ShareableBitmap.cpp +++ b/Userland/Libraries/LibGfx/ShareableBitmap.cpp @@ -13,11 +13,6 @@ namespace Gfx { -ShareableBitmap::ShareableBitmap(const Bitmap& bitmap) - : m_bitmap(bitmap.to_bitmap_backed_by_anonymous_buffer()) -{ -} - ShareableBitmap::ShareableBitmap(NonnullRefPtr<Bitmap> bitmap, Tag) : m_bitmap(move(bitmap)) { diff --git a/Userland/Libraries/LibGfx/ShareableBitmap.h b/Userland/Libraries/LibGfx/ShareableBitmap.h index 6b8e208fb0..e9616102dd 100644 --- a/Userland/Libraries/LibGfx/ShareableBitmap.h +++ b/Userland/Libraries/LibGfx/ShareableBitmap.h @@ -15,7 +15,6 @@ namespace Gfx { class ShareableBitmap { public: ShareableBitmap() { } - explicit ShareableBitmap(const Gfx::Bitmap&); enum Tag { ConstructWithKnownGoodBitmap }; ShareableBitmap(NonnullRefPtr<Gfx::Bitmap>, Tag); @@ -26,6 +25,8 @@ public: Bitmap* bitmap() { return m_bitmap; } private: + friend class Bitmap; + RefPtr<Bitmap> m_bitmap; }; |