Use cache for remembered last dice frames.

This commit is contained in:
John Preston 2020-03-30 14:57:14 +04:00
parent 2feaa85ed9
commit 570ab663b7

View file

@ -31,12 +31,22 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace HistoryView {
namespace {
double GetEmojiStickerZoom(not_null<Main::Session*> session) {
[[nodiscard]] double GetEmojiStickerZoom(not_null<Main::Session*> session) {
return session->account().appConfig().get<double>(
"emojies_animated_zoom",
0.625);
}
[[nodiscard]] QImage CacheDiceImage(int index, const QImage &image) {
static auto Cache = base::flat_map<int, QImage>();
const auto i = Cache.find(index);
if (i != end(Cache) && i->second.size() == image.size()) {
return i->second;
}
Cache[index] = image;
return image;
}
} // namespace
Sticker::Sticker(
@ -116,7 +126,7 @@ void Sticker::paintLottie(Painter &p, const QRect &r, bool selected) {
: Lottie::Animation::FrameInfo();
if (_nextLastDiceFrame) {
_nextLastDiceFrame = false;
_lastDiceFrame = frame.image;
_lastDiceFrame = CacheDiceImage(_diceIndex, frame.image);
}
const auto &image = _lastDiceFrame.isNull()
? frame.image