dirk,
On Wed, Jan 14, 2015 at 11:31 PM, Dirk Hohndel <[email protected]> wrote: > On Wed, Jan 14, 2015 at 10:56:37PM -0200, Tomaz Canabrava wrote: > > Lubomir, > > > > I'v removed almost every allocation that I could find. can you try this 8 > > patches and tell me if anything worked to reduce the cpu usage? > > I just pushed all of this to master > > > We can still do some stuff to not remove the animations (yup, I like > them) > > like using a square instead of a rounded - rect notification panel. > > It's the tradeoff between bling and speed. I don't see a strong demand > from users that Subsurface is too slow on their computers... > It seems that you forgot those: already rebased against master. > /D >
From 06eb40fbac8335b40c3f2ec22a8c57c69c2d3786 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Wed, 14 Jan 2015 17:11:41 -0200 Subject: [PATCH 1/2] Reuse the Entry tooltip Item and do less fnc calls for each mouse move While analizing the code for the mouse movement I'v discovered that we did a lot of uneeded things: Set the color, the pen, the size of a fixed-colored line, twice. We also deleted-newed the same Pixmap / Text for every mouse movement so now we reuse the 'entryToolTip' that consists of a huge line and a pixmap, and after that we add the other tooltips that are not static Also, reduced a lot the number of calls to expand() ( that did a lot of math ). Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/profile/divetooltipitem.cpp | 70 ++++++++++++++++++++++----------------- qt-ui/profile/divetooltipitem.h | 1 + 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp index db09632..fc76e50 100644 --- a/qt-ui/profile/divetooltipitem.cpp +++ b/qt-ui/profile/divetooltipitem.cpp @@ -23,27 +23,27 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QP { const IconMetrics& iconMetrics = defaultIconMetrics(); - QGraphicsPixmapItem *iconItem = 0, *pixmapItem = 0; + QGraphicsPixmapItem *iconItem = 0; double yValue = title->boundingRect().height() + iconMetrics.spacing; Q_FOREACH (ToolTip t, toolTips) { yValue += t.second->boundingRect().height(); } + if (entryToolTip.second) { + yValue += entryToolTip.second->boundingRect().height(); + } + iconItem = new QGraphicsPixmapItem(this); if (!icon.isNull()) { - iconItem = new QGraphicsPixmapItem(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small), this); - iconItem->setPos(iconMetrics.spacing, yValue); - } else { - if (!pixmap.isNull()) { - pixmapItem = new QGraphicsPixmapItem(pixmap, this); - pixmapItem->setPos(iconMetrics.spacing, yValue); - } + iconItem->setPixmap(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small)); + } else if (!pixmap.isNull()) { + iconItem->setPixmap(pixmap); } + iconItem->setPos(iconMetrics.spacing, yValue); QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this); textItem->setPos(iconMetrics.spacing + iconMetrics.sz_small + iconMetrics.spacing, yValue); textItem->setBrush(QBrush(Qt::white)); textItem->setFlag(ItemIgnoresTransformations); toolTips.push_back(qMakePair(iconItem, textItem)); - expand(); } void ToolTipItem::clear() @@ -111,11 +111,18 @@ void ToolTipItem::expand() const IconMetrics& iconMetrics = defaultIconMetrics(); double width = 0, height = title->boundingRect().height() + iconMetrics.spacing; - Q_FOREACH (ToolTip t, toolTips) { + Q_FOREACH (const ToolTip& t, toolTips) { if (t.second->boundingRect().width() > width) width = t.second->boundingRect().width(); height += t.second->boundingRect().height(); } + + if (entryToolTip.first) { + if (entryToolTip.second->boundingRect().width() > width) + width = entryToolTip.second->boundingRect().width(); + height += entryToolTip.second->boundingRect().height(); + } + /* Left padding, Icon Size, space, right padding */ width += iconMetrics.spacing + iconMetrics.sz_small + iconMetrics.spacing + iconMetrics.spacing; @@ -148,10 +155,22 @@ ToolTipItem::ToolTipItem(QGraphicsItem *parent) : QGraphicsPathItem(parent), lastTime(-1) { memset(&pInfo, 0, sizeof(pInfo)); - + entryToolTip.first = NULL; + entryToolTip.second = NULL; setFlags(ItemIgnoresTransformations | ItemIsMovable | ItemClipsChildrenToShape); updateTitlePosition(); setZValue(99); + + addToolTip(QString(), QIcon(), QPixmap(16,60)); + entryToolTip = toolTips.first(); + toolTips.clear(); + + separator->setFlag(ItemIgnoresTransformations); + separator->setPen(QPen(Qt::white)); + + title->setFlag(ItemIgnoresTransformations); + title->setPen(QPen(Qt::white, 1)); + title->setBrush(Qt::white); } ToolTipItem::~ToolTipItem() @@ -170,23 +189,13 @@ void ToolTipItem::updateTitlePosition() } title->setPos(boundingRect().width() / 2 - title->boundingRect().width() / 2 - 1, 0); - title->setFlag(ItemIgnoresTransformations); - title->setPen(QPen(Qt::white, 1)); - title->setBrush(Qt::white); - if (toolTips.size() > 0) { - double x1 = 3; - double y1 = title->pos().y() + iconMetrics.spacing / 2 + title->boundingRect().height(); - double x2 = boundingRect().width() - 10; - double y2 = y1; - - separator->setLine(x1, y1, x2, y2); - separator->setFlag(ItemIgnoresTransformations); - separator->setPen(QPen(Qt::white)); - separator->show(); - } else { - separator->hide(); - } + double x1 = 3; + double y1 = title->pos().y() + iconMetrics.spacing / 2 + title->boundingRect().height(); + double x2 = boundingRect().width() - 10; + double y2 = y1; + + separator->setLine(x1, y1, x2, y2); } bool ToolTipItem::isExpanded() const @@ -234,7 +243,6 @@ void ToolTipItem::setTimeAxis(DiveCartesianAxis *axis) void ToolTipItem::refresh(const QPointF &pos) { - int i; struct plot_data *entry; static QPixmap tissues(16,60); static QPainter painter(&tissues); @@ -263,10 +271,11 @@ void ToolTipItem::refresh(const QPointF &pos) painter.drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2, 16, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure /2); painter.setPen(QColor(0, 0, 0, 127)); - for (i=0; i<16; i++) { + for (int i=0; i<16; i++) { painter.drawLine(i, 60, i, 60 - entry->percentages[i] / 2); } - addToolTip(QString::fromUtf8(mb.buffer, mb.len),QIcon(), tissues); + entryToolTip.first->setPixmap(tissues); + entryToolTip.second->setText(QString::fromUtf8(mb.buffer, mb.len)); } Q_FOREACH (QGraphicsItem *item, scene()->items(pos, Qt::IntersectsItemBoundingRect @@ -274,6 +283,7 @@ void ToolTipItem::refresh(const QPointF &pos) if (!item->toolTip().isEmpty()) addToolTip(item->toolTip()); } + expand(); } void ToolTipItem::mousePressEvent(QGraphicsSceneMouseEvent *event) diff --git a/qt-ui/profile/divetooltipitem.h b/qt-ui/profile/divetooltipitem.h index bb3ad84..ca5bc89 100644 --- a/qt-ui/profile/divetooltipitem.h +++ b/qt-ui/profile/divetooltipitem.h @@ -50,6 +50,7 @@ slots: private: typedef QPair<QGraphicsPixmapItem *, QGraphicsSimpleTextItem *> ToolTip; QVector<ToolTip> toolTips; + ToolTip entryToolTip; QGraphicsPathItem *background; QGraphicsLineItem *separator; QGraphicsSimpleTextItem *title; -- 2.2.2
From 600ac41d750653951779f765e07cf3c8d4c921aa Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Wed, 14 Jan 2015 22:50:08 -0200 Subject: [PATCH 2/2] remove the amount of calls to create the background on the ToolTip We were deleting / recreating the graphics background item for *every* mouse movement. now we are just creating the painter path. no more allocations / desalocations, adding, removing from the scene. this should make things a tiny bit faster. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/profile/divetooltipitem.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp index fc76e50..790c222 100644 --- a/qt-ui/profile/divetooltipitem.cpp +++ b/qt-ui/profile/divetooltipitem.cpp @@ -60,11 +60,8 @@ void ToolTipItem::setRect(const QRectF &r) if( r == rectangle ) { return; } - delete background; rectangle = r; - setBrush(QBrush(Qt::white)); - setPen(QPen(Qt::black, 0.5)); // Creates a 2pixels border QPainterPath border; @@ -75,17 +72,7 @@ void ToolTipItem::setRect(const QRectF &r) QPainterPath bg; bg.addRoundedRect(-1, -1, rectangle.width() + 3, rectangle.height() + 4, 3, 3); - QColor c = QColor(Qt::black); - c.setAlpha(155); - - QGraphicsPathItem *b = new QGraphicsPathItem(bg, this); - b->setFlag(ItemStacksBehindParent); - b->setFlag(ItemIgnoresTransformations); - b->setBrush(c); - b->setPen(QPen(QBrush(Qt::transparent), 0)); - b->setZValue(-10); - background = b; - + background->setPath(bg); updateTitlePosition(); } @@ -158,6 +145,16 @@ ToolTipItem::ToolTipItem(QGraphicsItem *parent) : QGraphicsPathItem(parent), entryToolTip.first = NULL; entryToolTip.second = NULL; setFlags(ItemIgnoresTransformations | ItemIsMovable | ItemClipsChildrenToShape); + + QColor c = QColor(Qt::black); + c.setAlpha(155); + background = new QGraphicsPathItem(this); + background->setFlag(ItemStacksBehindParent); + background->setFlag(ItemIgnoresTransformations); + background->setBrush(c); + background->setPen(QPen(QBrush(Qt::transparent), 0)); + background->setZValue(-10); + updateTitlePosition(); setZValue(99); @@ -171,6 +168,9 @@ ToolTipItem::ToolTipItem(QGraphicsItem *parent) : QGraphicsPathItem(parent), title->setFlag(ItemIgnoresTransformations); title->setPen(QPen(Qt::white, 1)); title->setBrush(Qt::white); + + setBrush(QBrush(Qt::white)); + setPen(QPen(Qt::black, 0.5)); } ToolTipItem::~ToolTipItem() -- 2.2.2
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
