[cairo] [cairo-commit] src/cairo-quartz-surface.c

Carl Worth cworth at cworth.org
Mon Nov 19 11:09:08 PST 2007

On Sun, 18 Nov 2007 22:24:40 +0000, Baz wrote:
> On Nov 18, 2007 8:52 PM, Behdad Esfahbod <behdad at behdad.org> wrote:
> > I don't think other backends do this, do they?  Can you elaborate?
> cairo_image_surface_create does:
> "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)."

It's not as simple a question as whether a backend clears or doesn't

For example, although cairo_image_surface_create does clear, note that
cairo_image_surface_create_for_data does not.

The distinction is whether cairo is creating the storage that will hold
the surface content, or is accepting it from the user. When cairo
creates it, it should clear it. When cairo accepts some existing
storage, it should leave the contents alone.

So for quartz, from my naïve reading of cairo-quartz.h it would appear
that cairo_quartz_surface_create should be clearing the storage it's
allocating, and that cairo_quartz_surface_create_for_cgcontext should
not clear the storage it is accepting. And I'm guessing that's what
this patch is doing, (though it should also fixup the documentation
for cairo_quartz_surface_create at the same time).

> There's a calloc in pixman causing this behaviour. I havent
> investigated why the rest of the surfaces aren't failing these tests -
> what's going on appears to be that when the second 'similar' test is
> run for each of the 7 failures I had, a push-group is done to create
> the similar surface before the test is run, and these tests use a
> transparent background fill instead of solid white, so that the
> pop_group shows the background corruption.

I'm not sure what the distinction could be. Hopefully all backends are
following the rule I described above. Now, you've mentioned similar
surfaces, and those all involve cairo allocating storage. And
cairo_surface_create_similar is also documented as returning a surface
that is cleared. This clearing is not taking place in the backend
create_similar functions, but above in _cairo_surface_create_similar_solid.

> I'd be happy to revert and fix the test instead if you prefer. Vlad
> was surprised that the documented behaviour for the image surface was
> still that way.

The test could still have a bug, (I don't know---I haven't looked),
but the fix you did above appears to be correct. I think Vlad was
misremembering the history. In the very old days, cairo *never*
cleared anything, even when it created a surface's storage
itself. This meant that cairo_image_surface_create gave you a surface
that initially had garbage on it. Users rightfully complained about
how surprising and annoying this was, and we changed it, (in 1.2 if
my memory is correct).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20071119/1e379dbf/attachment.pgp 

More information about the cairo mailing list