[cairo] src surface clip problems

Vladimir Vukicevic vladimirv at gmail.com
Tue Aug 8 14:10:10 PDT 2006


I've been running into a strange case where the clip set on a surface
used as a source is affecting the destination; this seems to be a bug
in pixman, with the strange src-clip and dst-clip separation for
pixman images.  However, it only seems to appear if there is a
transform (e.g. scale) applied to the source image, which is why the
existing src-copy test doesn't seem to hit it.  I've attached the
test; the "success" result should be a blue rectangle in the middle of
a green background.  Failure is a blue rectangle in the middle of a
red background.

(Note that the resulting image still isn't correct, due to broken
pixman upscaling -- in particular, the left and right edges should be
solid green, and not green-mixed-with-.. black? transparent black?
something.)

    - Vlad
-------------- next part --------------
#include <math.h>
#include "cairo-test.h"
#include <stdio.h>

#define SIZE 40

static cairo_test_draw_function_t draw;

cairo_test_t test = {
    "src-clip",
    "Test a leftover clip on a source surface not affecting compositing",
    SIZE * 2, SIZE,
    draw
};

static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
    cairo_surface_t *surf2;
    cairo_t *cr2;

    /* cr: Fill the destination with our red background that should
     * get covered
     */
    cairo_set_source_rgb (cr, 1, 0, 0);
    cairo_paint (cr);

    surf2 = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, SIZE, SIZE);
    cr2 = cairo_create (surf2);

    /* cr2: Fill temp surface with green */
    cairo_set_source_rgb (cr2, 0, 1, 0);
    cairo_paint (cr2);

    /* cr2: Make a blue square in the middle */
    cairo_set_source_rgb (cr2, 0, 0, 2);
    cairo_save (cr2);
    cairo_new_path (cr2);
    cairo_rectangle (cr2, 10, 10, SIZE-20, SIZE-20);
    cairo_clip (cr2);
    cairo_paint (cr2);
    cairo_restore (cr2);

    /* If this is uncommented, the test works as expected, because this
     * forces the clip to be reset on surf2.
     */
    /* 
       cairo_new_path (cr2);
       cairo_rectangle (cr2, 0, 0, 0, 0);
       cairo_fill (cr2);
    */

    /* If this scale is commented out, the test displays
     * the green-and-blue square on the left side of the result.
     *
     * The correct "pass" image is the green-and-blue square image stretched
     * by 2x.  With this scale, however, only the blue (clipped) portion
     * of the src shows through.
     */
    cairo_scale (cr, 2.0, 1.0);

    cairo_set_source_surface (cr, surf2, 0, 0);
    cairo_paint (cr);

    cairo_destroy (cr2);
    cairo_surface_destroy (surf2);

    return CAIRO_TEST_SUCCESS;
}

int
main (void)
{
    return cairo_test (&test);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: src-clip-ref.png
Type: image/png
Size: 243 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20060808/1c874470/src-clip-ref.png


More information about the cairo mailing list