PDA

View Full Version : again QGraphicsView performance



medved6
17th December 2009, 00:13
Hi

I like QGraphicsView very much, but I vave some issue with performance. I used to search help on forums histroy but I still need some help.

On my scene I have a video some CLVideoWindow’s items ihereted from QGraphicsItem. Basicly each CLVideoWindow object dispaying live video ( video size is about 800x60, so boundingRect returns QRectF(0,0,800,600).

void CLVideoWindow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) function does some OpenGL shaders.

So, as you can see my items is preaty dynamic. I need to call item->update() function in gui thread ~20-30 times per second for each item.

And it works fine with 2 itimes, but as soon as I add third item on the scene gui thread cpu usage jumps form 6-8% up to 30-36%. Threre is no differences beween 1 2 and 3 items ( they just display different video content ).

Problem is not in CLVideoWindow::paint function. Even if I do not do anything inside paint(…) ( just return ) gui thread takes almost the same CPU time. If I do not call update() so ofen – it’s fine ( low cpu usage ).

The problem apears only if I add third item(no metter in what sequence). I also noticed that if I maximize application gui thread also takes more CPU ( but not always ).

After I add 4,5,6.. items cpu increased on 4-5% ( this is expactable ). But how come third item gives such dramatic increase?

I have QT.4.5.2 Windows Xp / Vista.


Here are options I use for my QGraphicsView( I do not use Antialiasing):



m_View.setViewport(new QGLWidget());

m_View.setViewportUpdateMode(QGraphicsView::Minima lViewportUpdate);

m_View.setCacheMode(QGraphicsView::CacheBackground );


m_View.setDragMode(QGraphicsView::ScrollHandDrag);

m_View.setOptimizationFlag(QGraphicsView::DontClip Painter);
m_View.setOptimizationFlag(QGraphicsView::DontSave PainterState);
m_View.setOptimizationFlag(QGraphicsView::DontAdju stForAntialiasing);

m_View.setVerticalScrollBarPolicy(Qt::ScrollBarAlw aysOff);
m_View.setHorizontalScrollBarPolicy(Qt::ScrollBarA lwaysOff);





Thank you in advance.

wysota
17th December 2009, 01:55
I would make sure all your updates are synchronized and I'd probably switch to FullViewportUpdate then to minimize the number of paint events you are going to get (although you are using a GL viewport, so it's already doing full viewport updates but nevertheless, it's worth to try). Apart from that it's best to run your application through a profiler to see where the bottleneck is. It's hard to improve performance if you don't know what is causing the slowdowns.

medved6
17th December 2009, 04:38
I'm sure that my updates are synchronized. All them called from gui thread. Some other threads just emits signal to call update function from gui.

My Intel Vtune profiler crashes with this application-( I'll try to use different one.

wysota
17th December 2009, 09:46
I'm sure that my updates are synchronized.
How do you know that?


All them called from gui thread.
Which doesn't mean they are synchronized. I'm not talking about threads but about doing a single update of your view instead of three.

medved6
17th December 2009, 19:09
Which doesn't mean they are synchronized. I'm not talking about threads but about doing a single update of your view instead of three.[/QUOTE]

Ok. How can I know/check that ?:confused:

wysota
17th December 2009, 21:01
If you didn't do anything to synchronize updates then they are probably not synchronized. You need to make sure all items are updated upon the same timeout from the same timer.

medved6
18th December 2009, 08:48
I see what you mean. It is better to call as much updates as possible per one time..., not separately.

In my apps it works like this... For each video window I have it's own thread. This thread decodes video comming from some quue, and calls some signal. The slot for that signal is function im gui thread, calling update().
Some video has 20.5 fps, some 33.67fps, some 4.5 fps... Video shoud be displayed smooth.
So I'm not sure can I synchronize updates.

wysota
18th December 2009, 08:58
Use a timer to synchronize updates.

medved6
19th December 2009, 00:43
I said I can not. I need to draw image as soon as possible, do not wait.

wysota
19th December 2009, 00:54
In that case you have to live with big cpu usage. You can't eat a pie and still have the pie. You either show all images at the same moment of time or not. If not then you have to redraw the same image many times hence slowing down the application. By the way, I'm sure that if you display the camera image 5ms later than "immediately" nobody would notice. But suit yourself.

medved6
19th December 2009, 02:35
Ok. Thank you for the advice! I'll see if it helps, it's easy to try.
Let you know here. Thank you again!

medved6
21st December 2009, 22:11
Thank you.
You advice about update synchronization was very helpfull. The problem is solved.
Now I have linear increment of CPU usage with every new video. No metter how many cams do I have I do updates ( if needded ) at one shot every 25 ms.