From 754371a29530cd570d900d7dc692410131bdcc12 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 6 Jul 2022 10:10:02 +0400 Subject: [PATCH] Optimize custom emoji repaints in pinned bar / reply info. --- Telegram/SourceFiles/history/history_widget.cpp | 8 +++++++- Telegram/SourceFiles/history/history_widget.h | 1 + .../history/view/history_view_replies_section.cpp | 2 +- Telegram/SourceFiles/ui/chat/message_bar.cpp | 9 +++++++++ Telegram/SourceFiles/ui/chat/message_bar.h | 2 ++ Telegram/SourceFiles/ui/chat/pinned_bar.cpp | 4 ++-- Telegram/SourceFiles/ui/chat/pinned_bar.h | 2 +- Telegram/lib_ui | 2 +- 8 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 00542b5a8..b44bbaef0 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -6410,7 +6410,7 @@ void HistoryWidget::checkPinnedBarState() { _pinnedBar->setContent(HistoryView::PinnedBarContent( &session(), _pinnedTracker->shownMessageId(), - [bar = _pinnedBar.get()] { bar->update(); })); + [bar = _pinnedBar.get()] { bar->customEmojiRepaint(); })); controller()->adaptive().oneColumnValue( ) | rpl::start_with_next([=](bool one) { @@ -7604,11 +7604,17 @@ void HistoryWidget::updateReplyToName() { } void HistoryWidget::updateField() { + if (_repaintFieldScheduled) { + return; + } + _repaintFieldScheduled = true; const auto fieldAreaTop = _scroll->y() + _scroll->height(); rtlupdate(0, fieldAreaTop, width(), height() - fieldAreaTop); } void HistoryWidget::drawField(Painter &p, const QRect &rect) { + _repaintFieldScheduled = false; + auto backy = _field->y() - st::historySendPadding; auto backh = _field->height() + 2 * st::historySendPadding; auto hasForward = readyToForward(); diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 6b1f0844c..df04a5fd6 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -650,6 +650,7 @@ private: int _requestsBarHeight = 0; bool _preserveScrollTop = false; + bool _repaintFieldScheduled = false; mtpRequestId _saveEditMsgRequestId = 0; diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index f39f7563a..3ecbe5fc4 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -397,7 +397,7 @@ void RepliesWidget::setupRootView() { RootViewContent( _history, _rootId, - [bar = _rootView.get()] { bar->update(); }), + [bar = _rootView.get()] { bar->customEmojiRepaint(); }), _rootVisible.value() ) | rpl::map([=](Ui::MessageBarContent &&content, bool shown) { return shown ? std::move(content) : Ui::MessageBarContent(); diff --git a/Telegram/SourceFiles/ui/chat/message_bar.cpp b/Telegram/SourceFiles/ui/chat/message_bar.cpp index cfce4ec85..55ee3a615 100644 --- a/Telegram/SourceFiles/ui/chat/message_bar.cpp +++ b/Telegram/SourceFiles/ui/chat/message_bar.cpp @@ -56,12 +56,21 @@ MessageBar::MessageBar( }, _widget.lifetime()); } +void MessageBar::customEmojiRepaint() { + if (_customEmojiRepaintScheduled) { + return; + } + _customEmojiRepaintScheduled = true; + _widget.update(); +} + void MessageBar::setup() { _widget.resize(0, st::historyReplyHeight); _widget.paintRequest( ) | rpl::start_with_next([=](QRect rect) { auto p = Painter(&_widget); p.setInactive(_customEmojiPaused()); + _customEmojiRepaintScheduled = false; paint(p); }, _widget.lifetime()); } diff --git a/Telegram/SourceFiles/ui/chat/message_bar.h b/Telegram/SourceFiles/ui/chat/message_bar.h index 52ce084f7..83fb393a6 100644 --- a/Telegram/SourceFiles/ui/chat/message_bar.h +++ b/Telegram/SourceFiles/ui/chat/message_bar.h @@ -42,6 +42,7 @@ public: return &_widget; } + void customEmojiRepaint(); void finishAnimating(); private: @@ -110,6 +111,7 @@ private: Ui::Text::String _title, _text; QPixmap _image, _topBarGradient, _bottomBarGradient; std::unique_ptr _animation; + bool _customEmojiRepaintScheduled = false; }; diff --git a/Telegram/SourceFiles/ui/chat/pinned_bar.cpp b/Telegram/SourceFiles/ui/chat/pinned_bar.cpp index e9747fbe5..bc3dc09fe 100644 --- a/Telegram/SourceFiles/ui/chat/pinned_bar.cpp +++ b/Telegram/SourceFiles/ui/chat/pinned_bar.cpp @@ -207,9 +207,9 @@ void PinnedBar::raise() { _shadow->raise(); } -void PinnedBar::update() { +void PinnedBar::customEmojiRepaint() { if (_bar) { - _bar->widget()->update(); + _bar->customEmojiRepaint(); } } diff --git a/Telegram/SourceFiles/ui/chat/pinned_bar.h b/Telegram/SourceFiles/ui/chat/pinned_bar.h index b5fb8f9b8..f48556a42 100644 --- a/Telegram/SourceFiles/ui/chat/pinned_bar.h +++ b/Telegram/SourceFiles/ui/chat/pinned_bar.h @@ -28,7 +28,7 @@ public: void show(); void hide(); void raise(); - void update(); + void customEmojiRepaint(); void finishAnimating(); void setShadowGeometryPostprocess(Fn postprocess); diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 9cb7bb58f..ec76a4c0b 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 9cb7bb58f658d7603f9493b9d051cf8a78a2cd41 +Subproject commit ec76a4c0bb9131ab14fe676630a1f465bfc05ee2