diff --git a/Telegram/SourceFiles/lottie/lottie_frame_renderer.cpp b/Telegram/SourceFiles/lottie/lottie_frame_renderer.cpp index 7ad3f20853..11eea316e8 100644 --- a/Telegram/SourceFiles/lottie/lottie_frame_renderer.cpp +++ b/Telegram/SourceFiles/lottie/lottie_frame_renderer.cpp @@ -47,7 +47,9 @@ public: explicit FrameRendererObject( crl::weak_on_queue weak); - void append(std::unique_ptr entry); + void append( + std::unique_ptr entry, + const FrameRequest &request); void frameShown(); void updateFrameRequest( not_null entry, @@ -132,10 +134,10 @@ FrameRendererObject::FrameRendererObject( : _weak(std::move(weak)) { } -void FrameRendererObject::append(std::unique_ptr state) { - _entries.push_back({ std::move(state) }); - auto &entry = _entries.back(); - entry.request = entry.state->frameForPaint()->request; +void FrameRendererObject::append( + std::unique_ptr state, + const FrameRequest &request) { + _entries.push_back({ std::move(state), request }); queueGenerateFrames(); } @@ -537,10 +539,12 @@ std::shared_ptr FrameRenderer::Instance() { return result; } -void FrameRenderer::append(std::unique_ptr entry) { - _wrapped.with([entry = std::move(entry)]( +void FrameRenderer::append( + std::unique_ptr entry, + const FrameRequest &request) { + _wrapped.with([=, entry = std::move(entry)]( FrameRendererObject &unwrapped) mutable { - unwrapped.append(std::move(entry)); + unwrapped.append(std::move(entry), request); }); } diff --git a/Telegram/SourceFiles/lottie/lottie_frame_renderer.h b/Telegram/SourceFiles/lottie/lottie_frame_renderer.h index ed634a55cd..07d0ae90d5 100644 --- a/Telegram/SourceFiles/lottie/lottie_frame_renderer.h +++ b/Telegram/SourceFiles/lottie/lottie_frame_renderer.h @@ -131,7 +131,9 @@ public: static std::shared_ptr CreateIndependent(); static std::shared_ptr Instance(); - void append(std::unique_ptr entry); + void append( + std::unique_ptr entry, + const FrameRequest &request); void updateFrameRequest( not_null entry, diff --git a/Telegram/SourceFiles/lottie/lottie_multi_player.cpp b/Telegram/SourceFiles/lottie/lottie_multi_player.cpp index 7b3144dd06..6c650cdcae 100644 --- a/Telegram/SourceFiles/lottie/lottie_multi_player.cpp +++ b/Telegram/SourceFiles/lottie/lottie_multi_player.cpp @@ -71,8 +71,8 @@ void MultiPlayer::startAtRightTime(std::unique_ptr state) { lastSyncTime, _delay); state->start(this, _started, _delay, frameIndex); - - _renderer->append(std::move(state)); + const auto request = state->frameForPaint()->request; + _renderer->append(std::move(state), request); } int MultiPlayer::countFrameIndex( @@ -323,20 +323,22 @@ void MultiPlayer::checkNextFrameRender() { void MultiPlayer::updateFrameRequest( not_null animation, const FrameRequest &request) { - const auto state = [&] { + const auto state = [&]() -> Lottie::SharedState* { const auto key = animation; if (const auto i = _active.find(animation); i != end(_active)) { - return i->second.get(); + return i->second; } else if (const auto j = _paused.find(animation); j != end(_paused)) { - return j->second.state.get(); + return j->second.state; } else if (const auto k = _pendingToStart.find(animation); k != end(_pendingToStart)) { - return k->second.state.get(); + return nullptr; } Unexpected("Animation in MultiPlayer::updateFrameRequest."); }(); - _renderer->updateFrameRequest(state, request); + if (state) { + _renderer->updateFrameRequest(state, request); + } } void MultiPlayer::markFrameDisplayed(crl::time now) { diff --git a/Telegram/SourceFiles/lottie/lottie_single_player.cpp b/Telegram/SourceFiles/lottie/lottie_single_player.cpp index 956c4c62d1..849f7bd6c0 100644 --- a/Telegram/SourceFiles/lottie/lottie_single_player.cpp +++ b/Telegram/SourceFiles/lottie/lottie_single_player.cpp @@ -45,7 +45,8 @@ void SinglePlayer::start( _state = state.get(); auto information = state->information(); state->start(this, crl::now()); - _renderer->append(std::move(state)); + const auto request = state->frameForPaint()->request; + _renderer->append(std::move(state), request); _updates.fire({ std::move(information) }); crl::on_main_update_requests(