atlas-texture: remove some use of _COGL_GET_CONTEXT

This removes several uses of _COGL_GET_CONTEXT in cogl-atlas-texture.c.
Notably this involved making CoglPangoGlyphCache track an associated
CoglContext pointer which cogl-pango can pass to
_cogl_atlas_texture_new_with_size().

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit d66afbd0758539330490945c699a05c0749c76aa)
This commit is contained in:
Robert Bragg 2012-11-09 10:54:32 +00:00
parent 579db9083d
commit fa5a9c88fe
5 changed files with 99 additions and 87 deletions

View File

@ -36,6 +36,8 @@ typedef struct _CoglPangoGlyphCacheKey CoglPangoGlyphCacheKey;
struct _CoglPangoGlyphCache
{
CoglContext *ctx;
/* Hash table to quickly check whether a particular glyph in a
particular font is already cached */
GHashTable *hash_table;
@ -111,12 +113,17 @@ cogl_pango_glyph_cache_equal_func (const void *a, const void *b)
}
CoglPangoGlyphCache *
cogl_pango_glyph_cache_new (CoglBool use_mipmapping)
cogl_pango_glyph_cache_new (CoglContext *ctx,
CoglBool use_mipmapping)
{
CoglPangoGlyphCache *cache;
cache = g_malloc (sizeof (CoglPangoGlyphCache));
/* Note: as a rule we don't take references to a CoglContext
* internally since */
cache->ctx = ctx;
cache->hash_table = g_hash_table_new_full
(cogl_pango_glyph_cache_hash_func,
cogl_pango_glyph_cache_equal_func,
@ -158,8 +165,11 @@ void
cogl_pango_glyph_cache_free (CoglPangoGlyphCache *cache)
{
if (cache->using_global_atlas)
_cogl_atlas_texture_remove_reorganize_callback
(cogl_pango_glyph_cache_reorganize_cb, cache);
{
_cogl_atlas_texture_remove_reorganize_callback (
cache->ctx,
cogl_pango_glyph_cache_reorganize_cb, cache);
}
cogl_pango_glyph_cache_clear (cache);
@ -213,7 +223,8 @@ cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache,
if (cache->use_mipmapping)
return FALSE;
texture = _cogl_atlas_texture_new_with_size (value->draw_width,
texture = _cogl_atlas_texture_new_with_size (cache->ctx,
value->draw_width,
value->draw_height,
COGL_TEXTURE_NONE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
@ -236,7 +247,8 @@ cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache,
if (!cache->using_global_atlas)
{
_cogl_atlas_texture_add_reorganize_callback
(cogl_pango_glyph_cache_reorganize_cb, cache);
(cache->ctx,
cogl_pango_glyph_cache_reorganize_cb, cache);
cache->using_global_atlas = TRUE;
}

View File

@ -60,7 +60,8 @@ typedef void (* CoglPangoGlyphCacheDirtyFunc) (PangoFont *font,
CoglPangoGlyphCacheValue *value);
CoglPangoGlyphCache *
cogl_pango_glyph_cache_new (CoglBool use_mipmapping);
cogl_pango_glyph_cache_new (CoglContext *ctx,
CoglBool use_mipmapping);
void
cogl_pango_glyph_cache_free (CoglPangoGlyphCache *cache);

View File

@ -214,8 +214,10 @@ _cogl_pango_renderer_constructed (GObject *gobject)
renderer->mipmap_caches.pipeline_cache =
_cogl_pango_pipeline_cache_new (ctx, TRUE);
renderer->no_mipmap_caches.glyph_cache = cogl_pango_glyph_cache_new (FALSE);
renderer->mipmap_caches.glyph_cache = cogl_pango_glyph_cache_new (TRUE);
renderer->no_mipmap_caches.glyph_cache =
cogl_pango_glyph_cache_new (ctx, FALSE);
renderer->mipmap_caches.glyph_cache =
cogl_pango_glyph_cache_new (ctx, TRUE);
_cogl_pango_renderer_set_use_mipmapping (renderer, FALSE);

View File

@ -64,17 +64,20 @@ _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
CoglError **error);
CoglAtlasTexture *
_cogl_atlas_texture_new_with_size (unsigned int width,
unsigned int height,
_cogl_atlas_texture_new_with_size (CoglContext *ctx,
int width,
int height,
CoglTextureFlags flags,
CoglPixelFormat internal_format);
void
_cogl_atlas_texture_add_reorganize_callback (GHookFunc callback,
_cogl_atlas_texture_add_reorganize_callback (CoglContext *ctx,
GHookFunc callback,
void *user_data);
void
_cogl_atlas_texture_remove_reorganize_callback (GHookFunc callback,
_cogl_atlas_texture_remove_reorganize_callback (CoglContext *ctx,
GHookFunc callback,
void *user_data);
CoglBool

View File

@ -59,9 +59,9 @@ static CoglSubTexture *
_cogl_atlas_texture_create_sub_texture (CoglTexture *full_texture,
const CoglRectangleMapEntry *rectangle)
{
CoglContext *ctx = full_texture->context;
/* Create a subtexture for the given rectangle not including the
1-pixel border */
_COGL_GET_CONTEXT (ctx, NULL);
return cogl_sub_texture_new (ctx,
full_texture,
rectangle->x + 1,
@ -193,15 +193,11 @@ _cogl_atlas_texture_atlas_destroyed_cb (void *user_data)
}
static CoglAtlas *
_cogl_atlas_texture_create_atlas (void)
_cogl_atlas_texture_create_atlas (CoglContext *ctx)
{
static CoglUserDataKey atlas_private_key;
CoglAtlas *atlas;
_COGL_GET_CONTEXT (ctx, NULL);
atlas = _cogl_atlas_new (COGL_PIXEL_FORMAT_RGBA_8888,
CoglAtlas *atlas = _cogl_atlas_new (COGL_PIXEL_FORMAT_RGBA_8888,
0,
_cogl_atlas_texture_update_position_cb);
@ -363,11 +359,15 @@ _cogl_atlas_texture_gl_flush_legacy_texobj_filters (CoglTexture *tex,
static void
_cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
{
/* Make sure this texture is not in the atlas */
if (atlas_tex->atlas)
{
CoglTexture *standalone_tex;
CoglContext *ctx;
/* Make sure this texture is not in the atlas */
if (!atlas_tex->atlas)
return;
ctx = COGL_TEXTURE (atlas_tex)->context;
COGL_NOTE (ATLAS, "Migrating texture out of the atlas");
@ -413,7 +413,6 @@ _cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
_cogl_atlas_texture_remove_from_atlas (atlas_tex);
}
}
static void
_cogl_atlas_texture_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
@ -660,8 +659,9 @@ _cogl_atlas_texture_can_use_format (CoglPixelFormat format)
}
CoglAtlasTexture *
_cogl_atlas_texture_new_with_size (unsigned int width,
unsigned int height,
_cogl_atlas_texture_new_with_size (CoglContext *ctx,
int width,
int height,
CoglTextureFlags flags,
CoglPixelFormat internal_format)
{
@ -669,8 +669,6 @@ _cogl_atlas_texture_new_with_size (unsigned int width,
CoglAtlas *atlas;
GSList *l;
_COGL_GET_CONTEXT (ctx, NULL);
/* Don't put textures in the atlas if the user has explicitly
requested to disable it */
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_ATLAS)))
@ -731,7 +729,7 @@ _cogl_atlas_texture_new_with_size (unsigned int width,
/* If we couldn't find a suitable atlas then start another */
if (l == NULL)
{
atlas = _cogl_atlas_texture_create_atlas ();
atlas = _cogl_atlas_texture_create_atlas (ctx);
COGL_NOTE (ATLAS, "Created new atlas for textures: %p", atlas);
if (!_cogl_atlas_reserve_space (atlas,
/* Add two pixels for the border */
@ -757,6 +755,7 @@ _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
CoglPixelFormat internal_format,
CoglError **error)
{
CoglContext *ctx = _cogl_bitmap_get_context (bmp);
CoglAtlasTexture *atlas_tex;
CoglBitmap *dst_bmp;
int bmp_width;
@ -772,7 +771,8 @@ _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
internal_format = _cogl_texture_determine_internal_format (bmp_format,
internal_format);
atlas_tex = _cogl_atlas_texture_new_with_size (bmp_width, bmp_height,
atlas_tex = _cogl_atlas_texture_new_with_size (ctx,
bmp_width, bmp_height,
flags, internal_format);
if (atlas_tex == NULL)
@ -816,28 +816,22 @@ _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
}
void
_cogl_atlas_texture_add_reorganize_callback (GHookFunc callback,
_cogl_atlas_texture_add_reorganize_callback (CoglContext *ctx,
GHookFunc callback,
void *user_data)
{
GHook *hook;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
hook = g_hook_alloc (&ctx->atlas_reorganize_callbacks);
GHook *hook = g_hook_alloc (&ctx->atlas_reorganize_callbacks);
hook->func = callback;
hook->data = user_data;
g_hook_prepend (&ctx->atlas_reorganize_callbacks, hook);
}
void
_cogl_atlas_texture_remove_reorganize_callback (GHookFunc callback,
_cogl_atlas_texture_remove_reorganize_callback (CoglContext *ctx,
GHookFunc callback,
void *user_data)
{
GHook *hook;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
hook = g_hook_find_func_data (&ctx->atlas_reorganize_callbacks,
GHook *hook = g_hook_find_func_data (&ctx->atlas_reorganize_callbacks,
FALSE,
callback,
user_data);