From dbdd9aa481f0e296ea9802475f97030fcdbdc7a4 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 11 Dec 2019 17:15:29 +0300 Subject: [PATCH] Stop GIFs that are far away from the screen. --- Telegram/SourceFiles/data/data_session.cpp | 9 ++++++--- .../SourceFiles/history/view/media/history_view_gif.cpp | 9 +++++---- .../SourceFiles/history/view/media/history_view_gif.h | 4 ++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index 49d982706..ec79b54ad 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -1389,9 +1389,10 @@ void Session::unloadHeavyViewParts( if (_heavyViewParts.empty()) { return; } - const auto remove = ranges::count(_heavyViewParts, delegate, [](not_null element) { - return element->delegate(); - }); + const auto remove = ranges::count( + _heavyViewParts, + delegate, + [](not_null element) { return element->delegate(); }); if (remove == _heavyViewParts.size()) { for (const auto view : base::take(_heavyViewParts)) { view->unloadHeavyPart(); @@ -3225,10 +3226,12 @@ void Session::unregisterContactItem( void Session::registerPlayingVideoFile(not_null view) { _playingVideoFiles.emplace(view); + registerHeavyViewPart(view); } void Session::unregisterPlayingVideoFile(not_null view) { _playingVideoFiles.remove(view); + unregisterHeavyViewPart(view); } void Session::stopPlayingVideoFiles() { diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp index 32801fe2d..a91b189a0 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.cpp @@ -369,10 +369,11 @@ void Gif::draw(Painter &p, const QRect &r, TextSelection selection, crl::time ms } if (radial - || (!streamed - && !startPlayAsync - && ((_streamed && _streamed->player().failed()) - || (!_data->loaded() && !_data->loading()) + || (!startPlayAsync + && (!_streamed + || _streamed->waitingShown() + || _streamed->player().failed()) + && ((!_data->loaded() && !_data->loading()) || !autoplayEnabled()))) { auto radialOpacity = (radial && _data->loaded() && item->id > 0) ? _animation->radial.opacity() diff --git a/Telegram/SourceFiles/history/view/media/history_view_gif.h b/Telegram/SourceFiles/history/view/media/history_view_gif.h index 7632c1f85..adf7e35f7 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_gif.h +++ b/Telegram/SourceFiles/history/view/media/history_view_gif.h @@ -80,6 +80,10 @@ public: void parentTextUpdated() override; + void unloadHeavyPart() override { + stopAnimation(); + } + private: float64 dataProgress() const override; bool dataFinished() const override;