[cairo] image memory alternatives

M.R. makrober at gmail.com
Wed Aug 18 10:52:37 PDT 2010

If, at the end of the drawing process I need to provide access to the
memory where the image resides to another process, I believe I have
two options:

1) let Cairo allocate the memory for the image by calling
cairo_image_surface_create(), then when the drawing is done obtain
the memory pointer of the image by calling
cairo_image_surface_get_data(), allocate an adequate block of
shared memory, move the image to the shared block, release Cairo
surface and pass the pointer to the shared block to the other process.

2) allocate a shared block of adequate size and force Cairo to draw to
that shared block by calling cairo_image_surface_create_for_data (),
then when the drawing is done, pass the pointer of the shared block to 
the other process.

I assume that method (1) will be preferred if there is a lot of drawing 
to be done, since back-end driver can use graphics device memory and 
hardware-accelerated primitives. In comparison, the time required to 
move the whole image from one memory block to another will be less of
a concern. If, however, there is very little drawing to be done,
(2) would be faster since there will be no need to move a large block
of memory to the shared memory each time the image is re-drawn.

Is my reasoning essentially correct?

Marko R.

More information about the cairo mailing list