From 6ee4945715286d5bb0478da692abf57091e1be2e Mon Sep 17 00:00:00 2001 From: nuuls Date: Thu, 24 May 2018 22:58:07 +0200 Subject: [PATCH 1/2] fixed mac stuff and added more debug code --- chatterino.pro | 5 +++++ src/messages/layouts/messagelayout.cpp | 5 +++++ src/singletons/fontmanager.cpp | 10 ++++++++-- src/singletons/windowmanager.hpp | 7 ++++--- src/util/benchmark.hpp | 21 +++++++++++++++++++++ src/widgets/helper/channelview.cpp | 8 ++++---- src/widgets/helper/notebooktab.cpp | 8 ++++---- 7 files changed, 51 insertions(+), 13 deletions(-) diff --git a/chatterino.pro b/chatterino.pro index 8a5651d24..f99c77bf1 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -26,6 +26,11 @@ equals(QMAKE_CXX, "clang++")|equals(QMAKE_CXX, "g++") { macx:ICON = resources/images/chatterino2.icns win32:RC_FILE = resources/windows.rc + +macx { + LIBS += -L/usr/local/lib +} + # Submodules include(dependencies/rapidjson.pri) include(dependencies/settings.pri) diff --git a/src/messages/layouts/messagelayout.cpp b/src/messages/layouts/messagelayout.cpp index f92d4b03b..d9a0f484a 100644 --- a/src/messages/layouts/messagelayout.cpp +++ b/src/messages/layouts/messagelayout.cpp @@ -3,6 +3,7 @@ #include "application.hpp" #include "singletons/emotemanager.hpp" #include "singletons/settingsmanager.hpp" +#include "util/benchmark.hpp" #include #include @@ -47,6 +48,8 @@ int MessageLayout::getHeight() const // return true if redraw is required bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags) { + BenchmarkGuard benchmark("MessageLayout::layout()"); + auto app = getApp(); bool layoutRequired = false; @@ -120,6 +123,8 @@ void MessageLayout::actuallyLayout(int width, MessageElement::Flags _flags) this->container.begin(width, this->scale, messageFlags); for (const std::unique_ptr &element : this->message->getElements()) { + BenchmarkGuard guard("addelement"); + element->addToContainer(this->container, _flags); } diff --git a/src/singletons/fontmanager.cpp b/src/singletons/fontmanager.cpp index 49d00c1ec..d57649ff4 100644 --- a/src/singletons/fontmanager.cpp +++ b/src/singletons/fontmanager.cpp @@ -115,10 +115,16 @@ FontManager::FontData FontManager::createFontData(Type type, float scale) // normal Ui font (use pt size) { +#ifdef Q_OS_MAC + constexpr float multiplier = 0.8f; +#else + constexpr float multiplier = 1.f; +#endif + static std::unordered_map defaultSize{ {Tiny, {8, "Monospace", false, QFont::Normal}}, - {UiMedium, {12, DEFAULT_FONT_FAMILY, false, QFont::Normal}}, - {UiTabs, {9, "Segoe UI", false, QFont::Normal}}, + {UiMedium, {int(12 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}}, + {UiTabs, {int(9 * multiplier), DEFAULT_FONT_FAMILY, false, QFont::Normal}}, }; UiFontData &data = defaultSize[type]; diff --git a/src/singletons/windowmanager.hpp b/src/singletons/windowmanager.hpp index d17452bf6..28c2cace9 100644 --- a/src/singletons/windowmanager.hpp +++ b/src/singletons/windowmanager.hpp @@ -1,11 +1,12 @@ #pragma once #include "widgets/window.hpp" +#include "widgets/splitcontainer.hpp" namespace chatterino { -namespace widgets { -struct SplitContainer::Node; -} +//namespace widgets { +//struct SplitContainer::Node; +//} namespace singletons { class WindowManager diff --git a/src/util/benchmark.hpp b/src/util/benchmark.hpp index 828f6d738..0093bd769 100644 --- a/src/util/benchmark.hpp +++ b/src/util/benchmark.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #define BENCH(x) \ QElapsedTimer x; \ @@ -11,3 +12,23 @@ #define MARK(x) \ qDebug() << BOOST_CURRENT_FUNCTION << __LINE__ \ << static_cast(x.nsecsElapsed()) / 100000.0 << "ms"; + +class BenchmarkGuard : boost::noncopyable { + QElapsedTimer timer; + QString name; + +public: + BenchmarkGuard(const QString &_name) + :name(_name) + { + timer.start(); + } + + ~BenchmarkGuard() { + qDebug() << this->name << float(timer.nsecsElapsed()) / 100000.0 << "ms"; + } + + qreal getElapsedMs() { + return qreal(timer.nsecsElapsed()) / 100000.0; + } +}; diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index 33d2eb91c..a7a086054 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -177,7 +177,7 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) { auto app = getApp(); - // BENCH(timer) + BENCH(timer) auto messagesSnapshot = this->getMessagesSnapshot(); if (messagesSnapshot.getLength() == 0) { @@ -264,7 +264,7 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) this->messageWasAdded = false; } - // MARK(timer); + MARK(timer); if (redrawRequired) { this->queueUpdate(); @@ -580,7 +580,7 @@ bool ChannelView::isPaused() void ChannelView::paintEvent(QPaintEvent * /*event*/) { - // BENCH(timer); + BENCH(timer); QPainter painter(this); @@ -589,7 +589,7 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/) // draw messages this->drawMessages(painter); - // MARK(timer); + MARK(timer); } // if overlays is false then it draws the message, if true then it draws things such as the grey diff --git a/src/widgets/helper/notebooktab.cpp b/src/widgets/helper/notebooktab.cpp index 621a37fc2..179cc47cd 100644 --- a/src/widgets/helper/notebooktab.cpp +++ b/src/widgets/helper/notebooktab.cpp @@ -86,7 +86,7 @@ void NotebookTab::updateSize() float scale = getScale(); int width; - QFontMetrics metrics = getApp()->fonts->getFontMetrics(FontStyle::UiTabs, this->getScale()); + QFontMetrics metrics = getApp()->fonts->getFontMetrics(FontStyle::UiTabs, this->getScale() * this->devicePixelRatioF()); if (this->hasXButton()) { width = (int)((metrics.width(this->title) + 32) * scale); @@ -188,7 +188,7 @@ void NotebookTab::paintEvent(QPaintEvent *) QPainter painter(this); float scale = this->getScale(); - painter.setFont(getApp()->fonts->getFont(FontStyle::UiTabs, scale)); + painter.setFont(getApp()->fonts->getFont(FontStyle::UiTabs, scale * this->devicePixelRatioF())); int height = (int)(scale * NOTEBOOK_TAB_HEIGHT); // int fullHeight = (int)(scale * 48); @@ -248,13 +248,13 @@ void NotebookTab::paintEvent(QPaintEvent *) if (true) { // legacy // painter.drawText(rect, this->getTitle(), QTextOption(Qt::AlignCenter)); int offset = (int)(scale * 8); - QRect textRect(offset, this->selected ? 0 : 1, this->width() - offset - offset, height); + QRect textRect(offset, this->selected ? 1 : 2, this->width() - offset - offset, height); if (this->shouldDrawXButton()) { textRect.setRight(textRect.right() - this->height() / 2); } - QTextOption option(Qt::AlignLeft | Qt::AlignVCenter); + QTextOption option(Qt::AlignHCenter | Qt::AlignVCenter); option.setWrapMode(QTextOption::NoWrap); painter.drawText(textRect, this->getTitle(), option); } else { From ec03bc2e8cfa8674ac3b262a9c0ede8d9e6ba3a5 Mon Sep 17 00:00:00 2001 From: nuuls Date: Thu, 24 May 2018 23:12:50 +0200 Subject: [PATCH 2/2] fixed performance --- src/messages/layouts/messagelayout.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/messages/layouts/messagelayout.cpp b/src/messages/layouts/messagelayout.cpp index d9a0f484a..860fb243f 100644 --- a/src/messages/layouts/messagelayout.cpp +++ b/src/messages/layouts/messagelayout.cpp @@ -76,6 +76,7 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags) // check if timestamp format changed bool timestampFormatChanged = this->timestampFormat != app->settings->timestampFormat; + this->timestampFormat = app->settings->timestampFormat.getValue(); layoutRequired |= timestampFormatChanged; @@ -86,6 +87,8 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags) imagesChanged |= scaleChanged; textChanged |= scaleChanged; +// assert(layoutRequired); + // update word sizes if needed if (imagesChanged) { // this->container.updateImages(); @@ -100,6 +103,8 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags) } // return if no layout is required + qDebug() << layoutRequired; + if (!layoutRequired) { return false; } @@ -123,8 +128,6 @@ void MessageLayout::actuallyLayout(int width, MessageElement::Flags _flags) this->container.begin(width, this->scale, messageFlags); for (const std::unique_ptr &element : this->message->getElements()) { - BenchmarkGuard guard("addelement"); - element->addToContainer(this->container, _flags); }