summaryrefslogtreecommitdiff
path: root/cogl/cogl-util.c
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2010-05-27 23:31:40 +0100
committerRobert Bragg <robert@linux.intel.com>2010-05-28 18:39:22 +0100
commit7bcea1c64eede09582cf0bbfafaec48cac42744c (patch)
treed9a59bdce5258ea1e31355e498085bc28d1fb409 /cogl/cogl-util.c
parent0f32fb4acd0835ecc24803a81a2d1a77174a920a (diff)
downloadcogl-7bcea1c64eede09582cf0bbfafaec48cac42744c.tar.gz
Start eradicating the CoglHandle typedef
CoglHandle is a common source of complaints and confusion because people expect a "handle" to be some form of integer type with some indirection to lookup the corresponding objects as opposed to a direct pointer. This patch starts by renaming CoglHandle to CoglObject * and creating corresponding cogl_object_ APIs to replace the cogl_handle ones. The next step though is to remove all use of CoglHandle in the Cogl APIs and replace with strongly typed pointer types such as CoglMaterial * or CoglTexture * etc also all occurrences of COGL_INVALID_HANDLE can just use NULL instead. After this we will consider switching to GTypeInstance internally so we can have inheritance for our types and hopefully improve how we handle bindings. Note all these changes will be done in a way that maintains the API and ABI.
Diffstat (limited to 'cogl/cogl-util.c')
-rw-r--r--cogl/cogl-util.c43
1 files changed, 31 insertions, 12 deletions
diff --git a/cogl/cogl-util.c b/cogl/cogl-util.c
index 622b7850..cc28b08e 100644
--- a/cogl/cogl-util.c
+++ b/cogl/cogl-util.c
@@ -61,48 +61,67 @@ cogl_util_next_p2 (int a)
/* gtypes */
-CoglHandle
-cogl_handle_ref (CoglHandle handle)
+void *
+cogl_object_ref (void *object)
{
- CoglHandleObject *obj = (CoglHandleObject *)handle;
+ CoglObject *obj = object;
- g_return_val_if_fail (handle != COGL_INVALID_HANDLE, COGL_INVALID_HANDLE);
+ g_return_val_if_fail (object != NULL, NULL);
obj->ref_count++;
- return handle;
+ return object;
+}
+
+CoglHandle
+cogl_handle_ref (CoglHandle handle)
+{
+ return cogl_object_ref (handle);
}
void
-cogl_handle_unref (CoglHandle handle)
+cogl_object_unref (void *object)
{
- CoglHandleObject *obj = (CoglHandleObject *)handle;
+ CoglObject *obj = object;
- g_return_if_fail (handle != COGL_INVALID_HANDLE);
+ g_return_if_fail (object != NULL);
g_return_if_fail (obj->ref_count > 0);
if (--obj->ref_count < 1)
{
void (*free_func)(void *obj);
- COGL_HANDLE_DEBUG_FREE (obj);
+ COGL_OBJECT_DEBUG_FREE (obj);
free_func = obj->klass->virt_free;
free_func (obj);
}
}
+void
+cogl_handle_unref (CoglHandle handle)
+{
+ cogl_object_unref (handle);
+}
+
GType
-cogl_handle_get_type (void)
+cogl_object_get_type (void)
{
static GType our_type = 0;
+ /* XXX: We are keeping the "CoglHandle" name for now incase it would
+ * break bindings to change to "CoglObject" */
if (G_UNLIKELY (our_type == 0))
our_type = g_boxed_type_register_static (g_intern_static_string ("CoglHandle"),
- (GBoxedCopyFunc) cogl_handle_ref,
- (GBoxedFreeFunc) cogl_handle_unref);
+ (GBoxedCopyFunc) cogl_object_ref,
+ (GBoxedFreeFunc) cogl_object_unref);
return our_type;
}
+GType
+cogl_handle_get_type (void)
+{
+ return cogl_object_get_type ();
+}
/*
* CoglFixed
*/