From c12a9916a5c98a3c7fa544088b3db9a5b8297fcb Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Tue, 21 Aug 2018 10:06:27 +0900 Subject: [PATCH] lottie:convert remaining raw pointer to unique_ptr. Change-Id: If85e7b8ffbbacd2cd305e6a3ef6d98ccd8ed7172 --- src/lottie/lottieitem.cpp | 58 ++++++++++++++++------------------------------- src/lottie/lottieitem.h | 25 +++++++++----------- 2 files changed, 31 insertions(+), 52 deletions(-) diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index cab0264..253e59b 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -231,13 +231,7 @@ VRle LOTLayerItem::maskRle(const VRect &clipRect) return rle; } -LOTLayerItem::LOTLayerItem(LOTLayerData *layerData) - : mLayerData(layerData), - mParentLayer(nullptr), - mPrecompLayer(nullptr), - mCombinedAlpha(0.0f), - mFrameNo(-1), - mDirtyFlag(DirtyFlagBit::All) +LOTLayerItem::LOTLayerItem(LOTLayerData *layerData): mLayerData(layerData) { if (mLayerData->mHasMask) { for (auto &i : mLayerData->mMasks) { @@ -457,63 +451,59 @@ void LOTNullLayerItem::updateContent() {} LOTShapeLayerItem::LOTShapeLayerItem(LOTLayerData *layerData) : LOTLayerItem(layerData) { - mRoot = new LOTContentGroupItem(nullptr); + mRoot = std::make_unique(nullptr); mRoot->addChildren(layerData); mRoot->processPaintOperation(); if (layerData->hasPathOperator()) mRoot->processTrimOperation(); } -LOTShapeLayerItem::~LOTShapeLayerItem() -{ - delete mRoot; -} - -LOTContentItem *LOTShapeLayerItem::createContentItem(LOTData *contentData) +std::unique_ptr +LOTShapeLayerItem::createContentItem(LOTData *contentData) { switch (contentData->type()) { case LOTData::Type::ShapeGroup: { - return new LOTContentGroupItem( + return std::make_unique( static_cast(contentData)); break; } case LOTData::Type::Rect: { - return new LOTRectItem(static_cast(contentData)); + return std::make_unique(static_cast(contentData)); break; } case LOTData::Type::Ellipse: { - return new LOTEllipseItem(static_cast(contentData)); + return std::make_unique(static_cast(contentData)); break; } case LOTData::Type::Shape: { - return new LOTShapeItem(static_cast(contentData)); + return std::make_unique(static_cast(contentData)); break; } case LOTData::Type::Polystar: { - return new LOTPolystarItem(static_cast(contentData)); + return std::make_unique(static_cast(contentData)); break; } case LOTData::Type::Fill: { - return new LOTFillItem(static_cast(contentData)); + return std::make_unique(static_cast(contentData)); break; } case LOTData::Type::GFill: { - return new LOTGFillItem(static_cast(contentData)); + return std::make_unique(static_cast(contentData)); break; } case LOTData::Type::Stroke: { - return new LOTStrokeItem(static_cast(contentData)); + return std::make_unique(static_cast(contentData)); break; } case LOTData::Type::GStroke: { - return new LOTGStrokeItem(static_cast(contentData)); + return std::make_unique(static_cast(contentData)); break; } case LOTData::Type::Repeater: { - return new LOTRepeaterItem(static_cast(contentData)); + return std::make_unique(static_cast(contentData)); break; } case LOTData::Type::Trim: { - return new LOTTrimItem(static_cast(contentData)); + return std::make_unique(static_cast(contentData)); break; } default: @@ -542,17 +532,9 @@ void LOTContentGroupItem::addChildren(LOTGroupData *data) { if (!data) return; - for (auto i : data->mChildren) { - LOTData * data = i.get(); - LOTContentItem *content = LOTShapeLayerItem::createContentItem(data); - if (content) mContents.push_back(content); - } -} - -LOTContentGroupItem::~LOTContentGroupItem() -{ - for (auto i : mContents) { - delete i; + for (auto &i : data->mChildren) { + auto content = LOTShapeLayerItem::createContentItem(i.get()); + if (content) mContents.push_back(std::move(content)); } } @@ -601,7 +583,7 @@ void LOTContentGroupItem::paintOperationHelper( { int curOpCount = list.size(); for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) { - auto child = *i; + auto child = (*i).get(); if (auto pathNode = dynamic_cast(child)) { // the node is a path data node add the paint operation list to it. pathNode->addPaintOperation(list, curOpCount); @@ -638,7 +620,7 @@ void LOTContentGroupItem::trimOperationHelper(std::vector &list) { int curOpCount = list.size(); for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) { - auto child = *i; + auto child = (*i).get(); if (auto pathNode = dynamic_cast(child)) { // the node is a path data node add the trim operation list to it. pathNode->addTrimOperation(list); diff --git a/src/lottie/lottieitem.h b/src/lottie/lottieitem.h index 2cf17b4..6dc0385 100644 --- a/src/lottie/lottieitem.h +++ b/src/lottie/lottieitem.h @@ -81,14 +81,13 @@ protected: protected: std::vector mDrawableList; std::vector> mMasks; - LOTLayerData *mLayerData; - LOTLayerItem *mParentLayer; - LOTLayerItem *mPrecompLayer; - VMatrix mCombinedMatrix; - float mCombinedAlpha; - int mFrameNo; - DirtyFlag mDirtyFlag; - bool mVisible; + LOTLayerData *mLayerData{nullptr}; + LOTLayerItem *mParentLayer{nullptr}; + LOTLayerItem *mPrecompLayer{nullptr}; + VMatrix mCombinedMatrix; + float mCombinedAlpha{0.0}; + int mFrameNo{-1}; + DirtyFlag mDirtyFlag{DirtyFlagBit::All}; bool mStatic; }; @@ -122,13 +121,12 @@ class LOTContentGroupItem; class LOTShapeLayerItem: public LOTLayerItem { public: - ~LOTShapeLayerItem(); LOTShapeLayerItem(LOTLayerData *layerData); - static LOTContentItem * createContentItem(LOTData *contentData); + static std::unique_ptr createContentItem(LOTData *contentData); void renderList(std::vector &list)final; protected: void updateContent() final; - LOTContentGroupItem *mRoot; + std::unique_ptr mRoot; }; class LOTNullLayerItem: public LOTLayerItem @@ -189,7 +187,6 @@ public: class LOTContentGroupItem: public LOTContentItem { public: - ~LOTContentGroupItem(); LOTContentGroupItem(LOTShapeGroupData *data); void addChildren(LOTGroupData *data); void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final; @@ -199,8 +196,8 @@ public: private: void paintOperationHelper(std::vector &list); void trimOperationHelper(std::vector &list); - LOTShapeGroupData *mData; - std::vector mContents; + LOTShapeGroupData *mData; + std::vector> mContents; }; class LOTPathDataItem : public LOTContentItem -- 2.7.4