common fill: code refactoring
authorHermet Park <chuneon.park@samsung.com>
Tue, 22 Sep 2020 01:56:53 +0000 (10:56 +0900)
committerHermet Park <chuneon.park@samsung.com>
Tue, 22 Sep 2020 05:00:17 +0000 (14:00 +0900)
removed unique_ptr in the interface because it's hard to get polymorphism benefits in programming perspective.

Change-Id: I1c1fc0a0b5047f365efb17ece3645291a4719224

inc/thorvg.h
src/lib/tvgFill.cpp
src/lib/tvgFill.h
src/lib/tvgLinearGradient.cpp
src/lib/tvgPaint.h
src/lib/tvgPictureImpl.h
src/lib/tvgRadialGradient.cpp
src/lib/tvgSceneImpl.h
src/lib/tvgShapeImpl.h

index e4f45a7..71f6b49 100644 (file)
@@ -122,7 +122,7 @@ public:
 
     uint32_t colorStops(const ColorStop** colorStops) const noexcept;
     FillSpread spread() const noexcept;
-    std::unique_ptr<Fill> duplicate() const noexcept;
+    Fill* duplicate() const noexcept;
 
     _TVG_DECALRE_IDENTIFIER();
     _TVG_DECLARE_PRIVATE(Fill);
index c9d3f1c..f89ba8b 100644 (file)
@@ -85,7 +85,7 @@ FillSpread Fill::spread() const noexcept
 }
 
 
-unique_ptr<Fill> Fill::duplicate() const noexcept
+Fill* Fill::duplicate() const noexcept
 {
     return pImpl->duplicate();
 }
index 07af49c..5036337 100644 (file)
@@ -28,7 +28,7 @@ template<typename T>
 struct DuplicateMethod
 {
     virtual ~DuplicateMethod(){}
-    virtual unique_ptr<T> duplicate() = 0;
+    virtual T* duplicate() = 0;
 };
 
 template<class T>
@@ -39,7 +39,7 @@ struct FillDup : DuplicateMethod<Fill>
     FillDup(T* _inst) : inst(_inst) {}
     ~FillDup(){}
 
-    unique_ptr<Fill> duplicate() override
+    Fill* duplicate() override
     {
         return inst->duplicate();
     }
@@ -63,7 +63,7 @@ struct Fill::Impl
         this->dup = dup;
     }
 
-    unique_ptr<Fill> duplicate()
+    Fill* duplicate()
     {
         auto ret = dup->duplicate();
         if (!ret) return nullptr;
index 5258b33..f647d44 100644 (file)
@@ -32,7 +32,7 @@ struct LinearGradient::Impl
     float x2 = 0;
     float y2 = 0;
 
-    unique_ptr<Fill> duplicate()
+    Fill* duplicate()
     {
         auto ret = LinearGradient::gen();
         if (!ret) return nullptr;
@@ -42,7 +42,7 @@ struct LinearGradient::Impl
         ret->pImpl->x2 = x2;
         ret->pImpl->y2 = y2;
 
-        return ret;
+        return ret.release();
     }
 };
 
index 63c0849..3bdba81 100644 (file)
@@ -34,7 +34,7 @@ namespace tvg
         virtual bool update(RenderMethod& renderer, const RenderTransform* transform, RenderUpdateFlag pFlag) = 0;
         virtual bool render(RenderMethod& renderer) = 0;
         virtual bool bounds(float* x, float* y, float* w, float* h) const = 0;
-        virtual unique_ptr<Paint> duplicate() = 0;
+        virtual Paint* duplicate() = 0;
     };
 
     struct Paint::Impl
@@ -150,7 +150,7 @@ namespace tvg
 
         Paint* duplicate()
         {
-            return smethod->duplicate().release();
+            return smethod->duplicate();
         }
     };
 
@@ -183,7 +183,7 @@ namespace tvg
             return inst->render(renderer);
         }
 
-        unique_ptr<Paint> duplicate() override
+        Paint* duplicate() override
         {
             return inst->duplicate();
         }
index b1e4fb1..b4c5ed5 100644 (file)
@@ -105,7 +105,7 @@ struct Picture::Impl
         return Result::Success;
     }
 
-    unique_ptr<Paint> duplicate()
+    Paint* duplicate()
     {
         //TODO:
         return nullptr;
index d02d2e0..03164ae 100644 (file)
@@ -31,7 +31,7 @@ struct RadialGradient::Impl
     float cy = 0;
     float radius = 0;
 
-    unique_ptr<Fill> duplicate()
+    Fill* duplicate()
     {
         auto ret = RadialGradient::gen();
         if (!ret) return nullptr;
@@ -40,7 +40,7 @@ struct RadialGradient::Impl
         ret->pImpl->cy = cy;
         ret->pImpl->radius = radius;
 
-        return ret;
+        return ret.release();
     }
 };
 
index 00f2ccc..d9d6094 100644 (file)
@@ -89,7 +89,7 @@ struct Scene::Impl
         return true;
     }
 
-    unique_ptr<Paint> duplicate()
+    Paint* duplicate()
     {
         //TODO:
         return nullptr;
index 5186003..7dc1811 100644 (file)
@@ -176,7 +176,7 @@ struct Shape::Impl
         return true;
     }
 
-    unique_ptr<Paint> duplicate()
+    Paint* duplicate()
     {
         auto ret = Shape::gen();
         if (!ret) return nullptr;
@@ -200,11 +200,11 @@ struct Shape::Impl
         }
 
         if (fill) {
-            dup->fill = fill->duplicate().release();
+            dup->fill = fill->duplicate();
             dup->flag |= RenderUpdateFlag::Gradient;
         }
 
-        return ret;
+        return ret.release();
     }
 };