[cairo-commit] 2 commits - src/cairo-surface-subsurface.c test/Makefile.sources test/subsurface-outside-target.argb32.ref.png test/subsurface-outside-target.c test/subsurface-outside-target.rgb24.ref.png
Benjamin Otte
company at kemper.freedesktop.org
Tue Aug 31 18:18:44 PDT 2010
src/cairo-surface-subsurface.c | 41 +++--
test/Makefile.sources | 1
test/subsurface-outside-target.argb32.ref.png |binary
test/subsurface-outside-target.c | 178 ++++++++++++++++++++++++++
test/subsurface-outside-target.rgb24.ref.png |binary
5 files changed, 202 insertions(+), 18 deletions(-)
New commits:
commit 61a1835e40d0b6d786951143779077d16ed2486e
Author: Benjamin Otte <otte at redhat.com>
Date: Wed Sep 1 03:17:12 2010 +0200
subsurface: Fix acquire_source_surface for out-of-bounds surfaces
See subsurface-outside-target test.
diff --git a/src/cairo-surface-subsurface.c b/src/cairo-surface-subsurface.c
index 9b21fa6..3cf8330 100644
--- a/src/cairo-surface-subsurface.c
+++ b/src/cairo-surface-subsurface.c
@@ -276,6 +276,24 @@ struct extra {
void *image_extra;
};
+static void
+cairo_surface_paint_to_target (cairo_surface_t *target,
+ cairo_surface_subsurface_t *subsurface)
+{
+ cairo_t *cr;
+
+ cr = cairo_create (target);
+
+ cairo_set_source_surface (cr,
+ subsurface->target,
+ - subsurface->extents.x,
+ - subsurface->extents.y);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_paint (cr);
+
+ cairo_destroy (cr);
+}
+
static cairo_status_t
_cairo_surface_subsurface_acquire_source_image (void *abstract_surface,
cairo_image_surface_t **image_out,
@@ -311,15 +329,7 @@ _cairo_surface_subsurface_acquire_source_image (void *abstrac
if (unlikely (image->base.status))
return image->base.status;
- cairo_surface_set_device_offset (&image->base,
- -surface->extents.x,
- -surface->extents.y);
-
- status = _cairo_recording_surface_replay (&meta->base, &image->base);
- if (unlikely (status)) {
- cairo_surface_destroy (&image->base);
- return status;
- }
+ cairo_surface_paint_to_target (&image->base, surface);
_cairo_surface_attach_snapshot (&surface->base, &image->base, NULL);
@@ -337,7 +347,7 @@ _cairo_surface_subsurface_acquire_source_image (void *abstrac
if (unlikely (status))
goto CLEANUP;
- ret = _cairo_surface_get_extents (extra->image, &target_extents);
+ ret = _cairo_surface_get_extents (&extra->image->base, &target_extents);
assert (ret);
/* only copy if we need to perform sub-byte manipulation */
@@ -360,6 +370,8 @@ _cairo_surface_subsurface_acquire_source_image (void *abstrac
extra->image->stride);
if (unlikely ((status = image->base.status)))
goto CLEANUP_IMAGE;
+
+ image->base.is_clear = FALSE;
} else {
image = (cairo_image_surface_t *)
_cairo_image_surface_create_with_pixman_format (NULL,
@@ -370,16 +382,9 @@ _cairo_surface_subsurface_acquire_source_image (void *abstrac
if (unlikely ((status = image->base.status)))
goto CLEANUP_IMAGE;
- pixman_image_composite32 (PIXMAN_OP_SRC,
- image->pixman_image, NULL, extra->image->pixman_image,
- surface->extents.x, surface->extents.y,
- 0, 0,
- 0, 0,
- surface->extents.width, surface->extents.height);
+ cairo_surface_paint_to_target (&image->base, surface);
}
- image->base.is_clear = FALSE;
-
*image_out = image;
*extra_out = extra;
return CAIRO_STATUS_SUCCESS;
commit f54c51e75c7abe872127d559e029bf4383439bca
Author: Benjamin Otte <otte at redhat.com>
Date: Wed Sep 1 02:10:51 2010 +0200
test: Add subsurface-outside-target
This test defines the behavior of subsurfaces when they are created to
be bigger than their target.
diff --git a/test/Makefile.sources b/test/Makefile.sources
index bf8979d..e497cd7 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -251,6 +251,7 @@ test_sources = \
subsurface-pad.c \
subsurface-modify-child.c \
subsurface-modify-parent.c \
+ subsurface-outside-target.c \
subsurface-similar-repeat.c \
surface-finish-twice.c \
surface-pattern.c \
diff --git a/test/subsurface-outside-target.argb32.ref.png b/test/subsurface-outside-target.argb32.ref.png
new file mode 100644
index 0000000..337cdd8
Binary files /dev/null and b/test/subsurface-outside-target.argb32.ref.png differ
diff --git a/test/subsurface-outside-target.c b/test/subsurface-outside-target.c
new file mode 100644
index 0000000..fd51243
--- /dev/null
+++ b/test/subsurface-outside-target.c
@@ -0,0 +1,178 @@
+/*
+ * Copyright 2010 Red Hat Inc.
+ *
+ * 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.
+ *
+ * Author: Benjamin Otte <otte at gnome.org>
+ */
+
+#include "cairo-test.h"
+
+#define ARRAY_LENGTH(array) (sizeof (array) / sizeof ((array)[0]))
+
+#define TARGET_SIZE 10
+
+#define SUB_SIZE 15
+#define SUB_OFFSET -5
+
+#define PAINT_OFFSET SUB_SIZE
+#define PAINT_SIZE (3 * SUB_SIZE)
+
+static cairo_content_t contents[] = { CAIRO_CONTENT_ALPHA,
+ CAIRO_CONTENT_COLOR,
+ CAIRO_CONTENT_COLOR_ALPHA };
+
+#define N_CONTENTS ARRAY_LENGTH (contents)
+#define N_PADS (CAIRO_EXTEND_PAD + 1)
+
+
+static cairo_surface_t *
+create_target (cairo_surface_t *similar_to,
+ cairo_content_t content)
+{
+ cairo_surface_t *surface;
+ cairo_t *cr;
+
+ surface = cairo_surface_create_similar (similar_to,
+ content,
+ TARGET_SIZE, TARGET_SIZE);
+
+ cr = cairo_create (surface);
+ cairo_test_paint_checkered (cr);
+ cairo_destroy (cr);
+
+ return surface;
+}
+
+static cairo_test_status_t
+check_surface_extents (const cairo_test_context_t *ctx,
+ cairo_surface_t * surface,
+ double x,
+ double y,
+ double width,
+ double height)
+{
+ double x1, y1, x2, y2;
+ cairo_t *cr;
+
+ cr = cairo_create (surface);
+ cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
+
+ if (x != x1 ||
+ y != y1 ||
+ width != x2 - x1 ||
+ height != y2 - y1) {
+ cairo_test_log (ctx,
+ "surface extents should be (%g, %g, %g, %g), but are (%g, %g, %g, %g)\n",
+ x, y, width, height,
+ x1, y1, x2 - x1, y2 - y1);
+ return CAIRO_TEST_FAILURE;
+ }
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+static cairo_test_status_t
+draw_for_size (cairo_t *cr,
+ double x,
+ double y)
+{
+ cairo_surface_t *target, *subsurface;
+ cairo_extend_t extend;
+ cairo_test_status_t check, result = CAIRO_TEST_SUCCESS;
+ unsigned int content;
+
+ for (content = 0; content < N_CONTENTS; content++) {
+ cairo_save (cr);
+
+ /* create a target surface for our subsurface */
+ target = create_target (cairo_get_target (cr),
+ contents[content]);
+
+ /* create a subsurface that extends the target surface */
+ subsurface = cairo_surface_create_for_rectangle (target,
+ x, y,
+ SUB_SIZE, SUB_SIZE);
+
+ /* ensure the extents are ok */
+ check = check_surface_extents (cairo_test_get_context (cr),
+ subsurface,
+ 0, 0,
+ SUB_SIZE, SUB_SIZE);
+ if (result == CAIRO_TEST_SUCCESS)
+ result = check;
+
+ /* paint this surface with all extend modes. */
+ for (extend = 0; extend < N_PADS; extend++) {
+ cairo_save (cr);
+
+ cairo_rectangle (cr, 0, 0, PAINT_SIZE, PAINT_SIZE);
+ cairo_clip (cr);
+
+ cairo_set_source_surface (cr, subsurface, PAINT_OFFSET, PAINT_OFFSET);
+ cairo_pattern_set_extend (cairo_get_source (cr), extend);
+ cairo_paint (cr);
+
+ cairo_restore (cr);
+
+ cairo_translate (cr, PAINT_SIZE + TARGET_SIZE, 0);
+ }
+
+ cairo_surface_destroy (subsurface);
+ cairo_surface_destroy (target);
+
+ cairo_restore (cr);
+
+ cairo_translate (cr, 0, PAINT_SIZE + TARGET_SIZE);
+ }
+
+ return result;
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+ cairo_test_status_t check, result = CAIRO_TEST_SUCCESS;
+
+ /* paint background in nice gray */
+ cairo_set_source_rgb (cr, 0.51613, 0.55555, 0.51613);
+ cairo_paint (cr);
+
+ /* Use CAIRO_OPERATOR_SOURCE in the tests so we get the actual
+ * contents of the subsurface */
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+
+ result = draw_for_size (cr, SUB_OFFSET, SUB_OFFSET);
+
+ check = draw_for_size (cr, 0, 0);
+ if (result == CAIRO_TEST_SUCCESS)
+ result = check;
+
+ return result;
+}
+
+CAIRO_TEST (subsurface_outside_target,
+ "Tests contents of subsurfaces outside target area",
+ "subsurface, pad", /* keywords */
+ NULL, /* requirements */
+ (PAINT_SIZE + TARGET_SIZE) * N_PADS - TARGET_SIZE,
+ (PAINT_SIZE + TARGET_SIZE) * N_CONTENTS * 2 - TARGET_SIZE,
+ NULL, draw)
diff --git a/test/subsurface-outside-target.rgb24.ref.png b/test/subsurface-outside-target.rgb24.ref.png
new file mode 100644
index 0000000..368936e
Binary files /dev/null and b/test/subsurface-outside-target.rgb24.ref.png differ
More information about the cairo-commit
mailing list