From 7808620764c6bc88d0dd54df6bbd0af53ae7fee5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 9 Apr 2019 13:03:17 +0400 Subject: [PATCH] Queue only one update call in animations manager. --- .../SourceFiles/ui/effects/animations.cpp | 20 +++++++++++++++---- Telegram/SourceFiles/ui/effects/animations.h | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/ui/effects/animations.cpp b/Telegram/SourceFiles/ui/effects/animations.cpp index 1f1c83697b..96d7fbbb1c 100644 --- a/Telegram/SourceFiles/ui/effects/animations.cpp +++ b/Telegram/SourceFiles/ui/effects/animations.cpp @@ -118,17 +118,25 @@ void Manager::update() { } void Manager::updateQueued() { - InvokeQueued(this, [=] { update(); }); + Expects(_timerId == 0); + + _timerId = -1; + crl::on_main(delayedCallGuard(), [=] { + Expects(_timerId < 0); + + _timerId = 0; + update(); + }); } void Manager::schedule() { - if (_scheduled) { + if (_scheduled || _timerId < 0) { return; } stopTimer(); _scheduled = true; - Ui::PostponeCall(static_cast(this), [=] { + Ui::PostponeCall(delayedCallGuard(), [=] { _scheduled = false; if (_forceImmediateUpdate) { _forceImmediateUpdate = false; @@ -145,8 +153,12 @@ void Manager::schedule() { }); } +not_null Manager::delayedCallGuard() const { + return static_cast(this); +} + void Manager::stopTimer() { - if (_timerId) { + if (_timerId > 0) { killTimer(base::take(_timerId)); } } diff --git a/Telegram/SourceFiles/ui/effects/animations.h b/Telegram/SourceFiles/ui/effects/animations.h index 38c147a43c..c5dee8b6df 100644 --- a/Telegram/SourceFiles/ui/effects/animations.h +++ b/Telegram/SourceFiles/ui/effects/animations.h @@ -158,6 +158,7 @@ private: void schedule(); void updateQueued(); void stopTimer(); + not_null delayedCallGuard() const; crl::time _lastUpdateTime = 0; int _timerId = 0;