From c796dd142b9e7a5aa5fe7fa13355a213f8f82102 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 28 Jun 2022 17:46:31 +0400 Subject: [PATCH] Optimize many animated emoji repaint requests. --- Telegram/SourceFiles/history/history_item.cpp | 7 +++++++ Telegram/SourceFiles/history/history_item.h | 2 ++ Telegram/SourceFiles/history/history_message.cpp | 3 +-- Telegram/SourceFiles/history/view/history_view_message.cpp | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 05a46a5b8..c099b7e20 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -375,6 +375,13 @@ void HistoryItem::invalidateChatListEntry() { history()->lastItemDialogsView.itemInvalidated(this); } +void HistoryItem::customEmojiRepaint() { + if (!_textRepaintScheduled) { + _textRepaintScheduled = true; + history()->owner().requestItemRepaint(this); + } +} + void HistoryItem::finishEditionToEmpty() { finishEdition(-1); _history->itemVanished(this); diff --git a/Telegram/SourceFiles/history/history_item.h b/Telegram/SourceFiles/history/history_item.h index 98f9430f6..658400f4a 100644 --- a/Telegram/SourceFiles/history/history_item.h +++ b/Telegram/SourceFiles/history/history_item.h @@ -463,6 +463,7 @@ protected: MessageFlags _flags = 0; void invalidateChatListEntry(); + void customEmojiRepaint(); void setGroupId(MessageGroupId groupId); @@ -473,6 +474,7 @@ protected: Ui::Text::String _text = { st::msgMinWidth }; int _textWidth = -1; int _textHeight = 0; + bool _textRepaintScheduled = false; struct SavedMediaData { TextWithEntities text; diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp index 8c66affd4..7b4f89409 100644 --- a/Telegram/SourceFiles/history/history_message.cpp +++ b/Telegram/SourceFiles/history/history_message.cpp @@ -1498,8 +1498,7 @@ void HistoryMessage::setText(const TextWithEntities &textWithEntities) { clearIsolatedEmoji(); const auto context = Core::MarkedTextContext{ .session = &history()->session(), - .customEmojiRepaint = [=] { - history()->owner().requestItemRepaint(this); }, + .customEmojiRepaint = [=] { customEmojiRepaint(); }, }; _text.setMarkedText( st::messageTextStyle, diff --git a/Telegram/SourceFiles/history/view/history_view_message.cpp b/Telegram/SourceFiles/history/view/history_view_message.cpp index d41f5352a..455178af0 100644 --- a/Telegram/SourceFiles/history/view/history_view_message.cpp +++ b/Telegram/SourceFiles/history/view/history_view_message.cpp @@ -1258,6 +1258,7 @@ void Message::paintText( 0, -1, context.selection); + item->_textRepaintScheduled = false; if (!_heavyCustomEmoji && custom) { _heavyCustomEmoji = true; history()->owner().registerHeavyViewPart(const_cast(this));