Frame advances no longer take place for GIF and Lottie animations unless update() has been called.

This commit is contained in:
Leon Styhre 2022-09-26 19:00:59 +02:00
parent 1c10fb7466
commit 577ed366b4
2 changed files with 16 additions and 6 deletions

View file

@ -37,7 +37,7 @@ GIFAnimComponent::GIFAnimComponent()
, mTimeAccumulator {0} , mTimeAccumulator {0}
, mLastRenderedFrame {-1} , mLastRenderedFrame {-1}
, mSkippedFrames {0} , mSkippedFrames {0}
, mHoldFrame {false} , mHoldFrame {true}
, mPause {false} , mPause {false}
, mExternalPause {false} , mExternalPause {false}
, mAlternate {false} , mAlternate {false}
@ -344,7 +344,7 @@ void GIFAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
void GIFAnimComponent::update(int deltaTime) void GIFAnimComponent::update(int deltaTime)
{ {
if (!isVisible() || mThemeOpacity == 0.0f || mAnimation == nullptr) if (mAnimation == nullptr || !isVisible() || mOpacity == 0.0f || mThemeOpacity == 0.0f)
return; return;
if (mWindow->getAllowFileAnimation()) { if (mWindow->getAllowFileAnimation()) {
@ -356,6 +356,9 @@ void GIFAnimComponent::update(int deltaTime)
return; return;
} }
// Make sure no frames are advanced unless update() has been called.
mHoldFrame = false;
// If the time accumulator value is really high something must have happened such as the // If the time accumulator value is really high something must have happened such as the
// application having been suspended. Reset it to zero in this case as it would otherwise // application having been suspended. Reset it to zero in this case as it would otherwise
// never recover. // never recover.
@ -392,7 +395,7 @@ void GIFAnimComponent::update(int deltaTime)
void GIFAnimComponent::render(const glm::mat4& parentTrans) void GIFAnimComponent::render(const glm::mat4& parentTrans)
{ {
if (!isVisible() || mThemeOpacity == 0.0f || mAnimation == nullptr) if (mAnimation == nullptr || !isVisible() || mOpacity == 0.0f || mThemeOpacity == 0.0f)
return; return;
glm::mat4 trans {parentTrans * getTransform()}; glm::mat4 trans {parentTrans * getTransform()};
@ -498,4 +501,6 @@ void GIFAnimComponent::render(const glm::mat4& parentTrans)
// Render it. // Render it.
mRenderer->drawTriangleStrips(&vertices[0], 4); mRenderer->drawTriangleStrips(&vertices[0], 4);
} }
mHoldFrame = true;
} }

View file

@ -32,7 +32,7 @@ LottieAnimComponent::LottieAnimComponent()
, mTimeAccumulator {0} , mTimeAccumulator {0}
, mLastRenderedFrame {-1} , mLastRenderedFrame {-1}
, mSkippedFrames {0} , mSkippedFrames {0}
, mHoldFrame {false} , mHoldFrame {true}
, mPause {false} , mPause {false}
, mExternalPause {false} , mExternalPause {false}
, mAlternate {false} , mAlternate {false}
@ -298,7 +298,7 @@ void LottieAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
void LottieAnimComponent::update(int deltaTime) void LottieAnimComponent::update(int deltaTime)
{ {
if (mAnimation == nullptr) if (mAnimation == nullptr || !isVisible() || mOpacity == 0.0f || mThemeOpacity == 0.0f)
return; return;
if (mWindow->getAllowFileAnimation()) { if (mWindow->getAllowFileAnimation()) {
@ -310,6 +310,9 @@ void LottieAnimComponent::update(int deltaTime)
return; return;
} }
// Make sure no frames are advanced unless update() has been called.
mHoldFrame = false;
// If the time accumulator value is really high something must have happened such as the // If the time accumulator value is really high something must have happened such as the
// application having been suspended. Reset it to zero in this case as it would otherwise // application having been suspended. Reset it to zero in this case as it would otherwise
// never recover. // never recover.
@ -346,7 +349,7 @@ void LottieAnimComponent::update(int deltaTime)
void LottieAnimComponent::render(const glm::mat4& parentTrans) void LottieAnimComponent::render(const glm::mat4& parentTrans)
{ {
if (!isVisible() || mThemeOpacity == 0.0f || mAnimation == nullptr) if (mAnimation == nullptr || !isVisible() || mOpacity == 0.0f || mThemeOpacity == 0.0f)
return; return;
glm::mat4 trans {parentTrans * getTransform()}; glm::mat4 trans {parentTrans * getTransform()};
@ -489,4 +492,6 @@ void LottieAnimComponent::render(const glm::mat4& parentTrans)
// Render it. // Render it.
mRenderer->drawTriangleStrips(&vertices[0], 4); mRenderer->drawTriangleStrips(&vertices[0], 4);
} }
mHoldFrame = true;
} }