mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-05 18:08:03 +02:00
[surface] Pass a separate closure for the mime-type destroy notifier.
A limitation of the current API was that the destroy notifier was called on the mime-data block. This prevents the user from passing in a pointer to a managed block, for example a mime-data block belonging to a ref-counted object. We can overcome this by allowing the user to specify the closure to be used with the destroy notifier.
This commit is contained in:
parent
ff0bd64e94
commit
2554d17598
7 changed files with 24 additions and 13 deletions
|
|
@ -662,7 +662,8 @@ read_png (struct png_read_closure_t *png_closure)
|
|||
CAIRO_MIME_TYPE_PNG,
|
||||
mime_data,
|
||||
mime_data_length,
|
||||
free);
|
||||
free,
|
||||
mime_data);
|
||||
if (status) {
|
||||
free (mime_data);
|
||||
cairo_surface_destroy (surface);
|
||||
|
|
|
|||
|
|
@ -640,8 +640,8 @@ _cairo_mime_data_destroy (void *ptr)
|
|||
if (! _cairo_reference_count_dec_and_test (&mime_data->ref_count))
|
||||
return;
|
||||
|
||||
if (mime_data->destroy && mime_data->data)
|
||||
mime_data->destroy (mime_data->data);
|
||||
if (mime_data->destroy && mime_data->closure)
|
||||
mime_data->destroy (mime_data->closure);
|
||||
|
||||
free (mime_data);
|
||||
}
|
||||
|
|
@ -655,6 +655,7 @@ _cairo_mime_data_destroy (void *ptr)
|
|||
* @destroy: a #cairo_destroy_func_t which will be called when the
|
||||
* surface is destroyed or when new image data is attached using the
|
||||
* same mime type.
|
||||
* @closure: the data to be passed to the @destroy notifier
|
||||
*
|
||||
* Attach an image in the format @mime_type to @surface. To remove
|
||||
* the data from a surface, call this function with same mime type
|
||||
|
|
@ -670,7 +671,8 @@ cairo_surface_set_mime_data (cairo_surface_t *surface,
|
|||
const char *mime_type,
|
||||
const unsigned char *data,
|
||||
unsigned int length,
|
||||
cairo_destroy_func_t destroy)
|
||||
cairo_destroy_func_t destroy,
|
||||
void *closure)
|
||||
{
|
||||
cairo_status_t status;
|
||||
cairo_mime_data_t *mime_data;
|
||||
|
|
@ -692,6 +694,7 @@ cairo_surface_set_mime_data (cairo_surface_t *surface,
|
|||
mime_data->data = (unsigned char *) data;
|
||||
mime_data->length = length;
|
||||
mime_data->destroy = destroy;
|
||||
mime_data->closure = closure;
|
||||
} else
|
||||
mime_data = NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -349,6 +349,7 @@ struct _cairo_mime_data {
|
|||
unsigned char *data;
|
||||
unsigned int length;
|
||||
cairo_destroy_func_t destroy;
|
||||
void *closure;
|
||||
};
|
||||
|
||||
#endif /* CAIRO_TYPES_PRIVATE_H */
|
||||
|
|
|
|||
11
src/cairo.h
11
src/cairo.h
|
|
@ -1957,11 +1957,12 @@ cairo_surface_get_mime_data (cairo_surface_t *surface,
|
|||
unsigned int *length);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_surface_set_mime_data (cairo_surface_t *surface,
|
||||
const char *mime_type,
|
||||
const unsigned char *data,
|
||||
unsigned int length,
|
||||
cairo_destroy_func_t destroy);
|
||||
cairo_surface_set_mime_data (cairo_surface_t *surface,
|
||||
const char *mime_type,
|
||||
const unsigned char *data,
|
||||
unsigned int length,
|
||||
cairo_destroy_func_t destroy,
|
||||
void *closure);
|
||||
|
||||
cairo_public void
|
||||
cairo_surface_get_font_options (cairo_surface_t *surface,
|
||||
|
|
|
|||
|
|
@ -96,7 +96,8 @@ paint_file (cairo_t *cr,
|
|||
image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 200, 50);
|
||||
|
||||
status = cairo_surface_set_mime_data (image, mime_type,
|
||||
mime_data, mime_length, free);
|
||||
mime_data, mime_length,
|
||||
free, mime_data);
|
||||
if (status) {
|
||||
cairo_surface_destroy (image);
|
||||
return cairo_test_status_from_status (ctx, status);
|
||||
|
|
|
|||
|
|
@ -106,7 +106,9 @@ preamble (cairo_test_context_t *ctx)
|
|||
return test_status;
|
||||
}
|
||||
|
||||
cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_JPEG, data, len, free);
|
||||
cairo_surface_set_mime_data (image, CAIRO_MIME_TYPE_JPEG,
|
||||
data, len,
|
||||
free, data);
|
||||
width = cairo_image_surface_get_width (image);
|
||||
height = cairo_image_surface_get_height (image);
|
||||
|
||||
|
|
|
|||
|
|
@ -2771,7 +2771,8 @@ cairo_surface_set_mime_data (cairo_surface_t *surface,
|
|||
const char *mime_type,
|
||||
const unsigned char *data,
|
||||
unsigned int length,
|
||||
cairo_destroy_func_t destroy)
|
||||
cairo_destroy_func_t destroy,
|
||||
void *closure)
|
||||
{
|
||||
if (surface != NULL && _write_lock ()) {
|
||||
_emit_surface (surface);
|
||||
|
|
@ -2787,7 +2788,8 @@ cairo_surface_set_mime_data (cairo_surface_t *surface,
|
|||
surface,
|
||||
mime_type,
|
||||
data, length,
|
||||
destroy);
|
||||
destroy,
|
||||
closure);
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue