Qwt minimize drawing part
Hi all,
I am concerning about optimization when redrawing of qwt plot.
A Qwtplot has a QwtPlotItem attached. When there is new data, calling plot.replot() will redraw everything including QwtScale. Is there anyway to call QwtPlotItem to update only when there is new data to avoid the rest to update (because my QwtScale is static all the time). Caching pixmap is one solution but it is a redraw anyway.
This can be apply to barchart, xy plot, qwtDial, etc.
Re: Qwt minimize drawing part
Time it takes to blit cached pixmap to the screen is insignificant when it comes to performance.
Redrawing the scales shouldn't be a bottleneck either.
Btw do you know rules of premature optimization?
Rule 1 : Don't optimize!
Rule 2 : Don't optimize jet!
I'm guessing that rule 1 applies here :)
Re: Qwt minimize drawing part
hi Spitfire,
Thank you for your quick reply. I cant see the difference between the two mentioned rules though :D
Let me use QwtDial for embedded device as an example.
I suppose that by default every parts of the dial apart from the needle has been cached right?
and you mean that the CPU usage spent for redrawing these cache pixmap is insignificant compared with one for redrawing the needle?
Added after 4 minutes:
In addition, pixmap of the needle can also be cached then we can rotate the pixmap to display updated value.
Re: Qwt minimize drawing part
In general it depends on your system if blitting a pixmap is a relevant operation. F.e. when using an unaccelerated framebuffer driver or the graphic board is connected via a slow bus it matters. I've seen such devices where blitting a 800x600 image takes about 70ms, what might be too slow for widgets like speedos. But on usual desktop PCs it shouldn't matter.
Also Qt Embedded platforms differ - depending on your plugin and how it is implemented. In most implementations I have seen the composition of the screen is done in memory and drawing a pixmap is not more than copying bits in memory. The bottlenecks are usually happening after the screen composition is done: so when you try to optimize something in application code the important thing is usually to reduce the regions to be updated - the parameter you can set in QWidget::update/repaint.
About Qwt: the situation for a widget like QwtDial is very different to QwtPlot - so better don't mix up both in the same discussion:
A) QwtDial
When the value of a QwtDial changes you could limit the update regions to the bounding rectangle of the previous and the new position.
An extra cache for the background of QwtDial is pointless as drawing the background ( including the scales ) is indeed no operation that takes much time. Caching the needle is no good idea as rotating a pixmap is a very slow operation ( more expensive than drawing a not too complex shape ) and the result is ugly ( artefacts instead of antialiasing ) - this makes no sense at all.
B) QwtPlot
QwtPlot/QwtPlotCanvas are optimized in many ways and most ( probably all ) what you wrote is wrong. But if you have questions in this area better come up with a detailed use case - general concerns are not helpful as plots and their requirements differ a lot.
Uwe