From b044e26e628f482f095c2324b9a5f888d66ca4b4 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Tue, 19 Sep 2023 11:20:04 +0200 Subject: [PATCH] cogl: Drop no longer used user data helpers This also drops the test-object conform test as it doesn't do anything interesting and the gobject qdata functionnality is already well tested across the platform Part-of: --- cogl/cogl/cogl-object-private.h | 21 ---- cogl/cogl/cogl-object.c | 164 --------------------------- cogl/cogl/cogl-object.h | 74 ------------ src/tests/cogl/conform/meson.build | 1 - src/tests/cogl/conform/test-object.c | 90 --------------- 5 files changed, 350 deletions(-) delete mode 100644 src/tests/cogl/conform/test-object.c diff --git a/cogl/cogl/cogl-object-private.h b/cogl/cogl/cogl-object-private.h index 93dd9d09d..d48ef330c 100644 --- a/cogl/cogl/cogl-object-private.h +++ b/cogl/cogl/cogl-object-private.h @@ -58,14 +58,6 @@ typedef struct _CoglObjectClass void *virt_unref; } CoglObjectClass; -#define COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES 2 - -typedef struct -{ - CoglUserDataKey *key; - void *user_data; - CoglUserDataDestroyInternalCallback destroy; -} CoglUserDataEntry; /* All Cogl objects inherit from this base object by adding a member: * @@ -78,11 +70,6 @@ struct _CoglObject { CoglObjectClass *klass; /* equivalent to GTypeInstance */ - CoglUserDataEntry user_data_entry[ - COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES]; - GArray *user_data_array; - int n_user_data_entries; - unsigned int ref_count; }; @@ -176,8 +163,6 @@ _cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \ CoglObject *obj = (CoglObject *)&new_obj->_parent; \ obj->ref_count = 0; \ cogl_object_ref (obj); \ - obj->n_user_data_entries = 0; \ - obj->user_data_array = NULL; \ \ obj->klass = &_cogl_##type_name##_class; \ if (!obj->klass->virt_free) \ @@ -244,11 +229,5 @@ _cogl_is_##type_name (void *object) \ #define COGL_OBJECT_INTERNAL_DEFINE(TypeName, type_name) \ COGL_OBJECT_INTERNAL_DEFINE_WITH_CODE (TypeName, type_name, (void) 0) -void -_cogl_object_set_user_data (CoglObject *object, - CoglUserDataKey *key, - void *user_data, - CoglUserDataDestroyInternalCallback destroy); - COGL_EXPORT void _cogl_object_default_unref (void *obj); diff --git a/cogl/cogl/cogl-object.c b/cogl/cogl/cogl-object.c index 3dbd85666..3a759904d 100644 --- a/cogl/cogl/cogl-object.c +++ b/cogl/cogl/cogl-object.c @@ -64,34 +64,6 @@ _cogl_object_default_unref (void *object) { void (*free_func)(void *obj); - if (obj->n_user_data_entries) - { - int i; - int count = MIN (obj->n_user_data_entries, - COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES); - - for (i = 0; i < count; i++) - { - CoglUserDataEntry *entry = &obj->user_data_entry[i]; - if (entry->destroy) - entry->destroy (entry->user_data, obj); - } - - if (obj->user_data_array != NULL) - { - for (i = 0; i < obj->user_data_array->len; i++) - { - CoglUserDataEntry *entry = - &g_array_index (obj->user_data_array, - CoglUserDataEntry, i); - - if (entry->destroy) - entry->destroy (entry->user_data, obj); - } - g_array_free (obj->user_data_array, TRUE); - } - } - COGL_OBJECT_DEBUG_FREE (obj); free_func = obj->klass->virt_free; free_func (obj); @@ -109,142 +81,6 @@ cogl_object_unref (void *obj) unref_func (obj); } -/* XXX: Unlike for cogl_object_get_user_data this code will return - * an empty entry if available and no entry for the given key can be - * found. */ -static CoglUserDataEntry * -_cogl_object_find_entry (CoglObject *object, CoglUserDataKey *key) -{ - CoglUserDataEntry *entry = NULL; - int count; - int i; - - count = MIN (object->n_user_data_entries, - COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES); - - for (i = 0; i < count; i++) - { - CoglUserDataEntry *current = &object->user_data_entry[i]; - if (current->key == key) - return current; - if (current->user_data == NULL) - entry = current; - } - - if (G_UNLIKELY (object->user_data_array != NULL)) - { - for (i = 0; i < object->user_data_array->len; i++) - { - CoglUserDataEntry *current = - &g_array_index (object->user_data_array, CoglUserDataEntry, i); - - if (current->key == key) - return current; - if (current->user_data == NULL) - entry = current; - } - } - - return entry; -} - -void -_cogl_object_set_user_data (CoglObject *object, - CoglUserDataKey *key, - void *user_data, - CoglUserDataDestroyInternalCallback destroy) -{ - CoglUserDataEntry new_entry; - CoglUserDataEntry *entry; - - if (user_data) - { - new_entry.key = key; - new_entry.user_data = user_data; - new_entry.destroy = destroy; - } - else - memset (&new_entry, 0, sizeof (new_entry)); - - entry = _cogl_object_find_entry (object, key); - if (entry) - { - if (G_LIKELY (entry->destroy)) - entry->destroy (entry->user_data, object); - } - else - { - /* NB: Setting a value of NULL is documented to delete the - * corresponding entry so we can return immediately in this - * case. */ - if (user_data == NULL) - return; - - if (G_LIKELY (object->n_user_data_entries < - COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES)) - entry = &object->user_data_entry[object->n_user_data_entries++]; - else - { - if (G_UNLIKELY (object->user_data_array == NULL)) - { - object->user_data_array = - g_array_new (FALSE, FALSE, sizeof (CoglUserDataEntry)); - } - - g_array_set_size (object->user_data_array, - object->user_data_array->len + 1); - entry = - &g_array_index (object->user_data_array, CoglUserDataEntry, - object->user_data_array->len - 1); - - object->n_user_data_entries++; - } - } - - *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) -{ - int count; - int i; - - count = MIN (object->n_user_data_entries, - COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES); - - for (i = 0; i < count; i++) - { - CoglUserDataEntry *entry = &object->user_data_entry[i]; - if (entry->key == key) - return entry->user_data; - } - - if (object->user_data_array != NULL) - { - for (i = 0; i < object->user_data_array->len; i++) - { - CoglUserDataEntry *entry = - &g_array_index (object->user_data_array, CoglUserDataEntry, i); - - if (entry->key == key) - return entry->user_data; - } - } - - return NULL; -} - void cogl_debug_object_foreach_type (CoglDebugObjectForeachTypeCallback func, void *user_data) diff --git a/cogl/cogl/cogl-object.h b/cogl/cogl/cogl-object.h index 8f1fd1b02..47f805347 100644 --- a/cogl/cogl/cogl-object.h +++ b/cogl/cogl/cogl-object.h @@ -89,41 +89,6 @@ cogl_object_unref (void *object); */ #define cogl_clear_object(object_ptr) g_clear_pointer ((object_ptr), cogl_object_unref) -/** - * CoglUserDataKey: - * @unused: ignored. - * - * A #CoglUserDataKey is used to declare a key for attaching data to a - * #CoglObject using cogl_object_set_user_data. The typedef only exists as a - * formality to make code self documenting since only the unique address of a - * #CoglUserDataKey is used. - * - * Typically you would declare a static #CoglUserDataKey and set private data - * on an object something like this: - * - * |[ - * static CoglUserDataKey path_private_key; - * - * static void - * destroy_path_private_cb (void *data) - * { - * g_free (data); - * } - * - * static void - * my_path_set_data (CoglPipeline *pipeline, void *data) - * { - * cogl_object_set_user_data (COGL_OBJECT (pipeline), - * &private_key, - * data, - * destroy_pipeline_private_cb); - * } - * ]| - */ -typedef struct { - int unused; -} CoglUserDataKey; - /** * CoglUserDataDestroyCallback: * @user_data: The data whose association with a #CoglObject has been @@ -160,45 +125,6 @@ typedef void (* CoglDebugObjectForeachTypeCallback) (const CoglDebugObjectTypeInfo *info, void *user_data); -/** - * cogl_object_set_user_data: (skip) - * @object: The object to associate private data with - * @key: The address of a #CoglUserDataKey which provides a unique value - * with which to index the private data. - * @user_data: The data to associate with the given object, - * or %NULL to remove a previous association. - * @destroy: A #CoglUserDataDestroyCallback to call if the object is - * destroyed or if the association is removed by later setting - * %NULL data for the same key. - * - * Associates some private @user_data with a given #CoglObject. To - * later remove the association call cogl_object_set_user_data() with - * the same @key but NULL for the @user_data. - */ -COGL_EXPORT void -cogl_object_set_user_data (CoglObject *object, - CoglUserDataKey *key, - void *user_data, - CoglUserDataDestroyCallback destroy); - -/** - * cogl_object_get_user_data: (skip) - * @object: The object with associated private data to query - * @key: The address of a #CoglUserDataKey which provides a unique value - * with which to index the private data. - * - * Finds the user data previously associated with @object using - * the given @key. If no user data has been associated with @object - * for the given @key this function returns NULL. - * - * Returns: (transfer none): The user data previously associated - * with @object using the given @key; or %NULL if no associated - * data is found. - */ -COGL_EXPORT void * -cogl_object_get_user_data (CoglObject *object, - CoglUserDataKey *key); - /** * cogl_debug_object_foreach_type: * @func: (scope call): A callback function for each type diff --git a/src/tests/cogl/conform/meson.build b/src/tests/cogl/conform/meson.build index 23541ec0b..bd725494c 100644 --- a/src/tests/cogl/conform/meson.build +++ b/src/tests/cogl/conform/meson.build @@ -45,7 +45,6 @@ cogl_tests = [ #unported = [ # "test-multitexture", # "test-npot-texture", -# "test-object", # "test-readpixels", # "test-texture-mipmaps", # "test-texture-pixmap-x11", diff --git a/src/tests/cogl/conform/test-object.c b/src/tests/cogl/conform/test-object.c deleted file mode 100644 index dbe5c6b9f..000000000 --- a/src/tests/cogl/conform/test-object.c +++ /dev/null @@ -1,90 +0,0 @@ - -#include -#include -#include - -#include "test-conform-common.h" - -static GQuark private_key0 = 0; -static GQuark private_key1 = 0; -static GQuark private_key2 = 0; - -static int user_data0; -static int user_data1; -static int user_data2; - -static int destroy0_count = 0; -static int destroy1_count = 0; -static int destroy2_count = 0; - -static void -destroy0_cb (void *user_data) -{ - g_assert (user_data == &user_data0); - destroy0_count++; -} - -static void -destroy1_cb (void *user_data) -{ - g_assert (user_data == &user_data1); - destroy1_count++; -} - -static void -destroy2_cb (void *user_data) -{ - g_assert (user_data == &user_data2); - destroy2_count++; -} - -void -test_object (TestUtilsGTestFixture *fixture, - void *data) -{ - CoglPipeline *pipeline; - - /* Assuming that COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES == 2 - * test associating 2 pointers to private data with an object */ - cogl_pipeline_new (); - pipeline = cogl_pipeline_path (); - - private_key0 = g_quark_from_static_string ("test-object-private_key0"); - private_key1 = g_quark_from_static_string ("test-object-private_key1"); - private_key2 = g_quark_from_static_string ("test-object-private_key2"); - - g_object_set_qdata_full (G_OBJECT (pipeline), - private_key0, - &user_data0, - destroy0_cb); - - g_object_set_qdata_full (G_OBJECT (pipeline), - private_key1, - &user_data1, - destroy1_cb); - - g_object_set_qdata_full (G_OBJECT (pipeline), - private_key2, - &user_data2, - destroy2_cb); - - g_object_set_qdata_full (G_OBJECT (pipeline), - private_key1, - NULL, - destroy1_cb); - - g_object_set_qdata_full (G_OBJECT (pipeline), - private_key1, - &user_data1, - destroy1_cb); - - g_object_unref (pipeline); - - g_assert_cmpint (destroy0_count, ==, 1); - g_assert_cmpint (destroy1_count, ==, 2); - g_assert_cmpint (destroy2_count, ==, 1); - - if (cogl_test_verbose ()) - g_print ("OK\n"); -} -