From 9dd6966e8cb53a43e4101273fcfe30676c91f559 Mon Sep 17 00:00:00 2001 From: fourtf Date: Tue, 26 Dec 2017 18:24:02 +0100 Subject: [PATCH] graphicbuffers of msgs offscreen get discarded now --- src/widgets/helper/channelview.cpp | 35 ++++++++++++++++++++++++++++++ src/widgets/helper/channelview.hpp | 4 ++++ 2 files changed, 39 insertions(+) diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index 67ab9b5d3..e8c17ec08 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -473,6 +473,8 @@ void ChannelView::drawMessages(QPainter &painter) int y = -(messagesSnapshot[start].get()->getHeight() * (fmod(this->scrollBar.getCurrentValue(), 1))); + messages::MessageRef *end = nullptr; + for (size_t i = start; i < messagesSnapshot.getLength(); ++i) { messages::MessageRef *messageRef = messagesSnapshot[i].get(); @@ -520,10 +522,43 @@ void ChannelView::drawMessages(QPainter &painter) y += messageRef->getHeight(); + end = messageRef; if (y > height()) { break; } } + + if (end == nullptr) { + return; + } + + // remove messages that are on screen + // the messages that are left at the end get their buffers reset + for (size_t i = start; i < messagesSnapshot.getLength(); ++i) { + messages::MessageRef *messageRef = messagesSnapshot[i].get(); + auto it = this->messagesOnScreen.find(messageRef); + if (it != this->messagesOnScreen.end()) { + this->messagesOnScreen.erase(it); + } + } + + // delete the message buffers that aren't on screen + for (MessageRef *item : this->messagesOnScreen) { + item->buffer.reset(); + } + + this->messagesOnScreen.clear(); + + // add all messages on screen to the map + for (size_t i = start; i < messagesSnapshot.getLength(); ++i) { + messages::MessageRef *messageRef = messagesSnapshot[i].get(); + + this->messagesOnScreen.insert(messageRef); + + if (messageRef == end) { + break; + } + } } void ChannelView::updateMessageBuffer(messages::MessageRef *messageRef, QPixmap *buffer, diff --git a/src/widgets/helper/channelview.hpp b/src/widgets/helper/channelview.hpp index e3ec9b68e..19fd79eb7 100644 --- a/src/widgets/helper/channelview.hpp +++ b/src/widgets/helper/channelview.hpp @@ -17,6 +17,7 @@ #include #include #include +#include namespace chatterino { namespace widgets { @@ -165,6 +166,9 @@ private: boost::signals2::connection layoutConnection; std::vector managedConnections; + + std::unordered_set messagesOnScreen; + private slots: void wordTypeMaskChanged() {