[cairo] Memory issues?

Carl Worth cworth at cworth.org
Tue Apr 11 08:35:29 PDT 2006

On Tue, 11 Apr 2006 13:52:09 +0530, Rajeev wrote:
> Im an evolution hacker, adding cairo support to UI of evolution
> calendar,. I love cairo and the wide variety of cool API's it
> provides,. Im having few issues which i list here,

Hey, that sounds like an interesting project. I hope you have a lot of
fun with cairo.

> 1. Is the cairo API documentation has complete list of what cairo API
> offers? [http://www.cairographics.org/manual].

I think that the list of functions is complete, but obviously the
descriptions are not.

>                                                Because API's like
> cairo_clip_intersect_to_rectangle
> which are so important in the present design of evolution UI are
> missing out in the available online documentation, which is very much
> a matter of concern, if its not, when can i expect that to be
> complete?

The _cairo_clip_intersect_to_rectangle function is a function that is
internal to cairo, and you should not need it in your use of cairo.

If you have a list of rectangles, (specified as (x,y) and
(width,height) with all 4 values integers), and you want to clip to
the region defined by their union, then you would do:

	for (i=0; i < num_rects; i++)
	    cairo_rectangle (cr, rects[i].x, rects[i].y,
			     rects[i].width, rects[i].height);
	cairo_clip (cr);

Each call to cairo_clip establishes a new clip that is the
intersection of the existing clip with the new path you have setup
within the current cairo context.

NOTE: For performance reasons, if you are wanting to clip to pixel
regions, then you need to ensure that the coordinates you are using to
clip, (as in the calls to cairo_rectangle above), correspond to
integers in device-space. (If you're not doing any scaling, rotating,
or other transformation, then this is as simple as passing integers).

> http://www.flickr.com/photo_zoom.gne?id=125074074&size=o
> http://www.flickr.com/photo_zoom.gne?id=125074073&size=o
> http://www.flickr.com/photo_zoom.gne?id=125074072&size=o

That's looking quite lovely[*]. Well done.

> i can see the UI hitting the maximum memory consumption for rendering
> it which was not there earlier.

Hmmm.... that sounds like a bug. I see you're doing strokes and fills
and gradient patterns. I'm not aware of any memory leaks in cairo in
these areas, (but they could be there). It could also be as simple as
your code missing something like cairo_pattern_destroy and leaking
that way.

> If necessary i can send the code as well, which i added here to the UI
> and i am so desperate to get that solved soon, :)

If you can show us a patch where there was no leak before the patch
and there is a leak after the patch, then I think that would be quite

> A cairo lover

Welcome aboard! Again, I hope you have as much fun as the rest of us.


[*] The one thing I see in those screenshots that could look even
better is if the coordinates of the stroked boundaries of the rounded
rectangles were snapped so that the boundaries of the stroke landed
directly on integers in device space. See the first answer here:

-------------- 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/20060411/32d4ef97/attachment-0001.pgp

More information about the cairo mailing list