lottie:convert remaining raw pointer to unique_ptr.

Change-Id: If85e7b8ffbbacd2cd305e6a3ef6d98ccd8ed7172
This commit is contained in:
subhransu mohanty 2018-08-21 10:06:27 +09:00 committed by Subhransu Mohanty
parent ded7532e57
commit c12a9916a5
2 changed files with 31 additions and 52 deletions

View File

@ -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<LOTContentGroupItem>(nullptr);
mRoot->addChildren(layerData);
mRoot->processPaintOperation();
if (layerData->hasPathOperator()) mRoot->processTrimOperation();
}
LOTShapeLayerItem::~LOTShapeLayerItem()
{
delete mRoot;
}
LOTContentItem *LOTShapeLayerItem::createContentItem(LOTData *contentData)
std::unique_ptr<LOTContentItem>
LOTShapeLayerItem::createContentItem(LOTData *contentData)
{
switch (contentData->type()) {
case LOTData::Type::ShapeGroup: {
return new LOTContentGroupItem(
return std::make_unique<LOTContentGroupItem>(
static_cast<LOTShapeGroupData *>(contentData));
break;
}
case LOTData::Type::Rect: {
return new LOTRectItem(static_cast<LOTRectData *>(contentData));
return std::make_unique<LOTRectItem>(static_cast<LOTRectData *>(contentData));
break;
}
case LOTData::Type::Ellipse: {
return new LOTEllipseItem(static_cast<LOTEllipseData *>(contentData));
return std::make_unique<LOTEllipseItem>(static_cast<LOTEllipseData *>(contentData));
break;
}
case LOTData::Type::Shape: {
return new LOTShapeItem(static_cast<LOTShapeData *>(contentData));
return std::make_unique<LOTShapeItem>(static_cast<LOTShapeData *>(contentData));
break;
}
case LOTData::Type::Polystar: {
return new LOTPolystarItem(static_cast<LOTPolystarData *>(contentData));
return std::make_unique<LOTPolystarItem>(static_cast<LOTPolystarData *>(contentData));
break;
}
case LOTData::Type::Fill: {
return new LOTFillItem(static_cast<LOTFillData *>(contentData));
return std::make_unique<LOTFillItem>(static_cast<LOTFillData *>(contentData));
break;
}
case LOTData::Type::GFill: {
return new LOTGFillItem(static_cast<LOTGFillData *>(contentData));
return std::make_unique<LOTGFillItem>(static_cast<LOTGFillData *>(contentData));
break;
}
case LOTData::Type::Stroke: {
return new LOTStrokeItem(static_cast<LOTStrokeData *>(contentData));
return std::make_unique<LOTStrokeItem>(static_cast<LOTStrokeData *>(contentData));
break;
}
case LOTData::Type::GStroke: {
return new LOTGStrokeItem(static_cast<LOTGStrokeData *>(contentData));
return std::make_unique<LOTGStrokeItem>(static_cast<LOTGStrokeData *>(contentData));
break;
}
case LOTData::Type::Repeater: {
return new LOTRepeaterItem(static_cast<LOTRepeaterData *>(contentData));
return std::make_unique<LOTRepeaterItem>(static_cast<LOTRepeaterData *>(contentData));
break;
}
case LOTData::Type::Trim: {
return new LOTTrimItem(static_cast<LOTTrimData *>(contentData));
return std::make_unique<LOTTrimItem>(static_cast<LOTTrimData *>(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<LOTPathDataItem *>(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<LOTTrimItem *> &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<LOTPathDataItem *>(child)) {
// the node is a path data node add the trim operation list to it.
pathNode->addTrimOperation(list);

View File

@ -81,14 +81,13 @@ protected:
protected:
std::vector<VDrawable *> mDrawableList;
std::vector<std::unique_ptr<LOTMaskItem>> 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<LOTContentItem> createContentItem(LOTData *contentData);
void renderList(std::vector<VDrawable *> &list)final;
protected:
void updateContent() final;
LOTContentGroupItem *mRoot;
std::unique_ptr<LOTContentGroupItem> 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<LOTPaintDataItem *> &list);
void trimOperationHelper(std::vector<LOTTrimItem *> &list);
LOTShapeGroupData *mData;
std::vector<LOTContentItem *> mContents;
LOTShapeGroupData *mData;
std::vector<std::unique_ptr<LOTContentItem>> mContents;
};
class LOTPathDataItem : public LOTContentItem