mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 14:15:38 +00:00
Fixed a frame caching issue in LottieComponent.
This commit is contained in:
parent
c3dbdd431c
commit
5a085c585e
|
@ -33,6 +33,7 @@ LottieComponent::LottieComponent(Window* window)
|
||||||
, mSpeedModifier{1.0f}
|
, mSpeedModifier{1.0f}
|
||||||
, mTargetPacing{0}
|
, mTargetPacing{0}
|
||||||
, mTimeAccumulator{0}
|
, mTimeAccumulator{0}
|
||||||
|
, mLastRenderedFrame{-1}
|
||||||
, mSkippedFrames{0}
|
, mSkippedFrames{0}
|
||||||
, mHoldFrame{false}
|
, mHoldFrame{false}
|
||||||
, mPause{false}
|
, mPause{false}
|
||||||
|
@ -84,6 +85,7 @@ void LottieComponent::setAnimation(const std::string& path)
|
||||||
mAnimation.reset();
|
mAnimation.reset();
|
||||||
mPictureRGBA.clear();
|
mPictureRGBA.clear();
|
||||||
mCacheSize = 0;
|
mCacheSize = 0;
|
||||||
|
mLastRenderedFrame = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mPath = path;
|
mPath = path;
|
||||||
|
@ -192,8 +194,12 @@ void LottieComponent::resetFileAnimation()
|
||||||
mTimeAccumulator = 0;
|
mTimeAccumulator = 0;
|
||||||
mFrameNum = mStartDirection == "reverse" ? mTotalFrames - 1 : 0;
|
mFrameNum = mStartDirection == "reverse" ? mTotalFrames - 1 : 0;
|
||||||
|
|
||||||
if (mAnimation != nullptr)
|
if (mAnimation != nullptr) {
|
||||||
|
if (mFuture.valid())
|
||||||
|
mFuture.get();
|
||||||
mFuture = mAnimation->render(mFrameNum, *mSurface, mKeepAspectRatio);
|
mFuture = mAnimation->render(mFrameNum, *mSurface, mKeepAspectRatio);
|
||||||
|
mLastRenderedFrame = mFrameNum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LottieComponent::onSizeChanged()
|
void LottieComponent::onSizeChanged()
|
||||||
|
@ -393,13 +399,15 @@ void LottieComponent::render(const glm::mat4& parentTrans)
|
||||||
// Cache frame if caching is enabled and we're not exceeding either the per-file
|
// Cache frame if caching is enabled and we're not exceeding either the per-file
|
||||||
// max cache size or the total cache size. Note that this is completely unrelated
|
// max cache size or the total cache size. Note that this is completely unrelated
|
||||||
// to the texture caching used for images.
|
// to the texture caching used for images.
|
||||||
if (mCacheFrames && mFrameCache.find(mFrameNum) == mFrameCache.end()) {
|
if (mCacheFrames && mLastRenderedFrame != -1 &&
|
||||||
|
mFrameCache.find(mLastRenderedFrame) == mFrameCache.end()) {
|
||||||
size_t newCacheSize = mCacheSize + mFrameSize;
|
size_t newCacheSize = mCacheSize + mFrameSize;
|
||||||
if (newCacheSize < mMaxCacheSize &&
|
if (newCacheSize < mMaxCacheSize &&
|
||||||
mTotalFrameCache + mFrameSize < mMaxTotalFrameCache) {
|
mTotalFrameCache + mFrameSize < mMaxTotalFrameCache) {
|
||||||
mFrameCache[mFrameNum] = mPictureRGBA;
|
mFrameCache[mLastRenderedFrame] = mPictureRGBA;
|
||||||
mCacheSize += mFrameSize;
|
mCacheSize += mFrameSize;
|
||||||
mTotalFrameCache += mFrameSize;
|
mTotalFrameCache += mFrameSize;
|
||||||
|
mLastRenderedFrame = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,8 +445,10 @@ void LottieComponent::render(const glm::mat4& parentTrans)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (renderNextFrame && !mHoldFrame)
|
if (renderNextFrame && !mHoldFrame) {
|
||||||
mFuture = mAnimation->render(mFrameNum, *mSurface, mKeepAspectRatio);
|
mFuture = mAnimation->render(mFrameNum, *mSurface, mKeepAspectRatio);
|
||||||
|
mLastRenderedFrame = mFrameNum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::setMatrix(trans);
|
Renderer::setMatrix(trans);
|
||||||
|
|
|
@ -71,6 +71,7 @@ private:
|
||||||
float mSpeedModifier;
|
float mSpeedModifier;
|
||||||
int mTargetPacing;
|
int mTargetPacing;
|
||||||
int mTimeAccumulator;
|
int mTimeAccumulator;
|
||||||
|
int mLastRenderedFrame;
|
||||||
int mSkippedFrames;
|
int mSkippedFrames;
|
||||||
|
|
||||||
bool mHoldFrame;
|
bool mHoldFrame;
|
||||||
|
|
Loading…
Reference in a new issue