PDA

View Full Version : refresh screen use more CPU



lzpmail
11th April 2011, 09:04
my program running in samsung s3c2440 processor, when i not refresh the paint pixmap, the program use CPU 1%-2%, but when use repaint() refresh the paint pixmap, the program use CPU 80%-90%(i invoke repaint() very fast, about 10 millisecond space), have any one have high efficiency ways to refresh the paint pixmap, thanks.

MarekR22
11th April 2011, 09:09
Just write better code.
If you want better answer then post better question.

lzpmail
11th April 2011, 09:40
yea, thank you

ChrisW67
11th April 2011, 10:15
You seem surprised that when you do no work the CPU is not busy, and when you do (a lot) of work the CPU is busy.

Run your code in a profiler to find out where the CPU really is spending its time and focus on improving that. Odds are you will need to code that only draws bits of the pixmap that change or, more obviously, do not refresh as frequently. I am not sure what application really needs to redraw at 100Hz frequency anyway.

lzpmail
11th April 2011, 13:23
yea, i test my program it, find when i repaint pixmap, use CPU more. my program need to draw wave, so if have data to draw, i first use Qpainter draw on the QPixmap, and then use repaint() invoke paintEvent() show the pixmap, i do not know whether or not have more good methods to show the pixmap.

wysota
11th April 2011, 13:45
How did you test your program? And why are you calling repaint() instead of update()?

lzpmail
12th April 2011, 05:40
i comment repaint code, and why me calling repaint() instead of update(), because if invoke repaint(), it will immediate execute, but if invoke update(), it will wait a while, so i think if use update() may affect show wave.

wysota
12th April 2011, 13:28
Hmm.... but if your screen refreshes at 60Hz rate and you're calling repaint() at 100Hz then you're not seeing half of the repaints so your app does twice as much as it can without losing any functionality. The fact that you call repaint() instead of update() doesn't mean the changes will be shown on the screen faster. It just means your application will be more busy doing empty repaints. Paint events can be merged to reduce the work but with repaint() you are not allowing a merge so your app has more to do. Consider this:

{
repaint();
repaint();
}
and this:

{
update();
update();
}
The first code will invoke the painting routine twice (or even more actually because the parent widget may also change and enforce an update of its child), the second will invoke it once. In both cases you will see the same result (when the display refreshes) only that the first code will execute n times longer than the second one.

I'm not even commenting the fact that your eye cannot detect changes at 100Hz rate, you can safely drop down the frame rate to about 30 per second.