From 79283c28b1e845a746a855ded2ea56930bbc28c0 Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Tue, 27 Nov 2018 11:28:27 +0900 Subject: [PATCH] lottie: Make path dirty only when it has changed from last frame. Change-Id: I827baef9bac182a25aa98479108307d03c45f5ce --- src/lottie/lottieitem.h | 13 ++++++++++++- src/lottie/lottiemodel.h | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lottie/lottieitem.h b/src/lottie/lottieitem.h index a92dd8d..5749f38 100644 --- a/src/lottie/lottieitem.h +++ b/src/lottie/lottieitem.h @@ -311,9 +311,20 @@ class LOTShapeItem: public LOTPathDataItem public: LOTShapeItem(LOTShapeData *data); private: + struct Cache { + int mFrameNo{-1}; + }; + Cache mCache; void updatePath(VPath& path, int frameNo) final; LOTShapeData *mData; - bool hasChanged(int) final { return true; } + bool hasChanged(int frameNo) final { + int prevFrame = mCache.mFrameNo; + mCache.mFrameNo = frameNo; + if (prevFrame == -1) return true; + if (prevFrame == frameNo) return false; + + return mData->mShape.changed(prevFrame, frameNo); + } }; class LOTPolystarItem: public LOTPathDataItem diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index 01ab083..da6502d 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -226,6 +226,18 @@ public: return 0; } + bool changed(int prevFrame, int curFrame) { + int first = mKeyFrames.front().mStartFrame; + int last = mKeyFrames.back().mEndFrame; + + if ((first > prevFrame && first > curFrame) || + (last < prevFrame && last < curFrame)) { + return false; + } + + return true; + } + public: std::vector> mKeyFrames; }; @@ -243,6 +255,9 @@ public: float angle(int frameNo) const { return isStatic() ? 0 : mAnimInfo->angle(frameNo); } + bool changed(int prevFrame, int curFrame) { + return isStatic() ? false : mAnimInfo->changed(prevFrame, curFrame); + } public: T mValue; int mPropertyIndex; /* "ix" */ -- 2.34.1