typedef struct _CoglObjectClass CoglHandleClass;
typedef struct _CoglObject CoglHandleObject;
+/* XXX: sadly we didn't fully consider when we copied the cairo API
+ * for _set_user_data that the callback doesn't get a pointer to the
+ * instance which is desired in most cases. This means you tend to end
+ * up creating micro allocations for the private data just so you can
+ * pair up the data of interest with the original instance for
+ * identification when it is later destroyed.
+ *
+ * Internally we use a small hack to avoid needing these micro
+ * allocations by actually passing the instance as a second argument
+ * to the callback */
+typedef void (*CoglUserDataDestroyInternalCallback) (void *user_data,
+ void *instance);
+
typedef struct _CoglObjectClass
{
GQuark type;
{
CoglUserDataKey *key;
void *user_data;
- CoglUserDataDestroyCallback destroy;
+ CoglUserDataDestroyInternalCallback destroy;
} CoglUserDataEntry;
/* All Cogl objects inherit from this base object by adding a member:
#define COGL_HANDLE_DEFINE(TypeName, type_name) \
COGL_HANDLE_DEFINE_WITH_CODE (TypeName, type_name, (void) 0)
+void
+_cogl_object_set_user_data (CoglObject *object,
+ CoglUserDataKey *key,
+ void *user_data,
+ CoglUserDataDestroyInternalCallback destroy);
+
#endif /* __COGL_OBJECT_PRIVATE_H */
{
CoglUserDataEntry *entry = &obj->user_data_entry[i];
if (entry->destroy)
- entry->destroy (entry->user_data);
+ entry->destroy (entry->user_data, obj);
}
if (obj->user_data_array != NULL)
CoglUserDataEntry, i);
if (entry->destroy)
- entry->destroy (entry->user_data);
+ entry->destroy (entry->user_data, obj);
}
g_array_free (obj->user_data_array, TRUE);
}
}
void
-cogl_object_set_user_data (CoglObject *object,
- CoglUserDataKey *key,
- void *user_data,
- CoglUserDataDestroyCallback destroy)
+_cogl_object_set_user_data (CoglObject *object,
+ CoglUserDataKey *key,
+ void *user_data,
+ CoglUserDataDestroyInternalCallback destroy)
{
CoglUserDataEntry new_entry;
CoglUserDataEntry *entry;
if (entry)
{
if (G_LIKELY (entry->destroy))
- entry->destroy (entry->user_data);
+ entry->destroy (entry->user_data, object);
}
else
{
*entry = new_entry;
}
+void
+cogl_object_set_user_data (CoglObject *object,
+ CoglUserDataKey *key,
+ void *user_data,
+ CoglUserDataDestroyCallback destroy)
+{
+ _cogl_object_set_user_data (object, key, user_data,
+ (CoglUserDataDestroyInternalCallback)destroy);
+}
+
void *
cogl_object_get_user_data (CoglObject *object, CoglUserDataKey *key)
{