[cairo] Question about cairo_paint

Antoine Azar cairo at antoineazar.com
Thu Feb 7 12:28:05 PST 2008


Thanks for the detailed reply Carl.

So to round up the possible optimizations (all concerning only opaque sources):

All verbs except paint, operator OVER, all extend modes: switch OVER to SOURCE
paint, operator OVER, extend none: switch OVER to SOURCE, call 
rectangle and fill instead of paint
paint, operator OVER, other extend modes: switch OVER to SOURCE

I'll implement that and see if it gets all the tests passing. If 
anyone can think of a potential problem with that, let me know.
Antoine


At 08:52 AM 2/7/2008, Carl Worth wrote:
>On Thu, 07 Feb 2008 03:01:00 -0500, Antoine Azar wrote:
> > 1- I disable that optimization when the extend mode is at none (as
> > there's a chance we'll sample transparent pixels outside the image)
>
>That would be a correct thing to do.
>
> > 2- The behavior shown is not the desired one and we never noticed it
> > before because we were using an OVER operator
>
>The semantics of cairo_paint is that it effectively paints an infinite
>area. So switching from OVER to SOURCE when there are translucent
>regions in the source, (including EXTEND_NONE regions outside an
>image), is wrong.
>
> > My question is then: when painting (cairo_paint) a small source onto
> > a larger destination, do we A) really want to sample the source for
> > every pixel of the destination, or do we B) only want to paint the
> > source within its bounds onto the destination (thus using its bounds
> > as a clip area)?
>
>As described above, the semantics of the operation is that there's an
>infinitely-large drawing operation occurring. As an internal
>optimization, though, we don't need to be sampling lots of pixels in
>the source that we "know" will have no effect. So if you can optimize
>this EXTEND_NONE case to guarantee it won't sample outside the image,
>(and still generate correct results in all cases), then you might be
>able to switch from OVER to SOURCE in this case.
>
> > If the answer is A), then my second question is: do we have any
> > better way to just paste a small source onto a larger destination
> > (without having to define a clip area each time)?
>
>The easiest thing for a user to do is certainly just cairo_paint() and
>we do encourage that, so it would be good to optimize that case as
>much as we can. Meanwhile, the user can also do
>cairo_rectangle();cairo_fill() to explicitly draw to a smaller region,
>(and that's still quite a lot easier than setting up a clip).
>
>-Carl



More information about the cairo mailing list