[cairo-commit] 4 commits - src/cairo-image-surface.c src/cairo-scaled-font.c test/bitmap-font.c test/user-font-rescale.c

Chris Wilson ickle at kemper.freedesktop.org
Tue May 4 10:44:56 PDT 2010


 src/cairo-image-surface.c |   55 +++++++++++++++++++++++++---------------------
 src/cairo-scaled-font.c   |   15 +++++++++++-
 test/bitmap-font.c        |   13 ++++++++--
 test/user-font-rescale.c  |   16 +++++++++----
 4 files changed, 65 insertions(+), 34 deletions(-)

New commits:
commit 19ac81f50ba353400934bf112523b4257ad9de2f
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue May 4 18:25:23 2010 +0100

    scaled-font: Remove MRU cache upon detection of error.

diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 5ed69b1..ce92354 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -895,7 +895,7 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
     cairo_status_t status;
     cairo_scaled_font_map_t *font_map;
     cairo_font_face_t *original_font_face = font_face;
-    cairo_scaled_font_t key, *old = NULL, *scaled_font = NULL;
+    cairo_scaled_font_t key, *old = NULL, *scaled_font = NULL, *dead = NULL;
     double det;
 
     status = font_face->status;
@@ -926,6 +926,7 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 	_cairo_scaled_font_matches (scaled_font,
 	                            font_face, font_matrix, ctm, options))
     {
+	assert (scaled_font->hash_entry.hash != ZOMBIE);
 	assert (! scaled_font->placeholder);
 
 	if (likely (scaled_font->status == CAIRO_STATUS_SUCCESS)) {
@@ -942,6 +943,8 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 	_cairo_hash_table_remove (font_map->hash_table,
 				  &scaled_font->hash_entry);
 	scaled_font->hash_entry.hash = ZOMBIE;
+	dead = scaled_font;
+	font_map->mru_scaled_font = NULL;
 
 	if (font_face->backend->get_implementation != NULL) {
 	    font_face = font_face->backend->get_implementation (font_face,
@@ -950,6 +953,7 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 								options);
 	    if (unlikely (font_face->status)) {
 		_cairo_scaled_font_map_unlock ();
+		cairo_scaled_font_destroy (scaled_font);
 		return _cairo_scaled_font_create_in_error (font_face->status);
 	    }
 	}
@@ -1049,6 +1053,9 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 	if (font_face != original_font_face)
 	    cairo_font_face_destroy (font_face);
 
+	if (dead != NULL)
+	    cairo_scaled_font_destroy (dead);
+
 	status = _cairo_font_face_set_error (font_face, status);
 	return _cairo_scaled_font_create_in_error (status);
     }
@@ -1058,6 +1065,9 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
 	if (font_face != original_font_face)
 	    cairo_font_face_destroy (font_face);
 
+	if (dead != NULL)
+	    cairo_scaled_font_destroy (dead);
+
 	return scaled_font;
     }
 
@@ -1084,6 +1094,9 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
     if (font_face != original_font_face)
 	cairo_font_face_destroy (font_face);
 
+    if (dead != NULL)
+	cairo_scaled_font_destroy (dead);
+
     if (unlikely (status)) {
 	/* We can't call _cairo_scaled_font_destroy here since it expects
 	 * that the font has already been successfully inserted into the
commit 6f2d4f5b2aba9344fee9375614dfd0c6236bfd7c
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue May 4 18:09:11 2010 +0100

    image: Propagate failure from pixman_image_fill_boxes().

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 492b8c3..8f1e87b 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -1618,7 +1618,7 @@ _pixman_image_for_pattern (const cairo_pattern_t *pattern,
     }
 }
 
-static void
+static cairo_status_t
 _cairo_image_surface_fixup_unbounded (cairo_image_surface_t *dst,
 				      const cairo_composite_rectangles_t *rects,
 				      cairo_clip_t *clip)
@@ -1641,7 +1641,7 @@ _cairo_image_surface_fixup_unbounded (cairo_image_surface_t *dst,
 	if (rects->bounded.width  == rects->unbounded.width &&
 	    rects->bounded.height == rects->unbounded.height)
 	{
-	    return;
+	    return CAIRO_STATUS_SUCCESS;
 	}
     }
 
@@ -1663,13 +1663,14 @@ _cairo_image_surface_fixup_unbounded (cairo_image_surface_t *dst,
             pixman_color_t color = { 0, };
             pixman_box32_t box = { x, y, width, height };
 
-            pixman_image_fill_boxes (PIXMAN_OP_CLEAR,
-                                     dst->pixman_image,
-                                     &color,
-                                     1, &box);
+            if (! pixman_image_fill_boxes (PIXMAN_OP_CLEAR,
+					   dst->pixman_image,
+					   &color,
+					   1, &box))
+		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	}
 
-	return;
+	return CAIRO_STATUS_SUCCESS;
     }
 
     /* top */
@@ -1720,12 +1721,17 @@ _cairo_image_surface_fixup_unbounded (cairo_image_surface_t *dst,
     } else {
         pixman_color_t color = { 0, };
 
-        pixman_image_fill_boxes (PIXMAN_OP_CLEAR,
-                                 dst->pixman_image,
-                                 &color,
-                                 n_boxes,
-                                 boxes);
+        if (! pixman_image_fill_boxes (PIXMAN_OP_CLEAR,
+				       dst->pixman_image,
+				       &color,
+				       n_boxes,
+				       boxes))
+	{
+	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	}
     }
+
+    return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_status_t
@@ -1740,10 +1746,8 @@ _cairo_image_surface_fixup_unbounded_boxes (cairo_image_surface_t *dst,
     struct _cairo_boxes_chunk *chunk;
     int i;
 
-    if (boxes->num_boxes <= 1 && clip_region == NULL) {
-	_cairo_image_surface_fixup_unbounded (dst, extents, NULL);
-	return CAIRO_STATUS_SUCCESS;
-    }
+    if (boxes->num_boxes <= 1 && clip_region == NULL)
+	return _cairo_image_surface_fixup_unbounded (dst, extents, NULL);
 
     _cairo_boxes_init (&clear);
 
@@ -2256,8 +2260,8 @@ _clip_and_composite (cairo_image_surface_t	*dst,
     }
 
     if (status == CAIRO_STATUS_SUCCESS && ! extents->is_bounded) {
-	_cairo_image_surface_fixup_unbounded (dst, extents,
-					      need_clip_surface ? clip : NULL);
+	status = _cairo_image_surface_fixup_unbounded (dst, extents,
+						       need_clip_surface ? clip : NULL);
     }
 
     if (clip_region != NULL)
@@ -4096,6 +4100,7 @@ _cairo_image_surface_composite (cairo_operator_t	 op,
     if (unlikely (src == NULL))
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
+    status = CAIRO_STATUS_SUCCESS;
     if (mask_pattern != NULL) {
 	pixman_image_t *mask;
 	int mask_offset_x, mask_offset_y;
@@ -4127,12 +4132,12 @@ _cairo_image_surface_composite (cairo_operator_t	 op,
     pixman_image_unref (src);
 
     if (! extents.is_bounded)
-	_cairo_image_surface_fixup_unbounded (dst, &extents, NULL);
+	status = _cairo_image_surface_fixup_unbounded (dst, &extents, NULL);
 
     if (clip_region != NULL)
 	_cairo_image_surface_unset_clip_region (dst);
 
-    return CAIRO_STATUS_SUCCESS;
+    return status;
 }
 
 static cairo_int_status_t
@@ -4269,7 +4274,7 @@ _cairo_image_surface_composite_trapezoids (cairo_operator_t	op,
 			       clip_region);
 
     if (status == CAIRO_STATUS_SUCCESS && ! extents.is_bounded)
-	_cairo_image_surface_fixup_unbounded (dst, &extents, NULL);
+	status = _cairo_image_surface_fixup_unbounded (dst, &extents, NULL);
 
     if (clip_region != NULL)
 	_cairo_image_surface_unset_clip_region (dst);
@@ -4361,10 +4366,9 @@ _cairo_image_surface_span_renderer_finish (void *abstract_renderer)
     cairo_image_surface_t *dst = renderer->dst;
     pixman_image_t *src;
     int src_x, src_y;
+    cairo_status_t status;
 
     if (renderer->clip_region != NULL) {
-	cairo_status_t status;
-
 	status = _cairo_image_surface_set_clip_region (dst, renderer->clip_region);
 	if (unlikely (status))
 	    return status;
@@ -4374,6 +4378,7 @@ _cairo_image_surface_span_renderer_finish (void *abstract_renderer)
     if (src == NULL)
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
+    status = CAIRO_STATUS_SUCCESS;
     pixman_image_composite32 (_pixman_operator (renderer->op),
                               src,
                               renderer->mask,
@@ -4385,12 +4390,12 @@ _cairo_image_surface_span_renderer_finish (void *abstract_renderer)
                               rects->bounded.width, rects->bounded.height);
 
     if (! rects->is_bounded)
-	_cairo_image_surface_fixup_unbounded (dst, rects, NULL);
+	status = _cairo_image_surface_fixup_unbounded (dst, rects, NULL);
 
     if (renderer->clip_region != NULL)
 	 _cairo_image_surface_unset_clip_region (dst);
 
-    return CAIRO_STATUS_SUCCESS;
+    return status;
 }
 
 static cairo_bool_t
commit ded7be0b9ce12f8d4a84c8c9dd622d92fe347a34
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue May 4 17:01:35 2010 +0100

    test/user-font-rescale: Use after free and check for memfault.

diff --git a/test/user-font-rescale.c b/test/user-font-rescale.c
index 54b3a20..8d2e897 100644
--- a/test/user-font-rescale.c
+++ b/test/user-font-rescale.c
@@ -258,10 +258,11 @@ get_user_font_face (cairo_font_face_t *substitute_font,
 					       &glyphs, &num_glyphs,
 					       NULL, NULL, NULL);
     cairo_font_options_destroy (options);
-    cairo_scaled_font_destroy (measure);
 
-    if (status)
+    if (status) {
+	cairo_scaled_font_destroy (measure);
 	return status;
+    }
 
     /* find the glyph range the text covers */
     max_index = glyphs[0].index;
@@ -282,11 +283,16 @@ get_user_font_face (cairo_font_face_t *substitute_font,
 	widths[glyphs[i].index - min_index] = extents.x_advance;
     }
 
+    status = cairo_scaled_font_status (measure);
+    cairo_scaled_font_destroy (measure);
     cairo_glyph_free (glyphs);
 
-    status = create_rescaled_font (substitute_font,
-				   min_index, count, widths,
-				   out);
+    if (status == CAIRO_STATUS_SUCCESS) {
+	status = create_rescaled_font (substitute_font,
+				       min_index, count, widths,
+				       out);
+    }
+
     free (widths);
     return status;
 }
commit b0052c52153376400a30dca1d67f4aca9735cc09
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue May 4 17:01:17 2010 +0100

    test/bitmap-font: Propagate memfault

diff --git a/test/bitmap-font.c b/test/bitmap-font.c
index 26a76db..1c13779 100644
--- a/test/bitmap-font.c
+++ b/test/bitmap-font.c
@@ -121,7 +121,16 @@ draw (cairo_t *cr, int width, int height)
 
     cairo_set_font_face (cr, font_face);
 
-#define CHECK_FONT_EXTENTS(comment) if (check_font_extents (ctx, cr, (comment)) != CAIRO_TEST_SUCCESS) return CAIRO_TEST_FAILURE
+    font_options = cairo_font_options_create ();
+
+#define CHECK_FONT_EXTENTS(comment) do {\
+    cairo_test_status_t test_status; \
+    test_status = check_font_extents (ctx, cr, (comment)); \
+    if (test_status != CAIRO_TEST_SUCCESS) { \
+	cairo_font_options_destroy (font_options); \
+	return test_status; \
+    } \
+} while (0)
 
     cairo_font_extents (cr, &font_extents);
     CHECK_FONT_EXTENTS ("default");
@@ -129,8 +138,6 @@ draw (cairo_t *cr, int width, int height)
     FcPatternDestroy (pattern);
     cairo_font_face_destroy (font_face);
 
-    font_options = cairo_font_options_create ();
-
     cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_ON);
     cairo_set_font_options (cr, font_options);
 


More information about the cairo-commit mailing list