1
0
Fork 0

cogl: Port Atlas 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:43:14 +02:00 committed by Marge Bot
parent f0923aab44
commit 4ea3593ebf
4 changed files with 57 additions and 38 deletions

View file

@ -156,7 +156,7 @@ cogl_pango_glyph_cache_reorganize_cb (void *user_data)
void
cogl_pango_glyph_cache_clear (CoglPangoGlyphCache *cache)
{
g_slist_foreach (cache->atlases, (GFunc) cogl_object_unref, NULL);
g_slist_foreach (cache->atlases, (GFunc) g_object_unref, NULL);
g_slist_free (cache->atlases);
cache->atlases = NULL;
cache->has_dirty_glyphs = FALSE;
@ -294,7 +294,7 @@ cogl_pango_glyph_cache_add_to_local_atlas (CoglPangoGlyphCache *cache,
value->draw_height + 1,
value))
{
cogl_object_unref (atlas);
g_object_unref (atlas);
return FALSE;
}

View file

@ -53,6 +53,7 @@
#include <stdlib.h>
static void _cogl_atlas_texture_free (CoglAtlasTexture *sub_tex);
static GQuark atlas_private_key = 0;
COGL_TEXTURE_DEFINE (AtlasTexture, atlas_texture);
COGL_GTYPE_DEFINE_CLASS (AtlasTexture, atlas_texture);
@ -199,7 +200,7 @@ _cogl_atlas_texture_atlas_destroyed_cb (void *user_data)
static CoglAtlas *
_cogl_atlas_texture_create_atlas (CoglContext *ctx)
{
static CoglUserDataKey atlas_private_key;
atlas_private_key = g_quark_from_static_string ("-cogl-atlas-texture-create-key");
CoglAtlas *atlas = _cogl_atlas_new (COGL_PIXEL_FORMAT_RGBA_8888,
0,
@ -217,8 +218,10 @@ _cogl_atlas_texture_create_atlas (CoglContext *ctx)
effectively holds a weak reference. We don't need a strong
reference because the atlas textures take a reference on the
atlas so it will stay alive */
cogl_object_set_user_data (COGL_OBJECT (atlas), &atlas_private_key, atlas,
_cogl_atlas_texture_atlas_destroyed_cb);
g_object_set_qdata_full (G_OBJECT (atlas),
atlas_private_key,
atlas,
_cogl_atlas_texture_atlas_destroyed_cb);
return atlas;
}
@ -269,7 +272,7 @@ _cogl_atlas_texture_remove_from_atlas (CoglAtlasTexture *atlas_tex)
_cogl_atlas_remove (atlas_tex->atlas,
&atlas_tex->rectangle);
cogl_object_unref (atlas_tex->atlas);
g_object_unref (atlas_tex->atlas);
atlas_tex->atlas = NULL;
}
}
@ -729,7 +732,7 @@ allocate_space (CoglAtlasTexture *atlas_tex,
/* We need to take a reference on the atlas before trying to
* reserve space because in some circumstances atlas migration
* can cause the atlas to be freed */
atlas = cogl_object_ref (l->data);
atlas = g_object_ref (l->data);
/* Try to make some space in the atlas for the texture */
if (_cogl_atlas_reserve_space (atlas,
/* Add two pixels for the border */
@ -741,7 +744,7 @@ allocate_space (CoglAtlasTexture *atlas_tex,
}
else
{
cogl_object_unref (atlas);
g_object_unref (atlas);
}
}
@ -756,7 +759,7 @@ allocate_space (CoglAtlasTexture *atlas_tex,
atlas_tex))
{
/* Ok, this means we really can't add it to the atlas */
cogl_object_unref (atlas);
g_object_unref (atlas);
g_set_error_literal (error,
COGL_SYSTEM_ERROR,

View file

@ -45,31 +45,13 @@
#include <stdlib.h>
static void _cogl_atlas_free (CoglAtlas *atlas);
COGL_OBJECT_INTERNAL_DEFINE (Atlas, atlas);
CoglAtlas *
_cogl_atlas_new (CoglPixelFormat texture_format,
CoglAtlasFlags flags,
CoglAtlasUpdatePositionCallback update_position_cb)
{
CoglAtlas *atlas = g_new (CoglAtlas, 1);
atlas->update_position_cb = update_position_cb;
atlas->map = NULL;
atlas->texture = NULL;
atlas->flags = flags;
atlas->texture_format = texture_format;
g_hook_list_init (&atlas->pre_reorganize_callbacks, sizeof (GHook));
g_hook_list_init (&atlas->post_reorganize_callbacks, sizeof (GHook));
return _cogl_atlas_object_new (atlas);
}
G_DEFINE_TYPE (CoglAtlas, cogl_atlas, G_TYPE_OBJECT);
static void
_cogl_atlas_free (CoglAtlas *atlas)
cogl_atlas_dispose (GObject *object)
{
CoglAtlas *atlas = COGL_ATLAS (object);
COGL_NOTE (ATLAS, "%p: Atlas destroyed", atlas);
if (atlas->texture)
@ -80,7 +62,38 @@ _cogl_atlas_free (CoglAtlas *atlas)
g_hook_list_clear (&atlas->pre_reorganize_callbacks);
g_hook_list_clear (&atlas->post_reorganize_callbacks);
g_free (atlas);
G_OBJECT_CLASS (cogl_atlas_parent_class)->dispose (object);
}
static void
cogl_atlas_init (CoglAtlas *atlas)
{
}
static void
cogl_atlas_class_init (CoglAtlasClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->dispose = cogl_atlas_dispose;
}
CoglAtlas *
_cogl_atlas_new (CoglPixelFormat texture_format,
CoglAtlasFlags flags,
CoglAtlasUpdatePositionCallback update_position_cb)
{
CoglAtlas *atlas = g_object_new (COGL_TYPE_ATLAS, NULL);
atlas->update_position_cb = update_position_cb;
atlas->map = NULL;
atlas->texture = NULL;
atlas->flags = flags;
atlas->texture_format = texture_format;
g_hook_list_init (&atlas->pre_reorganize_callbacks, sizeof (GHook));
g_hook_list_init (&atlas->post_reorganize_callbacks, sizeof (GHook));
return atlas;
}
typedef struct _CoglAtlasRepositionData

View file

@ -29,7 +29,6 @@
#pragma once
#include "cogl/cogl-rectangle-map.h"
#include "cogl/cogl-object-private.h"
#include "cogl/cogl-texture.h"
typedef void
@ -45,11 +44,18 @@ typedef enum
typedef struct _CoglAtlas CoglAtlas;
#define COGL_ATLAS(object) ((CoglAtlas *) object)
#define COGL_TYPE_ATLAS (cogl_atlas_get_type ())
COGL_EXPORT
G_DECLARE_FINAL_TYPE (CoglAtlas,
cogl_atlas,
COGL,
ATLAS,
GObject)
struct _CoglAtlas
{
CoglObject _parent;
GObject parent_instance;
CoglRectangleMap *map;
@ -97,6 +103,3 @@ _cogl_atlas_remove_reorganize_callback (CoglAtlas *atlas,
GHookFunc pre_callback,
GHookFunc post_callback,
void *user_data);
gboolean
_cogl_is_atlas (void *object);