diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2010-03-23 10:44:16 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2010-03-23 10:44:16 +0000 |
commit | 61ad28fe7d334c63197ae3881d5edd074d63cfec (patch) | |
tree | 7ca745271c86c1f37fb970ffbe50d7c1f4cb7c67 /src/cairo-device.c | |
parent | 8a8c2f6c282c1822dc1a638c2258c8449b1d678b (diff) | |
download | cairo-61ad28fe7d334c63197ae3881d5edd074d63cfec.tar.gz |
device: Add language binding interfaces.
Damien Carbonne reported that cairo_device_t lacked the language binding
hooks normally associated with cairo objects. So add the missing
get_reference_count, get_user_data and set_user_data.
Diffstat (limited to 'src/cairo-device.c')
-rw-r--r-- | src/cairo-device.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/cairo-device.c b/src/cairo-device.c index f0614eac1..9befb59a9 100644 --- a/src/cairo-device.c +++ b/src/cairo-device.c @@ -118,6 +118,8 @@ _cairo_device_init (cairo_device_t *device, device->mutex_depth = 0; device->finished = FALSE; + + _cairo_user_data_array_init (&device->user_data); } cairo_device_t * @@ -192,6 +194,8 @@ cairo_device_destroy (cairo_device_t *device) cairo_device_finish (device); + _cairo_user_data_array_fini (&device->user_data); + assert (device->mutex_depth == 0); CAIRO_MUTEX_FINI (device->mutex); @@ -263,3 +267,77 @@ _cairo_device_set_error (cairo_device_t *device, return _cairo_error (status); } + +/** + * cairo_device_get_reference_count: + * @device: a #cairo_device_t + * + * Returns the current reference count of @device. + * + * Return value: the current reference count of @device. If the + * object is a nil object, 0 will be returned. + * + * Since: 1.10 + **/ +unsigned int +cairo_device_get_reference_count (cairo_device_t *device) +{ + if (device == NULL || + CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) + return 0; + + return CAIRO_REFERENCE_COUNT_GET_VALUE (&device->ref_count); +} + +/** + * cairo_device_get_user_data: + * @device: a #cairo_device_t + * @key: the address of the #cairo_user_data_key_t the user data was + * attached to + * + * Return user data previously attached to @device using the + * specified key. If no user data has been attached with the given + * key this function returns %NULL. + * + * Return value: the user data previously attached or %NULL. + * + * Since: 1.10 + **/ +void * +cairo_device_get_user_data (cairo_device_t *device, + const cairo_user_data_key_t *key) +{ + return _cairo_user_data_array_get_data (&device->user_data, + key); +} + +/** + * cairo_device_set_user_data: + * @device: a #cairo_device_t + * @key: the address of a #cairo_user_data_key_t to attach the user data to + * @user_data: the user data to attach to the #cairo_device_t + * @destroy: a #cairo_destroy_func_t which will be called when the + * #cairo_t is destroyed or when new user data is attached using the + * same key. + * + * Attach user data to @device. To remove user data from a surface, + * call this function with the key that was used to set it and %NULL + * for @data. + * + * Return value: %CAIRO_STATUS_SUCCESS or %CAIRO_STATUS_NO_MEMORY if a + * slot could not be allocated for the user data. + * + * Since: 1.10 + **/ +cairo_status_t +cairo_device_set_user_data (cairo_device_t *device, + const cairo_user_data_key_t *key, + void *user_data, + cairo_destroy_func_t destroy) +{ + if (CAIRO_REFERENCE_COUNT_IS_INVALID (&device->ref_count)) + return device->status; + + return _cairo_user_data_array_set_data (&device->user_data, + key, user_data, destroy); +} |