[cairo] about cairo_stroke's performance
oken
okenjian at 163.com
Mon Sep 27 06:56:30 PDT 2010
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:
void drawLines(cairo_surface_t *surface, int nCount)
{
cairo_t *cr = cairo_create (surface);
cairo_set_source_rgb(cr, 1, 0, 0);
/*cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);*/
srand(time(NULL));
CTimer timer;
timer.Restart();
for (int i = 0; i < nCount; i++)
{
double x1 = rand() % 500;
double y1 = rand() % 500;
double x2 = rand() % 1500 + 100;
double y2 = rand() % 1000 + 100;
cairo_move_to(cr, x1, y1);
cairo_line_to(cr, x2, y2);
cairo_stroke(cr);
}
timer.Stop();
printf("drawlines, %d times:%d(ms)\n", nCount, timer.ElapsedMsec());
cairo_surface_write_to_png(surface, "drawLines.png");
cairo_destroy (cr);
}
TEST(DrawLine, ImageBackend)
{
cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1000, 1000);
drawLines(surface, 1000);
cairo_surface_destroy (surface);
}
TEST(DrawLine, HDCBackend)
{
HDC hdc = GetDC(NULL);
cairo_surface_t *surface = cairo_win32_surface_create(hdc);
drawLines(surface, 1000);
cairo_surface_destroy (surface);
ReleaseDC(NULL, hdc);
}
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.
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!).
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?
2. is it possible to improve it ? how?
3. what can i do the improve the performance of cairo if i am using it under wine?
thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20100927/bbcc0dc6/attachment.htm>
More information about the cairo
mailing list