2009-07-29 16:21:07 +00:00
|
|
|
/*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Cogl
|
2009-07-29 16:21:07 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2009-07-29 16:21:07 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008 OpenedHand
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2009-07-29 16:21:07 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2009-07-29 16:21:07 +00:00
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2009-07-29 16:21:07 +00:00
|
|
|
*/
|
|
|
|
|
2016-05-05 14:21:51 +00:00
|
|
|
#include "cogl-config.h"
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "cogl-pango-glyph-cache.h"
|
|
|
|
#include "cogl-pango-private.h"
|
2010-08-04 17:05:21 +00:00
|
|
|
#include "cogl/cogl-atlas.h"
|
2010-02-18 17:35:14 +00:00
|
|
|
#include "cogl/cogl-atlas-texture-private.h"
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
typedef struct _CoglPangoGlyphCacheKey CoglPangoGlyphCacheKey;
|
|
|
|
|
|
|
|
struct _CoglPangoGlyphCache
|
|
|
|
{
|
2012-11-09 10:54:32 +00:00
|
|
|
CoglContext *ctx;
|
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
/* Hash table to quickly check whether a particular glyph in a
|
|
|
|
particular font is already cached */
|
2010-08-04 17:05:21 +00:00
|
|
|
GHashTable *hash_table;
|
|
|
|
|
|
|
|
/* List of CoglAtlases */
|
|
|
|
GSList *atlases;
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2010-08-04 17:05:21 +00:00
|
|
|
/* List of callbacks to invoke when an atlas is reorganized */
|
2011-03-14 17:58:31 +00:00
|
|
|
GHookList reorganize_callbacks;
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2011-03-30 11:56:09 +00:00
|
|
|
/* TRUE if we've ever stored a texture in the global atlas. This is
|
|
|
|
used to make sure we only register one callback to listen for
|
|
|
|
global atlas reorganizations */
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean using_global_atlas;
|
2011-03-30 11:56:09 +00:00
|
|
|
|
2010-08-04 17:05:21 +00:00
|
|
|
/* True if some of the glyphs are dirty. This is used as an
|
|
|
|
optimization in _cogl_pango_glyph_cache_set_dirty_glyphs to avoid
|
|
|
|
iterating the hash table if we know none of them are dirty */
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean has_dirty_glyphs;
|
2010-02-18 17:35:14 +00:00
|
|
|
|
|
|
|
/* Whether mipmapping is being used for this cache. This only
|
|
|
|
affects whether we decide to put the glyph in the global atlas */
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean use_mipmapping;
|
2009-07-29 16:21:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _CoglPangoGlyphCacheKey
|
|
|
|
{
|
|
|
|
PangoFont *font;
|
|
|
|
PangoGlyph glyph;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogl_pango_glyph_cache_value_free (CoglPangoGlyphCacheValue *value)
|
|
|
|
{
|
2010-02-22 16:40:49 +00:00
|
|
|
if (value->texture)
|
2011-08-24 20:30:34 +00:00
|
|
|
cogl_object_unref (value->texture);
|
2020-10-18 11:46:08 +00:00
|
|
|
g_free (value);
|
2009-07-29 16:21:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogl_pango_glyph_cache_key_free (CoglPangoGlyphCacheKey *key)
|
|
|
|
{
|
|
|
|
g_object_unref (key->font);
|
2020-10-18 11:46:08 +00:00
|
|
|
g_free (key);
|
2009-07-29 16:21:07 +00:00
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
static unsigned int
|
|
|
|
cogl_pango_glyph_cache_hash_func (const void *key)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
|
|
|
const CoglPangoGlyphCacheKey *cache_key
|
|
|
|
= (const CoglPangoGlyphCacheKey *) key;
|
|
|
|
|
|
|
|
/* Generate a number affected by both the font and the glyph
|
|
|
|
number. We can safely directly compare the pointers because the
|
|
|
|
key holds a reference to the font so it is not possible that a
|
|
|
|
different font will have the same memory address */
|
|
|
|
return GPOINTER_TO_UINT (cache_key->font) ^ cache_key->glyph;
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
cogl_pango_glyph_cache_equal_func (const void *a, const void *b)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
|
|
|
const CoglPangoGlyphCacheKey *key_a
|
|
|
|
= (const CoglPangoGlyphCacheKey *) a;
|
|
|
|
const CoglPangoGlyphCacheKey *key_b
|
|
|
|
= (const CoglPangoGlyphCacheKey *) b;
|
|
|
|
|
|
|
|
/* We can safely directly compare the pointers for the fonts because
|
|
|
|
the key holds a reference to the font so it is not possible that
|
|
|
|
a different font will have the same memory address */
|
|
|
|
return key_a->font == key_b->font
|
|
|
|
&& key_a->glyph == key_b->glyph;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglPangoGlyphCache *
|
2012-11-09 10:54:32 +00:00
|
|
|
cogl_pango_glyph_cache_new (CoglContext *ctx,
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean use_mipmapping)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
|
|
|
CoglPangoGlyphCache *cache;
|
|
|
|
|
|
|
|
cache = g_malloc (sizeof (CoglPangoGlyphCache));
|
|
|
|
|
2012-11-09 10:54:32 +00:00
|
|
|
/* Note: as a rule we don't take references to a CoglContext
|
|
|
|
* internally since */
|
|
|
|
cache->ctx = ctx;
|
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
cache->hash_table = g_hash_table_new_full
|
|
|
|
(cogl_pango_glyph_cache_hash_func,
|
|
|
|
cogl_pango_glyph_cache_equal_func,
|
|
|
|
(GDestroyNotify) cogl_pango_glyph_cache_key_free,
|
|
|
|
(GDestroyNotify) cogl_pango_glyph_cache_value_free);
|
|
|
|
|
2010-08-04 17:05:21 +00:00
|
|
|
cache->atlases = NULL;
|
2011-03-14 17:58:31 +00:00
|
|
|
g_hook_list_init (&cache->reorganize_callbacks, sizeof (GHook));
|
2010-08-04 17:05:21 +00:00
|
|
|
|
|
|
|
cache->has_dirty_glyphs = FALSE;
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2012-03-13 13:01:52 +00:00
|
|
|
cache->using_global_atlas = FALSE;
|
|
|
|
|
2010-02-18 17:35:14 +00:00
|
|
|
cache->use_mipmapping = use_mipmapping;
|
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
2011-03-30 11:56:09 +00:00
|
|
|
static void
|
|
|
|
cogl_pango_glyph_cache_reorganize_cb (void *user_data)
|
|
|
|
{
|
|
|
|
CoglPangoGlyphCache *cache = user_data;
|
|
|
|
|
|
|
|
g_hook_list_invoke (&cache->reorganize_callbacks, FALSE);
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
void
|
|
|
|
cogl_pango_glyph_cache_clear (CoglPangoGlyphCache *cache)
|
|
|
|
{
|
2010-11-27 13:06:38 +00:00
|
|
|
g_slist_foreach (cache->atlases, (GFunc) cogl_object_unref, NULL);
|
2010-08-04 17:05:21 +00:00
|
|
|
g_slist_free (cache->atlases);
|
|
|
|
cache->atlases = NULL;
|
|
|
|
cache->has_dirty_glyphs = FALSE;
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
g_hash_table_remove_all (cache->hash_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pango_glyph_cache_free (CoglPangoGlyphCache *cache)
|
|
|
|
{
|
2011-03-30 11:56:09 +00:00
|
|
|
if (cache->using_global_atlas)
|
2012-11-09 10:54:32 +00:00
|
|
|
{
|
|
|
|
_cogl_atlas_texture_remove_reorganize_callback (
|
|
|
|
cache->ctx,
|
|
|
|
cogl_pango_glyph_cache_reorganize_cb, cache);
|
|
|
|
}
|
2011-03-30 11:56:09 +00:00
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
cogl_pango_glyph_cache_clear (cache);
|
|
|
|
|
|
|
|
g_hash_table_unref (cache->hash_table);
|
|
|
|
|
2011-03-14 17:58:31 +00:00
|
|
|
g_hook_list_clear (&cache->reorganize_callbacks);
|
2010-08-04 17:05:21 +00:00
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
g_free (cache);
|
|
|
|
}
|
|
|
|
|
2010-08-04 17:05:21 +00:00
|
|
|
static void
|
|
|
|
cogl_pango_glyph_cache_update_position_cb (void *user_data,
|
2012-04-16 13:14:10 +00:00
|
|
|
CoglTexture *new_texture,
|
2010-08-04 17:05:21 +00:00
|
|
|
const CoglRectangleMapEntry *rect)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
2010-08-04 17:05:21 +00:00
|
|
|
CoglPangoGlyphCacheValue *value = user_data;
|
|
|
|
float tex_width, tex_height;
|
|
|
|
|
|
|
|
if (value->texture)
|
2011-08-24 20:30:34 +00:00
|
|
|
cogl_object_unref (value->texture);
|
|
|
|
value->texture = cogl_object_ref (new_texture);
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2010-08-04 17:05:21 +00:00
|
|
|
tex_width = cogl_texture_get_width (new_texture);
|
|
|
|
tex_height = cogl_texture_get_height (new_texture);
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2010-08-04 17:05:21 +00:00
|
|
|
value->tx1 = rect->x / tex_width;
|
|
|
|
value->ty1 = rect->y / tex_height;
|
|
|
|
value->tx2 = (rect->x + value->draw_width) / tex_width;
|
|
|
|
value->ty2 = (rect->y + value->draw_height) / tex_height;
|
|
|
|
|
|
|
|
value->tx_pixel = rect->x;
|
|
|
|
value->ty_pixel = rect->y;
|
|
|
|
|
|
|
|
/* The glyph has changed position so it will need to be redrawn */
|
|
|
|
value->dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2010-02-18 17:35:14 +00:00
|
|
|
cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache,
|
|
|
|
PangoFont *font,
|
|
|
|
PangoGlyph glyph,
|
|
|
|
CoglPangoGlyphCacheValue *value)
|
|
|
|
{
|
2012-04-16 13:14:10 +00:00
|
|
|
CoglAtlasTexture *texture;
|
2019-06-18 06:02:10 +00:00
|
|
|
GError *ignore_error = NULL;
|
2010-02-18 17:35:14 +00:00
|
|
|
|
2011-03-30 15:39:38 +00:00
|
|
|
if (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SHARED_ATLAS))
|
|
|
|
return FALSE;
|
|
|
|
|
2010-02-18 17:35:14 +00:00
|
|
|
/* If the cache is using mipmapping then we can't use the global
|
|
|
|
atlas because it would just get migrated back out */
|
|
|
|
if (cache->use_mipmapping)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-06-08 00:58:05 +00:00
|
|
|
texture = cogl_atlas_texture_new_with_size (cache->ctx,
|
|
|
|
value->draw_width,
|
2013-07-02 00:48:54 +00:00
|
|
|
value->draw_height);
|
|
|
|
if (!cogl_texture_allocate (COGL_TEXTURE (texture), &ignore_error))
|
2012-11-22 23:01:08 +00:00
|
|
|
{
|
2019-06-18 06:02:10 +00:00
|
|
|
g_error_free (ignore_error);
|
2012-11-22 23:01:08 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-02-18 17:35:14 +00:00
|
|
|
|
2012-04-16 13:14:10 +00:00
|
|
|
value->texture = COGL_TEXTURE (texture);
|
2010-02-18 17:35:14 +00:00
|
|
|
value->tx1 = 0;
|
|
|
|
value->ty1 = 0;
|
|
|
|
value->tx2 = 1;
|
|
|
|
value->ty2 = 1;
|
|
|
|
value->tx_pixel = 0;
|
|
|
|
value->ty_pixel = 0;
|
|
|
|
|
2011-03-30 11:56:09 +00:00
|
|
|
/* The first time we store a texture in the global atlas we'll
|
|
|
|
register for notifications when the global atlas is reorganized
|
|
|
|
so we can forward the notification on as a glyph
|
|
|
|
reorganization */
|
|
|
|
if (!cache->using_global_atlas)
|
|
|
|
{
|
|
|
|
_cogl_atlas_texture_add_reorganize_callback
|
2012-11-09 10:54:32 +00:00
|
|
|
(cache->ctx,
|
|
|
|
cogl_pango_glyph_cache_reorganize_cb, cache);
|
2011-03-30 11:56:09 +00:00
|
|
|
cache->using_global_atlas = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-02-18 17:35:14 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2010-02-18 17:35:14 +00:00
|
|
|
cogl_pango_glyph_cache_add_to_local_atlas (CoglPangoGlyphCache *cache,
|
|
|
|
PangoFont *font,
|
|
|
|
PangoGlyph glyph,
|
|
|
|
CoglPangoGlyphCacheValue *value)
|
|
|
|
{
|
|
|
|
CoglAtlas *atlas = NULL;
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
/* Look for an atlas that can reserve the space */
|
|
|
|
for (l = cache->atlases; l; l = l->next)
|
|
|
|
if (_cogl_atlas_reserve_space (l->data,
|
|
|
|
value->draw_width + 1,
|
|
|
|
value->draw_height + 1,
|
|
|
|
value))
|
|
|
|
{
|
|
|
|
atlas = l->data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we couldn't find one then start a new atlas */
|
|
|
|
if (atlas == NULL)
|
|
|
|
{
|
|
|
|
atlas = _cogl_atlas_new (COGL_PIXEL_FORMAT_A_8,
|
|
|
|
COGL_ATLAS_CLEAR_TEXTURE |
|
|
|
|
COGL_ATLAS_DISABLE_MIGRATION,
|
|
|
|
cogl_pango_glyph_cache_update_position_cb);
|
|
|
|
COGL_NOTE (ATLAS, "Created new atlas for glyphs: %p", atlas);
|
|
|
|
/* If we still can't reserve space then something has gone
|
|
|
|
seriously wrong so we'll just give up */
|
|
|
|
if (!_cogl_atlas_reserve_space (atlas,
|
|
|
|
value->draw_width + 1,
|
|
|
|
value->draw_height + 1,
|
|
|
|
value))
|
|
|
|
{
|
|
|
|
cogl_object_unref (atlas);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_cogl_atlas_add_reorganize_callback
|
|
|
|
(atlas, cogl_pango_glyph_cache_reorganize_cb, NULL, cache);
|
|
|
|
|
|
|
|
cache->atlases = g_slist_prepend (cache->atlases, atlas);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-07-29 16:21:07 +00:00
|
|
|
CoglPangoGlyphCacheValue *
|
2010-08-04 17:05:21 +00:00
|
|
|
cogl_pango_glyph_cache_lookup (CoglPangoGlyphCache *cache,
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean create,
|
2010-08-04 17:05:21 +00:00
|
|
|
PangoFont *font,
|
|
|
|
PangoGlyph glyph)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
2010-08-04 17:05:21 +00:00
|
|
|
CoglPangoGlyphCacheKey lookup_key;
|
2009-07-29 16:21:07 +00:00
|
|
|
CoglPangoGlyphCacheValue *value;
|
|
|
|
|
2010-08-04 17:05:21 +00:00
|
|
|
lookup_key.font = font;
|
|
|
|
lookup_key.glyph = glyph;
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2010-08-04 17:05:21 +00:00
|
|
|
value = g_hash_table_lookup (cache->hash_table, &lookup_key);
|
2009-07-29 16:21:07 +00:00
|
|
|
|
2010-08-04 17:05:21 +00:00
|
|
|
if (create && value == NULL)
|
2009-07-29 16:21:07 +00:00
|
|
|
{
|
2010-08-04 17:05:21 +00:00
|
|
|
CoglPangoGlyphCacheKey *key;
|
|
|
|
PangoRectangle ink_rect;
|
2010-02-18 17:35:14 +00:00
|
|
|
|
2020-10-18 11:46:08 +00:00
|
|
|
value = g_new0 (CoglPangoGlyphCacheValue, 1);
|
2011-08-24 20:30:34 +00:00
|
|
|
value->texture = NULL;
|
2010-08-04 17:05:21 +00:00
|
|
|
|
|
|
|
pango_font_get_glyph_extents (font, glyph, &ink_rect, NULL);
|
|
|
|
pango_extents_to_pixels (&ink_rect, NULL);
|
|
|
|
|
|
|
|
value->draw_x = ink_rect.x;
|
|
|
|
value->draw_y = ink_rect.y;
|
|
|
|
value->draw_width = ink_rect.width;
|
|
|
|
value->draw_height = ink_rect.height;
|
|
|
|
|
2010-02-22 16:40:49 +00:00
|
|
|
/* If the glyph is zero-sized then we don't need to reserve any
|
|
|
|
space for it and we can just avoid painting anything */
|
|
|
|
if (ink_rect.width < 1 || ink_rect.height < 1)
|
|
|
|
value->dirty = FALSE;
|
|
|
|
else
|
2010-08-04 17:05:21 +00:00
|
|
|
{
|
2010-02-22 16:40:49 +00:00
|
|
|
/* Try adding the glyph to the global atlas... */
|
|
|
|
if (!cogl_pango_glyph_cache_add_to_global_atlas (cache,
|
|
|
|
font,
|
|
|
|
glyph,
|
|
|
|
value) &&
|
|
|
|
/* If it fails try the local atlas */
|
|
|
|
!cogl_pango_glyph_cache_add_to_local_atlas (cache,
|
|
|
|
font,
|
|
|
|
glyph,
|
|
|
|
value))
|
|
|
|
{
|
|
|
|
cogl_pango_glyph_cache_value_free (value);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
value->dirty = TRUE;
|
|
|
|
cache->has_dirty_glyphs = TRUE;
|
2010-08-04 17:05:21 +00:00
|
|
|
}
|
|
|
|
|
2020-10-18 11:46:08 +00:00
|
|
|
key = g_new0 (CoglPangoGlyphCacheKey, 1);
|
2010-08-04 17:05:21 +00:00
|
|
|
key->font = g_object_ref (font);
|
|
|
|
key->glyph = glyph;
|
|
|
|
|
|
|
|
g_hash_table_insert (cache->hash_table, key, value);
|
|
|
|
}
|
2009-07-29 16:21:07 +00:00
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
2010-08-04 17:05:21 +00:00
|
|
|
|
|
|
|
static void
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
_cogl_pango_glyph_cache_set_dirty_glyphs_cb (void *key_ptr,
|
|
|
|
void *value_ptr,
|
|
|
|
void *user_data)
|
2010-08-04 17:05:21 +00:00
|
|
|
{
|
|
|
|
CoglPangoGlyphCacheKey *key = key_ptr;
|
|
|
|
CoglPangoGlyphCacheValue *value = value_ptr;
|
|
|
|
CoglPangoGlyphCacheDirtyFunc func = user_data;
|
|
|
|
|
|
|
|
if (value->dirty)
|
|
|
|
{
|
|
|
|
func (key->font, key->glyph, value);
|
|
|
|
|
|
|
|
value->dirty = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pango_glyph_cache_set_dirty_glyphs (CoglPangoGlyphCache *cache,
|
|
|
|
CoglPangoGlyphCacheDirtyFunc func)
|
|
|
|
{
|
|
|
|
/* If we know that there are no dirty glyphs then we can shortcut
|
|
|
|
out early */
|
|
|
|
if (!cache->has_dirty_glyphs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_hash_table_foreach (cache->hash_table,
|
|
|
|
_cogl_pango_glyph_cache_set_dirty_glyphs_cb,
|
|
|
|
func);
|
|
|
|
|
|
|
|
cache->has_dirty_glyphs = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pango_glyph_cache_add_reorganize_callback (CoglPangoGlyphCache *cache,
|
2011-03-14 17:58:31 +00:00
|
|
|
GHookFunc func,
|
2010-08-04 17:05:21 +00:00
|
|
|
void *user_data)
|
|
|
|
{
|
2011-03-14 17:58:31 +00:00
|
|
|
GHook *hook = g_hook_alloc (&cache->reorganize_callbacks);
|
|
|
|
hook->func = func;
|
|
|
|
hook->data = user_data;
|
|
|
|
g_hook_prepend (&cache->reorganize_callbacks, hook);
|
2010-08-04 17:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_pango_glyph_cache_remove_reorganize_callback (CoglPangoGlyphCache *cache,
|
2011-03-14 17:58:31 +00:00
|
|
|
GHookFunc func,
|
2010-08-04 17:05:21 +00:00
|
|
|
void *user_data)
|
|
|
|
{
|
2011-03-14 17:58:31 +00:00
|
|
|
GHook *hook = g_hook_find_func_data (&cache->reorganize_callbacks,
|
|
|
|
FALSE,
|
|
|
|
func,
|
|
|
|
user_data);
|
|
|
|
|
|
|
|
if (hook)
|
|
|
|
g_hook_destroy_link (&cache->reorganize_callbacks, hook);
|
2010-08-04 17:05:21 +00:00
|
|
|
}
|