[cairo-commit] 5 commits - boilerplate/cairo-boilerplate-svg.c src/cairo-ft-font.c src/cairo-image-surface.c src/cairo-paginated-surface.c src/cairo-scaled-font.c test/cairo-test.c test/png.c test/pthread-same-source.c test/surface-source.c test/toy-font-face.c test/user-data.c test/xlib-surface-source.c
Chris Wilson
ickle at kemper.freedesktop.org
Mon May 3 11:22:59 PDT 2010
boilerplate/cairo-boilerplate-svg.c | 2 -
src/cairo-ft-font.c | 4 --
src/cairo-image-surface.c | 12 +++++++-
src/cairo-paginated-surface.c | 26 +++++++++---------
src/cairo-scaled-font.c | 8 +++++
test/cairo-test.c | 21 ++++++++++++--
test/png.c | 34 ++++++++++++++++--------
test/pthread-same-source.c | 7 ++++
test/surface-source.c | 11 ++++++-
test/toy-font-face.c | 16 +++++++++--
test/user-data.c | 51 +++++++++++++++++++++++++-----------
test/xlib-surface-source.c | 7 ++++
12 files changed, 145 insertions(+), 54 deletions(-)
New commits:
commit af26560f258d93cc78782ddd0208128756874c11
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Mon May 3 19:21:59 2010 +0100
test: Improve memfault behaviour.
Various minor tweaks to convert asserts into error returns and to
improve error checking on intermediate surfaces.
diff --git a/boilerplate/cairo-boilerplate-svg.c b/boilerplate/cairo-boilerplate-svg.c
index 583f9a1..dbfa0d6 100644
--- a/boilerplate/cairo-boilerplate-svg.c
+++ b/boilerplate/cairo-boilerplate-svg.c
@@ -242,7 +242,7 @@ static void
_cairo_boilerplate_svg_cleanup (void *closure)
{
svg_target_closure_t *ptc = closure;
- if (ptc->target) {
+ if (ptc->target != NULL) {
cairo_surface_finish (ptc->target);
cairo_surface_destroy (ptc->target);
}
diff --git a/test/cairo-test.c b/test/cairo-test.c
index f78519f..aa8dd3a 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -917,10 +917,23 @@ REPEAT:
goto UNWIND_SURFACE;
}
- cairo_surface_set_user_data (surface,
- &cairo_boilerplate_output_basename_key,
- base_path,
- NULL);
+ if (cairo_surface_set_user_data (surface,
+ &cairo_boilerplate_output_basename_key,
+ base_path,
+ NULL))
+ {
+#if HAVE_MEMFAULT
+ cairo_surface_destroy (surface);
+
+ if (target->cleanup)
+ target->cleanup (closure);
+
+ goto REPEAT;
+#else
+ ret = CAIRO_TEST_FAILURE;
+ goto UNWIND_SURFACE;
+#endif
+ }
cairo_surface_set_device_offset (surface, dev_offset, dev_offset);
diff --git a/test/png.c b/test/png.c
index 9f082c9..e90ac66 100644
--- a/test/png.c
+++ b/test/png.c
@@ -55,6 +55,7 @@ format_to_string (cairo_format_t format)
switch (format) {
case CAIRO_FORMAT_A1: return "a1";
case CAIRO_FORMAT_A8: return "a8";
+ case CAIRO_FORMAT_RGB16_565: return "rgb16";
case CAIRO_FORMAT_RGB24: return "rgb24";
case CAIRO_FORMAT_ARGB32: return "argb32";
case CAIRO_FORMAT_INVALID:
@@ -79,61 +80,72 @@ preamble (cairo_test_context_t *ctx)
cairo_surface_t *surface0, *surface1;
cairo_status_t status;
uint32_t argb32 = 0xdeadbede;
- cairo_test_status_t result = CAIRO_TEST_SUCCESS;
surface0 = cairo_image_surface_create_for_data ((unsigned char *) &argb32,
CAIRO_FORMAT_ARGB32,
1, 1, 4);
- assert (cairo_surface_status (surface0) == CAIRO_STATUS_SUCCESS);
status = cairo_surface_write_to_png (surface0, filename);
if (status) {
cairo_test_log (ctx, "Error writing '%s': %s\n",
filename, cairo_status_to_string (status));
- result = CAIRO_TEST_FAILURE;
+
+ cairo_surface_destroy (surface0);
+ return cairo_test_status_from_status (ctx, status);
}
surface1 = cairo_image_surface_create_from_png (filename);
status = cairo_surface_status (surface1);
if (status) {
cairo_test_log (ctx, "Error reading '%s': %s\n",
filename, cairo_status_to_string (status));
- result = CAIRO_TEST_FAILURE;
+
+ cairo_surface_destroy (surface1);
+ cairo_surface_destroy (surface0);
+ return cairo_test_status_from_status (ctx, status);
}
if (! image_surface_equals (surface0, surface1)) {
cairo_test_log (ctx, "Error surface mismatch.\n");
cairo_test_log (ctx, "to png: "); print_surface (ctx, surface0);
cairo_test_log (ctx, "from png: "); print_surface (ctx, surface1);
- result = CAIRO_TEST_FAILURE;
+
+ cairo_surface_destroy (surface0);
+ cairo_surface_destroy (surface1);
+ return CAIRO_TEST_FAILURE;
}
assert (*(uint32_t *) cairo_image_surface_get_data (surface1) == argb32);
cairo_surface_destroy (surface0);
cairo_surface_destroy (surface1);
-
surface0 = cairo_image_surface_create_for_data ((unsigned char *) &argb32,
CAIRO_FORMAT_RGB24,
1, 1, 4);
- assert (cairo_surface_status (surface0) == CAIRO_STATUS_SUCCESS);
status = cairo_surface_write_to_png (surface0, filename);
if (status) {
cairo_test_log (ctx, "Error writing '%s': %s\n",
filename, cairo_status_to_string (status));
- result = CAIRO_TEST_FAILURE;
+ cairo_surface_destroy (surface0);
+ return cairo_test_status_from_status (ctx, status);
}
surface1 = cairo_image_surface_create_from_png (filename);
status = cairo_surface_status (surface1);
if (status) {
cairo_test_log (ctx, "Error reading '%s': %s\n",
filename, cairo_status_to_string (status));
- result = CAIRO_TEST_FAILURE;
+
+ cairo_surface_destroy (surface1);
+ cairo_surface_destroy (surface0);
+ return cairo_test_status_from_status (ctx, status);
}
if (! image_surface_equals (surface0, surface1)) {
cairo_test_log (ctx, "Error surface mismatch.\n");
cairo_test_log (ctx, "to png: "); print_surface (ctx, surface0);
cairo_test_log (ctx, "from png: "); print_surface (ctx, surface1);
- result = CAIRO_TEST_FAILURE;
+
+ cairo_surface_destroy (surface0);
+ cairo_surface_destroy (surface1);
+ return CAIRO_TEST_FAILURE;
}
assert ((*(uint32_t *) cairo_image_surface_get_data (surface1) & RGB_MASK)
== (argb32 & RGB_MASK));
@@ -141,7 +153,7 @@ preamble (cairo_test_context_t *ctx)
cairo_surface_destroy (surface0);
cairo_surface_destroy (surface1);
- return result;
+ return CAIRO_TEST_SUCCESS;
}
CAIRO_TEST (png,
diff --git a/test/pthread-same-source.c b/test/pthread-same-source.c
index 50102d9..49123b4 100644
--- a/test/pthread-same-source.c
+++ b/test/pthread-same-source.c
@@ -113,9 +113,16 @@ draw (cairo_t *cr, int width, int height)
thread_data_t thread_data[N_THREADS];
cairo_test_status_t test_status = CAIRO_TEST_SUCCESS;
cairo_surface_t *source;
+ cairo_status_t status;
int i;
source = create_source (cairo_get_target (cr));
+ status = cairo_surface_status (source);
+ if (status) {
+ cairo_surface_destroy (source);
+ return cairo_test_status_from_status (cairo_test_get_context (cr),
+ status);
+ }
for (i = 0; i < N_THREADS; i++) {
thread_data[i].target = cairo_surface_create_similar (cairo_get_target (cr),
diff --git a/test/surface-source.c b/test/surface-source.c
index eb8be19..657a0c8 100644
--- a/test/surface-source.c
+++ b/test/surface-source.c
@@ -111,6 +111,7 @@ draw (cairo_t *cr, int width, int height)
{
cairo_surface_t *surface;
cairo_surface_t *similar;
+ cairo_status_t status;
cairo_t *cr2;
cairo_set_source_rgb (cr, 0, 0, 0);
@@ -143,21 +144,27 @@ draw (cairo_t *cr, int width, int height)
cairo_fill (cr);
/* destroy the surface last, as this triggers XCloseDisplay */
+ cairo_surface_finish (surface);
+ status = cairo_surface_status (surface);
cairo_surface_destroy (surface);
- return CAIRO_TEST_SUCCESS;
+ return cairo_test_status_from_status (cairo_test_get_context (cr),
+ status);
}
static cairo_test_status_t
preamble (cairo_test_context_t *ctx)
{
cairo_surface_t *surface;
+ cairo_status_t status;
surface = create_source_surface (SOURCE_SIZE);
if (surface == NULL) /* can't create the source so skip the test */
return CAIRO_TEST_UNTESTED;
+ cairo_surface_finish (surface);
+ status = cairo_surface_status (surface);
cairo_surface_destroy (surface);
- return CAIRO_TEST_SUCCESS;
+ return cairo_test_status_from_status (ctx, status);
}
diff --git a/test/toy-font-face.c b/test/toy-font-face.c
index 147c43b..cbebf84 100644
--- a/test/toy-font-face.c
+++ b/test/toy-font-face.c
@@ -51,6 +51,7 @@ preamble (cairo_test_context_t *ctx)
cairo_t *cr;
cairo_surface_t *surface;
cairo_font_face_t *font_face;
+ cairo_status_t status;
surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 0, 0);
cr = cairo_create (surface);
@@ -61,9 +62,12 @@ preamble (cairo_test_context_t *ctx)
assert (cairo_toy_font_face_get_family (font_face) != NULL);
assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_NORMAL);
assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_NORMAL);
- assert (cairo_font_face_status(font_face) == CAIRO_STATUS_SUCCESS);
+ status = cairo_font_face_status(font_face);
cairo_font_face_destroy (font_face);
+ if (status)
+ return cairo_test_status_from_status (ctx, status);
+
cairo_select_font_face (cr,
"bizarre",
CAIRO_FONT_SLANT_OBLIQUE,
@@ -73,9 +77,12 @@ preamble (cairo_test_context_t *ctx)
assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "bizarre"));
assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_OBLIQUE);
assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_BOLD);
- assert (cairo_font_face_status(font_face) == CAIRO_STATUS_SUCCESS);
+ status = cairo_font_face_status(font_face);
cairo_font_face_destroy (font_face);
+ if (status)
+ return cairo_test_status_from_status (ctx, status);
+
font_face = cairo_toy_font_face_create ("bozarre",
CAIRO_FONT_SLANT_OBLIQUE,
CAIRO_FONT_WEIGHT_BOLD);
@@ -83,9 +90,12 @@ preamble (cairo_test_context_t *ctx)
assert (0 == (strcmp) (cairo_toy_font_face_get_family (font_face), "bozarre"));
assert (cairo_toy_font_face_get_slant (font_face) == CAIRO_FONT_SLANT_OBLIQUE);
assert (cairo_toy_font_face_get_weight (font_face) == CAIRO_FONT_WEIGHT_BOLD);
- assert (cairo_font_face_status(font_face) == CAIRO_STATUS_SUCCESS);
+ status = cairo_font_face_status(font_face);
cairo_font_face_destroy (font_face);
+ if (status)
+ return cairo_test_status_from_status (ctx, status);
+
font_face = cairo_toy_font_face_create (NULL,
CAIRO_FONT_SLANT_OBLIQUE,
CAIRO_FONT_WEIGHT_BOLD);
diff --git a/test/user-data.c b/test/user-data.c
index f0e62d1..532107a 100644
--- a/test/user-data.c
+++ b/test/user-data.c
@@ -42,43 +42,64 @@ destroy_data2 (void *p)
static cairo_test_status_t
preamble (cairo_test_context_t *ctx)
{
- cairo_surface_t *surface;
static const cairo_user_data_key_t key1, key2;
+ cairo_surface_t *surface;
+ cairo_status_t status;
int data1, data2;
data1 = 0;
data2 = 0;
+
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
- assert (cairo_surface_set_user_data (surface, &key1, &data1, destroy_data1)
- == CAIRO_STATUS_SUCCESS);
- assert (cairo_surface_set_user_data (surface, &key2, &data2, destroy_data2)
- == CAIRO_STATUS_SUCCESS);
+ status = cairo_surface_set_user_data (surface, &key1, &data1, destroy_data1);
+ if (status)
+ goto error;
+
+ status = cairo_surface_set_user_data (surface, &key2, &data2, destroy_data2);
+ if (status)
+ goto error;
+
assert (cairo_surface_get_user_data (surface, &key1) == &data1);
- assert (cairo_surface_set_user_data (surface, &key1, NULL, NULL)
- == CAIRO_STATUS_SUCCESS);
+ status = cairo_surface_set_user_data (surface, &key1, NULL, NULL);
+ if (status)
+ goto error;
+
assert (cairo_surface_get_user_data (surface, &key1) == NULL);
assert (data1 == 1);
assert (data2 == 0);
- assert (cairo_surface_set_user_data (surface, &key2, NULL, NULL)
- == CAIRO_STATUS_SUCCESS);
+ status = cairo_surface_set_user_data (surface, &key2, NULL, NULL);
+ if (status)
+ goto error;
+
assert (data2 == 2);
data1 = 0;
- assert (cairo_surface_set_user_data (surface, &key1, &data1, NULL)
- == CAIRO_STATUS_SUCCESS);
- assert (cairo_surface_set_user_data (surface, &key1, NULL, NULL)
- == CAIRO_STATUS_SUCCESS);
+ status = cairo_surface_set_user_data (surface, &key1, &data1, NULL);
+ if (status)
+ goto error;
+
+ status = cairo_surface_set_user_data (surface, &key1, NULL, NULL);
+ if (status)
+ goto error;
+
assert (data1 == 0);
assert (cairo_surface_get_user_data (surface, &key1) == NULL);
- assert (cairo_surface_set_user_data (surface, &key1, &data1, destroy_data1)
- == CAIRO_STATUS_SUCCESS);
+ status = cairo_surface_set_user_data (surface, &key1, &data1, destroy_data1);
+ if (status)
+ goto error;
+
cairo_surface_destroy (surface);
+
assert (data1 == 1);
assert (data2 == 2);
return CAIRO_TEST_SUCCESS;
+
+error:
+ cairo_surface_destroy (surface);
+ return cairo_test_status_from_status (ctx, status);
}
CAIRO_TEST (user_data,
diff --git a/test/xlib-surface-source.c b/test/xlib-surface-source.c
index 65a9fdf..7d2ed71 100644
--- a/test/xlib-surface-source.c
+++ b/test/xlib-surface-source.c
@@ -79,7 +79,12 @@ create_source_surface (int size)
xrender_format,
size, size);
data->device = cairo_device_reference (cairo_surface_get_device (surface));
- cairo_surface_set_user_data (surface, &closure_key, data, cleanup);
+ if (cairo_surface_set_user_data (surface, &closure_key, data, cleanup)) {
+ cairo_surface_finish (surface);
+ cairo_surface_destroy (surface);
+ cleanup (data);
+ return NULL;
+ }
return surface;
#else
commit c549203c8d69474be4362037f702e4fb59c9929e
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Mon May 3 19:21:18 2010 +0100
scaled-font: Check for an error return when retrieving the implementation
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 016adab..5ed69b1 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -948,6 +948,10 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
font_matrix,
ctm,
options);
+ if (unlikely (font_face->status)) {
+ _cairo_scaled_font_map_unlock ();
+ return _cairo_scaled_font_create_in_error (font_face->status);
+ }
}
_cairo_scaled_font_init_key (&key, font_face,
@@ -960,6 +964,10 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
font_matrix,
ctm,
options);
+ if (unlikely (font_face->status)) {
+ _cairo_scaled_font_map_unlock ();
+ return _cairo_scaled_font_create_in_error (font_face->status);
+ }
}
_cairo_scaled_font_init_key (&key, font_face,
commit c93e6f014d9678b1aea34fd7a30a1fc2f51c6347
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Mon May 3 19:20:42 2010 +0100
paginated: propagate malloc failures more cleanly.
diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c
index 064cd1e..98260b8 100644
--- a/src/cairo-paginated-surface.c
+++ b/src/cairo-paginated-surface.c
@@ -160,8 +160,7 @@ _cairo_paginated_surface_finish (void *abstract_surface)
/* Bypass some of the sanity checking in cairo-surface.c, as we
* know that the surface is finished...
*/
- if (surface->base.backend->show_page != NULL)
- status = surface->base.backend->show_page (&surface->base);
+ status = _cairo_paginated_surface_show_page (surface);
}
/* XXX We want to propagate any errors from destroy(), but those are not
@@ -169,11 +168,10 @@ _cairo_paginated_surface_finish (void *abstract_surface)
* and check the status afterwards. However, we can only call finish()
* on the target, if we own it.
*/
- if (CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->target->ref_count) == 1) {
+ if (CAIRO_REFERENCE_COUNT_GET_VALUE (&surface->target->ref_count) == 1)
cairo_surface_finish (surface->target);
- if (status == CAIRO_STATUS_SUCCESS)
- status = cairo_surface_status (surface->target);
- }
+ if (status == CAIRO_STATUS_SUCCESS)
+ status = cairo_surface_status (surface->target);
cairo_surface_destroy (surface->target);
cairo_surface_finish (surface->recording_surface);
@@ -477,15 +475,17 @@ _cairo_paginated_surface_show_page (void *abstract_surface)
if (unlikely (status))
return status;
- cairo_surface_destroy (surface->recording_surface);
+ if (! surface->base.finished) {
+ cairo_surface_destroy (surface->recording_surface);
- surface->recording_surface = _create_recording_surface_for_target (surface->target,
- surface->content);
- status = surface->recording_surface->status;
- if (unlikely (status))
- return status;
+ surface->recording_surface = _create_recording_surface_for_target (surface->target,
+ surface->content);
+ status = surface->recording_surface->status;
+ if (unlikely (status))
+ return status;
- surface->page_num++;
+ surface->page_num++;
+ }
return CAIRO_STATUS_SUCCESS;
}
commit 8e9fd9c01732c3102c27c7dee50f6e494ba7cdd8
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Mon May 3 19:20:07 2010 +0100
image: A few missing tests for malloc failure
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 21951c2..21cfe4d 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -871,6 +871,8 @@ _pixman_transparent_image (void)
color.alpha = 0x00;
image = pixman_image_create_solid_fill (&color);
+ if (unlikely (image == NULL))
+ return NULL;
if (_cairo_atomic_ptr_cmpxchg (&__pixman_transparent_image,
NULL, image))
@@ -900,6 +902,8 @@ _pixman_black_image (void)
color.alpha = 0xffff;
image = pixman_image_create_solid_fill (&color);
+ if (unlikely (image == NULL))
+ return NULL;
if (_cairo_atomic_ptr_cmpxchg (&__pixman_black_image,
NULL, image))
@@ -929,6 +933,8 @@ _pixman_white_image (void)
color.alpha = 0xffff;
image = pixman_image_create_solid_fill (&color);
+ if (unlikely (image == NULL))
+ return NULL;
if (_cairo_atomic_ptr_cmpxchg (&__pixman_white_image,
NULL, image))
@@ -1126,6 +1132,9 @@ _pixman_image_for_gradient (const cairo_gradient_pattern_t *pattern,
if (pixman_stops != pixman_stops_static)
free (pixman_stops);
+ if (unlikely (pixman_image == NULL))
+ return NULL;
+
tx = pattern->base.matrix.x0;
ty = pattern->base.matrix.y0;
if (! _cairo_matrix_is_translation (&pattern->base.matrix) ||
@@ -3805,7 +3814,8 @@ _composite_glyphs_via_mask (void *closure,
CLEANUP:
_cairo_scaled_font_thaw_cache (font);
- pixman_image_unref (mask);
+ if (mask != NULL)
+ pixman_image_unref (mask);
pixman_image_unref (src);
pixman_image_unref (white);
commit 87781ffbd914bca29b4d744fb48678ab06a07108
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Mon May 3 19:18:49 2010 +0100
ft: Convert an assert into an unlikely error return.
The assert depends upon good behaviour from fontconfig, which is no
guaranteed under memfault, so return an error instead.
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 82f0e65..ae09740 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -2624,13 +2624,11 @@ _cairo_ft_resolve_pattern (FcPattern *pattern,
}
status = _cairo_ft_unscaled_font_create_for_pattern (resolved, &unscaled);
- if (unlikely (status)) {
+ if (unlikely (status || unscaled == NULL)) {
font_face = (cairo_font_face_t *)&_cairo_font_face_nil;
goto FREE_RESOLVED;
}
- assert (unscaled != NULL);
-
_get_pattern_ft_options (resolved, &ft_options);
font_face = _cairo_ft_font_face_create (unscaled, &ft_options);
_cairo_unscaled_font_destroy (&unscaled->base);
More information about the cairo-commit
mailing list