1
0
Fork 0

cogl: Port Attribute away from CoglObject

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3193>
This commit is contained in:
Bilal Elmoussaoui 2023-08-18 09:03:09 +02:00 committed by Marge Bot
parent 9d71949b26
commit f0923aab44
12 changed files with 71 additions and 81 deletions

View file

@ -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;
}

View file

@ -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,

View file

@ -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;

View file

@ -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 <string.h>
#include <stdio.h>
#include <stdlib.h>
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,

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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);
}

View file

@ -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);

View file

@ -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);

View file

@ -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;
}

View file

@ -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);
}