Selaa lähdekoodia

LibGfx: Use ErrorOr<T> for Bitmap::flipped()

Andreas Kling 3 vuotta sitten
vanhempi
commit
db90b4554e

+ 1 - 1
Userland/Applications/ImageViewer/ViewWidget.cpp

@@ -47,7 +47,7 @@ void ViewWidget::clear()
 
 void ViewWidget::flip(Gfx::Orientation orientation)
 {
-    m_bitmap = m_bitmap->flipped(orientation);
+    m_bitmap = m_bitmap->flipped(orientation).release_value_but_fixme_should_propagate_errors();
     set_scale(m_scale);
 
     resize_window();

+ 1 - 2
Userland/Applications/PixelPaint/Image.cpp

@@ -506,8 +506,7 @@ void Image::set_path(String path)
 void Image::flip(Gfx::Orientation orientation)
 {
     for (auto& layer : m_layers) {
-        auto flipped = layer.bitmap().flipped(orientation);
-        VERIFY(flipped);
+        auto flipped = layer.bitmap().flipped(orientation).release_value_but_fixme_should_propagate_errors();
         layer.set_bitmap(*flipped);
         layer.did_modify_bitmap(rect());
     }

+ 6 - 4
Userland/Libraries/LibGfx/Bitmap.cpp

@@ -372,11 +372,13 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::rotated(Gfx::RotationDirection rotat
     return new_bitmap.release_nonnull();
 }
 
-RefPtr<Gfx::Bitmap> Bitmap::flipped(Gfx::Orientation orientation) const
+ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::flipped(Gfx::Orientation orientation) const
 {
     auto new_bitmap = Gfx::Bitmap::try_create(this->format(), { width(), height() }, scale());
-    if (!new_bitmap)
-        return nullptr;
+    if (!new_bitmap) {
+        // FIXME: Propagate the *real* error, once we have it.
+        return Error::from_errno(ENOMEM);
+    }
 
     auto w = this->physical_width();
     auto h = this->physical_height();
@@ -390,7 +392,7 @@ RefPtr<Gfx::Bitmap> Bitmap::flipped(Gfx::Orientation orientation) const
         }
     }
 
-    return new_bitmap;
+    return new_bitmap.release_nonnull();
 }
 
 RefPtr<Gfx::Bitmap> Bitmap::scaled(int sx, int sy) const

+ 1 - 1
Userland/Libraries/LibGfx/Bitmap.h

@@ -112,7 +112,7 @@ public:
     ErrorOr<NonnullRefPtr<Gfx::Bitmap>> clone() const;
 
     ErrorOr<NonnullRefPtr<Gfx::Bitmap>> rotated(Gfx::RotationDirection) const;
-    [[nodiscard]] RefPtr<Gfx::Bitmap> flipped(Gfx::Orientation) const;
+    ErrorOr<NonnullRefPtr<Gfx::Bitmap>> flipped(Gfx::Orientation) const;
     [[nodiscard]] RefPtr<Gfx::Bitmap> scaled(int sx, int sy) const;
     [[nodiscard]] RefPtr<Gfx::Bitmap> scaled(float sx, float sy) const;
     [[nodiscard]] RefPtr<Gfx::Bitmap> cropped(Gfx::IntRect) const;