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(); }); 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) { void MediaPreviewWidget::paintEvent(QPaintEvent *e) {
Painter p(this); Painter p(this);
QRect r(e->rect()); QRect r(e->rect());
@ -1048,7 +1055,11 @@ void MediaPreviewWidget::setupLottie() {
_lottie->updates( _lottie->updates(
) | rpl::start_with_next_error([=](Lottie::Update update) { ) | rpl::start_with_next_error([=](Lottie::Update update) {
update.data.match([&](const Lottie::Information &) {
this->update(); this->update();
}, [&](const Lottie::DisplayFrameRequest &) {
this->update(updateArea());
});
}, [=](Lottie::Error error) { }, [=](Lottie::Error error) {
}, lifetime()); }, lifetime());
} }
@ -1152,7 +1163,7 @@ void MediaPreviewWidget::clipCallback(Media::Clip::Notification notification) {
case NotificationRepaint: { case NotificationRepaint: {
if (_gif && !_gif->currentDisplayed()) { if (_gif && !_gif->currentDisplayed()) {
update(); updateArea();
} }
} break; } break;
} }

View File

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