Optimize custom emoji repaints in pinned bar / reply info.

This commit is contained in:
John Preston 2022-07-06 10:10:02 +04:00
parent 68ee753fc7
commit 754371a295
8 changed files with 24 additions and 6 deletions

View file

@ -6410,7 +6410,7 @@ void HistoryWidget::checkPinnedBarState() {
_pinnedBar->setContent(HistoryView::PinnedBarContent( _pinnedBar->setContent(HistoryView::PinnedBarContent(
&session(), &session(),
_pinnedTracker->shownMessageId(), _pinnedTracker->shownMessageId(),
[bar = _pinnedBar.get()] { bar->update(); })); [bar = _pinnedBar.get()] { bar->customEmojiRepaint(); }));
controller()->adaptive().oneColumnValue( controller()->adaptive().oneColumnValue(
) | rpl::start_with_next([=](bool one) { ) | rpl::start_with_next([=](bool one) {
@ -7604,11 +7604,17 @@ void HistoryWidget::updateReplyToName() {
} }
void HistoryWidget::updateField() { void HistoryWidget::updateField() {
if (_repaintFieldScheduled) {
return;
}
_repaintFieldScheduled = true;
const auto fieldAreaTop = _scroll->y() + _scroll->height(); const auto fieldAreaTop = _scroll->y() + _scroll->height();
rtlupdate(0, fieldAreaTop, width(), height() - fieldAreaTop); rtlupdate(0, fieldAreaTop, width(), height() - fieldAreaTop);
} }
void HistoryWidget::drawField(Painter &p, const QRect &rect) { void HistoryWidget::drawField(Painter &p, const QRect &rect) {
_repaintFieldScheduled = false;
auto backy = _field->y() - st::historySendPadding; auto backy = _field->y() - st::historySendPadding;
auto backh = _field->height() + 2 * st::historySendPadding; auto backh = _field->height() + 2 * st::historySendPadding;
auto hasForward = readyToForward(); auto hasForward = readyToForward();

View file

@ -650,6 +650,7 @@ private:
int _requestsBarHeight = 0; int _requestsBarHeight = 0;
bool _preserveScrollTop = false; bool _preserveScrollTop = false;
bool _repaintFieldScheduled = false;
mtpRequestId _saveEditMsgRequestId = 0; mtpRequestId _saveEditMsgRequestId = 0;

View file

@ -397,7 +397,7 @@ void RepliesWidget::setupRootView() {
RootViewContent( RootViewContent(
_history, _history,
_rootId, _rootId,
[bar = _rootView.get()] { bar->update(); }), [bar = _rootView.get()] { bar->customEmojiRepaint(); }),
_rootVisible.value() _rootVisible.value()
) | rpl::map([=](Ui::MessageBarContent &&content, bool shown) { ) | rpl::map([=](Ui::MessageBarContent &&content, bool shown) {
return shown ? std::move(content) : Ui::MessageBarContent(); return shown ? std::move(content) : Ui::MessageBarContent();

View file

@ -56,12 +56,21 @@ MessageBar::MessageBar(
}, _widget.lifetime()); }, _widget.lifetime());
} }
void MessageBar::customEmojiRepaint() {
if (_customEmojiRepaintScheduled) {
return;
}
_customEmojiRepaintScheduled = true;
_widget.update();
}
void MessageBar::setup() { void MessageBar::setup() {
_widget.resize(0, st::historyReplyHeight); _widget.resize(0, st::historyReplyHeight);
_widget.paintRequest( _widget.paintRequest(
) | rpl::start_with_next([=](QRect rect) { ) | rpl::start_with_next([=](QRect rect) {
auto p = Painter(&_widget); auto p = Painter(&_widget);
p.setInactive(_customEmojiPaused()); p.setInactive(_customEmojiPaused());
_customEmojiRepaintScheduled = false;
paint(p); paint(p);
}, _widget.lifetime()); }, _widget.lifetime());
} }

View file

@ -42,6 +42,7 @@ public:
return &_widget; return &_widget;
} }
void customEmojiRepaint();
void finishAnimating(); void finishAnimating();
private: private:
@ -110,6 +111,7 @@ private:
Ui::Text::String _title, _text; Ui::Text::String _title, _text;
QPixmap _image, _topBarGradient, _bottomBarGradient; QPixmap _image, _topBarGradient, _bottomBarGradient;
std::unique_ptr<Animation> _animation; std::unique_ptr<Animation> _animation;
bool _customEmojiRepaintScheduled = false;
}; };

View file

@ -207,9 +207,9 @@ void PinnedBar::raise() {
_shadow->raise(); _shadow->raise();
} }
void PinnedBar::update() { void PinnedBar::customEmojiRepaint() {
if (_bar) { if (_bar) {
_bar->widget()->update(); _bar->customEmojiRepaint();
} }
} }

View file

@ -28,7 +28,7 @@ public:
void show(); void show();
void hide(); void hide();
void raise(); void raise();
void update(); void customEmojiRepaint();
void finishAnimating(); void finishAnimating();
void setShadowGeometryPostprocess(Fn<QRect(QRect)> postprocess); void setShadowGeometryPostprocess(Fn<QRect(QRect)> postprocess);

@ -1 +1 @@
Subproject commit 9cb7bb58f658d7603f9493b9d051cf8a78a2cd41 Subproject commit ec76a4c0bb9131ab14fe676630a1f465bfc05ee2