[cairo] about cairo_stroke's performance

oken okenjian at 163.com
Mon Sep 27 21:16:27 PDT 2010


2010/9/27 oken <okenjian at 163.com>: 
> Hi, all, 
> I am using cairo 1.8.10 under wine, and i find that in some situations, 
> cairo_stroke works very slow. 
> drawing 1000 lines on an image surface takes only 915ms, but on a Win32 
> surface it takes 10,493ms! 
> the testing code is as follow: 

This is also what I see in my app (mostly scrolling text), the 
framerate using an image surface is much higher. 

> I run my test under both wine and win7, and i get the similar result:drawing 
> on an image surface is much faster than WIN32 surface does. 
> Most of the time is consumed by cairo_stroke. 
> I know i can move cairo_stroke out of the for loop and call it only once, it 
> improve the performance a lot. 

The win32 surface is really basic, since it uses the windows GDI 
subsystem. Pixman has a lot of fast paths using e.g. SSE2 assembly, 
which makes the image surface quite fast. 
calling GDI'S API to draw something under wine is very fast.
But if i create a WIN32 surface using that HDC then call cairo's API to draw lines, 
it becomes very slow.
Why?

> I also find that drawing rectangles on a win32 surface is fast if the 
> parameters are integer, however using double decrease the performance a 
> lot(about 10 times slower!). 

By double do you mean, non-integer doubles? That is expected, because 
the rectangles are not pixel-aligned. 

Yes, i do mean non-integer doubles. the rectangles are not pixel-aligned. 
But, why is it that pixel-aligned affects the performance?

> I have a few questions: 
> 1. does it make sense that drawing a single line(not horizontal or vertical) 
> or a rectangle(with double parameters) on a WIN32 surface takes about 10ms? 

I guess so. 
Do you mean that drawing a single line(not horizontal or vertical) 
or a rectangle(with non-integer parameters) on a WIN32 surface takes about 10ms reasonable?
It is really very slow, 10 times slower than on the image surface.

> 2. is it possible to improve it ? how? 

Render all your lines to an image surface and when you're done, blit 
the pixels to the win32 surface. 
it may works. but we  have to modify most of the code.
besides, cairo_fill and cairo_clip suffer the same problem.

> 3. what can i do the improve the performance of cairo if i am using it under 
> wine? 
> 
> thanks! 

Maarten 
. 

I find it that no matter what the surface is, cairo_stroke will call _cairo_surface_fallback_stroke.
what makes the performance 's difference between using an image surface and a win32 surface?

will cairo1.2 fix the problems?

oken
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20100928/36056f0d/attachment-0001.html>


More information about the cairo mailing list