diff --git a/clutter/clutter/clutter-deform-effect.c b/clutter/clutter/clutter-deform-effect.c index 9088a6d59..645a2604d 100644 --- a/clutter/clutter/clutter-deform-effect.c +++ b/clutter/clutter/clutter-deform-effect.c @@ -491,7 +491,7 @@ clutter_deform_effect_init_arrays (ClutterDeformEffect *self) cogl_object_unref (indices); for (i = 0; i < 3; i++) - cogl_object_unref (attributes[i]); + g_object_unref (attributes[i]); priv->is_dirty = TRUE; } diff --git a/cogl/cogl-pango/cogl-pango-display-list.c b/cogl/cogl-pango/cogl-pango-display-list.c index 9f694d691..c66e07456 100644 --- a/cogl/cogl-pango/cogl-pango-display-list.c +++ b/cogl/cogl-pango/cogl-pango-display-list.c @@ -365,8 +365,8 @@ emit_vertex_buffer_geometry (CoglFramebuffer *fb, node->d.texture.primitive = prim; cogl_object_unref (buffer); - cogl_object_unref (attributes[0]); - cogl_object_unref (attributes[1]); + g_object_unref (attributes[0]); + g_object_unref (attributes[1]); } cogl_primitive_draw (node->d.texture.primitive, diff --git a/cogl/cogl/cogl-attribute-private.h b/cogl/cogl/cogl-attribute-private.h index be74246f4..ffb0596a4 100644 --- a/cogl/cogl/cogl-attribute-private.h +++ b/cogl/cogl/cogl-attribute-private.h @@ -33,11 +33,9 @@ #pragma once -#include "cogl/cogl-object-private.h" #include "cogl/cogl-attribute.h" #include "cogl/cogl-framebuffer.h" #include "cogl/cogl-pipeline-private.h" -#include "cogl/cogl-boxed-value.h" typedef enum { @@ -60,7 +58,7 @@ typedef struct _CoglAttributeNameState struct _CoglAttribute { - CoglObject _parent; + GObject parent_instance; const CoglAttributeNameState *name_state; gboolean normalized; diff --git a/cogl/cogl/cogl-attribute.c b/cogl/cogl/cogl-attribute.c index b3f6e92d4..01b2fb611 100644 --- a/cogl/cogl/cogl-attribute.c +++ b/cogl/cogl/cogl-attribute.c @@ -35,7 +35,6 @@ #include "cogl/cogl-util.h" #include "cogl/cogl-context-private.h" -#include "cogl/cogl-object-private.h" #include "cogl/cogl-journal-private.h" #include "cogl/cogl-attribute.h" #include "cogl/cogl-attribute-private.h" @@ -45,16 +44,39 @@ #include "cogl/cogl-framebuffer-private.h" #include "cogl/cogl-indices-private.h" #include "cogl/cogl-private.h" -#include "cogl/cogl-gtype-private.h" #include #include #include -static void _cogl_attribute_free (CoglAttribute *attribute); +G_DEFINE_TYPE (CoglAttribute, cogl_attribute, G_TYPE_OBJECT); -COGL_OBJECT_DEFINE (Attribute, attribute); -COGL_GTYPE_DEFINE_CLASS (Attribute, attribute); +static void +cogl_attribute_dispose (GObject *object) +{ + CoglAttribute *attribute = COGL_ATTRIBUTE (object); + + if (attribute->is_buffered) + cogl_object_unref (attribute->d.buffered.attribute_buffer); + else + _cogl_boxed_value_destroy (&attribute->d.constant.boxed); + + + G_OBJECT_CLASS (cogl_attribute_parent_class)->dispose (object); +} + +static void +cogl_attribute_init (CoglAttribute *attribute) +{ +} + +static void +cogl_attribute_class_init (CoglAttributeClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->dispose = cogl_attribute_dispose; +} static gboolean validate_cogl_attribute_name (const char *name, @@ -190,7 +212,7 @@ cogl_attribute_new (CoglAttributeBuffer *attribute_buffer, int n_components, CoglAttributeType type) { - CoglAttribute *attribute = g_new0 (CoglAttribute, 1); + CoglAttribute *attribute = g_object_new (COGL_TYPE_ATTRIBUTE, NULL); CoglBuffer *buffer = COGL_BUFFER (attribute_buffer); CoglContext *ctx = buffer->context; @@ -225,10 +247,10 @@ cogl_attribute_new (CoglAttributeBuffer *attribute_buffer, else attribute->normalized = FALSE; - return _cogl_attribute_object_new (attribute); + return attribute; error: - _cogl_attribute_free (attribute); + g_object_unref (attribute); return NULL; } @@ -240,7 +262,7 @@ _cogl_attribute_new_const (CoglContext *context, gboolean transpose, const float *value) { - CoglAttribute *attribute = g_new0 (CoglAttribute, 1); + CoglAttribute *attribute = g_object_new (COGL_TYPE_ATTRIBUTE, NULL); attribute->name_state = g_hash_table_lookup (context->attribute_name_states_hash, name); @@ -283,10 +305,10 @@ _cogl_attribute_new_const (CoglContext *context, value); } - return _cogl_attribute_object_new (attribute); + return attribute; error: - _cogl_attribute_free (attribute); + g_object_unref (attribute); return NULL; } @@ -435,7 +457,7 @@ cogl_attribute_new_const_4x4fv (CoglContext *context, gboolean cogl_attribute_get_normalized (CoglAttribute *attribute) { - g_return_val_if_fail (cogl_is_attribute (attribute), FALSE); + g_return_val_if_fail (COGL_IS_ATTRIBUTE (attribute), FALSE); return attribute->normalized; } @@ -456,7 +478,7 @@ void cogl_attribute_set_normalized (CoglAttribute *attribute, gboolean normalized) { - g_return_if_fail (cogl_is_attribute (attribute)); + g_return_if_fail (COGL_IS_ATTRIBUTE (attribute)); if (G_UNLIKELY (attribute->immutable_ref)) warn_about_midscene_changes (); @@ -467,7 +489,7 @@ cogl_attribute_set_normalized (CoglAttribute *attribute, CoglAttributeBuffer * cogl_attribute_get_buffer (CoglAttribute *attribute) { - g_return_val_if_fail (cogl_is_attribute (attribute), NULL); + g_return_val_if_fail (COGL_IS_ATTRIBUTE (attribute), NULL); g_return_val_if_fail (attribute->is_buffered, NULL); return attribute->d.buffered.attribute_buffer; @@ -477,7 +499,7 @@ void cogl_attribute_set_buffer (CoglAttribute *attribute, CoglAttributeBuffer *attribute_buffer) { - g_return_if_fail (cogl_is_attribute (attribute)); + g_return_if_fail (COGL_IS_ATTRIBUTE (attribute)); g_return_if_fail (attribute->is_buffered); if (G_UNLIKELY (attribute->immutable_ref)) @@ -494,7 +516,7 @@ _cogl_attribute_immutable_ref (CoglAttribute *attribute) { CoglBuffer *buffer = COGL_BUFFER (attribute->d.buffered.attribute_buffer); - g_return_val_if_fail (cogl_is_attribute (attribute), NULL); + g_return_val_if_fail (COGL_IS_ATTRIBUTE (attribute), NULL); attribute->immutable_ref++; _cogl_buffer_immutable_ref (buffer); @@ -506,24 +528,13 @@ _cogl_attribute_immutable_unref (CoglAttribute *attribute) { CoglBuffer *buffer = COGL_BUFFER (attribute->d.buffered.attribute_buffer); - g_return_if_fail (cogl_is_attribute (attribute)); + g_return_if_fail (COGL_IS_ATTRIBUTE (attribute)); g_return_if_fail (attribute->immutable_ref > 0); attribute->immutable_ref--; _cogl_buffer_immutable_unref (buffer); } -static void -_cogl_attribute_free (CoglAttribute *attribute) -{ - if (attribute->is_buffered) - cogl_object_unref (attribute->d.buffered.attribute_buffer); - else - _cogl_boxed_value_destroy (&attribute->d.constant.boxed); - - g_free (attribute); -} - static gboolean validate_layer_cb (CoglPipeline *pipeline, int layer_index, diff --git a/cogl/cogl/cogl-attribute.h b/cogl/cogl/cogl-attribute.h index 1966681c7..91651d03f 100644 --- a/cogl/cogl/cogl-attribute.h +++ b/cogl/cogl/cogl-attribute.h @@ -49,21 +49,14 @@ typedef struct _CoglAttribute CoglAttribute; G_BEGIN_DECLS -/** - * SECTION:cogl-attribute - * @short_description: Functions for declaring and drawing vertex - * attributes - * - * FIXME - */ +#define COGL_TYPE_ATTRIBUTE (cogl_attribute_get_type ()) -/** - * cogl_attribute_get_gtype: - * - * Returns: a #GType that can be used with the GLib type system. - */ COGL_EXPORT -GType cogl_attribute_get_gtype (void); +G_DECLARE_FINAL_TYPE (CoglAttribute, + cogl_attribute, + COGL, + ATTRIBUTE, + GObject) /** * cogl_attribute_new: (constructor) @@ -521,16 +514,4 @@ COGL_EXPORT void cogl_attribute_set_buffer (CoglAttribute *attribute, CoglAttributeBuffer *attribute_buffer); -/** - * cogl_is_attribute: - * @object: A #CoglObject - * - * Gets whether the given object references a #CoglAttribute. - * - * Return value: %TRUE if the @object references a #CoglAttribute, - * %FALSE otherwise - */ -COGL_EXPORT gboolean -cogl_is_attribute (void *object); - G_END_DECLS diff --git a/cogl/cogl/cogl-journal.c b/cogl/cogl/cogl-journal.c index 5b5733317..6f1da9a30 100644 --- a/cogl/cogl/cogl-journal.c +++ b/cogl/cogl/cogl-journal.c @@ -521,7 +521,7 @@ _cogl_journal_flush_texcoord_vbo_offsets_and_entries ( /* NB: attributes 0 and 1 are position and color */ for (i = 2; i < state->attributes->len; i++) - cogl_object_unref (g_array_index (state->attributes, CoglAttribute *, i)); + g_object_unref (g_array_index (state->attributes, CoglAttribute *, i)); g_array_set_size (state->attributes, batch_start->n_layers + 2); @@ -589,7 +589,7 @@ _cogl_journal_flush_vbo_offsets_and_entries (CoglJournalEntry *batch_start, state->stride = stride; for (i = 0; i < state->attributes->len; i++) - cogl_object_unref (g_array_index (state->attributes, CoglAttribute *, i)); + g_object_unref (g_array_index (state->attributes, CoglAttribute *, i)); g_array_set_size (state->attributes, 2); @@ -1459,7 +1459,7 @@ _cogl_journal_flush (CoglJournal *journal) &state); for (i = 0; i < state.attributes->len; i++) - cogl_object_unref (g_array_index (state.attributes, CoglAttribute *, i)); + g_object_unref (g_array_index (state.attributes, CoglAttribute *, i)); g_array_set_size (state.attributes, 0); cogl_object_unref (state.attribute_buffer); diff --git a/cogl/cogl/cogl-primitive.c b/cogl/cogl/cogl-primitive.c index 6c801678e..420f40e97 100644 --- a/cogl/cogl/cogl-primitive.c +++ b/cogl/cogl/cogl-primitive.c @@ -72,9 +72,9 @@ cogl_primitive_new_with_attributes (CoglVerticesMode mode, for (i = 0; i < n_attributes; i++) { CoglAttribute *attribute = attributes[i]; - cogl_object_ref (attribute); + g_object_ref (attribute); - g_return_val_if_fail (cogl_is_attribute (attribute), NULL); + g_return_val_if_fail (COGL_IS_ATTRIBUTE (attribute), NULL); primitive->attributes[i] = attribute; } @@ -100,7 +100,7 @@ _cogl_primitive_new_with_attributes_unref (CoglVerticesMode mode, n_attributes); for (i = 0; i < n_attributes; i++) - cogl_object_unref (attributes[i]); + g_object_unref (attributes[i]); return primitive; } @@ -381,7 +381,7 @@ _cogl_primitive_free (CoglPrimitive *primitive) int i; for (i = 0; i < primitive->n_attributes; i++) - cogl_object_unref (primitive->attributes[i]); + g_object_unref (primitive->attributes[i]); if (primitive->attributes != &primitive->embedded_attribute) g_free (primitive->attributes); @@ -424,12 +424,12 @@ cogl_primitive_set_attributes (CoglPrimitive *primitive, * attribute that's actually in the new list too. */ for (i = 0; i < n_attributes; i++) { - g_return_if_fail (cogl_is_attribute (attributes[i])); - cogl_object_ref (attributes[i]); + g_return_if_fail (COGL_IS_ATTRIBUTE (attributes[i])); + g_object_ref (attributes[i]); } for (i = 0; i < primitive->n_attributes; i++) - cogl_object_unref (primitive->attributes[i]); + g_object_unref (primitive->attributes[i]); /* First try to use the embedded storage associated with the * primitive, else fallback to slice allocating separate storage for diff --git a/cogl/cogl/cogl-primitives.c b/cogl/cogl/cogl-primitives.c index bd18be5a9..6d2892e72 100644 --- a/cogl/cogl/cogl-primitives.c +++ b/cogl/cogl/cogl-primitives.c @@ -740,7 +740,7 @@ cogl_2d_primitives_immediate (CoglFramebuffer *framebuffer, COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH); - cogl_object_unref (attributes[0]); + g_object_unref (attributes[0]); cogl_object_unref (attribute_buffer); } diff --git a/src/tests/cogl/conform/test-custom-attributes.c b/src/tests/cogl/conform/test-custom-attributes.c index f25a816a8..7e12414c1 100644 --- a/src/tests/cogl/conform/test-custom-attributes.c +++ b/src/tests/cogl/conform/test-custom-attributes.c @@ -72,8 +72,8 @@ test_float_verts (TestState *state, int offset_x, int offset_y) cogl_framebuffer_pop_matrix (test_fb); - cogl_object_unref (attributes[1]); - cogl_object_unref (attributes[0]); + g_object_unref (attributes[1]); + g_object_unref (attributes[0]); cogl_object_unref (buffer); test_utils_check_pixel (test_fb, offset_x + 5, offset_y + 5, 0xff0000ff); @@ -131,7 +131,7 @@ test_byte_verts (TestState *state, int offset_x, int offset_y) cogl_primitive_draw (primitive, test_fb, state->pipeline); cogl_object_unref (primitive); - cogl_object_unref (attributes[1]); + g_object_unref (attributes[1]); /* Test again with unnormalized attributes */ unnorm_buffer = cogl_attribute_buffer_new (test_ctx, @@ -155,8 +155,8 @@ test_byte_verts (TestState *state, int offset_x, int offset_y) cogl_framebuffer_pop_matrix (test_fb); - cogl_object_unref (attributes[0]); - cogl_object_unref (attributes[1]); + g_object_unref (attributes[0]); + g_object_unref (attributes[1]); cogl_object_unref (buffer); cogl_object_unref (unnorm_buffer); @@ -217,7 +217,7 @@ test_short_verts (TestState *state, int offset_x, int offset_y) cogl_framebuffer_pop_matrix (test_fb); - cogl_object_unref (attributes[0]); + g_object_unref (attributes[0]); /* Test again treating the attribute as unsigned */ attributes[0] = cogl_attribute_new (buffer, @@ -252,7 +252,7 @@ test_short_verts (TestState *state, int offset_x, int offset_y) cogl_framebuffer_pop_matrix (test_fb); - cogl_object_unref (attributes[0]); + g_object_unref (attributes[0]); cogl_object_unref (pipeline2); cogl_object_unref (pipeline); diff --git a/src/tests/cogl/conform/test-map-buffer-range.c b/src/tests/cogl/conform/test-map-buffer-range.c index 92ac39752..d2dc077b7 100644 --- a/src/tests/cogl/conform/test-map-buffer-range.c +++ b/src/tests/cogl/conform/test-map-buffer-range.c @@ -118,8 +118,8 @@ test_map_buffer_range (void) test_utils_check_pixel (test_fb, fb_width - 2, fb_height - 2, 0xff0000ff); cogl_object_unref (buffer); - cogl_object_unref (pos_attribute); - cogl_object_unref (tex_coord_attribute); + g_object_unref (pos_attribute); + g_object_unref (tex_coord_attribute); cogl_object_unref (pipeline); cogl_object_unref (tex); diff --git a/src/tests/cogl/conform/test-point-size-attribute.c b/src/tests/cogl/conform/test-point-size-attribute.c index 457432e5c..bed41b9d4 100644 --- a/src/tests/cogl/conform/test-point-size-attribute.c +++ b/src/tests/cogl/conform/test-point-size-attribute.c @@ -92,7 +92,7 @@ create_primitive (const char *attribute_name) 2 /* n_attributes */); for (i = 0; i < 2; i++) - cogl_object_unref (attributes[i]); + g_object_unref (attributes[i]); return prim; } diff --git a/src/tests/cogl/conform/test-primitive.c b/src/tests/cogl/conform/test-primitive.c index b658ba839..b432c88c5 100644 --- a/src/tests/cogl/conform/test-primitive.c +++ b/src/tests/cogl/conform/test-primitive.c @@ -306,7 +306,7 @@ test_copy (TestState *state) cogl_object_unref (indices); for (i = 0; i < N_ATTRIBS; i++) - cogl_object_unref (attributes[i]); + g_object_unref (attributes[i]); cogl_object_unref (buffer); }