[cairo] Making cairo_image_surface_create zero out the surface

Carl Worth cworth at cworth.org
Fri Apr 14 16:29:47 PDT 2006

OK, this has caused some pain for others before:

	Image surfaces do not start out blank by default

	a lot of noise in regions that are supposed to be transparent

And now it's causing me some pain within cairo as well.

So I just committed the patch below to change
cairo_image_surface_create so that it will zero out the surface it
returns. The semantics of cairo_image_surface_create_for_data do not
change---it still leaves the original data intact.

Does anybody see any problem with this? The documented behavior before
was that the contents were undefined, so there's certaonly no backward
compatibility problem.

Someone might argue it's "wasteful" to clear the buffer if it's about
to get painted over anyway. But, in an ARGB world, transparent is an
awfully useful starting position much of the time. And create_for_data
is still available to avoid the initial clearing. (And it would even
be possible for someone to implement the new semantics by lazily
clearing at the first clip, get_data, or non-paint drawing
operations. That exercise is left to anyone who thinks this is really
the most significant performance problem in cairo today.)


diff-tree 0e44e798b5f6fd58cc586e40f926d363cd8fff50 (from e8a0da637fda4a29281cfb4f463169e51c300c42)
Author: Dom Lachowicz <cinamod at hotmail.com>
Date:   Fri Apr 14 16:15:29 2006 -0700

    Change cairo_image_surface_create to zero out surface contents.
    This closes bug #5816:
    	Image surfaces do not start out blank by default
    This also fixes all of the test suite failures introduced by moving
    the CLEAR on blank page optimization up to the paginated surface from
    the PS surface.

diff --git a/pixman/src/icpixels.c b/pixman/src/icpixels.c
index cdec492..2ad34f4 100644
--- a/pixman/src/icpixels.c
+++ b/pixman/src/icpixels.c
@@ -70,6 +70,7 @@ FbPixelsCreate (int width, int height, i
 	return NULL;
     buf = (pixman_bits_t *) ((char *)pixels + base + adjust);
+    memset (buf, 0, height * stride);
     FbPixelsInit (pixels, buf, width, height, depth, bpp, stride);
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index e095aa0..cef455b 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -188,9 +188,10 @@ _create_pixman_format (cairo_format_t fo
  * @height: height of the surface, in pixels
  * Creates an image surface of the specified format and
- * dimensions. The initial contents of the surface is undefined; you
- * must explicitly initialize the surface contents, using, for
- * example, cairo_paint().
+ * dimensions. Initially the surface contents are all
+ * 0. (Specifically, within each pixel, each color or alpha channel
+ * belonging to format will be 0. The contents of bits within a pixel,
+ * but not belonging to the given format are undefined).
  * Return value: a pointer to the newly created surface. The caller
  * owns the surface and should call cairo_surface_destroy when done
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20060414/ccd2bd1b/attachment.pgp

More information about the cairo mailing list