[cairo-commit] src/cairo-device.c src/cairo-device-private.h src/cairo.h
Chris Wilson
ickle at kemper.freedesktop.org
Tue Mar 23 03:46:29 PDT 2010
src/cairo-device-private.h | 1
src/cairo-device.c | 78 +++++++++++++++++++++++++++++++++++++++++++++
src/cairo.h | 14 ++++++++
3 files changed, 93 insertions(+)
New commits:
commit 61ad28fe7d334c63197ae3881d5edd074d63cfec
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Mar 23 10:44:16 2010 +0000
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.
diff --git a/src/cairo-device-private.h b/src/cairo-device-private.h
index 39bf67b..54ca4c0 100644
--- a/src/cairo-device-private.h
+++ b/src/cairo-device-private.h
@@ -44,6 +44,7 @@
struct _cairo_device {
cairo_reference_count_t ref_count;
cairo_status_t status;
+ cairo_user_data_array_t user_data;
const cairo_device_backend_t *backend;
diff --git a/src/cairo-device.c b/src/cairo-device.c
index f0614ea..9befb59 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);
+}
diff --git a/src/cairo.h b/src/cairo.h
index c1bf44a..feb564a 100644
--- a/src/cairo.h
+++ b/src/cairo.h
@@ -2026,6 +2026,20 @@ cairo_device_finish (cairo_device_t *device);
cairo_public void
cairo_device_destroy (cairo_device_t *device);
+cairo_public unsigned int
+cairo_device_get_reference_count (cairo_device_t *device);
+
+cairo_public void *
+cairo_device_get_user_data (cairo_device_t *device,
+ const cairo_user_data_key_t *key);
+
+cairo_public 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);
+
+
/* Surface manipulation */
cairo_public cairo_surface_t *
More information about the cairo-commit
mailing list