[cairo] why cairo is so slow on Windows, is there any plan to improve cairo performance on Windows?
rainman.lee at gmail.com
Mon Jun 29 22:36:58 PDT 2009
yes, I want users see an animation, not pictures, so I have to update
the screen as soon as possible.
Here is my test result:
kept my test code no change, the total elapsed time was 5652ms
replaced CAIRO_FORMAT_ARGB32 with CAIRO_FORMAT_RGB24, the total time was 4124ms
finally set the tarContext operator as CAIRO_OPERATOR_SOURCE, the
total time was 3892ms
I just wonder whether we should use a buffer surface, because without
it, the total time was only 2987ms, but still far behind GDI+, which
score is 1259ms...
Is there any possible to opitmize more ?
On Tue, Jun 30, 2009 at 12:36 PM, Vladimir Vukicevic<vladimir at pobox.com> wrote:
> 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_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_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,
>> cairo_set_source_surface(tarContext, bufSurface, 0, 0);
> 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
>> // destroy all drawing contexts
>> // destory all drawing surfaces
>> 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