[cairo] Cairo + GTK animation - high Xorg load

David J. Herzfeld herzfeldd at gmail.com
Thu Oct 27 18:40:15 UTC 2016


On Thu, Oct 27, 2016 at 6:56 AM, Stefan Salewski <mail at ssalewski.de> 
wrote:
> I think that drawing 1000 lines with 60 Hz in fullscreen mode is 
> indeed
> a high load for Cairo.

Actually, it's only 1000 points on a single line, not 1000 lines. So, I 
figures this is pretty simplistic, and should have a relatively low 
load.

I timed out the draw function <http://pastebin.com/0m0PF9Xc>. On my 
system, fullscreen, draw takes only 0.50ms (so a theoretical maximum 
frame rate of ~2kHz). So very low execution time in my written 
function, but Xorg still uses 30% of the CPU. I have a feeling it's not 
my drawing, but the interaction Cairo with the backend after draw() 
returns.

> 
> What you can do is of course: Shift the already drawn curve to the 
> left
> and draw only the new part. Cairo offers fast routines for copying
> areas, so for that case cpu load should be really low. For the trivial
> case of a plain sine wave, you can even draw the size extended curve 
> to
> a backup area and then just copy the desired area to your window, so 
> no
> drawing is necessary at all. That is what I did for my schematics
> editor for the background grid. (Of course complete redraw is easier,
> and when copying areas there is a minimal risk that you can get
> artefacts at the borders of old and new area.)

I agree completely. There's many strategies that I could use to speed 
the actual draw call up. What I actually do in my program is draw to a 
buffer, and then in the draw function, just call 
cairo_set_source_surface().

I've updated the example again, to use exactly this model 
<http://pastebin.com/apaFiGyd>. Here, the Xorg load is decreased 
somewhat (at the expense of increased load for the actual application), 
but Xorg load is still ~15% and scales with the size of the window. I 
don't understand this - I've already done all of the necessary drawing 
work in the thread. I could understand if the thread load increased 
with the size of the surface (which it does not appear to), but why 
should Xorg's? Essentially I want to say - here is this pixel buffer - 
just display it as is. Perhaps this is too simplistic an understanding 
of how Cairo is interacting with the display system.

Any pointers would be appreciated.

> 
> Other backends: As far as I know there is no hope for much speedup 
> when
> using the not well supported opengl backend

Thanks! I figured it was worth asking.

Thanks again for all of your help!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20161027/749465ff/attachment.html>


More information about the cairo mailing list