[cairo] clear operator

control H control.h at gmail.com
Wed Jun 1 01:06:23 PDT 2011


>>  surf1=cairo_surface_create_similar(cairo_get_target(cr),
>>                                     CAIRO_CONTENT_COLOR_ALPHA,
>>                                     w,h);
>>  cr1=cairo_create(surf1);
>>  cairo_set_source_rgba(cr1,0.,1.,0.,.8);
>>  cairo_move_to(cr1,w/2,h/2);
>>  cairo_arc(cr1,w/2,h/2,MIN(w,h)/3,0,2*G_PI);
>>  cairo_fill(cr1);
>>
>>  surf2=cairo_surface_create_similar(cairo_get_target(cr),
>>                                     CAIRO_CONTENT_COLOR_ALPHA,
>>                                     w,h);
>>  cr2=cairo_create(surf2);
>>  cairo_set_source_rgba(cr2,1.,1.,0.,.7);
>>  cairo_arc(cr2,w/2.5,h/2,MIN(w,h)/4,0,2*G_PI);
>>  cairo_fill(cr2);
>>
>>  cairo_set_operator(cr1,CAIRO_OPERATOR_CLEAR);
>>  //cairo_set_operator(cr1,CAIRO_OPERATOR_DEST_OUT);
>>  cairo_set_source_surface(cr1,surf2,0,0);
>>  cairo_paint(cr1);
>
> surf1 is now completely transparent

I don't understand. I expect surf1 to be the circle, except for the
parts where is any pixel in surf2. That is what I want at least, but
also how I interpret the operators at
http://cairographics.org/operators/. I do understand the result if I
change the operator into any other, like DEST_OUT. So could you please
explain why in this case surf1 becomes _completely_ transparent?

>>  cairo_set_source_surface(cr,surf1,0,0);
>>  cairo_set_operator(cr,CAIRO_OPERATOR_OVER);
>>  cairo_paint(cr);
>
> This is actually a no-op.
>
>>
>>  cairo_surface_destroy(surf1);
>>  cairo_surface_destroy(surf2);
>>  cairo_destroy(cr1);
>>  cairo_destroy(cr2);
>>
>>  cairo_destroy (cr);
>>
>>  return TRUE;
>> }
>>
>> The result is just a white screen. However, if I change
>
> This is expected. When you paint() cr1 with a CLEAR
> operator, you make it completely transparent.
> Painting surf1 OVER cr has thus no effect at all
> and correctly leaves surface white.
>
> Andrea

Sure, when surf1 is already transparent that makes sense :)


More information about the cairo mailing list