mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Cache interactions in four cache keys.
This commit is contained in:
parent
26b9146c32
commit
42cc24e167
5 changed files with 52 additions and 17 deletions
|
@ -60,12 +60,11 @@ auto LottieFromDocument(
|
|||
Method &&method,
|
||||
not_null<Data::DocumentMedia*> 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<Lottie::SinglePlayer> 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<Lottie::Animation*> LottieAnimationFromDocument(
|
||||
|
@ -130,8 +126,7 @@ not_null<Lottie::Animation*> LottieAnimationFromDocument(
|
|||
const auto method = [&](auto &&...args) {
|
||||
return player->append(std::forward<decltype(args)>(args)...);
|
||||
};
|
||||
const auto limit = kDontCacheLottieAfterArea;
|
||||
return LottieFromDocument(method, media, uint8(sizeTag), box, limit);
|
||||
return LottieFromDocument(method, media, uint8(sizeTag), box);
|
||||
}
|
||||
|
||||
bool HasLottieThumbnail(
|
||||
|
|
|
@ -45,6 +45,9 @@ enum class StickerLottieSize : uchar {
|
|||
SetsListThumbnail,
|
||||
InlineResults,
|
||||
EmojiInteraction,
|
||||
EmojiInteractionReserved1,
|
||||
EmojiInteractionReserved2,
|
||||
EmojiInteractionReserved3,
|
||||
};
|
||||
|
||||
[[nodiscard]] std::unique_ptr<Lottie::SinglePlayer> LottiePlayerFromDocument(
|
||||
|
|
|
@ -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<Lottie::SinglePlayer> EmojiInteractions::preparePlayer(
|
||||
not_null<Data::DocumentMedia*> 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<void(QByteArray &&cached)> 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<Lottie::SinglePlayer>(
|
||||
kCachesCount,
|
||||
get,
|
||||
put,
|
||||
Lottie::ReadContent(data, filepath),
|
||||
Lottie::FrameRequest{
|
||||
_emojiSize * kSizeMultiplier * style::DevicePixelRatio() },
|
||||
Lottie::Quality::High);
|
||||
}
|
||||
|
||||
void EmojiInteractions::visibleAreaUpdated(
|
||||
int visibleTop,
|
||||
int visibleBottom) {
|
||||
|
|
|
@ -68,6 +68,9 @@ private:
|
|||
bool incoming);
|
||||
void checkDelayed();
|
||||
|
||||
[[nodiscard]] std::unique_ptr<Lottie::SinglePlayer> preparePlayer(
|
||||
not_null<Data::DocumentMedia*> media);
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
|
||||
int _visibleTop = 0;
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit ddeb78f28a8b9e6ec4dbb1b79f317243b5f748d7
|
||||
Subproject commit 11003d490b8a89b5b62e4185ea34b79565b5da16
|
Loading…
Add table
Reference in a new issue