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

Vladimir Vukicevic vladimir at pobox.com
Mon Jun 29 21:36:34 PDT 2009


On 6/29/09 8:34 PM, Rainman Lee wrote:
> 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);

Use CAIRO_FORMAT_RGB24 -- you don't need alpha, as your final surface 
won't have alpha.

> 	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);
> 		cairo_paint(bufContext);
>
> 		// 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);
> 		cairo_fill(tarContext);

Er, why are you drawing this inside the loop?  Or are you trying to 
animate the rotation as quickly as possible?

Either way, you want to use cairo_set_operator(tarContext, 
CAIRO_OPERATOR_SOURCE) -- otherwise you get the default OVER, and will 
be doing alpha blending.

> 	}
>
> 	// destroy the source pattern
> 	cairo_pattern_destroy(srcPattern);
>
> 	// destroy all drawing contexts
> 	cairo_destroy(bufContext);
> 	cairo_destroy(tarContext);
>
> 	// destory all drawing surfaces
> 	cairo_surface_destroy(srcSurface);
> 	cairo_surface_destroy(bufSurface);
> 	cairo_surface_destroy(tarSurface);
>
>
> 	ReleaseDC(m_hWnd, hdc);
>
> Is there any code I can optimize?

Try those two changes and let me know how it goes.

     - Vlad


More information about the cairo mailing list