[cogl] object: Add a virtual pointer for the unref function



commit 688a3e196bbe8a4ceb522ec819e8debc980fc6ad
Author: Neil Roberts <neil linux intel com>
Date:   Tue Jan 24 16:36:16 2012 +0000

    object: Add a virtual pointer for the unref function
    
    The virtual function gets called in cogl_object_unref. Any definition
    of a CoglObject type can replace the default unref function by using
    COGL_OBJECT_DEFINE_WITH_CODE to directly manipulate the
    CoglObjectClass struct. The generated object constructors set the
    pointer to the default implementation. The default implementation is
    exported in the private header so that any overriding implementations
    can chain up to it.
    
    Reviewed-by: Robert Bragg <robert linux intel com>

 cogl/cogl-object-private.h |    6 ++++++
 cogl/cogl-object.c         |    9 ++++++++-
 2 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/cogl/cogl-object-private.h b/cogl/cogl-object-private.h
index d335589..d7c3412 100644
--- a/cogl/cogl-object-private.h
+++ b/cogl/cogl-object-private.h
@@ -53,6 +53,7 @@ typedef struct _CoglObjectClass
 {
   const char *name;
   void *virt_free;
+  void *virt_unref;
 } CoglObjectClass;
 
 #define COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES 2
@@ -167,6 +168,8 @@ _cogl_##type_name##_object_new (Cogl##TypeName *new_obj)                \
                                                                         \
       obj->klass->virt_free =                                           \
         _cogl_object_##type_name##_indirect_free;                       \
+      obj->klass->virt_unref =                                          \
+        _cogl_object_default_unref;                                     \
       obj->klass->name = "Cogl"#TypeName,                               \
                                                                         \
       g_hash_table_insert (_cogl_debug_instances,                       \
@@ -287,5 +290,8 @@ _cogl_object_set_user_data (CoglObject *object,
                             void *user_data,
                             CoglUserDataDestroyInternalCallback destroy);
 
+void
+_cogl_object_default_unref (void *obj);
+
 #endif /* __COGL_OBJECT_PRIVATE_H */
 
diff --git a/cogl/cogl-object.c b/cogl/cogl-object.c
index 7f06d8d..4e0b4ed 100644
--- a/cogl/cogl-object.c
+++ b/cogl/cogl-object.c
@@ -52,7 +52,7 @@ cogl_handle_ref (CoglHandle handle)
 }
 
 void
-cogl_object_unref (void *object)
+_cogl_object_default_unref (void *object)
 {
   CoglObject *obj = object;
 
@@ -98,6 +98,13 @@ cogl_object_unref (void *object)
 }
 
 void
+cogl_object_unref (void *obj)
+{
+  void (* unref_func) (void *) = ((CoglObject *) obj)->klass->virt_unref;
+  unref_func (obj);
+}
+
+void
 cogl_handle_unref (CoglHandle handle)
 {
   cogl_object_unref (handle);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]