mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 19:42:05 +00:00
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:
parent
579db9083d
commit
fa5a9c88fe
@ -36,6 +36,8 @@ typedef struct _CoglPangoGlyphCacheKey CoglPangoGlyphCacheKey;
|
|||||||
|
|
||||||
struct _CoglPangoGlyphCache
|
struct _CoglPangoGlyphCache
|
||||||
{
|
{
|
||||||
|
CoglContext *ctx;
|
||||||
|
|
||||||
/* Hash table to quickly check whether a particular glyph in a
|
/* Hash table to quickly check whether a particular glyph in a
|
||||||
particular font is already cached */
|
particular font is already cached */
|
||||||
GHashTable *hash_table;
|
GHashTable *hash_table;
|
||||||
@ -111,12 +113,17 @@ cogl_pango_glyph_cache_equal_func (const void *a, const void *b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CoglPangoGlyphCache *
|
CoglPangoGlyphCache *
|
||||||
cogl_pango_glyph_cache_new (CoglBool use_mipmapping)
|
cogl_pango_glyph_cache_new (CoglContext *ctx,
|
||||||
|
CoglBool use_mipmapping)
|
||||||
{
|
{
|
||||||
CoglPangoGlyphCache *cache;
|
CoglPangoGlyphCache *cache;
|
||||||
|
|
||||||
cache = g_malloc (sizeof (CoglPangoGlyphCache));
|
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
|
cache->hash_table = g_hash_table_new_full
|
||||||
(cogl_pango_glyph_cache_hash_func,
|
(cogl_pango_glyph_cache_hash_func,
|
||||||
cogl_pango_glyph_cache_equal_func,
|
cogl_pango_glyph_cache_equal_func,
|
||||||
@ -158,8 +165,11 @@ void
|
|||||||
cogl_pango_glyph_cache_free (CoglPangoGlyphCache *cache)
|
cogl_pango_glyph_cache_free (CoglPangoGlyphCache *cache)
|
||||||
{
|
{
|
||||||
if (cache->using_global_atlas)
|
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);
|
cogl_pango_glyph_cache_clear (cache);
|
||||||
|
|
||||||
@ -213,7 +223,8 @@ cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache,
|
|||||||
if (cache->use_mipmapping)
|
if (cache->use_mipmapping)
|
||||||
return FALSE;
|
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,
|
value->draw_height,
|
||||||
COGL_TEXTURE_NONE,
|
COGL_TEXTURE_NONE,
|
||||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
|
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)
|
if (!cache->using_global_atlas)
|
||||||
{
|
{
|
||||||
_cogl_atlas_texture_add_reorganize_callback
|
_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;
|
cache->using_global_atlas = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,8 @@ typedef void (* CoglPangoGlyphCacheDirtyFunc) (PangoFont *font,
|
|||||||
CoglPangoGlyphCacheValue *value);
|
CoglPangoGlyphCacheValue *value);
|
||||||
|
|
||||||
CoglPangoGlyphCache *
|
CoglPangoGlyphCache *
|
||||||
cogl_pango_glyph_cache_new (CoglBool use_mipmapping);
|
cogl_pango_glyph_cache_new (CoglContext *ctx,
|
||||||
|
CoglBool use_mipmapping);
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_pango_glyph_cache_free (CoglPangoGlyphCache *cache);
|
cogl_pango_glyph_cache_free (CoglPangoGlyphCache *cache);
|
||||||
|
@ -214,8 +214,10 @@ _cogl_pango_renderer_constructed (GObject *gobject)
|
|||||||
renderer->mipmap_caches.pipeline_cache =
|
renderer->mipmap_caches.pipeline_cache =
|
||||||
_cogl_pango_pipeline_cache_new (ctx, TRUE);
|
_cogl_pango_pipeline_cache_new (ctx, TRUE);
|
||||||
|
|
||||||
renderer->no_mipmap_caches.glyph_cache = cogl_pango_glyph_cache_new (FALSE);
|
renderer->no_mipmap_caches.glyph_cache =
|
||||||
renderer->mipmap_caches.glyph_cache = cogl_pango_glyph_cache_new (TRUE);
|
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);
|
_cogl_pango_renderer_set_use_mipmapping (renderer, FALSE);
|
||||||
|
|
||||||
|
@ -64,17 +64,20 @@ _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
|
|||||||
CoglError **error);
|
CoglError **error);
|
||||||
|
|
||||||
CoglAtlasTexture *
|
CoglAtlasTexture *
|
||||||
_cogl_atlas_texture_new_with_size (unsigned int width,
|
_cogl_atlas_texture_new_with_size (CoglContext *ctx,
|
||||||
unsigned int height,
|
int width,
|
||||||
|
int height,
|
||||||
CoglTextureFlags flags,
|
CoglTextureFlags flags,
|
||||||
CoglPixelFormat internal_format);
|
CoglPixelFormat internal_format);
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_atlas_texture_add_reorganize_callback (GHookFunc callback,
|
_cogl_atlas_texture_add_reorganize_callback (CoglContext *ctx,
|
||||||
|
GHookFunc callback,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_atlas_texture_remove_reorganize_callback (GHookFunc callback,
|
_cogl_atlas_texture_remove_reorganize_callback (CoglContext *ctx,
|
||||||
|
GHookFunc callback,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
CoglBool
|
CoglBool
|
||||||
|
@ -59,9 +59,9 @@ static CoglSubTexture *
|
|||||||
_cogl_atlas_texture_create_sub_texture (CoglTexture *full_texture,
|
_cogl_atlas_texture_create_sub_texture (CoglTexture *full_texture,
|
||||||
const CoglRectangleMapEntry *rectangle)
|
const CoglRectangleMapEntry *rectangle)
|
||||||
{
|
{
|
||||||
|
CoglContext *ctx = full_texture->context;
|
||||||
/* Create a subtexture for the given rectangle not including the
|
/* Create a subtexture for the given rectangle not including the
|
||||||
1-pixel border */
|
1-pixel border */
|
||||||
_COGL_GET_CONTEXT (ctx, NULL);
|
|
||||||
return cogl_sub_texture_new (ctx,
|
return cogl_sub_texture_new (ctx,
|
||||||
full_texture,
|
full_texture,
|
||||||
rectangle->x + 1,
|
rectangle->x + 1,
|
||||||
@ -193,15 +193,11 @@ _cogl_atlas_texture_atlas_destroyed_cb (void *user_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CoglAtlas *
|
static CoglAtlas *
|
||||||
_cogl_atlas_texture_create_atlas (void)
|
_cogl_atlas_texture_create_atlas (CoglContext *ctx)
|
||||||
{
|
{
|
||||||
static CoglUserDataKey atlas_private_key;
|
static CoglUserDataKey atlas_private_key;
|
||||||
|
|
||||||
CoglAtlas *atlas;
|
CoglAtlas *atlas = _cogl_atlas_new (COGL_PIXEL_FORMAT_RGBA_8888,
|
||||||
|
|
||||||
_COGL_GET_CONTEXT (ctx, NULL);
|
|
||||||
|
|
||||||
atlas = _cogl_atlas_new (COGL_PIXEL_FORMAT_RGBA_8888,
|
|
||||||
0,
|
0,
|
||||||
_cogl_atlas_texture_update_position_cb);
|
_cogl_atlas_texture_update_position_cb);
|
||||||
|
|
||||||
@ -363,11 +359,15 @@ _cogl_atlas_texture_gl_flush_legacy_texobj_filters (CoglTexture *tex,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
_cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
|
_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;
|
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");
|
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);
|
_cogl_atlas_texture_remove_from_atlas (atlas_tex);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_cogl_atlas_texture_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
_cogl_atlas_texture_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
|
||||||
@ -660,8 +659,9 @@ _cogl_atlas_texture_can_use_format (CoglPixelFormat format)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CoglAtlasTexture *
|
CoglAtlasTexture *
|
||||||
_cogl_atlas_texture_new_with_size (unsigned int width,
|
_cogl_atlas_texture_new_with_size (CoglContext *ctx,
|
||||||
unsigned int height,
|
int width,
|
||||||
|
int height,
|
||||||
CoglTextureFlags flags,
|
CoglTextureFlags flags,
|
||||||
CoglPixelFormat internal_format)
|
CoglPixelFormat internal_format)
|
||||||
{
|
{
|
||||||
@ -669,8 +669,6 @@ _cogl_atlas_texture_new_with_size (unsigned int width,
|
|||||||
CoglAtlas *atlas;
|
CoglAtlas *atlas;
|
||||||
GSList *l;
|
GSList *l;
|
||||||
|
|
||||||
_COGL_GET_CONTEXT (ctx, NULL);
|
|
||||||
|
|
||||||
/* Don't put textures in the atlas if the user has explicitly
|
/* Don't put textures in the atlas if the user has explicitly
|
||||||
requested to disable it */
|
requested to disable it */
|
||||||
if (G_UNLIKELY (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_ATLAS)))
|
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 we couldn't find a suitable atlas then start another */
|
||||||
if (l == NULL)
|
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);
|
COGL_NOTE (ATLAS, "Created new atlas for textures: %p", atlas);
|
||||||
if (!_cogl_atlas_reserve_space (atlas,
|
if (!_cogl_atlas_reserve_space (atlas,
|
||||||
/* Add two pixels for the border */
|
/* Add two pixels for the border */
|
||||||
@ -757,6 +755,7 @@ _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
|
|||||||
CoglPixelFormat internal_format,
|
CoglPixelFormat internal_format,
|
||||||
CoglError **error)
|
CoglError **error)
|
||||||
{
|
{
|
||||||
|
CoglContext *ctx = _cogl_bitmap_get_context (bmp);
|
||||||
CoglAtlasTexture *atlas_tex;
|
CoglAtlasTexture *atlas_tex;
|
||||||
CoglBitmap *dst_bmp;
|
CoglBitmap *dst_bmp;
|
||||||
int bmp_width;
|
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 = _cogl_texture_determine_internal_format (bmp_format,
|
||||||
internal_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);
|
flags, internal_format);
|
||||||
|
|
||||||
if (atlas_tex == NULL)
|
if (atlas_tex == NULL)
|
||||||
@ -816,28 +816,22 @@ _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_atlas_texture_add_reorganize_callback (GHookFunc callback,
|
_cogl_atlas_texture_add_reorganize_callback (CoglContext *ctx,
|
||||||
|
GHookFunc callback,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
GHook *hook;
|
GHook *hook = g_hook_alloc (&ctx->atlas_reorganize_callbacks);
|
||||||
|
|
||||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
||||||
|
|
||||||
hook = g_hook_alloc (&ctx->atlas_reorganize_callbacks);
|
|
||||||
hook->func = callback;
|
hook->func = callback;
|
||||||
hook->data = user_data;
|
hook->data = user_data;
|
||||||
g_hook_prepend (&ctx->atlas_reorganize_callbacks, hook);
|
g_hook_prepend (&ctx->atlas_reorganize_callbacks, hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_atlas_texture_remove_reorganize_callback (GHookFunc callback,
|
_cogl_atlas_texture_remove_reorganize_callback (CoglContext *ctx,
|
||||||
|
GHookFunc callback,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
GHook *hook;
|
GHook *hook = g_hook_find_func_data (&ctx->atlas_reorganize_callbacks,
|
||||||
|
|
||||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
||||||
|
|
||||||
hook = g_hook_find_func_data (&ctx->atlas_reorganize_callbacks,
|
|
||||||
FALSE,
|
FALSE,
|
||||||
callback,
|
callback,
|
||||||
user_data);
|
user_data);
|
||||||
|
Loading…
Reference in New Issue
Block a user