Re: Drawing a lot of SVG images is slow

Quentin Cosendey <[email protected]> Sun, 6 Apr 2025 16:41:20 +0200
Newsgroups gmane.comp.lib.wxwindows.general
Message-ID <[email protected]>
Hello,


I have tried LunaSVG and that library works well... but it doesn't solve 
the slugginess problem.


I finally have found the cause, and it has nothing to do with the SVG 
library in use, nor the resterization process. Caching works well also 
with wxBitmapBundle.


First on the OnPaint method, I added:

auto updateRegion = GetUpdateRegion();

gc->Clip(updateRegion);


So to make the system only actually only paint the zone of the screen it 
really needs to paint.


My second, and much bigger error, was to systematically call Refresh() 
on every key down and everytime the mouse is moved over a different item 
(to highlight the item in focus). I wasn't aware that it caused the 
whole control to be repainted, and **that** was the primary cause of the 
slugginess, while it was only necessary to repaint the previously and 
the newly highlighted items.

Calling RefreshRect, or any method indirectly calling RefreshRect like 
RefreshRow, RefreshColumn, RefeshRowColumn or RefreshRowsColumns instead 
of just Refresh makes the UI working as smooth as it can.

It seems that even if there are 1000 calls to 
wxGraphicsContext::DrawBitmap, the system is smart enough to ignore them 
completely if it's outside the update region.


Thank you very much for your help.




Le 02.04.2025 à 18:24, Vadim Zeitlin a écrit :
> On Wed, 2 Apr 2025 06:36:27 +0200 Quentin Cosendey wrote:
>
> QC> How can I check if I'm always returned the same cached bitmap or not ? /
> QC> if caching works as expected ?
>
>   There is no simple way to do it, unfortunately. I'd probably just use the
> debugger to check that the bitmaps are not re-rendered, but it might be a
> better idea to add some logging to this code.
>
> QC> I'll check that, but I don't think wxBitmapBundle allows that easily. If
> QC> it effectively doesn't, probably that I should try to find another way
> QC> to draw my SVG images.
>
>   You can do caching outside of wxBitmapBundle too.
>
> QC> QC> Isn't there a more direct way to draw SVG images ?
> QC> VZ>  Not currently, no.
> QC>
> QC> OK, sad! Is rasterization an obligation ?
>
>   Yes, of course, you need to turn vector graphics into pixels.
>
> QC> Would it be technically possible and interesting to translate directly
> QC> from SVG commands to wxGraphicsContext or DC calls on the window,
> QC> without drawing first to an intermediate bitmap ? Sorry for the newbie
> QC> question.
>
>   It would, but it still would be much slower than just rasterizing to a
> bitmap once and then simply blitting it to the screen, so it's not really
> interesting.
>
>   Regards,
> VZ
>

-- 
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
--- 
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/wx-users/36bfaeb4-bb62-46d1-bef2-3013cd682a68%40bluewin.ch.