[cairo] _cairo_image_surface_assume_ownership_of_data
Owen Taylor
otaylor at redhat.com
Sat Dec 18 09:21:50 PST 2004
On Fri, 2004-12-17 at 18:15 -0800, Keith Packard wrote:
> I'm writing a simple .png -> pattern conversion function and what I want
> is for cairo to 'own' the resulting data; that way, dereferencing the
> pattern will dereference the surface and (in turn) free the image data.
>
> There are two obvious ways to manage this -- either provide some way to
> get the image data pointer back from cairo after having it allocate the
> memory or by having cairo 'assume' ownership of the data.
>
> There's already an internal function to perform the latter called
> _cairo_image_surface_assume_ownership_of_data, there is no mechanism to
> get through the underlying pixman object to effect the former.
What worked well for me recently was:
LmcBits *lmc_bits_new (LmcBitsFormat format,
int width,
int height,
guchar *data,
int rowstride,
GDestroyNotify notify,
gpointer notify_data);
So, you can do, say:
gui->action_cursor_bits = lmc_bits_new (LMC_BITS_ARGB_32,
image->width, image->height,
(guchar *)image->pixels,
image->width * 4,
(GDestroyNotify)XcursorImageDestroy,
image);
or:
texture->quantum_bits = lmc_bits_new (LMC_BITS_ARGB_32,
rect->width, rect->height,
tmp_bits, rect->width * 4,
(GDestroyNotify)g_free, tmp_bits);
Separating out the data passed to the destroy notify function from the
image data gives huge amounts of useful flexibility. Even if you don't go
that route, I'd encourage not hardcoding free() but allowing the caller to pass
in the function that will be called when the surface is destroyed.
Regards,
Owen
(GdkPixbuf passes *both* the image data and user data to the destroy
notify function for gdk_pixbuf_new_from_data(), but I think that just
makes it harder to reuse existing functions for the destroy notify)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20041218/cea32cf0/attachment.pgp
More information about the cairo
mailing list