diff --git a/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp b/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp index ae3ccd078..c10c5e95c 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_lottie.cpp @@ -60,12 +60,11 @@ auto LottieFromDocument( Method &&method, not_null media, uint8 keyShift, - QSize box, - int cacheAreaLimit) { + QSize box) { const auto document = media->owner(); const auto data = media->bytes(); const auto filepath = document->filepath(); - if (box.width() * box.height() > cacheAreaLimit) { + if (box.width() * box.height() > kDontCacheLottieAfterArea) { // Don't use frame caching for large stickers. return method( Lottie::ReadContent(data, filepath), @@ -114,12 +113,9 @@ std::unique_ptr LottiePlayerFromDocument( replacements, std::move(renderer)); }; - const auto limit = (sizeTag == StickerLottieSize::EmojiInteraction) - ? (3 * kDontCacheLottieAfterArea) - : kDontCacheLottieAfterArea; const auto tag = replacements ? replacements->tag : uint8(0); const auto keyShift = ((tag << 4) & 0xF0) | (uint8(sizeTag) & 0x0F); - return LottieFromDocument(method, media, uint8(keyShift), box, limit); + return LottieFromDocument(method, media, uint8(keyShift), box); } not_null LottieAnimationFromDocument( @@ -130,8 +126,7 @@ not_null LottieAnimationFromDocument( const auto method = [&](auto &&...args) { return player->append(std::forward(args)...); }; - const auto limit = kDontCacheLottieAfterArea; - return LottieFromDocument(method, media, uint8(sizeTag), box, limit); + return LottieFromDocument(method, media, uint8(sizeTag), box); } bool HasLottieThumbnail( diff --git a/Telegram/SourceFiles/chat_helpers/stickers_lottie.h b/Telegram/SourceFiles/chat_helpers/stickers_lottie.h index d4274b665..3a24b6422 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_lottie.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_lottie.h @@ -45,6 +45,9 @@ enum class StickerLottieSize : uchar { SetsListThumbnail, InlineResults, EmojiInteraction, + EmojiInteractionReserved1, + EmojiInteractionReserved2, + EmojiInteractionReserved3, }; [[nodiscard]] std::unique_ptr LottiePlayerFromDocument( diff --git a/Telegram/SourceFiles/history/view/history_view_emoji_interactions.cpp b/Telegram/SourceFiles/history/view/history_view_emoji_interactions.cpp index cb2fb1001..449f36578 100644 --- a/Telegram/SourceFiles/history/view/history_view_emoji_interactions.cpp +++ b/Telegram/SourceFiles/history/view/history_view_emoji_interactions.cpp @@ -25,7 +25,7 @@ namespace HistoryView { namespace { constexpr auto kSizeMultiplier = 3; - +constexpr auto kCachesCount = 4; constexpr auto kMaxPlays = 5; constexpr auto kMaxPlaysWithSmallDelay = 3; constexpr auto kSmallDelay = crl::time(200); @@ -90,12 +90,9 @@ void EmojiInteractions::play( || _visibleTop == _visibleBottom) { return; } - auto lottie = ChatHelpers::LottiePlayerFromDocument( - media.get(), - nullptr, - ChatHelpers::StickerLottieSize::EmojiInteraction, - _emojiSize * kSizeMultiplier * style::DevicePixelRatio(), - Lottie::Quality::High); + + auto lottie = preparePlayer(media.get()); + const auto shift = GenerateRandomShift(_emojiSize); lottie->updates( ) | rpl::start_with_next([=](Lottie::Update update) { @@ -121,6 +118,43 @@ void EmojiInteractions::play( } } +std::unique_ptr EmojiInteractions::preparePlayer( + not_null media) { + // Shortened copy from stickers_lottie module. + const auto document = media->owner(); + const auto baseKey = document->bigFileBaseCacheKey(); + const auto tag = uint8(0); + const auto keyShift = ((tag << 4) & 0xF0) + | (uint8(ChatHelpers::StickerLottieSize::EmojiInteraction) & 0x0F); + const auto key = Storage::Cache::Key{ + baseKey.high, + baseKey.low + keyShift + }; + const auto get = [=](int i, FnMut handler) { + document->owner().cacheBigFile().get( + { key.high, key.low + i }, + std::move(handler)); + }; + const auto weak = base::make_weak(&document->session()); + const auto put = [=](int i, QByteArray &&cached) { + crl::on_main(weak, [=, data = std::move(cached)]() mutable { + weak->data().cacheBigFile().put( + { key.high, key.low + i }, + std::move(data)); + }); + }; + const auto data = media->bytes(); + const auto filepath = document->filepath(); + return std::make_unique( + kCachesCount, + get, + put, + Lottie::ReadContent(data, filepath), + Lottie::FrameRequest{ + _emojiSize * kSizeMultiplier * style::DevicePixelRatio() }, + Lottie::Quality::High); +} + void EmojiInteractions::visibleAreaUpdated( int visibleTop, int visibleBottom) { diff --git a/Telegram/SourceFiles/history/view/history_view_emoji_interactions.h b/Telegram/SourceFiles/history/view/history_view_emoji_interactions.h index 6de853e2b..8184091df 100644 --- a/Telegram/SourceFiles/history/view/history_view_emoji_interactions.h +++ b/Telegram/SourceFiles/history/view/history_view_emoji_interactions.h @@ -68,6 +68,9 @@ private: bool incoming); void checkDelayed(); + [[nodiscard]] std::unique_ptr preparePlayer( + not_null media); + const not_null _session; int _visibleTop = 0; diff --git a/Telegram/lib_lottie b/Telegram/lib_lottie index ddeb78f28..11003d490 160000 --- a/Telegram/lib_lottie +++ b/Telegram/lib_lottie @@ -1 +1 @@ -Subproject commit ddeb78f28a8b9e6ec4dbb1b79f317243b5f748d7 +Subproject commit 11003d490b8a89b5b62e4185ea34b79565b5da16