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?


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.


On Wed, Jan 14, 2015 at 10:41 PM, Tomaz Canabrava <[email protected]>
wrote:

> another wasteful calls removed.
>
> On Wed, Jan 14, 2015 at 10:36 PM, Tomaz Canabrava <[email protected]>
> wrote:
>
>> This patch remove some of uneeded animation calls.
>>
>>
>> On Wed, Jan 14, 2015 at 10:26 PM, Tomaz Canabrava <[email protected]>
>> wrote:
>>
>>> Well, another one here.
>>> we were creating / removing the biggest tooltip string ( that can have
>>> up to 16 lines sometimes ) by allocking / freeing it *every* pixel moved.
>>> now we cache it and do not free.
>>>
>>> On Wed, Jan 14, 2015 at 6:23 PM, Lubomir I. Ivanov <[email protected]>
>>> wrote:
>>>
>>>> On 14 January 2015 at 22:08, Lubomir I. Ivanov <[email protected]>
>>>> wrote:
>>>> > i suspect that if we rasterize the whole tooltip (i.e. use QPainter's
>>>> > methods on a surface) and disable the animation, it will be times
>>>> > faster.
>>>> >
>>>>
>>>> and by that i mean override ::paint() and do all the calculations and
>>>> drawing in there and possibly only re-draw if the input data changed
>>>> etc...
>>>> that's a much larger re-work, but i think that custom drawing might be
>>>> the most optimal way for the tooltip to perform well.
>>>>
>>>> lubomir
>>>> --
>>>>
>>>
>>>
>>
>
From e444026e920f109ad5afce6627af04e1cf8d889f Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Wed, 14 Jan 2015 22:50:08 -0200
Subject: [PATCH 8/8] 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

Reply via email to