[cairo] graph plotting using cairo

Kalle Vahlman kalle.vahlman at gmail.com
Sat Aug 11 02:23:03 PDT 2007


2007/8/10, Milan Stanojević <milanst at gmail.com>:
> I draw on Gtk DrawArea widget and
> I use surface_create_similar to create surfaces. I tried image
> surfaces as well, but that was much slower, which makes me suspect
> that cairo is probably going through xrender when drawing onto gtk
> widget.

Yes, the surfaces created will be X drawables so copy operations will
be much more efficient since it happens on the server, instead of
having to upload the image data from the client-side image surfaces.
And of course the possibly accelerated drawing operations with Render.

> The problem arises when the whole graph has to be redrawn, for example
> on window resize. Then I have to plot all the points that are visible
> (on the order of 10k points) which takes a bit.

Hard to say what goes on here without profiling with sysprof or
similar tools... or seeing the code at least.

> I've also noticed that
> text drawing is taking a lot of time (when drawing plot axis).
> That stuff I can even ignore, although I would appreciate if someone
> could give me any advice how to make it faster.

I'm not sure how you are drawing the text, I hope with Pango since
it's a GTK+ program. I've noticed that in otherwise similar
conditions, using pango_cairo_show_layout() is vastly superior in
speed than setting the layout_path() and either stroking or filling it
to the context (fill of course gives a bit different visual result as
the others):

show_layout() finished in 0,002034
layout_path() & fill() finished in 0,164095
layout_path() & stroke() finished in 0,624981

The numbers are seconds elapsed during drawing 100 times the text
"Test text" with each method, offsetting each iteration with
translation and having a global translation and rotation of 15
degrees.

Perhaps Behdad could hint on why this is and if there is possibly some
hidden downside to using show_layout() (since it seems too good to be
true ;)?

> What worries is more is CPU load. Anything more frequent than 10
> frames a second basically hogs my CPU. The application itself is not
> consuming a lot of CPU, but Xorg is. With 10frames a second, it goes
> to over 80%. I measured time needed to draw a frame, and it is around
> 0.25ms when everything can be optimized, and going all the way to
> 200ms when everything needs to be redrawn.

Xorg using a lot of CPU sounds like falling back to software
rendering, do you have any experiences in other setups (different
drivers, different graphics card)?

-- 
Kalle Vahlman, zuh at iki.fi
Powered by http://movial.fi
Interesting stuff at http://syslog.movial.fi


More information about the cairo mailing list