diff options
-rw-r--r-- | Userland/Libraries/LibGfx/Bitmap.cpp | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Bitmap.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/OutOfProcessWebView.cpp | 8 |
3 files changed, 11 insertions, 14 deletions
diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index 787cdee79a..52fde5c20c 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -11,6 +11,7 @@ #include <AK/Optional.h> #include <AK/ScopeGuard.h> #include <AK/String.h> +#include <AK/Try.h> #include <LibGfx/BMPLoader.h> #include <LibGfx/Bitmap.h> #include <LibGfx/DDSLoader.h> @@ -73,21 +74,17 @@ RefPtr<Bitmap> Bitmap::try_create(BitmapFormat format, const IntSize& size, int return adopt_ref(*new Bitmap(format, size, scale_factor, backing_store_or_error.release_value())); } -RefPtr<Bitmap> Bitmap::try_create_shareable(BitmapFormat format, const IntSize& size, int scale_factor) +ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_shareable(BitmapFormat format, const IntSize& size, int scale_factor) { if (size_would_overflow(format, size, scale_factor)) - return nullptr; + return Error::from_string_literal("Gfx::Bitmap::try_create_shareable size overflow"sv); const auto pitch = minimum_pitch(size.width() * scale_factor, format); const auto data_size = size_in_bytes(pitch, size.height() * scale_factor); - auto buffer_or_error = Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(data_size, PAGE_SIZE)); - if (buffer_or_error.is_error()) - return nullptr; - auto bitmap_or_error = Bitmap::try_create_with_anonymous_buffer(format, buffer_or_error.release_value(), size, scale_factor, {}); - if (bitmap_or_error.is_error()) - return nullptr; - return bitmap_or_error.release_value(); + auto buffer = TRY(Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(data_size, PAGE_SIZE))); + auto bitmap = TRY(Bitmap::try_create_with_anonymous_buffer(format, buffer, size, scale_factor, {})); + return bitmap; } Bitmap::Bitmap(BitmapFormat format, const IntSize& size, int scale_factor, const BackingStore& backing_store) diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h index e430773a7a..223bd3d5d5 100644 --- a/Userland/Libraries/LibGfx/Bitmap.h +++ b/Userland/Libraries/LibGfx/Bitmap.h @@ -91,7 +91,7 @@ enum RotationDirection { class Bitmap : public RefCounted<Bitmap> { public: [[nodiscard]] static RefPtr<Bitmap> try_create(BitmapFormat, const IntSize&, int intrinsic_scale = 1); - [[nodiscard]] static RefPtr<Bitmap> try_create_shareable(BitmapFormat, const IntSize&, int intrinsic_scale = 1); + [[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_create_shareable(BitmapFormat, IntSize const&, int intrinsic_scale = 1); [[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_create_wrapper(BitmapFormat, IntSize const&, int intrinsic_scale, size_t pitch, void*); [[nodiscard]] static RefPtr<Bitmap> try_load_from_file(String const& path, int scale_factor = 1); [[nodiscard]] static RefPtr<Bitmap> try_load_from_fd_and_close(int fd, String const& path, int scale_factor = 1); diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index 292a31b3a1..a5b7ccf693 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -141,14 +141,14 @@ void OutOfProcessWebView::handle_resize() if (available_size().is_empty()) return; - if (auto new_bitmap = Gfx::Bitmap::try_create_shareable(Gfx::BitmapFormat::BGRx8888, available_size())) { - m_client_state.front_bitmap.bitmap = move(new_bitmap); + if (auto new_bitmap_or_error = Gfx::Bitmap::try_create_shareable(Gfx::BitmapFormat::BGRx8888, available_size()); !new_bitmap_or_error.is_error()) { + m_client_state.front_bitmap.bitmap = new_bitmap_or_error.release_value(); m_client_state.front_bitmap.id = m_client_state.next_bitmap_id++; client().async_add_backing_store(m_client_state.front_bitmap.id, m_client_state.front_bitmap.bitmap->to_shareable_bitmap()); } - if (auto new_bitmap = Gfx::Bitmap::try_create_shareable(Gfx::BitmapFormat::BGRx8888, available_size())) { - m_client_state.back_bitmap.bitmap = move(new_bitmap); + if (auto new_bitmap_or_error = Gfx::Bitmap::try_create_shareable(Gfx::BitmapFormat::BGRx8888, available_size()); !new_bitmap_or_error.is_error()) { + m_client_state.back_bitmap.bitmap = new_bitmap_or_error.release_value(); m_client_state.back_bitmap.id = m_client_state.next_bitmap_id++; client().async_add_backing_store(m_client_state.back_bitmap.id, m_client_state.back_bitmap.bitmap->to_shareable_bitmap()); } |