[cogl/wip/cogl-1.14: 99/177] atlas-texture: remove some use of _COGL_GET_CONTEXT



commit 62a854976f7b3e17fb0eb4490c052b7f0ecbbd91
Author: Robert Bragg <robert linux intel com>
Date:   Fri Nov 9 10:54:32 2012 +0000

    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)

 cogl-pango/cogl-pango-glyph-cache.c |   22 ++++-
 cogl-pango/cogl-pango-glyph-cache.h |    3 +-
 cogl-pango/cogl-pango-render.c      |    6 +-
 cogl/cogl-atlas-texture-private.h   |   13 ++-
 cogl/cogl-atlas-texture.c           |  154 +++++++++++++++++------------------
 5 files changed, 105 insertions(+), 93 deletions(-)
---
diff --git a/cogl-pango/cogl-pango-glyph-cache.c b/cogl-pango/cogl-pango-glyph-cache.c
index a46bfd9..14c8295 100644
--- a/cogl-pango/cogl-pango-glyph-cache.c
+++ b/cogl-pango/cogl-pango-glyph-cache.c
@@ -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;
     }
 
diff --git a/cogl-pango/cogl-pango-glyph-cache.h b/cogl-pango/cogl-pango-glyph-cache.h
index 5ab0572..fc25a71 100644
--- a/cogl-pango/cogl-pango-glyph-cache.h
+++ b/cogl-pango/cogl-pango-glyph-cache.h
@@ -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);
diff --git a/cogl-pango/cogl-pango-render.c b/cogl-pango/cogl-pango-render.c
index 6c63ee6..a5abaa6 100644
--- a/cogl-pango/cogl-pango-render.c
+++ b/cogl-pango/cogl-pango-render.c
@@ -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);
 
diff --git a/cogl/cogl-atlas-texture-private.h b/cogl/cogl-atlas-texture-private.h
index 7a70f54..52fdf06 100644
--- a/cogl/cogl-atlas-texture-private.h
+++ b/cogl/cogl-atlas-texture-private.h
@@ -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);
+                                   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
diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c
index 20cb6e2..a7098b6 100644
--- a/cogl/cogl-atlas-texture.c
+++ b/cogl/cogl-atlas-texture.c
@@ -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,17 +193,13 @@ _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,
-                           0,
-                           _cogl_atlas_texture_update_position_cb);
+  CoglAtlas *atlas = _cogl_atlas_new (COGL_PIXEL_FORMAT_RGBA_8888,
+                                      0,
+                                      _cogl_atlas_texture_update_position_cb);
 
   _cogl_atlas_add_reorganize_callback (atlas,
                                        _cogl_atlas_texture_pre_reorganize_cb,
@@ -364,55 +360,58 @@ _cogl_atlas_texture_gl_flush_legacy_texobj_filters (CoglTexture *tex,
 static void
 _cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
 {
+  CoglTexture *standalone_tex;
+  CoglContext *ctx;
+
   /* Make sure this texture is not in the atlas */
-  if (atlas_tex->atlas)
-    {
-      CoglTexture *standalone_tex;
-
-      COGL_NOTE (ATLAS, "Migrating texture out of the atlas");
-
-      /* We don't know if any journal entries currently depend on
-       * 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 =
-        _cogl_atlas_copy_rectangle (atlas_tex->atlas,
-                                    atlas_tex->rectangle.x + 1,
-                                    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;
-
-      /* Notify cogl-pipeline.c that the texture's underlying GL texture
-       * storage is changing so it knows it may need to bind a new texture
-       * if the CoglTexture is reused with the same texture unit. */
-      _cogl_pipeline_texture_storage_change_notify (COGL_TEXTURE (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);
-    }
+  if (!atlas_tex->atlas)
+    return;
+
+  ctx = COGL_TEXTURE (atlas_tex)->context;
+
+  COGL_NOTE (ATLAS, "Migrating texture out of the atlas");
+
+  /* We don't know if any journal entries currently depend on
+   * 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 =
+    _cogl_atlas_copy_rectangle (atlas_tex->atlas,
+                                atlas_tex->rectangle.x + 1,
+                                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;
+
+  /* Notify cogl-pipeline.c that the texture's underlying GL texture
+   * storage is changing so it knows it may need to bind a new texture
+   * if the CoglTexture is reused with the same texture unit. */
+  _cogl_pipeline_texture_storage_change_notify (COGL_TEXTURE (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
@@ -660,16 +659,15 @@ _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)
 {
   CoglAtlasTexture *atlas_tex;
-  CoglAtlas        *atlas;
-  GSList           *l;
-
-  _COGL_GET_CONTEXT (ctx, NULL);
+  CoglAtlas *atlas;
+  GSList *l;
 
   /* Don't put textures in the atlas if the user has explicitly
      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 (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,31 +816,25 @@ _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,
-                                FALSE,
-                                callback,
-                                user_data);
+  GHook *hook = g_hook_find_func_data (&ctx->atlas_reorganize_callbacks,
+                                       FALSE,
+                                       callback,
+                                       user_data);
 
   if (hook)
     g_hook_destroy_link (&ctx->atlas_reorganize_callbacks, hook);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]