lottie: use unique_ptr instead of raw pointer. 04/187104/4
authorsubhransu mohanty <sub.mohanty@samsung.com>
Mon, 20 Aug 2018 03:36:50 +0000 (12:36 +0900)
committerYoungbok Shin <youngb.shin@samsung.com>
Mon, 20 Aug 2018 04:44:59 +0000 (13:44 +0900)
Change-Id: Ic5b416c72a96427dff3a99316550d8edb7ffece9

src/lottie/lottieitem.cpp
src/lottie/lottieitem.h

index c835e02..39d95bf 100644 (file)
@@ -17,28 +17,29 @@ LOTCompItem::LOTCompItem(LOTModel *model)
     : mRootModel(model), mUpdateViewBox(false), mCurFrameNo(-1)
 {
     mCompData = model->mRoot.get();
-    mRootLayer = std::unique_ptr<LOTLayerItem>(createLayerItem(mCompData->mRootLayer.get()));
+    mRootLayer = createLayerItem(mCompData->mRootLayer.get());
     mRootLayer->updateStaticProperty();
     mViewSize = mCompData->size();
 }
 
-LOTLayerItem *LOTCompItem::createLayerItem(LOTLayerData *layerData)
+std::unique_ptr<LOTLayerItem>
+LOTCompItem::createLayerItem(LOTLayerData *layerData)
 {
     switch (layerData->mLayerType) {
     case LayerType::Precomp: {
-        return new LOTCompLayerItem(layerData);
+        return std::make_unique<LOTCompLayerItem>(layerData);
         break;
     }
     case LayerType::Solid: {
-        return new LOTSolidLayerItem(layerData);
+        return std::make_unique<LOTSolidLayerItem>(layerData);
         break;
     }
     case LayerType::Shape: {
-        return new LOTShapeLayerItem(layerData);
+        return std::make_unique<LOTShapeLayerItem>(layerData);
         break;
     }
     case LayerType::Null: {
-        return new LOTNullLayerItem(layerData);
+        return std::make_unique<LOTNullLayerItem>(layerData);
         break;
     }
     default:
@@ -309,8 +310,8 @@ LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel)
     for (auto &i : mLayerData->mChildren) {
         LOTLayerData *layerModel = dynamic_cast<LOTLayerData *>(i.get());
         if (layerModel) {
-            LOTLayerItem *layerItem = LOTCompItem::createLayerItem(layerModel);
-            if (layerItem) mLayers.push_back(layerItem);
+            auto layerItem = LOTCompItem::createLayerItem(layerModel);
+            if (layerItem) mLayers.push_back(std::move(layerItem));
         }
     }
 
@@ -320,7 +321,7 @@ LOTCompLayerItem::LOTCompLayerItem(LOTLayerData *layerModel)
         if (id >= 0) {
             auto search = std::find_if(mLayers.begin(), mLayers.end(),
                             [id](const auto& val){ return val->id() == id;});
-            if (search != mLayers.end()) i->setParentLayer(*search);
+            if (search != mLayers.end()) i->setParentLayer((*search).get());
         }
         // update the precomp layer if its not the root layer.
         if (!layerModel->root()) i->setPrecompLayer(this);
@@ -358,7 +359,7 @@ void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask, LOTLay
 
     LOTLayerItem *matteLayer = nullptr;
     for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
-        LOTLayerItem *layer = *i;
+        LOTLayerItem *layer = (*i).get();
 
         if (!matteLayer && layer->hasMatte()) {
             matteLayer = layer;
@@ -374,19 +375,11 @@ void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask, LOTLay
     }
 }
 
-LOTCompLayerItem::~LOTCompLayerItem()
-{
-    for (auto &i : mLayers) {
-        delete i;
-    }
-}
-
 void LOTCompLayerItem::updateContent()
 {
     // update the layer from back to front
     for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
-        LOTLayerItem *layer = *i;
-        layer->update(frameNo(), combinedMatrix(), combinedAlpha());
+        (*i)->update(frameNo(), combinedMatrix(), combinedAlpha());
     }
 }
 
@@ -396,8 +389,7 @@ void LOTCompLayerItem::renderList(std::vector<VDrawable *> &list)
 
     // update the layer from back to front
     for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
-        LOTLayerItem *layer = *i;
-        layer->renderList(list);
+        (*i)->renderList(list);
     }
 }
 
index c9e01a7..57da07e 100644 (file)
@@ -31,7 +31,7 @@ class LOTCompItem
 {
 public:
    LOTCompItem(LOTModel *model);
-   static LOTLayerItem * createLayerItem(LOTLayerData *layerData);
+   static std::unique_ptr<LOTLayerItem> createLayerItem(LOTLayerData *layerData);
    bool update(int frameNo);
    void resize(const VSize &size);
    VSize size() const;
@@ -95,7 +95,6 @@ protected:
 class LOTCompLayerItem: public LOTLayerItem
 {
 public:
-   ~LOTCompLayerItem();
    LOTCompLayerItem(LOTLayerData *layerData);
    void renderList(std::vector<VDrawable *> &list)final;
    void updateStaticProperty() final;
@@ -103,7 +102,7 @@ public:
 protected:
    void updateContent() final;
 private:
-   std::vector<LOTLayerItem *>                  mLayers;
+   std::vector<std::unique_ptr<LOTLayerItem>>   mLayers;
    int                                          mLastFrame;
 };