mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2025-12-28 07:30:12 +01:00
test: Add record-extend
Exercise the extend modes with a clipped paint, because once upon a time we had a bug... Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
parent
deb88cca13
commit
99c129dd13
7 changed files with 225 additions and 0 deletions
|
|
@ -1010,6 +1010,10 @@ REFERENCE_IMAGES = \
|
|||
random-intersections-nonzero.quartz.ref.png \
|
||||
random-intersections-nonzero.ref.png \
|
||||
random-intersections-nonzero.xlib.ref.png \
|
||||
record-extend-none.ref.png \
|
||||
record-extend-pad.ref.png \
|
||||
record-extend-reflect.ref.png \
|
||||
record-extend-repeat.ref.png \
|
||||
record-fill-alpha.ref.png \
|
||||
record-paint-alpha-clip-mask.ref.png \
|
||||
record-paint-alpha-clip.ref.png \
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@ test_sources = \
|
|||
random-intersections-curves-eo.c \
|
||||
random-intersections-curves-nz.c \
|
||||
record.c \
|
||||
record-extend.c \
|
||||
recording-surface-pattern.c \
|
||||
recording-surface-extend.c \
|
||||
rectangle-rounding-error.c \
|
||||
|
|
|
|||
BIN
test/record-extend-none.ref.png
Normal file
BIN
test/record-extend-none.ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 293 B |
BIN
test/record-extend-pad.ref.png
Normal file
BIN
test/record-extend-pad.ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 298 B |
BIN
test/record-extend-reflect.ref.png
Normal file
BIN
test/record-extend-reflect.ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 335 B |
BIN
test/record-extend-repeat.ref.png
Normal file
BIN
test/record-extend-repeat.ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 286 B |
220
test/record-extend.c
Normal file
220
test/record-extend.c
Normal file
|
|
@ -0,0 +1,220 @@
|
|||
/*
|
||||
* Copyright © 2007 Red Hat, Inc.
|
||||
* Copyright © 2011 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Behdad Esfahbod <behdad@behdad.org>
|
||||
* Chris Wilson <chris@chris-wilson.co.uk>
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include "cairo-test.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define SIZE 90
|
||||
|
||||
/* This is written using clip+paint to exercise a bug that once was in the
|
||||
* recording surface.
|
||||
*/
|
||||
|
||||
static cairo_surface_t *
|
||||
source (void)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
|
||||
/* Create a 4-pixel image surface with my favorite four colors in each
|
||||
* quadrant. */
|
||||
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 2, 2);
|
||||
cr = cairo_create (surface);
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
/* upper-left = white */
|
||||
cairo_set_source_rgb (cr, 1, 1, 1);
|
||||
cairo_rectangle (cr, 0, 0, 1, 1);
|
||||
cairo_fill (cr);
|
||||
|
||||
/* upper-right = red */
|
||||
cairo_set_source_rgb (cr, 1, 0, 0);
|
||||
cairo_rectangle (cr, 1, 0, 1, 1);
|
||||
cairo_fill (cr);
|
||||
|
||||
/* lower-left = green */
|
||||
cairo_set_source_rgb (cr, 0, 1, 0);
|
||||
cairo_rectangle (cr, 0, 1, 1, 1);
|
||||
cairo_fill (cr);
|
||||
|
||||
/* lower-right = blue */
|
||||
cairo_set_source_rgb (cr, 0, 0, 1);
|
||||
cairo_rectangle (cr, 1, 1, 1, 1);
|
||||
cairo_fill (cr);
|
||||
|
||||
surface = cairo_surface_reference (cairo_get_target (cr));
|
||||
cairo_destroy (cr);
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
static cairo_t *
|
||||
extend (cairo_t *cr, cairo_extend_t mode)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
|
||||
cairo_set_source_rgb (cr, 0, 1, 1);
|
||||
cairo_paint (cr);
|
||||
|
||||
/* Now use extend modes to cover most of the surface with those 4 colors */
|
||||
surface = source ();
|
||||
cairo_set_source_surface (cr, surface, SIZE/2 - 1, SIZE/2 - 1);
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
cairo_pattern_set_extend (cairo_get_source (cr), mode);
|
||||
|
||||
cairo_rectangle (cr, 10, 10, SIZE-20, SIZE-20);
|
||||
cairo_clip (cr);
|
||||
cairo_paint (cr);
|
||||
|
||||
return cr;
|
||||
}
|
||||
|
||||
static cairo_t *
|
||||
extend_none (cairo_t *cr)
|
||||
{
|
||||
return extend (cr, CAIRO_EXTEND_NONE);
|
||||
}
|
||||
|
||||
static cairo_t *
|
||||
extend_pad (cairo_t *cr)
|
||||
{
|
||||
return extend (cr, CAIRO_EXTEND_PAD);
|
||||
}
|
||||
|
||||
static cairo_t *
|
||||
extend_repeat (cairo_t *cr)
|
||||
{
|
||||
return extend (cr, CAIRO_EXTEND_REPEAT);
|
||||
}
|
||||
|
||||
static cairo_t *
|
||||
extend_reflect (cairo_t *cr)
|
||||
{
|
||||
return extend (cr, CAIRO_EXTEND_REFLECT);
|
||||
}
|
||||
|
||||
static cairo_t *
|
||||
record_create (cairo_t *target)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
|
||||
surface = cairo_recording_surface_create (cairo_surface_get_content (cairo_get_target (target)), NULL);
|
||||
cr = cairo_create (surface);
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
return cr;
|
||||
}
|
||||
|
||||
static cairo_surface_t *
|
||||
record_get (cairo_t *target)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
|
||||
surface = cairo_surface_reference (cairo_get_target (target));
|
||||
cairo_destroy (target);
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
static cairo_test_status_t
|
||||
record_replay (cairo_t *cr, cairo_t *(*func)(cairo_t *), int width, int height)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
int x, y;
|
||||
|
||||
surface = record_get (func (record_create (cr)));
|
||||
|
||||
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_set_source_surface (cr, surface, 0, 0);
|
||||
cairo_surface_destroy (surface);
|
||||
cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_NONE);
|
||||
|
||||
for (y = 0; y < height; y += 2) {
|
||||
for (x = 0; x < width; x += 2) {
|
||||
cairo_rectangle (cr, x, y, 2, 2);
|
||||
cairo_clip (cr);
|
||||
cairo_paint (cr);
|
||||
cairo_reset_clip (cr);
|
||||
}
|
||||
}
|
||||
|
||||
return CAIRO_TEST_SUCCESS;
|
||||
}
|
||||
|
||||
static cairo_test_status_t
|
||||
record_extend_none (cairo_t *cr, int width, int height)
|
||||
{
|
||||
return record_replay (cr, extend_none, width, height);
|
||||
}
|
||||
|
||||
static cairo_test_status_t
|
||||
record_extend_pad (cairo_t *cr, int width, int height)
|
||||
{
|
||||
return record_replay (cr, extend_pad, width, height);
|
||||
}
|
||||
|
||||
static cairo_test_status_t
|
||||
record_extend_repeat (cairo_t *cr, int width, int height)
|
||||
{
|
||||
return record_replay (cr, extend_repeat, width, height);
|
||||
}
|
||||
|
||||
static cairo_test_status_t
|
||||
record_extend_reflect (cairo_t *cr, int width, int height)
|
||||
{
|
||||
return record_replay (cr, extend_reflect, width, height);
|
||||
}
|
||||
|
||||
CAIRO_TEST (record_extend_none,
|
||||
"Test CAIRO_EXTEND_NONE for recorded surface patterns",
|
||||
"record, extend", /* keywords */
|
||||
NULL, /* requirements */
|
||||
SIZE, SIZE,
|
||||
NULL, record_extend_none)
|
||||
CAIRO_TEST (record_extend_pad,
|
||||
"Test CAIRO_EXTEND_PAD for recorded surface patterns",
|
||||
"record, extend", /* keywords */
|
||||
NULL, /* requirements */
|
||||
SIZE, SIZE,
|
||||
NULL, record_extend_pad)
|
||||
CAIRO_TEST (record_extend_repeat,
|
||||
"Test CAIRO_EXTEND_REPEAT for recorded surface patterns",
|
||||
"record, extend", /* keywords */
|
||||
NULL, /* requirements */
|
||||
SIZE, SIZE,
|
||||
NULL, record_extend_repeat)
|
||||
CAIRO_TEST (record_extend_reflect,
|
||||
"Test CAIRO_EXTEND_REFLECT for recorded surface patterns",
|
||||
"record, extend", /* keywords */
|
||||
NULL, /* requirements */
|
||||
SIZE, SIZE,
|
||||
NULL, record_extend_reflect)
|
||||
Loading…
Add table
Reference in a new issue