[cairo] Creating an opaque fade-in effect with Cairo

Andrea Canciani ranma42 at gmail.com
Fri Jan 21 04:03:19 PST 2011


On Fri, Jan 21, 2011 at 12:22 PM, Maarten Bosmans <mkbosmans at gmail.com> wrote:
> 2011/1/21 Tristan Schmelcher <tschmelcher at google.com>:
>> On 20 January 2011 14:26, Andrea Canciani <ranma42 at gmail.com> wrote:
>>> If your destination is always opaque, you can do everything like this:
>>>
>>> cairo_set_operator (cr, CAIRO_OPERATOR_IN);
>>> cairo_set_source (cr, the_fading_surface);
>>> cairo_paint_with_alpha (cr, the_fade_parameter);
>>>
>>> This should be sufficient to completely replace the old content assuming that
>>> the destination has a content of type CAIRO_CONTENT_COLOR.
>>> It is slightly less flexible than your code, because this will only allow
>>> fading from/to black, but I expect it to be faster, because it performs only
>>> one compositing operation.
>>
>> Thanks for the info! My destination is indeed of type
>> CAIRO_CONTENT_COLOR, so your suggestion works great, but surprisingly
>> it seems to be slightly slower. When I make it render as fast as it
>> can, the CLEAR+OVER approach gets an average of 13 fps while the IN
>> approach gets an average of 12 fps. Rather strange ... I definitely
>> agree with you that it ought to be the faster method.
>
> Why not just use CAIRO_OPERATOR_SOURCE? It is likely faster than
> CAIRO_OPERATOR_IN.

It should not be faster, because pixman already replaces IN with SRC when it
is used on an opaque destination.
Worse, cairo defines SOURCE as bounded, which means that if you use
it with a non-opaque mask it will not completely replace the underlying color,
so it will not provide the result Tristan was looking for.
(Even worse, cairo-image will probably create a temporary surface to
make sure that the result will be that of a bounded operator instead of
pixman SRC operator).

Andrea


More information about the cairo mailing list