[cairo] Redoing SOURCE and CLEAR

Owen Taylor otaylor at redhat.com
Wed Aug 17 09:57:06 PDT 2005

On Wed, 2005-08-17 at 11:55 -0400, Behdad Esfahbod wrote:
> Hi Owen,
> I like your general reasoning, but after thinking a bit more I
> don't like your proposal.  I've made a mental model like this:
>   - Any area out of clip wouldn't be touched,
>   - mask is tayloring the source,
>   - taylored source is applied to dest according to the operator

Yes, that is the current model; so you've internalized "how
it works" well. But I think the real question for what operators
we should have are:
 - What is useful for people
 - What makes sense to people

(And it's tailoring, unless I'm doing it. :-)

> And so I can easily reason that if I use the SOURCE operator,
> no evidence of dest would remain.  And that matches the old
> behavior.
> If we change according to your proposal, I don't see any easy way
> to achieve the old behavior other than first clearing and then
> doing source.

Well, if you really want SRC IN MASK, and no traces of DEST inside
the clip, then you *can* clear beforehand. So, we haven't made
the operation impossible. The question is "what do people actually
want to do" ... if the new SOURCE matches that better, and it
matches people's expectations better, it is better.

> Moreover, it reduces SOURCE to IN somehow, but a broken one.  The
> fact that it's differentiating between a alpha of 0 in the
> source, and a point ouside the mask is confusing. 

I don't see the relationship between the new SOURCE and IN.

>  So for example
> these two are not the same:
>   cr = cairo_create (scratch);
>   cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
>   cairo_paint (cr);
>   cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
>   cairo_rectangle (cr, x, y, width, height);
>   cairo_set_source_rgba (cr, 0, 0, 0);
>   cairo_fill (cr);
>   cairo_destroy (cr);
>   cr = cairo_create (canvas);
>   cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
>   cairo_set_source_surface (cr, scratch);
>   cairo_paint (cr);
>   cairo_destory (cr);
> and:
>   cr = cairo_create (canvas);
>   cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
>   cairo_rectangle (cr, x, y, width, height);
>   cairo_set_source_rgba (cr, 0, 0, 0);
>   cairo_fill (cr);
>   cairo_destroy (cr);

> What's happening is that in the first case, I have a transparent
> surface with a black rectangle inside.  I paint my surface with
> that and expect to get a transparent surface with a black
> rectangle inside, that I get.  In the second case, I don't have
> such a surface, but try to get the same effect by defining a path
> and color that represent the rectangle, and I *do the same
> operation*, but what I will get is garbage outside, not
> transparency.

But what's *wrong* with doing:

   cr = cairo_create (canvas);
   cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
   cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
   cairo_set_source_rgba (cr, 0, 0, 0);
   cairo_rectangle (cr, x, y, width, height);
   cairo_fill (cr);
   cairo_destroy (cr);

Yes, it touches the pixels in the rectangle twice, but it's not
going to be a big performance difference. And it's more apparent
what it is doing.

(Note also that create_similar() clears the surface, for better
or worse.)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050817/9d20d6e3/attachment.pgp

More information about the cairo mailing list