again QGraphicsView performance
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):
Code:
m_View.
setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
m_View.
setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing);
m_View.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_View.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Thank you in advance.
Re: again QGraphicsView performance
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.
Re: again QGraphicsView performance
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.
Re: again QGraphicsView performance
Quote:
Originally Posted by
medved6
I'm sure that my updates are synchronized.
How do you know that?
Quote:
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.
Re: again QGraphicsView performance
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:
Re: again QGraphicsView performance
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.
Re: again QGraphicsView performance
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.
Re: again QGraphicsView performance
Use a timer to synchronize updates.
Re: again QGraphicsView performance
I said I can not. I need to draw image as soon as possible, do not wait.
Re: again QGraphicsView performance
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.
Re: again QGraphicsView performance
Ok. Thank you for the advice! I'll see if it helps, it's easy to try.
Let you know here. Thank you again!
Re: again QGraphicsView performance
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.