mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
lottie: refactor pathChange computation without keeping cache.
Change-Id: I14ed8b36e33dd5d4a20b632b26d329fde68ae55b
This commit is contained in:
@@ -794,7 +794,6 @@ void LOTRectItem::updatePath(VPath& path, int frameNo)
|
|||||||
|
|
||||||
path.reset();
|
path.reset();
|
||||||
path.addRoundRect(r, roundness, mData->direction());
|
path.addRoundRect(r, roundness, mData->direction());
|
||||||
updateCache(frameNo, pos, size, roundness);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOTEllipseItem::LOTEllipseItem(LOTEllipseData *data)
|
LOTEllipseItem::LOTEllipseItem(LOTEllipseData *data)
|
||||||
@@ -811,7 +810,6 @@ void LOTEllipseItem::updatePath(VPath& path, int frameNo)
|
|||||||
|
|
||||||
path.reset();
|
path.reset();
|
||||||
path.addOval(r, mData->direction());
|
path.addOval(r, mData->direction());
|
||||||
updateCache(frameNo, pos, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOTShapeItem::LOTShapeItem(LOTShapeData *data)
|
LOTShapeItem::LOTShapeItem(LOTShapeData *data)
|
||||||
@@ -853,8 +851,6 @@ void LOTPolystarItem::updatePath(VPath& path, int frameNo)
|
|||||||
m.translate(pos.x(), pos.y()).rotate(rotation);
|
m.translate(pos.x(), pos.y()).rotate(rotation);
|
||||||
m.rotate(rotation);
|
m.rotate(rotation);
|
||||||
path.transform(m);
|
path.transform(m);
|
||||||
updateCache(frameNo, pos, points, innerRadius, outerRadius,
|
|
||||||
innerRoundness, outerRoundness, rotation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -222,11 +222,20 @@ public:
|
|||||||
bool staticPath() const { return mStaticPath; }
|
bool staticPath() const { return mStaticPath; }
|
||||||
protected:
|
protected:
|
||||||
virtual void updatePath(VPath& path, int frameNo) = 0;
|
virtual void updatePath(VPath& path, int frameNo) = 0;
|
||||||
virtual bool hasChanged(int frameNo) = 0;
|
virtual bool hasChanged(int prevFrame, int curFrame) = 0;
|
||||||
private:
|
private:
|
||||||
|
bool hasChanged(int frameNo) {
|
||||||
|
int prevFrame = mFrameNo;
|
||||||
|
mFrameNo = frameNo;
|
||||||
|
if (prevFrame == -1) return true;
|
||||||
|
if (mStaticPath ||
|
||||||
|
(prevFrame == frameNo)) return false;
|
||||||
|
return hasChanged(prevFrame, frameNo);
|
||||||
|
}
|
||||||
VPath mLocalPath;
|
VPath mLocalPath;
|
||||||
VPath mTemp;
|
VPath mTemp;
|
||||||
VPath mFinalPath;
|
VPath mFinalPath;
|
||||||
|
int mFrameNo{-1};
|
||||||
bool mPathChanged{true};
|
bool mPathChanged{true};
|
||||||
bool mNeedUpdate{true};
|
bool mNeedUpdate{true};
|
||||||
bool mStaticPath;
|
bool mStaticPath;
|
||||||
@@ -240,34 +249,10 @@ protected:
|
|||||||
void updatePath(VPath& path, int frameNo) final;
|
void updatePath(VPath& path, int frameNo) final;
|
||||||
LOTRectData *mData;
|
LOTRectData *mData;
|
||||||
|
|
||||||
struct Cache {
|
bool hasChanged(int prevFrame, int curFrame) final {
|
||||||
int mFrameNo{-1};
|
return (mData->mPos.changed(prevFrame, curFrame) ||
|
||||||
float mRoundness;
|
mData->mSize.changed(prevFrame, curFrame) ||
|
||||||
VPointF mPos;
|
mData->mRound.changed(prevFrame, curFrame)) ? true : false;
|
||||||
VPointF mSize;
|
|
||||||
};
|
|
||||||
Cache mCache;
|
|
||||||
|
|
||||||
void updateCache(int frameNo, VPointF pos, VPointF size, float roundness) {
|
|
||||||
mCache.mFrameNo = frameNo;
|
|
||||||
mCache.mPos = pos;
|
|
||||||
mCache.mSize = size;
|
|
||||||
mCache.mRoundness = roundness;
|
|
||||||
}
|
|
||||||
bool hasChanged(int frameNo) final {
|
|
||||||
if (mCache.mFrameNo != -1 && staticPath()) return false;
|
|
||||||
if (mCache.mFrameNo == frameNo) return false;
|
|
||||||
|
|
||||||
VPointF pos = mData->mPos.value(frameNo);
|
|
||||||
VPointF size = mData->mSize.value(frameNo);
|
|
||||||
float roundness = mData->mRound.value(frameNo);
|
|
||||||
|
|
||||||
if (vCompare(mCache.mPos.x(), pos.x()) && vCompare(mCache.mPos.y(), pos.y()) &&
|
|
||||||
vCompare(mCache.mSize.x(), size.x()) && vCompare(mCache.mSize.y(), size.y()) &&
|
|
||||||
vCompare(mCache.mRoundness, roundness))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -278,31 +263,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
void updatePath(VPath& path, int frameNo) final;
|
void updatePath(VPath& path, int frameNo) final;
|
||||||
LOTEllipseData *mData;
|
LOTEllipseData *mData;
|
||||||
|
bool hasChanged(int prevFrame, int curFrame) final {
|
||||||
struct Cache {
|
return (mData->mPos.changed(prevFrame, curFrame) ||
|
||||||
int mFrameNo{-1};
|
mData->mSize.changed(prevFrame, curFrame)) ? true : false;
|
||||||
VPointF mPos;
|
|
||||||
VPointF mSize;
|
|
||||||
};
|
|
||||||
Cache mCache;
|
|
||||||
|
|
||||||
void updateCache(int frameNo, VPointF pos, VPointF size) {
|
|
||||||
mCache.mFrameNo = frameNo;
|
|
||||||
mCache.mPos = pos;
|
|
||||||
mCache.mSize = size;
|
|
||||||
}
|
|
||||||
bool hasChanged(int frameNo) final {
|
|
||||||
if (mCache.mFrameNo != -1 && staticPath()) return false;
|
|
||||||
if (mCache.mFrameNo == frameNo) return false;
|
|
||||||
|
|
||||||
VPointF pos = mData->mPos.value(frameNo);
|
|
||||||
VPointF size = mData->mSize.value(frameNo);
|
|
||||||
|
|
||||||
if (vCompare(mCache.mPos.x(), pos.x()) && vCompare(mCache.mPos.y(), pos.y()) &&
|
|
||||||
vCompare(mCache.mSize.x(), size.x()) && vCompare(mCache.mSize.y(), size.y()))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -311,19 +274,10 @@ class LOTShapeItem: public LOTPathDataItem
|
|||||||
public:
|
public:
|
||||||
LOTShapeItem(LOTShapeData *data);
|
LOTShapeItem(LOTShapeData *data);
|
||||||
private:
|
private:
|
||||||
struct Cache {
|
|
||||||
int mFrameNo{-1};
|
|
||||||
};
|
|
||||||
Cache mCache;
|
|
||||||
void updatePath(VPath& path, int frameNo) final;
|
void updatePath(VPath& path, int frameNo) final;
|
||||||
LOTShapeData *mData;
|
LOTShapeData *mData;
|
||||||
bool hasChanged(int frameNo) final {
|
bool hasChanged(int prevFrame, int curFrame) final {
|
||||||
int prevFrame = mCache.mFrameNo;
|
return mData->mShape.changed(prevFrame, curFrame);
|
||||||
mCache.mFrameNo = frameNo;
|
|
||||||
if (prevFrame == -1) return true;
|
|
||||||
if (prevFrame == frameNo) return false;
|
|
||||||
|
|
||||||
return mData->mShape.changed(prevFrame, frameNo);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -335,48 +289,14 @@ private:
|
|||||||
void updatePath(VPath& path, int frameNo) final;
|
void updatePath(VPath& path, int frameNo) final;
|
||||||
LOTPolystarData *mData;
|
LOTPolystarData *mData;
|
||||||
|
|
||||||
struct Cache {
|
bool hasChanged(int prevFrame, int curFrame) final {
|
||||||
int mFrameNo{-1};
|
return (mData->mPos.changed(prevFrame, curFrame) ||
|
||||||
VPointF mPos;
|
mData->mPointCount.changed(prevFrame, curFrame) ||
|
||||||
float mPoints{0};
|
mData->mInnerRadius.changed(prevFrame, curFrame) ||
|
||||||
float mInnerRadius{0};
|
mData->mOuterRadius.changed(prevFrame, curFrame) ||
|
||||||
float mOuterRadius{0};
|
mData->mInnerRoundness.changed(prevFrame, curFrame) ||
|
||||||
float mInnerRoundness{0};
|
mData->mOuterRoundness.changed(prevFrame, curFrame) ||
|
||||||
float mOuterRoundness{0};
|
mData->mRotation.changed(prevFrame, curFrame)) ? true : false;
|
||||||
float mRotation{0};
|
|
||||||
};
|
|
||||||
Cache mCache;
|
|
||||||
|
|
||||||
void updateCache(int frameNo, VPointF pos, float points, float innerRadius, float outerRadius,
|
|
||||||
float innerRoundness, float outerRoundness, float rotation) {
|
|
||||||
mCache.mFrameNo = frameNo;
|
|
||||||
mCache.mPos = pos;
|
|
||||||
mCache.mPoints = points;
|
|
||||||
mCache.mInnerRadius = innerRadius;
|
|
||||||
mCache.mOuterRadius = outerRadius;
|
|
||||||
mCache.mInnerRoundness = innerRoundness;
|
|
||||||
mCache.mOuterRoundness = outerRoundness;
|
|
||||||
mCache.mRotation = rotation;
|
|
||||||
}
|
|
||||||
bool hasChanged(int frameNo) final {
|
|
||||||
if (mCache.mFrameNo != -1 && staticPath()) return false;
|
|
||||||
if (mCache.mFrameNo == frameNo) return false;
|
|
||||||
|
|
||||||
VPointF pos = mData->mPos.value(frameNo);
|
|
||||||
float points = mData->mPointCount.value(frameNo);
|
|
||||||
float innerRadius = mData->mInnerRadius.value(frameNo);
|
|
||||||
float outerRadius = mData->mOuterRadius.value(frameNo);
|
|
||||||
float innerRoundness = mData->mInnerRoundness.value(frameNo);
|
|
||||||
float outerRoundness = mData->mOuterRoundness.value(frameNo);
|
|
||||||
float rotation = mData->mRotation.value(frameNo);
|
|
||||||
|
|
||||||
if (vCompare(mCache.mPos.x(), pos.x()) && vCompare(mCache.mPos.y(), pos.y()) &&
|
|
||||||
vCompare(mCache.mPoints, points) && vCompare(mCache.mRotation, rotation) &&
|
|
||||||
vCompare(mCache.mInnerRadius, innerRadius) && vCompare(mCache.mOuterRadius, outerRadius) &&
|
|
||||||
vCompare(mCache.mInnerRoundness, innerRoundness) && vCompare(mCache.mOuterRoundness, outerRoundness))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user