diff --git a/Userland/Applications/MouseSettings/ThemeWidget.cpp b/Userland/Applications/MouseSettings/ThemeWidget.cpp index a36bcefd6c..cab8736420 100644 --- a/Userland/Applications/MouseSettings/ThemeWidget.cpp +++ b/Userland/Applications/MouseSettings/ThemeWidget.cpp @@ -66,7 +66,7 @@ void MouseCursorModel::invalidate() auto cursor_bitmap = Gfx::Bitmap::try_load_from_file(cursor.path); auto cursor_bitmap_rect = cursor_bitmap->rect(); cursor.params = Gfx::CursorParams::parse_from_filename(cursor.name, cursor_bitmap_rect.center()).constrained(*cursor_bitmap); - cursor.bitmap = cursor_bitmap->cropped(Gfx::IntRect(Gfx::FloatRect(cursor_bitmap_rect).scaled(1.0 / cursor.params.frames(), 1.0))); + cursor.bitmap = cursor_bitmap->cropped(Gfx::IntRect(Gfx::FloatRect(cursor_bitmap_rect).scaled(1.0 / cursor.params.frames(), 1.0))).release_value_but_fixme_should_propagate_errors(); m_cursors.append(move(cursor)); } diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp index f2f3b55090..cade0b884e 100644 --- a/Userland/Applications/PixelPaint/Image.cpp +++ b/Userland/Applications/PixelPaint/Image.cpp @@ -187,7 +187,10 @@ RefPtr Image::try_copy_bitmap(Selection const& selection) const if (!full_bitmap) return {}; - return full_bitmap->cropped(selection_rect); + auto cropped_bitmap_or_error = full_bitmap->cropped(selection_rect); + if (cropped_bitmap_or_error.is_error()) + return nullptr; + return cropped_bitmap_or_error.release_value_but_fixme_should_propagate_errors(); } Result Image::export_bmp_to_fd_and_close(int fd, bool preserve_alpha_channel) @@ -529,8 +532,7 @@ void Image::rotate(Gfx::RotationDirection direction) void Image::crop(Gfx::IntRect const& cropped_rect) { for (auto& layer : m_layers) { - auto cropped = layer.bitmap().cropped(cropped_rect); - VERIFY(cropped); + auto cropped = layer.bitmap().cropped(cropped_rect).release_value_but_fixme_should_propagate_errors(); layer.set_bitmap(*cropped); layer.did_modify_bitmap(rect()); } diff --git a/Userland/Demos/WidgetGallery/GalleryModels.h b/Userland/Demos/WidgetGallery/GalleryModels.h index ad457d625a..119777f919 100644 --- a/Userland/Demos/WidgetGallery/GalleryModels.h +++ b/Userland/Demos/WidgetGallery/GalleryModels.h @@ -77,7 +77,7 @@ public: auto cursor_bitmap_rect = cursor_bitmap->rect(); cursor.params = Gfx::CursorParams::parse_from_filename(cursor.name, cursor_bitmap_rect.center()).constrained(*cursor_bitmap); - cursor.bitmap = cursor_bitmap->cropped(Gfx::IntRect(Gfx::FloatRect(cursor_bitmap_rect).scaled(1.0 / cursor.params.frames(), 1.0))); + cursor.bitmap = cursor_bitmap->cropped(Gfx::IntRect(Gfx::FloatRect(cursor_bitmap_rect).scaled(1.0 / cursor.params.frames(), 1.0))).release_value_but_fixme_should_propagate_errors(); m_cursors.append(move(cursor)); } diff --git a/Userland/Libraries/LibGfx/Bitmap.cpp b/Userland/Libraries/LibGfx/Bitmap.cpp index 3d534285c7..5d3e85edd5 100644 --- a/Userland/Libraries/LibGfx/Bitmap.cpp +++ b/Userland/Libraries/LibGfx/Bitmap.cpp @@ -511,11 +511,13 @@ ErrorOr> Bitmap::scaled(float sx, float sy) const return new_bitmap.release_nonnull(); } -RefPtr Bitmap::cropped(Gfx::IntRect crop) const +ErrorOr> Bitmap::cropped(Gfx::IntRect crop) const { auto new_bitmap = Gfx::Bitmap::try_create(format(), { crop.width(), crop.height() }, 1); - if (!new_bitmap) - return nullptr; + if (!new_bitmap) { + // FIXME: Propagate the *real* error, once we have it. + return Error::from_errno(ENOMEM); + } for (int y = 0; y < crop.height(); ++y) { for (int x = 0; x < crop.width(); ++x) { @@ -528,7 +530,7 @@ RefPtr Bitmap::cropped(Gfx::IntRect crop) const } } } - return new_bitmap; + return new_bitmap.release_nonnull(); } RefPtr Bitmap::to_bitmap_backed_by_anonymous_buffer() const diff --git a/Userland/Libraries/LibGfx/Bitmap.h b/Userland/Libraries/LibGfx/Bitmap.h index abf7eadbfc..28e6333b02 100644 --- a/Userland/Libraries/LibGfx/Bitmap.h +++ b/Userland/Libraries/LibGfx/Bitmap.h @@ -115,7 +115,7 @@ public: ErrorOr> flipped(Gfx::Orientation) const; ErrorOr> scaled(int sx, int sy) const; ErrorOr> scaled(float sx, float sy) const; - [[nodiscard]] RefPtr cropped(Gfx::IntRect) const; + ErrorOr> cropped(Gfx::IntRect) const; [[nodiscard]] RefPtr to_bitmap_backed_by_anonymous_buffer() const; [[nodiscard]] ByteBuffer serialize_to_byte_buffer() const; diff --git a/Userland/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp index 9c17d1012c..ea4d0b28e5 100644 --- a/Userland/Services/WindowServer/ClientConnection.cpp +++ b/Userland/Services/WindowServer/ClientConnection.cpp @@ -974,8 +974,12 @@ Messages::WindowServer::GetScreenBitmapResponse ClientConnection::get_screen_bit return { Gfx::ShareableBitmap() }; } if (rect.has_value()) { - auto bitmap = Compositor::the().front_bitmap_for_screenshot({}, *screen).cropped(rect.value()); - return bitmap->to_shareable_bitmap(); + auto bitmap_or_error = Compositor::the().front_bitmap_for_screenshot({}, *screen).cropped(rect.value()); + if (bitmap_or_error.is_error()) { + dbgln("get_screen_bitmap: Failed to crop screenshot: {}", bitmap_or_error.error()); + return { Gfx::ShareableBitmap() }; + } + return bitmap_or_error.release_value()->to_shareable_bitmap(); } auto& bitmap = Compositor::the().front_bitmap_for_screenshot({}, *screen); return bitmap.to_shareable_bitmap(); @@ -1022,8 +1026,12 @@ Messages::WindowServer::GetScreenBitmapAroundCursorResponse ClientConnection::ge if (intersecting_with_screens == 1) { auto& screen = Screen::closest_to_rect(rect); auto crop_rect = rect.translated(-screen.rect().location()) * screen_scale_factor; - auto bitmap = Compositor::the().front_bitmap_for_screenshot({}, screen).cropped(crop_rect); - return bitmap->to_shareable_bitmap(); + auto bitmap_or_error = Compositor::the().front_bitmap_for_screenshot({}, screen).cropped(crop_rect); + if (bitmap_or_error.is_error()) { + dbgln("get_screen_bitmap_around_cursor: Failed to crop screenshot: {}", bitmap_or_error.error()); + return { {} }; + } + return bitmap_or_error.release_value()->to_shareable_bitmap(); } if (auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, rect.size(), 1)) {