mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-05 14:02:48 +00:00
lottie: reuse path for reducing constructor/destructor calls from getPath()/toPath()
It helps to improve performance by avoiding constructor/destructor calls. The getPath function is renamed to updatePath function. And it does not return VPath anymore. Change-Id: I6e6cc52ec3f1560aac2ee0633cdf5a8c224dcc6e
This commit is contained in:
parent
4b823247bd
commit
b9fe04a251
@ -172,10 +172,10 @@ void LOTMaskItem::update(int frameNo, const VMatrix &parentMatrix,
|
||||
{
|
||||
if (mData->mShape.isStatic()) {
|
||||
if (mLocalPath.isEmpty()) {
|
||||
mLocalPath = mData->mShape.value(frameNo).toPath();
|
||||
mData->mShape.value(frameNo).toPath(mLocalPath);
|
||||
}
|
||||
} else {
|
||||
mLocalPath = mData->mShape.value(frameNo).toPath();
|
||||
mData->mShape.value(frameNo).toPath(mLocalPath);
|
||||
}
|
||||
float opacity = mData->opacity(frameNo);
|
||||
opacity = opacity * parentAlpha;
|
||||
@ -670,7 +670,7 @@ void LOTPathDataItem::update(int frameNo, const VMatrix &parentMatrix,
|
||||
|
||||
// 1. update the local path if needed
|
||||
if (!(mInit && mStaticPath)) {
|
||||
mLocalPath = getPath(frameNo);
|
||||
updatePath(mLocalPath, frameNo);
|
||||
mInit = true;
|
||||
mPathChanged = true;
|
||||
}
|
||||
@ -726,7 +726,7 @@ LOTRectItem::LOTRectItem(LOTRectData *data)
|
||||
{
|
||||
}
|
||||
|
||||
VPath LOTRectItem::getPath(int frameNo)
|
||||
void LOTRectItem::updatePath(VPath& path, int frameNo)
|
||||
{
|
||||
VPointF pos = mData->mPos.value(frameNo);
|
||||
VPointF size = mData->mSize.value(frameNo);
|
||||
@ -734,10 +734,8 @@ VPath LOTRectItem::getPath(int frameNo)
|
||||
VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
|
||||
size.y());
|
||||
|
||||
VPath path;
|
||||
path.reset();
|
||||
path.addRoundRect(r, radius, radius, mData->direction());
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
LOTEllipseItem::LOTEllipseItem(LOTEllipseData *data)
|
||||
@ -745,17 +743,15 @@ LOTEllipseItem::LOTEllipseItem(LOTEllipseData *data)
|
||||
{
|
||||
}
|
||||
|
||||
VPath LOTEllipseItem::getPath(int frameNo)
|
||||
void LOTEllipseItem::updatePath(VPath& path, int frameNo)
|
||||
{
|
||||
VPointF pos = mData->mPos.value(frameNo);
|
||||
VPointF size = mData->mSize.value(frameNo);
|
||||
VRectF r(pos.x() - size.x() / 2, pos.y() - size.y() / 2, size.x(),
|
||||
size.y());
|
||||
|
||||
VPath path;
|
||||
path.reset();
|
||||
path.addOval(r, mData->direction());
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
LOTShapeItem::LOTShapeItem(LOTShapeData *data)
|
||||
@ -763,9 +759,9 @@ LOTShapeItem::LOTShapeItem(LOTShapeData *data)
|
||||
{
|
||||
}
|
||||
|
||||
VPath LOTShapeItem::getPath(int frameNo)
|
||||
void LOTShapeItem::updatePath(VPath& path, int frameNo)
|
||||
{
|
||||
return mData->mShape.value(frameNo).toPath();
|
||||
mData->mShape.value(frameNo).toPath(path);
|
||||
}
|
||||
|
||||
LOTPolystarItem::LOTPolystarItem(LOTPolystarData *data)
|
||||
@ -773,7 +769,7 @@ LOTPolystarItem::LOTPolystarItem(LOTPolystarData *data)
|
||||
{
|
||||
}
|
||||
|
||||
VPath LOTPolystarItem::getPath(int frameNo)
|
||||
void LOTPolystarItem::updatePath(VPath& path, int frameNo)
|
||||
{
|
||||
VPointF pos = mData->mPos.value(frameNo);
|
||||
float points = mData->mPointCount.value(frameNo);
|
||||
@ -783,7 +779,7 @@ VPath LOTPolystarItem::getPath(int frameNo)
|
||||
float outerRoundness = mData->mOuterRoundness.value(frameNo);
|
||||
float rotation = mData->mRotation.value(frameNo);
|
||||
|
||||
VPath path;
|
||||
path.reset();
|
||||
VMatrix m;
|
||||
|
||||
if (mData->mType == LOTPolystarData::PolyType::Star) {
|
||||
@ -797,8 +793,6 @@ VPath LOTPolystarItem::getPath(int frameNo)
|
||||
m.translate(pos.x(), pos.y()).rotate(rotation);
|
||||
m.rotate(rotation);
|
||||
path.transform(m);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -225,7 +225,7 @@ private:
|
||||
bool mPathChanged;
|
||||
float mCombinedAlpha;
|
||||
protected:
|
||||
virtual VPath getPath(int frameNo) = 0;
|
||||
virtual void updatePath(VPath& path, int frameNo) = 0;
|
||||
};
|
||||
|
||||
class LOTRectItem: public LOTPathDataItem
|
||||
@ -233,7 +233,7 @@ class LOTRectItem: public LOTPathDataItem
|
||||
public:
|
||||
LOTRectItem(LOTRectData *data);
|
||||
protected:
|
||||
VPath getPath(int frameNo) final;
|
||||
void updatePath(VPath& path, int frameNo) final;
|
||||
LOTRectData *mData;
|
||||
};
|
||||
|
||||
@ -242,7 +242,7 @@ class LOTEllipseItem: public LOTPathDataItem
|
||||
public:
|
||||
LOTEllipseItem(LOTEllipseData *data);
|
||||
private:
|
||||
VPath getPath(int frameNo) final;
|
||||
void updatePath(VPath& path, int frameNo) final;
|
||||
LOTEllipseData *mData;
|
||||
};
|
||||
|
||||
@ -251,7 +251,7 @@ class LOTShapeItem: public LOTPathDataItem
|
||||
public:
|
||||
LOTShapeItem(LOTShapeData *data);
|
||||
private:
|
||||
VPath getPath(int frameNo) final;
|
||||
void updatePath(VPath& path, int frameNo) final;
|
||||
LOTShapeData *mData;
|
||||
};
|
||||
|
||||
@ -260,7 +260,7 @@ class LOTPolystarItem: public LOTPathDataItem
|
||||
public:
|
||||
LOTPolystarItem(LOTPolystarData *data);
|
||||
private:
|
||||
VPath getPath(int frameNo) final;
|
||||
void updatePath(VPath& path, int frameNo) final;
|
||||
LOTPolystarData *mData;
|
||||
};
|
||||
|
||||
|
||||
@ -106,10 +106,11 @@ public:
|
||||
void reserve(int size) {
|
||||
mPoints.reserve(mPoints.size() + size);
|
||||
}
|
||||
VPath toPath() const{
|
||||
if (mPoints.empty()) return VPath();
|
||||
void toPath(VPath& path) {
|
||||
path.reset();
|
||||
|
||||
if (mPoints.empty()) return;
|
||||
|
||||
VPath path;
|
||||
int size = mPoints.size();
|
||||
const VPointF *points = mPoints.data();
|
||||
/* reserve exact memory requirement at once
|
||||
@ -123,8 +124,6 @@ public:
|
||||
}
|
||||
if (mClosed)
|
||||
path.close();
|
||||
|
||||
return path;
|
||||
}
|
||||
public:
|
||||
std::vector<VPointF> mPoints;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user