Browse Source

PixelPaint: Use move semantics around Layer construction and accessors

Andreas Kling 4 years ago
parent
commit
c7f7c1f7f0

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

@@ -98,7 +98,9 @@ RefPtr<Image> Image::try_create_from_pixel_paint_file(String const& file_path)
         auto bitmap_base64_encoded = json_layer_object.get("bitmap").as_string();
         auto bitmap_data = decode_base64(bitmap_base64_encoded);
         auto image_decoder = Gfx::ImageDecoder::create(bitmap_data);
-        layer->set_bitmap(*image_decoder->bitmap());
+        auto bitmap = image_decoder->bitmap();
+        VERIFY(bitmap);
+        layer->set_bitmap(bitmap.release_nonnull());
         image->add_layer(*layer);
     });
 

+ 10 - 10
Userland/Applications/PixelPaint/Layer.cpp

@@ -10,7 +10,7 @@
 
 namespace PixelPaint {
 
-RefPtr<Layer> Layer::try_create_with_size(Image& image, Gfx::IntSize const& size, String const& name)
+RefPtr<Layer> Layer::try_create_with_size(Image& image, Gfx::IntSize const& size, String name)
 {
     if (size.is_empty())
         return nullptr;
@@ -18,10 +18,10 @@ RefPtr<Layer> Layer::try_create_with_size(Image& image, Gfx::IntSize const& size
     if (size.width() > 16384 || size.height() > 16384)
         return nullptr;
 
-    return adopt_ref(*new Layer(image, size, name));
+    return adopt_ref(*new Layer(image, size, move(name)));
 }
 
-RefPtr<Layer> Layer::try_create_with_bitmap(Image& image, Gfx::Bitmap const& bitmap, String const& name)
+RefPtr<Layer> Layer::try_create_with_bitmap(Image& image, Gfx::Bitmap const& bitmap, String name)
 {
     if (bitmap.size().is_empty())
         return nullptr;
@@ -29,7 +29,7 @@ RefPtr<Layer> Layer::try_create_with_bitmap(Image& image, Gfx::Bitmap const& bit
     if (bitmap.size().width() > 16384 || bitmap.size().height() > 16384)
         return nullptr;
 
-    return adopt_ref(*new Layer(image, bitmap, name));
+    return adopt_ref(*new Layer(image, bitmap, move(name)));
 }
 
 RefPtr<Layer> Layer::try_create_snapshot(Image& image, Layer const& layer)
@@ -49,16 +49,16 @@ RefPtr<Layer> Layer::try_create_snapshot(Image& image, Layer const& layer)
     return snapshot;
 }
 
-Layer::Layer(Image& image, Gfx::IntSize const& size, String const& name)
+Layer::Layer(Image& image, Gfx::IntSize const& size, String name)
     : m_image(image)
-    , m_name(name)
+    , m_name(move(name))
 {
     m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size);
 }
 
-Layer::Layer(Image& image, Gfx::Bitmap const& bitmap, String const& name)
+Layer::Layer(Image& image, Gfx::Bitmap const& bitmap, String name)
     : m_image(image)
-    , m_name(name)
+    , m_name(move(name))
     , m_bitmap(bitmap)
 {
 }
@@ -84,11 +84,11 @@ void Layer::set_opacity_percent(int opacity_percent)
     m_image.layer_did_modify_properties({}, *this);
 }
 
-void Layer::set_name(String const& name)
+void Layer::set_name(String name)
 {
     if (m_name == name)
         return;
-    m_name = name;
+    m_name = move(name);
     m_image.layer_did_modify_properties({}, *this);
 }
 

+ 6 - 6
Userland/Applications/PixelPaint/Layer.h

@@ -24,8 +24,8 @@ class Layer
     AK_MAKE_NONMOVABLE(Layer);
 
 public:
-    static RefPtr<Layer> try_create_with_size(Image&, Gfx::IntSize const&, String const& name);
-    static RefPtr<Layer> try_create_with_bitmap(Image&, Gfx::Bitmap const&, String const& name);
+    static RefPtr<Layer> try_create_with_size(Image&, Gfx::IntSize const&, String name);
+    static RefPtr<Layer> try_create_with_bitmap(Image&, Gfx::Bitmap const&, String name);
     static RefPtr<Layer> try_create_snapshot(Image&, Layer const&);
 
     ~Layer() { }
@@ -41,9 +41,9 @@ public:
     Gfx::IntRect rect() const { return { {}, size() }; }
 
     String const& name() const { return m_name; }
-    void set_name(String const&);
+    void set_name(String);
 
-    void set_bitmap(Gfx::Bitmap& bitmap) { m_bitmap = bitmap; }
+    void set_bitmap(NonnullRefPtr<Gfx::Bitmap> bitmap) { m_bitmap = move(bitmap); }
 
     void did_modify_bitmap(Image&);
 
@@ -57,8 +57,8 @@ public:
     void set_opacity_percent(int);
 
 private:
-    Layer(Image&, Gfx::IntSize const&, String const& name);
-    Layer(Image&, Gfx::Bitmap const&, String const& name);
+    Layer(Image&, Gfx::IntSize const&, String name);
+    Layer(Image&, Gfx::Bitmap const&, String name);
 
     Image& m_image;