[cairo] why cairo is so slow on Windows, is there any plan to improve cairo performance on Windows?

Rainman Lee rainman.lee at gmail.com
Mon Jun 29 20:34:22 PDT 2009

I tried, it was more slower.....here is my test code

	HDC hdc = GetDC(m_hWnd);
	RECT rcClient; GetClientRect(m_hWnd, &rcClient);

	// create all drawing surfaces
	cairo_surface_t* srcSurface = cairo_image_surface_create_from_png("ren.png");
	cairo_surface_t* bufSurface =
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1440, 900);
	cairo_surface_t* tarSurface = cairo_win32_surface_create(hdc);

	// create all drawing contexts
	cairo_t* bufContext = cairo_create(bufSurface);
	cairo_t* tarContext = cairo_create(tarSurface);

	// create source pattern
	cairo_pattern_t* srcPattern = cairo_pattern_create_for_surface(srcSurface);
	cairo_pattern_set_filter(srcPattern, CAIRO_FILTER_FAST);

	// initialize the buffer context
	cairo_translate(bufContext, 600, 300);
	cairo_set_antialias(bufContext, CAIRO_ANTIALIAS_NONE);

	double angle = M_PI / 180;

	for (int i = 0; i < 360; i++)
		// paint on the buffer
		cairo_rotate(bufContext, angle);
		cairo_set_source(bufContext, srcPattern);

		// then fill the target with buffer
		// no rotation
		cairo_rectangle(tarContext, 0, 0, rcClient.right, rcClient.bottom);
		cairo_set_source_surface(tarContext, bufSurface, 0, 0);

	// destroy the source pattern

	// destroy all drawing contexts

	// destory all drawing surfaces

	ReleaseDC(m_hWnd, hdc);

Is there any code I can optimize?

Thank you!


On Tue, Jun 30, 2009 at 10:43 AM, Vladimir Vukicevic<vladimir at pobox.com> wrote:
> Right, that's going to be slow.  What Owen is suggesting is that you create
> an image surface the same size as your update region, then draw your rotated
> image into it.  Then use StretchDIBits or equivalent to draw it onto the
> window's DC.
> Or, create a win32 DIB surface using cairo_win32_surface_create_with_dib as
> your destination, and then draw that onto the window DC, since that
> operation will be fast.  If I'm not making sense:
> HDC winDC;
> cairo_surface_t *winSurf = cairo_win32_surface_create_for_dc(winDC);
> cairo_surface_t *target = cairo_win32_surface_create_with_dib(..., width,
> height);
> cairo_surface_t *src = cairo_image_surface_create(...);
> draw src -> target rotated, etc.
> finally draw target -> winSurf 1:1, no rotation, etc.
>    - Vlad
> On 6/29/09 7:20 PM, Rainman Lee wrote:
>> I did not use DDB bitmap :@)
>> I just created a image surface from a png file and a cairo win32
>> surface from a window dc,
>> then fill the win32 surface with the image surface by rotation
>> transforms from 0 degree up to 360 degree.
>> On Tue, Jun 30, 2009 at 4:01 AM, Owen Taylor<otaylor at redhat.com>  wrote:
>>> On Mon, 2009-06-29 at 12:48 +0800, Rainman Lee wrote:
>>>> Hi everyone,
>>>> I use cairo on windows for a while. I found that cairo was so slow
>>>> whenever fill a surface to another with scaling, rotating, or even a
>>>> non-integer translaton. I compared it with GDI+, which is at least 7
>>>> times faster than cairo :(
>>>> It seems that if a source pixel can not map to a dest pixel which has
>>>> an integer coordinate, cairo will use a subpixel algorithm, and it
>>>> will terribly hurt the performance. I made a filling test, firstly by
>>>> a 0.5 pixel step horz translation transform, and a 1 pixel step horz
>>>> translation transform then, each of which looped 100 times. the first
>>>> case was extremely slow than the second one.
>>>> Is there any idea to speed up cairo in this case? I tryed to set
>>>> antialias with none, but it had no effect.
>>> Only a very small subset of Cairo can be done using hardware
>>> acceleration via the GDI API. For everything else, if your bitmap
>>> is in video memory (a DDB) Cairo will need to read, make the changes
>>> and write back. This is very slow.
>>> For complex rendering, you are much better off rendering to a DIB.
>>> - Owen
>> _______________________________________________
>> cairo mailing list
>> cairo at cairographics.org
>> http://lists.cairographics.org/mailman/listinfo/cairo

More information about the cairo mailing list