Optimize animated sticker preview.

This commit is contained in:
John Preston 2019-06-25 14:59:22 +02:00
parent 0d6ee3929d
commit 21dfb310f3
2 changed files with 14 additions and 2 deletions

View File

@ -864,6 +864,13 @@ MediaPreviewWidget::MediaPreviewWidget(
subscribe(Auth().downloaderTaskFinished(), [this] { update(); });
}
QRect MediaPreviewWidget::updateArea() const {
const auto size = currentDimensions();
return QRect(
QPoint((width() - size.width()) / 2, (height() - size.height()) / 2),
size);
}
void MediaPreviewWidget::paintEvent(QPaintEvent *e) {
Painter p(this);
QRect r(e->rect());
@ -1048,7 +1055,11 @@ void MediaPreviewWidget::setupLottie() {
_lottie->updates(
) | rpl::start_with_next_error([=](Lottie::Update update) {
this->update();
update.data.match([&](const Lottie::Information &) {
this->update();
}, [&](const Lottie::DisplayFrameRequest &) {
this->update(updateArea());
});
}, [=](Lottie::Error error) {
}, lifetime());
}
@ -1152,7 +1163,7 @@ void MediaPreviewWidget::clipCallback(Media::Clip::Notification notification) {
case NotificationRepaint: {
if (_gif && !_gif->currentDisplayed()) {
update();
updateArea();
}
} break;
}

View File

@ -226,6 +226,7 @@ private:
void startShow();
void fillEmojiString();
void resetGifAndCache();
QRect updateArea() const;
not_null<Window::SessionController*> _controller;