mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-04 08:17:59 +02:00
Harmonize implementations of source-clip and source-clip-scale to make similarities more evident.
This commit is contained in:
parent
524507c39f
commit
64d2feb9f6
5 changed files with 42 additions and 53 deletions
1
test/.gitignore
vendored
1
test/.gitignore
vendored
|
|
@ -102,6 +102,7 @@ set-source
|
|||
show-glyphs-many
|
||||
show-text-current-point
|
||||
source-clip
|
||||
source-clip-scale
|
||||
source-surface-scale-paint
|
||||
surface-finish-twice
|
||||
surface-pattern
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 133 B |
Binary file not shown.
|
Before Width: | Height: | Size: 243 B After Width: | Height: | Size: 161 B |
|
|
@ -27,13 +27,13 @@
|
|||
#include "cairo-test.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define SIZE 40
|
||||
#define SIZE 12
|
||||
|
||||
static cairo_test_draw_function_t draw;
|
||||
|
||||
cairo_test_t test = {
|
||||
"source-clip-scale",
|
||||
"Test a leftover clip on a source surface not affecting compositing",
|
||||
"Test that a source surface is not affected by a clip when scaling",
|
||||
SIZE * 2, SIZE,
|
||||
draw
|
||||
};
|
||||
|
|
@ -41,54 +41,44 @@ cairo_test_t test = {
|
|||
static cairo_test_status_t
|
||||
draw (cairo_t *cr, int width, int height)
|
||||
{
|
||||
cairo_surface_t *surf2;
|
||||
cairo_surface_t *source;
|
||||
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);
|
||||
source = cairo_surface_create_similar (cairo_get_target (cr),
|
||||
CAIRO_CONTENT_COLOR_ALPHA,
|
||||
SIZE, SIZE);
|
||||
cr2 = cairo_create (source);
|
||||
|
||||
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 */
|
||||
/* Fill the source 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);
|
||||
/* Draw a blue square in the middle of the source with clipping.
|
||||
* Note that we are only clipping within a save/restore block but
|
||||
* the buggy behavior demonstrates that the clip remains present
|
||||
* on the surface. */
|
||||
cairo_save (cr2);
|
||||
cairo_new_path (cr2);
|
||||
cairo_rectangle (cr2, 10, 10, SIZE-20, SIZE-20);
|
||||
cairo_rectangle (cr2,
|
||||
SIZE / 4, SIZE / 4,
|
||||
SIZE / 2, SIZE / 2);
|
||||
cairo_clip (cr2);
|
||||
cairo_set_source_rgb (cr2, 0, 0, 1);
|
||||
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);
|
||||
*/
|
||||
/* Fill the destination surface with solid red (should not appear
|
||||
* in final result) */
|
||||
cairo_set_source_rgb (cr, 1, 0, 0);
|
||||
cairo_paint (cr);
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
/* Now draw the source surface onto the destination with scaling. */
|
||||
cairo_scale (cr, 2.0, 1.0);
|
||||
|
||||
cairo_set_source_surface (cr, surf2, 0, 0);
|
||||
cairo_set_source_surface (cr, source, 0, 0);
|
||||
cairo_paint (cr);
|
||||
|
||||
cairo_destroy (cr2);
|
||||
cairo_surface_destroy (surf2);
|
||||
cairo_surface_destroy (source);
|
||||
|
||||
return CAIRO_TEST_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,13 +27,13 @@
|
|||
#include "cairo-test.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define SIZE 50
|
||||
#define SIZE 12
|
||||
|
||||
static cairo_test_draw_function_t draw;
|
||||
|
||||
cairo_test_t test = {
|
||||
"source-clip",
|
||||
"Test using a surface with an active clip as a source",
|
||||
"Test that a source surface is not affected by a clip",
|
||||
SIZE, SIZE,
|
||||
draw
|
||||
};
|
||||
|
|
@ -41,43 +41,41 @@ cairo_test_t test = {
|
|||
static cairo_test_status_t
|
||||
draw (cairo_t *cr, int width, int height)
|
||||
{
|
||||
cairo_pattern_t *pattern;
|
||||
cairo_surface_t *source_surface;
|
||||
cairo_surface_t *source;
|
||||
cairo_t *cr2;
|
||||
|
||||
source_surface = cairo_surface_create_similar (cairo_get_target (cr),
|
||||
CAIRO_CONTENT_COLOR_ALPHA,
|
||||
SIZE, SIZE);
|
||||
source = cairo_surface_create_similar (cairo_get_target (cr),
|
||||
CAIRO_CONTENT_COLOR_ALPHA,
|
||||
SIZE, SIZE);
|
||||
|
||||
cr2 = cairo_create (source_surface);
|
||||
cr2 = cairo_create (source);
|
||||
|
||||
/* Fill the source surface with solid black */
|
||||
cairo_set_source_rgb (cr2, 0, 0, 0);
|
||||
/* Fill the source surface with green */
|
||||
cairo_set_source_rgb (cr2, 0, 1, 0);
|
||||
cairo_paint (cr2);
|
||||
|
||||
/* Now leave a clip in place */
|
||||
/* Draw a blue square in the middle of the source with clipping,
|
||||
* and leave the clip there. */
|
||||
cairo_rectangle (cr2,
|
||||
SIZE / 4, SIZE / 4,
|
||||
SIZE / 2, SIZE / 2);
|
||||
cairo_clip (cr2);
|
||||
cairo_set_source_rgb (cr2, 0, 0, 1);
|
||||
cairo_paint (cr2);
|
||||
|
||||
/* Fill the destination surface with solid white */
|
||||
cairo_set_source_rgb (cr, 1, 1, 1);
|
||||
/* Fill the destination surface with solid red (should not appear
|
||||
* in final result) */
|
||||
cairo_set_source_rgb (cr, 1, 0, 0);
|
||||
cairo_paint (cr);
|
||||
|
||||
/* Now draw the source surface onto the destination surface */
|
||||
pattern = cairo_pattern_create_for_surface (source_surface);
|
||||
cairo_set_source (cr, pattern);
|
||||
cairo_set_source_surface (cr, source, 0, 0);
|
||||
cairo_paint (cr);
|
||||
|
||||
/* As the clip shouldn't matter, the result should be solid black */
|
||||
|
||||
cairo_destroy (cr2);
|
||||
cairo_pattern_destroy (pattern);
|
||||
cairo_surface_destroy (source_surface);
|
||||
cairo_surface_destroy (source);
|
||||
|
||||
return CAIRO_TEST_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue