[cairo-commit] 2 commits - src/cairo-image-surface.c

Chris Wilson ickle at kemper.freedesktop.org
Mon Oct 1 11:51:17 PDT 2007


 src/cairo-image-surface.c |   68 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 62 insertions(+), 6 deletions(-)

New commits:
diff-tree c9a9f1299c2bd5b6a8e53fdb264c233a43e0c44a (from e241205f0c6d823150cf018c0deb6652dd8b8d02)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 1 17:00:38 2007 +0100

    [cairo-image-surface] Avoid trying to create surfaces with invalid strides.
    
    pixman does not (yet?) support arbitrary strides and will fail to
    generate an image for the data. We misinterpret that failure as a
    CAIRO_STATUS_NO_MEMORY, so instead return CAIRO_STATUS_INVALID_FORMAT
    before attempting to create the pixman image.

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 0a6568b..6459329 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -541,7 +541,10 @@ cairo_image_surface_create_for_data (uns
 {
     pixman_format_code_t pixman_format;
 
-    if (! CAIRO_FORMAT_VALID (format)) {
+    /* XXX pixman does not support images with arbitrary strides and
+     * attempting to create such surfaces will failure but we will interpret
+     * such failure as CAIRO_STATUS_NO_MEMORY.  */
+    if (! CAIRO_FORMAT_VALID (format) || stride % sizeof (uint32_t) != 0) {
 	_cairo_error (CAIRO_STATUS_INVALID_FORMAT);
 	return (cairo_surface_t*) &_cairo_image_surface_nil_invalid_format;
     }
diff-tree e241205f0c6d823150cf018c0deb6652dd8b8d02 (from b4f86638cc4b87bfaf10568ae9beb89626e26613)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 1 16:54:16 2007 +0100

    [cairo-image-surface] Return correct error surfaces.
    
    Avoid returning the "generic" _cairo_surface_nil (which corresponds to
    CAIRO_STATUS_NO_MEMORY) when the user asks us to create a surface with
    an invalid format or content.

diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 24c83ec..0a6568b 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -84,6 +84,53 @@ static const cairo_image_surface_t _cair
     0,					/* depth */
     NULL				/* pixman_image */
 };
+static const cairo_image_surface_t _cairo_image_surface_nil_invalid_content = {
+    {
+	&cairo_image_surface_backend,	/* backend */
+	CAIRO_SURFACE_TYPE_IMAGE,
+	CAIRO_CONTENT_COLOR,
+	CAIRO_REFERENCE_COUNT_INVALID,	/* ref_count */
+	CAIRO_STATUS_INVALID_CONTENT,	/* status */
+	FALSE,				/* finished */
+	{ 0,	/* size */
+	  0,	/* num_elements */
+	  0,	/* element_size */
+	  NULL,	/* elements */
+	},				/* user_data */
+	{ 1.0, 0.0,
+	  0.0, 1.0,
+	  0.0, 0.0
+	},				/* device_transform */
+	{ 1.0, 0.0,
+	  0.0, 1.0,
+	  0.0, 0.0
+	},				/* device_transform_inverse */
+	0.0,				/* x_resolution */
+	0.0,				/* y_resolution */
+	0.0,				/* x_fallback_resolution */
+	0.0,				/* y_fallback_resolution */
+	NULL,				/* clip */
+	0,				/* next_clip_serial */
+	0,				/* current_clip_serial */
+	FALSE,				/* is_snapshot */
+	FALSE,				/* has_font_options */
+	{ CAIRO_ANTIALIAS_DEFAULT,
+	  CAIRO_SUBPIXEL_ORDER_DEFAULT,
+	  CAIRO_HINT_STYLE_DEFAULT,
+	  CAIRO_HINT_METRICS_DEFAULT
+	}				/* font_options */
+    },					/* base */
+    PIXMAN_a8r8g8b8,			/* pixman_format */
+    CAIRO_FORMAT_ARGB32,		/* format */
+    NULL,				/* data */
+    FALSE,				/* owns_data */
+    FALSE,				/* has_clip */
+    0,					/* width */
+    0,					/* height */
+    0,					/* stride */
+    0,					/* depth */
+    NULL				/* pixman_image */
+};
 
 static cairo_format_t
 _cairo_format_from_pixman_format (pixman_format_code_t pixman_format)
@@ -446,8 +493,10 @@ _cairo_image_surface_create_with_content
 					  int			width,
 					  int			height)
 {
-    if (! CAIRO_CONTENT_VALID (content))
-	return (cairo_surface_t*) &_cairo_surface_nil;
+    if (! CAIRO_CONTENT_VALID (content)) {
+	_cairo_error (CAIRO_STATUS_INVALID_CONTENT);
+	return (cairo_surface_t*) &_cairo_image_surface_nil_invalid_content;
+    }
 
     return cairo_image_surface_create (_cairo_format_from_content (content),
 				       width, height);
@@ -492,8 +541,10 @@ cairo_image_surface_create_for_data (uns
 {
     pixman_format_code_t pixman_format;
 
-    if (! CAIRO_FORMAT_VALID (format))
-	return (cairo_surface_t*) &_cairo_surface_nil;
+    if (! CAIRO_FORMAT_VALID (format)) {
+	_cairo_error (CAIRO_STATUS_INVALID_FORMAT);
+	return (cairo_surface_t*) &_cairo_image_surface_nil_invalid_format;
+    }
 
     pixman_format = _cairo_format_to_pixman_format_code (format);
 
@@ -509,8 +560,10 @@ _cairo_image_surface_create_for_data_wit
 						   int			 height,
 						   int			 stride)
 {
-    if (! CAIRO_CONTENT_VALID (content))
-	return (cairo_surface_t*) &_cairo_surface_nil;
+    if (! CAIRO_CONTENT_VALID (content)) {
+	_cairo_error (CAIRO_STATUS_INVALID_CONTENT);
+	return (cairo_surface_t*) &_cairo_image_surface_nil_invalid_content;
+    }
 
     return cairo_image_surface_create_for_data (data,
 						_cairo_format_from_content (content),


More information about the cairo-commit mailing list