[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
Sun Jul 5 22:26:54 PDT 2009


Hi Vladimir
Have you read my test result?
How do you think it?
was it a cairo's problem?

On Tue, Jun 30, 2009 at 1:36 PM, Rainman Lee<rainman.lee at gmail.com> wrote:
> Hi,
> 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 ?
>
> Thank you!
>
> Rainman.
>
>
>
> 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_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