[Pixman] Source clipping: how-to and tests

Siarhei Siamashka siarhei.siamashka at gmail.com
Mon Mar 2 07:33:16 PST 2015


On Mon, 2 Mar 2015 14:47:01 +0200
Pekka Paalanen <ppaalanen at gmail.com> wrote:

> Hi,
> 
> I've been trying to use source clipping in Weston's Pixman-renderer,
> and I found something that seems strange.
> 
> The scenario is that I have:
> - source clip in source image coordinates
> - transformation (matrix)
> - destination clip in destination coordinates
> - potentially a mask (to apply global alpha
> 
> Then call pixman_image_composite32() to render.
> 
> Apart from the source clip everything works fine. Some special cases
> really need a source clip, so I'm looking into that. I finally realized
> I need all three to actually get any effect:
> 
> 	pixman_image_set_clip_region32(ps->image, &buffer_region);
> 	pixman_image_set_source_clipping(ps->image, 1);
> 	pixman_image_set_has_client_clip(ps->image, 1);
> 
> It seems that is as designed, that's ok.
> 
> The strange thing is that the source clip seems to be done in
> the destination, not in the source. Is this expected?

Yes, this is expected. Søren can probably provide better explanations
about the rationale. But here are some old links:

http://lists.cairographics.org/archives/xorg-devel/2009-May/000819.html
http://lists.cairographics.org/archives/xorg-devel/2009-May/000820.html
http://cgit.freedesktop.org/pixman/commit/?id=78ca4eea6467dbb6b9da1198b9526750a0a8dca3

> Using source clip looks like it replaces the destination clip, instead
> of clipping in the source image coordinate space. I'm testing with
> Pixman 0.32.4.
> 
> I would really need clipping both before and after the transformation.
> Is there a way to achieve that, or do I have to start looking into
> trapezoids or something? (I suppose I will next look into creating a
> mask image.)

Can you provide a bit more details about your exact use case?

In some cases, the source image clipping might be simulated by
just wrapping a rectangular area of an existing image as a new
pixman_image_t. And then using it as the source image in the
compositing operation.

> Another question is, since source clipping really needs both
> set_source_clipping and set_has_client_clip, do some of the tests have
> a bug in that respect?
> 
> Grepping Pixman master, these do use set_has_client_clip:
> 	test/glyph-test.c
> 	test/stress-test.c
> 
> These use set_source_clipping, but do not use set_has_client_clip:
> 	test/affine-test.c
> 	test/composite-traps-test.c
> 	test/scaling-test.c

Yes, looks like these set_source_clipping() calls indeed have no effect
there.

> Unless I'm mistaken, nothing is testing the correctness of source
> clipping? Except maybe the glyph test?

The source clipping is (attempted to be) set as part of fuzzing. But
this is only should help to detect unexpected changes in behaviour, and
does not really test if the clipping is actually done correctly. This
surely could be improved.

-- 
Best regards,
Siarhei Siamashka


More information about the Pixman mailing list