From df8ae83040ff01f7b4878698527548fe8cff5f0e Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Fri, 18 Aug 2023 09:52:51 +0200 Subject: [PATCH] cogl: Port Indices away from CoglObject Also renames Indices.get_type to Indices.get_indices_type to avoid a conflict with the generated Object.get_type function Part-of: --- clutter/clutter/clutter-deform-effect.c | 2 +- cogl/cogl/cogl-context.c | 4 +- cogl/cogl/cogl-framebuffer.c | 4 +- cogl/cogl/cogl-indices-private.h | 3 +- cogl/cogl/cogl-indices.c | 53 ++++++++++++++--------- cogl/cogl/cogl-indices.h | 29 ++++--------- cogl/cogl/cogl-primitive.c | 6 +-- cogl/cogl/driver/gl/cogl-framebuffer-gl.c | 4 +- src/tests/cogl/conform/test-primitive.c | 2 +- 9 files changed, 52 insertions(+), 55 deletions(-) diff --git a/clutter/clutter/clutter-deform-effect.c b/clutter/clutter/clutter-deform-effect.c index 645a2604d..8086bb6c6 100644 --- a/clutter/clutter/clutter-deform-effect.c +++ b/clutter/clutter/clutter-deform-effect.c @@ -488,7 +488,7 @@ clutter_deform_effect_init_arrays (ClutterDeformEffect *self) n_indices); } - cogl_object_unref (indices); + g_object_unref (indices); for (i = 0; i < 3; i++) g_object_unref (attributes[i]); diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c index c397bdad9..e65f10461 100644 --- a/cogl/cogl/cogl-context.c +++ b/cogl/cogl/cogl-context.c @@ -95,9 +95,9 @@ cogl_context_dispose (GObject *object) g_array_free (context->journal_clip_bounds, TRUE); if (context->rectangle_byte_indices) - cogl_object_unref (context->rectangle_byte_indices); + g_object_unref (context->rectangle_byte_indices); if (context->rectangle_short_indices) - cogl_object_unref (context->rectangle_short_indices); + g_object_unref (context->rectangle_short_indices); if (context->default_pipeline) cogl_object_unref (context->default_pipeline); diff --git a/cogl/cogl/cogl-framebuffer.c b/cogl/cogl/cogl-framebuffer.c index f607dd30f..1b1df3a99 100644 --- a/cogl/cogl/cogl-framebuffer.c +++ b/cogl/cogl/cogl-framebuffer.c @@ -2195,7 +2195,7 @@ get_wire_line_indices (CoglContext *ctx, indices = _cogl_buffer_map (COGL_BUFFER (index_buffer), COGL_BUFFER_ACCESS_READ, 0, NULL); - indices_type = cogl_indices_get_type (user_indices); + indices_type = cogl_indices_get_indices_type (user_indices); } else { @@ -2375,7 +2375,7 @@ draw_wireframe (CoglContext *ctx, flags); COGL_DEBUG_SET_FLAG (COGL_DEBUG_WIREFRAME); - cogl_object_unref (wire_indices); + g_object_unref (wire_indices); } #endif diff --git a/cogl/cogl/cogl-indices-private.h b/cogl/cogl/cogl-indices-private.h index bb802e225..d50c57cbc 100644 --- a/cogl/cogl/cogl-indices-private.h +++ b/cogl/cogl/cogl-indices-private.h @@ -33,13 +33,12 @@ #pragma once -#include "cogl/cogl-object-private.h" #include "cogl/cogl-index-buffer-private.h" #include "cogl/cogl-types.h" struct _CoglIndices { - CoglObject _parent; + GObject parent_instance; CoglIndexBuffer *buffer; size_t offset; diff --git a/cogl/cogl/cogl-indices.c b/cogl/cogl/cogl-indices.c index fb00eca01..1e64c2314 100644 --- a/cogl/cogl/cogl-indices.c +++ b/cogl/cogl/cogl-indices.c @@ -35,19 +35,37 @@ #include "cogl-config.h" #include "cogl/cogl-util.h" -#include "cogl/cogl-object-private.h" #include "cogl/cogl-context-private.h" #include "cogl/cogl-indices.h" #include "cogl/cogl-indices-private.h" #include "cogl/cogl-index-buffer.h" -#include "cogl/cogl-gtype-private.h" #include -static void _cogl_indices_free (CoglIndices *indices); +G_DEFINE_TYPE (CoglIndices, cogl_indices, G_TYPE_OBJECT); -COGL_OBJECT_DEFINE (Indices, indices); -COGL_GTYPE_DEFINE_CLASS (Indices, indices); +static void +cogl_indices_dispose (GObject *object) +{ + CoglIndices *indices = COGL_INDICES (object); + + cogl_object_unref (indices->buffer); + + G_OBJECT_CLASS (cogl_indices_parent_class)->dispose (object); +} + +static void +cogl_indices_init (CoglIndices *indices) +{ +} + +static void +cogl_indices_class_init (CoglIndicesClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->dispose = cogl_indices_dispose; +} static size_t sizeof_indices_type (CoglIndicesType type) @@ -69,7 +87,7 @@ cogl_indices_new_for_buffer (CoglIndicesType type, CoglIndexBuffer *buffer, size_t offset) { - CoglIndices *indices = g_new0 (CoglIndices, 1); + CoglIndices *indices = g_object_new (COGL_TYPE_INDICES, NULL); indices->buffer = cogl_object_ref (buffer); indices->offset = offset; @@ -78,7 +96,7 @@ cogl_indices_new_for_buffer (CoglIndicesType type, indices->immutable_ref = 0; - return _cogl_indices_object_new (indices); + return indices; } CoglIndices * @@ -118,9 +136,9 @@ cogl_indices_get_buffer (CoglIndices *indices) } CoglIndicesType -cogl_indices_get_type (CoglIndices *indices) +cogl_indices_get_indices_type (CoglIndices *indices) { - g_return_val_if_fail (cogl_is_indices (indices), + g_return_val_if_fail (COGL_IS_INDICES (indices), COGL_INDICES_TYPE_UNSIGNED_BYTE); return indices->type; } @@ -128,7 +146,7 @@ cogl_indices_get_type (CoglIndices *indices) size_t cogl_indices_get_offset (CoglIndices *indices) { - g_return_val_if_fail (cogl_is_indices (indices), 0); + g_return_val_if_fail (COGL_IS_INDICES (indices), 0); return indices->offset; } @@ -149,7 +167,7 @@ void cogl_indices_set_offset (CoglIndices *indices, size_t offset) { - g_return_if_fail (cogl_is_indices (indices)); + g_return_if_fail (COGL_IS_INDICES (indices)); if (G_UNLIKELY (indices->immutable_ref)) warn_about_midscene_changes (); @@ -157,17 +175,10 @@ cogl_indices_set_offset (CoglIndices *indices, indices->offset = offset; } -static void -_cogl_indices_free (CoglIndices *indices) -{ - cogl_object_unref (indices->buffer); - g_free (indices); -} - CoglIndices * _cogl_indices_immutable_ref (CoglIndices *indices) { - g_return_val_if_fail (cogl_is_indices (indices), NULL); + g_return_val_if_fail (COGL_IS_INDICES (indices), NULL); indices->immutable_ref++; _cogl_buffer_immutable_ref (COGL_BUFFER (indices->buffer)); @@ -177,7 +188,7 @@ _cogl_indices_immutable_ref (CoglIndices *indices) void _cogl_indices_immutable_unref (CoglIndices *indices) { - g_return_if_fail (cogl_is_indices (indices)); + g_return_if_fail (COGL_IS_INDICES (indices)); g_return_if_fail (indices->immutable_ref > 0); indices->immutable_ref--; @@ -230,7 +241,7 @@ cogl_get_rectangle_indices (CoglContext *ctx, int n_rectangles) int i, vert_num = 0; if (ctx->rectangle_short_indices != NULL) - cogl_object_unref (ctx->rectangle_short_indices); + g_object_unref (ctx->rectangle_short_indices); /* Pick a power of two >= MAX (512, n_indices) */ if (ctx->rectangle_short_indices_len == 0) ctx->rectangle_short_indices_len = 512; diff --git a/cogl/cogl/cogl-indices.h b/cogl/cogl/cogl-indices.h index 9c2df103e..d0b748178 100644 --- a/cogl/cogl/cogl-indices.h +++ b/cogl/cogl/cogl-indices.h @@ -49,8 +49,9 @@ typedef struct _CoglIndices CoglIndices; G_BEGIN_DECLS /** - * SECTION:cogl-indices - * @short_description: Describe vertex indices stored in a #CoglIndexBuffer. + * CoglIndices: + * + * Describe vertex indices stored in a #CoglIndexBuffer. * * Indices allow you to avoid duplicating vertices in your vertex data * by virtualizing your data and instead providing a sequence of index @@ -106,13 +107,11 @@ G_BEGIN_DECLS * for drawing quads as above. */ -/** - * cogl_indices_get_gtype: - * - * Returns: a #GType that can be used with the GLib type system. - */ +#define COGL_TYPE_INDICES (cogl_indices_get_type ()) + COGL_EXPORT -GType cogl_indices_get_gtype (void); +G_DECLARE_FINAL_TYPE (CoglIndices, cogl_indices, + COGL, INDICES, GObject) COGL_EXPORT CoglIndices * cogl_indices_new (CoglContext *context, @@ -129,7 +128,7 @@ COGL_EXPORT CoglIndexBuffer * cogl_indices_get_buffer (CoglIndices *indices); COGL_EXPORT CoglIndicesType -cogl_indices_get_type (CoglIndices *indices); +cogl_indices_get_indices_type (CoglIndices *indices); COGL_EXPORT size_t cogl_indices_get_offset (CoglIndices *indices); @@ -141,16 +140,4 @@ cogl_indices_set_offset (CoglIndices *indices, COGL_EXPORT CoglIndices * cogl_get_rectangle_indices (CoglContext *context, int n_rectangles); -/** - * cogl_is_indices: - * @object: A #CoglObject pointer - * - * Gets whether the given object references a #CoglIndices. - * - * Return value: %TRUE if the object references a #CoglIndices - * and %FALSE otherwise. - */ -COGL_EXPORT gboolean -cogl_is_indices (void *object); - G_END_DECLS diff --git a/cogl/cogl/cogl-primitive.c b/cogl/cogl/cogl-primitive.c index 420f40e97..e61a23c0c 100644 --- a/cogl/cogl/cogl-primitive.c +++ b/cogl/cogl/cogl-primitive.c @@ -387,7 +387,7 @@ _cogl_primitive_free (CoglPrimitive *primitive) g_free (primitive->attributes); if (primitive->indices) - cogl_object_unref (primitive->indices); + g_object_unref (primitive->indices); g_free (primitive); } @@ -532,9 +532,9 @@ cogl_primitive_set_indices (CoglPrimitive *primitive, } if (indices) - cogl_object_ref (indices); + g_object_ref (indices); if (primitive->indices) - cogl_object_unref (primitive->indices); + g_object_unref (primitive->indices); primitive->indices = indices; primitive->n_vertices = n_indices; } diff --git a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c index f5592e902..d944f763f 100644 --- a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c +++ b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c @@ -383,9 +383,9 @@ cogl_gl_framebuffer_draw_indexed_attributes (CoglFramebufferDriver *driver, base = _cogl_buffer_gl_bind (buffer, COGL_BUFFER_BIND_TARGET_INDEX_BUFFER, NULL); buffer_offset = cogl_indices_get_offset (indices); - index_size = sizeof_index_type (cogl_indices_get_type (indices)); + index_size = sizeof_index_type (cogl_indices_get_indices_type (indices)); - switch (cogl_indices_get_type (indices)) + switch (cogl_indices_get_indices_type (indices)) { case COGL_INDICES_TYPE_UNSIGNED_BYTE: indices_gl_type = GL_UNSIGNED_BYTE; diff --git a/src/tests/cogl/conform/test-primitive.c b/src/tests/cogl/conform/test-primitive.c index b432c88c5..b95be43ab 100644 --- a/src/tests/cogl/conform/test-primitive.c +++ b/src/tests/cogl/conform/test-primitive.c @@ -303,7 +303,7 @@ test_copy (TestState *state) cogl_object_unref (prim_a); cogl_object_unref (prim_b); - cogl_object_unref (indices); + g_object_unref (indices); for (i = 0; i < N_ATTRIBS; i++) g_object_unref (attributes[i]);