[cairo] Isn't there a way to pass multiple points to Cairo? (sorry for duplicate)

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Jul 30 09:04:22 PDT 2011


I was temporarily unsubscribed and this could be a duplicate post, I
apologize if that's so.

If I want to draw a waveform made out of 400 points and connect the
points together to form lines (meaning point one has a line to point
two, point two to pint three, etc.), I have to call cairo_move_to()
and cairo_line_to() 400 times each.

Benchmarking shows this takes ~36 milliseconds when antialiasing is
set to off, otherwise ~60 milliseconds with antialiasing on to draw on
my machine.

Here's an example image in Cairo: http://i.imgur.com/gaMSF.jpg

Compare that to, say, using the WinAPI Polyline() function, which
takes an array of Points (a Point is a struct with int x,y fields). It
takes an average of 150 microseconds, or 0.15 milliseconds to connect
the 400 points and draw them as lines on the screen.

Here's the image using GDI: http://i.imgur.com/x8Ln9.jpg

I believe GDI is hardware-accelerated by default so this could account
for why it's fast, but still I have to wonder if the massive amount of
function calls is what is slowing down Cairo. I'm dynamically linking
to Cairo so I can't inline any function calls.

Isn't there a function in Cairo that can take a pointer to an array of
some {int x, y} - like structure so we could make one function call
and paint that with cairo_stroke/cairo_paint/etc? And if not, how
come?

I'm not too sure if it really is the amount of function calls that
slows down the painting, or if the painting itself is slow with a
large number of points on a path.


More information about the cairo mailing list