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,17 +193,13 @@ _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,
|
||||||
|
0,
|
||||||
_COGL_GET_CONTEXT (ctx, NULL);
|
_cogl_atlas_texture_update_position_cb);
|
||||||
|
|
||||||
atlas = _cogl_atlas_new (COGL_PIXEL_FORMAT_RGBA_8888,
|
|
||||||
0,
|
|
||||||
_cogl_atlas_texture_update_position_cb);
|
|
||||||
|
|
||||||
_cogl_atlas_add_reorganize_callback (atlas,
|
_cogl_atlas_add_reorganize_callback (atlas,
|
||||||
_cogl_atlas_texture_pre_reorganize_cb,
|
_cogl_atlas_texture_pre_reorganize_cb,
|
||||||
@ -364,55 +360,58 @@ _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)
|
||||||
{
|
{
|
||||||
|
CoglTexture *standalone_tex;
|
||||||
|
CoglContext *ctx;
|
||||||
|
|
||||||
/* Make sure this texture is not in the atlas */
|
/* Make sure this texture is not in the atlas */
|
||||||
if (atlas_tex->atlas)
|
if (!atlas_tex->atlas)
|
||||||
{
|
return;
|
||||||
CoglTexture *standalone_tex;
|
|
||||||
|
|
||||||
COGL_NOTE (ATLAS, "Migrating texture out of the atlas");
|
ctx = COGL_TEXTURE (atlas_tex)->context;
|
||||||
|
|
||||||
/* We don't know if any journal entries currently depend on
|
COGL_NOTE (ATLAS, "Migrating texture out of the atlas");
|
||||||
* OpenGL texture coordinates that would be invalidated by
|
|
||||||
* migrating textures in this atlas so we flush all journals
|
|
||||||
* before migrating.
|
|
||||||
*
|
|
||||||
* We are assuming that texture atlas migration never happens
|
|
||||||
* during a flush so we don't have to consider recursion here.
|
|
||||||
*/
|
|
||||||
cogl_flush ();
|
|
||||||
|
|
||||||
standalone_tex =
|
/* We don't know if any journal entries currently depend on
|
||||||
_cogl_atlas_copy_rectangle (atlas_tex->atlas,
|
* OpenGL texture coordinates that would be invalidated by
|
||||||
atlas_tex->rectangle.x + 1,
|
* migrating textures in this atlas so we flush all journals
|
||||||
atlas_tex->rectangle.y + 1,
|
* before migrating.
|
||||||
atlas_tex->rectangle.width - 2,
|
*
|
||||||
atlas_tex->rectangle.height - 2,
|
* We are assuming that texture atlas migration never happens
|
||||||
COGL_TEXTURE_NO_ATLAS,
|
* during a flush so we don't have to consider recursion here.
|
||||||
atlas_tex->format);
|
*/
|
||||||
/* Note: we simply silently ignore failures to migrate a texture
|
cogl_flush ();
|
||||||
* out (most likely due to lack of memory) and hope for the
|
|
||||||
* best.
|
|
||||||
*
|
|
||||||
* Maybe we should find a way to report the problem back to the
|
|
||||||
* app.
|
|
||||||
*/
|
|
||||||
if (!standalone_tex)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Notify cogl-pipeline.c that the texture's underlying GL texture
|
standalone_tex =
|
||||||
* storage is changing so it knows it may need to bind a new texture
|
_cogl_atlas_copy_rectangle (atlas_tex->atlas,
|
||||||
* if the CoglTexture is reused with the same texture unit. */
|
atlas_tex->rectangle.x + 1,
|
||||||
_cogl_pipeline_texture_storage_change_notify (COGL_TEXTURE (atlas_tex));
|
atlas_tex->rectangle.y + 1,
|
||||||
|
atlas_tex->rectangle.width - 2,
|
||||||
|
atlas_tex->rectangle.height - 2,
|
||||||
|
COGL_TEXTURE_NO_ATLAS,
|
||||||
|
atlas_tex->format);
|
||||||
|
/* Note: we simply silently ignore failures to migrate a texture
|
||||||
|
* out (most likely due to lack of memory) and hope for the
|
||||||
|
* best.
|
||||||
|
*
|
||||||
|
* Maybe we should find a way to report the problem back to the
|
||||||
|
* app.
|
||||||
|
*/
|
||||||
|
if (!standalone_tex)
|
||||||
|
return;
|
||||||
|
|
||||||
/* We need to unref the sub texture after doing the copy because
|
/* Notify cogl-pipeline.c that the texture's underlying GL texture
|
||||||
the copy can involve rendering which might cause the texture
|
* storage is changing so it knows it may need to bind a new texture
|
||||||
to be used if it is used from a layer that is left in a
|
* if the CoglTexture is reused with the same texture unit. */
|
||||||
texture unit */
|
_cogl_pipeline_texture_storage_change_notify (COGL_TEXTURE (atlas_tex));
|
||||||
cogl_object_unref (atlas_tex->sub_texture);
|
|
||||||
atlas_tex->sub_texture = standalone_tex;
|
|
||||||
|
|
||||||
_cogl_atlas_texture_remove_from_atlas (atlas_tex);
|
/* We need to unref the sub texture after doing the copy because
|
||||||
}
|
the copy can involve rendering which might cause the texture
|
||||||
|
to be used if it is used from a layer that is left in a
|
||||||
|
texture unit */
|
||||||
|
cogl_object_unref (atlas_tex->sub_texture);
|
||||||
|
atlas_tex->sub_texture = standalone_tex;
|
||||||
|
|
||||||
|
_cogl_atlas_texture_remove_from_atlas (atlas_tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -660,16 +659,15 @@ _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)
|
||||||
{
|
{
|
||||||
CoglAtlasTexture *atlas_tex;
|
CoglAtlasTexture *atlas_tex;
|
||||||
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 */
|
||||||
@ -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,31 +816,25 @@ _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,
|
||||||
|
FALSE,
|
||||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
callback,
|
||||||
|
user_data);
|
||||||
hook = g_hook_find_func_data (&ctx->atlas_reorganize_callbacks,
|
|
||||||
FALSE,
|
|
||||||
callback,
|
|
||||||
user_data);
|
|
||||||
|
|
||||||
if (hook)
|
if (hook)
|
||||||
g_hook_destroy_link (&ctx->atlas_reorganize_callbacks, hook);
|
g_hook_destroy_link (&ctx->atlas_reorganize_callbacks, hook);
|
||||||
|
Loading…
Reference in New Issue
Block a user