mutter/cogl/cogl-pango/cogl-pango-glyph-cache.c

434 lines
13 KiB
C
Raw Normal View History

/*
This re-licenses Cogl 1.18 under the MIT license Since the Cogl 1.18 branch is actively maintained in parallel with the master branch; this is a counter part to commit 1b83ef938fc16b which re-licensed the master branch to use the MIT license. This re-licensing is a follow up to the proposal that was sent to the Cogl mailing list: http://lists.freedesktop.org/archives/cogl/2013-December/001465.html Note: there was a copyright assignment policy in place for Clutter (and therefore Cogl which was part of Clutter at the time) until the 11th of June 2010 and so we only checked the details after that point (commit 0bbf50f905) For each file, authors were identified via this Git command: $ git blame -p -C -C -C20 -M -M10 0bbf50f905..HEAD We received blanket approvals for re-licensing all Red Hat and Collabora contributions which reduced how many people needed to be contacted individually: - http://lists.freedesktop.org/archives/cogl/2013-December/001470.html - http://lists.freedesktop.org/archives/cogl/2014-January/001536.html Individual approval requests were sent to all the other identified authors who all confirmed the re-license on the Cogl mailinglist: http://lists.freedesktop.org/archives/cogl/2014-January As well as updating the copyright header in all sources files, the COPYING file has been updated to reflect the license change and also document the other licenses used in Cogl such as the SGI Free Software License B, version 2.0 and the 3-clause BSD license. This patch was not simply cherry-picked from master; but the same methodology was used to check the source files.
2014-02-21 20:28:54 -05:00
* Cogl
*
This re-licenses Cogl 1.18 under the MIT license Since the Cogl 1.18 branch is actively maintained in parallel with the master branch; this is a counter part to commit 1b83ef938fc16b which re-licensed the master branch to use the MIT license. This re-licensing is a follow up to the proposal that was sent to the Cogl mailing list: http://lists.freedesktop.org/archives/cogl/2013-December/001465.html Note: there was a copyright assignment policy in place for Clutter (and therefore Cogl which was part of Clutter at the time) until the 11th of June 2010 and so we only checked the details after that point (commit 0bbf50f905) For each file, authors were identified via this Git command: $ git blame -p -C -C -C20 -M -M10 0bbf50f905..HEAD We received blanket approvals for re-licensing all Red Hat and Collabora contributions which reduced how many people needed to be contacted individually: - http://lists.freedesktop.org/archives/cogl/2013-December/001470.html - http://lists.freedesktop.org/archives/cogl/2014-January/001536.html Individual approval requests were sent to all the other identified authors who all confirmed the re-license on the Cogl mailinglist: http://lists.freedesktop.org/archives/cogl/2014-January As well as updating the copyright header in all sources files, the COPYING file has been updated to reflect the license change and also document the other licenses used in Cogl such as the SGI Free Software License B, version 2.0 and the 3-clause BSD license. This patch was not simply cherry-picked from master; but the same methodology was used to check the source files.
2014-02-21 20:28:54 -05:00
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C) 2008 OpenedHand
*
This re-licenses Cogl 1.18 under the MIT license Since the Cogl 1.18 branch is actively maintained in parallel with the master branch; this is a counter part to commit 1b83ef938fc16b which re-licensed the master branch to use the MIT license. This re-licensing is a follow up to the proposal that was sent to the Cogl mailing list: http://lists.freedesktop.org/archives/cogl/2013-December/001465.html Note: there was a copyright assignment policy in place for Clutter (and therefore Cogl which was part of Clutter at the time) until the 11th of June 2010 and so we only checked the details after that point (commit 0bbf50f905) For each file, authors were identified via this Git command: $ git blame -p -C -C -C20 -M -M10 0bbf50f905..HEAD We received blanket approvals for re-licensing all Red Hat and Collabora contributions which reduced how many people needed to be contacted individually: - http://lists.freedesktop.org/archives/cogl/2013-December/001470.html - http://lists.freedesktop.org/archives/cogl/2014-January/001536.html Individual approval requests were sent to all the other identified authors who all confirmed the re-license on the Cogl mailinglist: http://lists.freedesktop.org/archives/cogl/2014-January As well as updating the copyright header in all sources files, the COPYING file has been updated to reflect the license change and also document the other licenses used in Cogl such as the SGI Free Software License B, version 2.0 and the 3-clause BSD license. This patch was not simply cherry-picked from master; but the same methodology was used to check the source files.
2014-02-21 20:28:54 -05: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:
*
This re-licenses Cogl 1.18 under the MIT license Since the Cogl 1.18 branch is actively maintained in parallel with the master branch; this is a counter part to commit 1b83ef938fc16b which re-licensed the master branch to use the MIT license. This re-licensing is a follow up to the proposal that was sent to the Cogl mailing list: http://lists.freedesktop.org/archives/cogl/2013-December/001465.html Note: there was a copyright assignment policy in place for Clutter (and therefore Cogl which was part of Clutter at the time) until the 11th of June 2010 and so we only checked the details after that point (commit 0bbf50f905) For each file, authors were identified via this Git command: $ git blame -p -C -C -C20 -M -M10 0bbf50f905..HEAD We received blanket approvals for re-licensing all Red Hat and Collabora contributions which reduced how many people needed to be contacted individually: - http://lists.freedesktop.org/archives/cogl/2013-December/001470.html - http://lists.freedesktop.org/archives/cogl/2014-January/001536.html Individual approval requests were sent to all the other identified authors who all confirmed the re-license on the Cogl mailinglist: http://lists.freedesktop.org/archives/cogl/2014-January As well as updating the copyright header in all sources files, the COPYING file has been updated to reflect the license change and also document the other licenses used in Cogl such as the SGI Free Software License B, version 2.0 and the 3-clause BSD license. This patch was not simply cherry-picked from master; but the same methodology was used to check the source files.
2014-02-21 20:28:54 -05:00
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
This re-licenses Cogl 1.18 under the MIT license Since the Cogl 1.18 branch is actively maintained in parallel with the master branch; this is a counter part to commit 1b83ef938fc16b which re-licensed the master branch to use the MIT license. This re-licensing is a follow up to the proposal that was sent to the Cogl mailing list: http://lists.freedesktop.org/archives/cogl/2013-December/001465.html Note: there was a copyright assignment policy in place for Clutter (and therefore Cogl which was part of Clutter at the time) until the 11th of June 2010 and so we only checked the details after that point (commit 0bbf50f905) For each file, authors were identified via this Git command: $ git blame -p -C -C -C20 -M -M10 0bbf50f905..HEAD We received blanket approvals for re-licensing all Red Hat and Collabora contributions which reduced how many people needed to be contacted individually: - http://lists.freedesktop.org/archives/cogl/2013-December/001470.html - http://lists.freedesktop.org/archives/cogl/2014-January/001536.html Individual approval requests were sent to all the other identified authors who all confirmed the re-license on the Cogl mailinglist: http://lists.freedesktop.org/archives/cogl/2014-January As well as updating the copyright header in all sources files, the COPYING file has been updated to reflect the license change and also document the other licenses used in Cogl such as the SGI Free Software License B, version 2.0 and the 3-clause BSD license. This patch was not simply cherry-picked from master; but the same methodology was used to check the source files.
2014-02-21 20:28:54 -05: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.
*/
#ifdef HAVE_CONFIG_H
#include "cogl-config.h"
#endif
#include <glib.h>
#include "cogl-pango-glyph-cache.h"
#include "cogl-pango-private.h"
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
#include "cogl/cogl-atlas.h"
#include "cogl/cogl-atlas-texture-private.h"
typedef struct _CoglPangoGlyphCacheKey CoglPangoGlyphCacheKey;
struct _CoglPangoGlyphCache
{
CoglContext *ctx;
/* Hash table to quickly check whether a particular glyph in a
particular font is already cached */
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
GHashTable *hash_table;
/* List of CoglAtlases */
GSList *atlases;
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
/* List of callbacks to invoke when an atlas is reorganized */
GHookList reorganize_callbacks;
/* 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 */
CoglBool using_global_atlas;
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04: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 */
CoglBool has_dirty_glyphs;
/* Whether mipmapping is being used for this cache. This only
affects whether we decide to put the glyph in the global atlas */
CoglBool use_mipmapping;
};
struct _CoglPangoGlyphCacheKey
{
PangoFont *font;
PangoGlyph glyph;
};
static void
cogl_pango_glyph_cache_value_free (CoglPangoGlyphCacheValue *value)
{
if (value->texture)
Add a strong CoglTexture type to replace CoglHandle As part of the on going, incremental effort to purge the non type safe CoglHandle type from the Cogl API this patch tackles most of the CoglHandle uses relating to textures. We'd postponed making this change for quite a while because we wanted to have a clearer understanding of how we wanted to evolve the texture APIs towards Cogl 2.0 before exposing type safety here which would be difficult to change later since it would imply breaking APIs. The basic idea that we are steering towards now is that CoglTexture can be considered to be the most primitive interface we have for any object representing a texture. The texture interface would provide roughly these methods: cogl_texture_get_width cogl_texture_get_height cogl_texture_can_repeat cogl_texture_can_mipmap cogl_texture_generate_mipmap; cogl_texture_get_format cogl_texture_set_region cogl_texture_get_region Besides the texture interface we will then start to expose types corresponding to specific texture types: CoglTexture2D, CoglTexture3D, CoglTexture2DSliced, CoglSubTexture, CoglAtlasTexture and CoglTexturePixmapX11. We will then also expose an interface for the high-level texture types we have (such as CoglTexture2DSlice, CoglSubTexture and CoglAtlasTexture) called CoglMetaTexture. CoglMetaTexture is an additional interface that lets you iterate a virtual region of a meta texture and get mappings of primitive textures to sub-regions of that virtual region. Internally we already have this kind of abstraction for dealing with sliced texture, sub-textures and atlas textures in a consistent way, so this will just make that abstraction public. The aim here is to clarify that there is a difference between primitive textures (CoglTexture2D/3D) and some of the other high-level textures, and also enable developers to implement primitives that can support meta textures since they can only be used with the cogl_rectangle API currently. The thing that's not so clean-cut with this are the texture constructors we have currently; such as cogl_texture_new_from_file which no longer make sense when CoglTexture is considered to be an interface. These will basically just become convenient factory functions and it's just a bit unusual that they are within the cogl_texture namespace. It's worth noting here that all the texture type APIs will also have their own type specific constructors so these functions will only be used for the convenience of being able to create a texture without really wanting to know the details of what type of texture you need. Longer term for 2.0 we may come up with replacement names for these factory functions or the other thing we are considering is designing some asynchronous factory functions instead since it's so often detrimental to application performance to be blocked waiting for a texture to be uploaded to the GPU. Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-24 16:30:34 -04:00
cogl_object_unref (value->texture);
g_slice_free (CoglPangoGlyphCacheValue, value);
}
static void
cogl_pango_glyph_cache_key_free (CoglPangoGlyphCacheKey *key)
{
g_object_unref (key->font);
g_slice_free (CoglPangoGlyphCacheKey, key);
}
static unsigned int
cogl_pango_glyph_cache_hash_func (const void *key)
{
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;
}
static CoglBool
cogl_pango_glyph_cache_equal_func (const void *a, const void *b)
{
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 *
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,
(GDestroyNotify) cogl_pango_glyph_cache_key_free,
(GDestroyNotify) cogl_pango_glyph_cache_value_free);
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
cache->atlases = NULL;
g_hook_list_init (&cache->reorganize_callbacks, sizeof (GHook));
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
cache->has_dirty_glyphs = FALSE;
cache->using_global_atlas = FALSE;
cache->use_mipmapping = use_mipmapping;
return cache;
}
static void
cogl_pango_glyph_cache_reorganize_cb (void *user_data)
{
CoglPangoGlyphCache *cache = user_data;
g_hook_list_invoke (&cache->reorganize_callbacks, FALSE);
}
void
cogl_pango_glyph_cache_clear (CoglPangoGlyphCache *cache)
{
g_slist_foreach (cache->atlases, (GFunc) cogl_object_unref, NULL);
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
g_slist_free (cache->atlases);
cache->atlases = NULL;
cache->has_dirty_glyphs = FALSE;
g_hash_table_remove_all (cache->hash_table);
}
void
cogl_pango_glyph_cache_free (CoglPangoGlyphCache *cache)
{
if (cache->using_global_atlas)
{
_cogl_atlas_texture_remove_reorganize_callback (
cache->ctx,
cogl_pango_glyph_cache_reorganize_cb, cache);
}
cogl_pango_glyph_cache_clear (cache);
g_hash_table_unref (cache->hash_table);
g_hook_list_clear (&cache->reorganize_callbacks);
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
g_free (cache);
}
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
static void
cogl_pango_glyph_cache_update_position_cb (void *user_data,
CoglTexture *new_texture,
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
const CoglRectangleMapEntry *rect)
{
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
CoglPangoGlyphCacheValue *value = user_data;
float tex_width, tex_height;
if (value->texture)
Add a strong CoglTexture type to replace CoglHandle As part of the on going, incremental effort to purge the non type safe CoglHandle type from the Cogl API this patch tackles most of the CoglHandle uses relating to textures. We'd postponed making this change for quite a while because we wanted to have a clearer understanding of how we wanted to evolve the texture APIs towards Cogl 2.0 before exposing type safety here which would be difficult to change later since it would imply breaking APIs. The basic idea that we are steering towards now is that CoglTexture can be considered to be the most primitive interface we have for any object representing a texture. The texture interface would provide roughly these methods: cogl_texture_get_width cogl_texture_get_height cogl_texture_can_repeat cogl_texture_can_mipmap cogl_texture_generate_mipmap; cogl_texture_get_format cogl_texture_set_region cogl_texture_get_region Besides the texture interface we will then start to expose types corresponding to specific texture types: CoglTexture2D, CoglTexture3D, CoglTexture2DSliced, CoglSubTexture, CoglAtlasTexture and CoglTexturePixmapX11. We will then also expose an interface for the high-level texture types we have (such as CoglTexture2DSlice, CoglSubTexture and CoglAtlasTexture) called CoglMetaTexture. CoglMetaTexture is an additional interface that lets you iterate a virtual region of a meta texture and get mappings of primitive textures to sub-regions of that virtual region. Internally we already have this kind of abstraction for dealing with sliced texture, sub-textures and atlas textures in a consistent way, so this will just make that abstraction public. The aim here is to clarify that there is a difference between primitive textures (CoglTexture2D/3D) and some of the other high-level textures, and also enable developers to implement primitives that can support meta textures since they can only be used with the cogl_rectangle API currently. The thing that's not so clean-cut with this are the texture constructors we have currently; such as cogl_texture_new_from_file which no longer make sense when CoglTexture is considered to be an interface. These will basically just become convenient factory functions and it's just a bit unusual that they are within the cogl_texture namespace. It's worth noting here that all the texture type APIs will also have their own type specific constructors so these functions will only be used for the convenience of being able to create a texture without really wanting to know the details of what type of texture you need. Longer term for 2.0 we may come up with replacement names for these factory functions or the other thing we are considering is designing some asynchronous factory functions instead since it's so often detrimental to application performance to be blocked waiting for a texture to be uploaded to the GPU. Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-24 16:30:34 -04:00
cogl_object_unref (value->texture);
value->texture = cogl_object_ref (new_texture);
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
tex_width = cogl_texture_get_width (new_texture);
tex_height = cogl_texture_get_height (new_texture);
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04: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;
}
static CoglBool
cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache,
PangoFont *font,
PangoGlyph glyph,
CoglPangoGlyphCacheValue *value)
{
CoglAtlasTexture *texture;
CoglError *ignore_error = NULL;
if (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SHARED_ATLAS))
return FALSE;
/* 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;
texture = cogl_atlas_texture_new_with_size (cache->ctx,
value->draw_width,
value->draw_height);
if (!cogl_texture_allocate (COGL_TEXTURE (texture), &ignore_error))
{
cogl_error_free (ignore_error);
return FALSE;
}
value->texture = COGL_TEXTURE (texture);
value->tx1 = 0;
value->ty1 = 0;
value->tx2 = 1;
value->ty2 = 1;
value->tx_pixel = 0;
value->ty_pixel = 0;
/* 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
(cache->ctx,
cogl_pango_glyph_cache_reorganize_cb, cache);
cache->using_global_atlas = TRUE;
}
return TRUE;
}
static CoglBool
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;
}
CoglPangoGlyphCacheValue *
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
cogl_pango_glyph_cache_lookup (CoglPangoGlyphCache *cache,
CoglBool create,
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
PangoFont *font,
PangoGlyph glyph)
{
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
CoglPangoGlyphCacheKey lookup_key;
CoglPangoGlyphCacheValue *value;
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
lookup_key.font = font;
lookup_key.glyph = glyph;
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
value = g_hash_table_lookup (cache->hash_table, &lookup_key);
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
if (create && value == NULL)
{
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
CoglPangoGlyphCacheKey *key;
PangoRectangle ink_rect;
value = g_slice_new (CoglPangoGlyphCacheValue);
Add a strong CoglTexture type to replace CoglHandle As part of the on going, incremental effort to purge the non type safe CoglHandle type from the Cogl API this patch tackles most of the CoglHandle uses relating to textures. We'd postponed making this change for quite a while because we wanted to have a clearer understanding of how we wanted to evolve the texture APIs towards Cogl 2.0 before exposing type safety here which would be difficult to change later since it would imply breaking APIs. The basic idea that we are steering towards now is that CoglTexture can be considered to be the most primitive interface we have for any object representing a texture. The texture interface would provide roughly these methods: cogl_texture_get_width cogl_texture_get_height cogl_texture_can_repeat cogl_texture_can_mipmap cogl_texture_generate_mipmap; cogl_texture_get_format cogl_texture_set_region cogl_texture_get_region Besides the texture interface we will then start to expose types corresponding to specific texture types: CoglTexture2D, CoglTexture3D, CoglTexture2DSliced, CoglSubTexture, CoglAtlasTexture and CoglTexturePixmapX11. We will then also expose an interface for the high-level texture types we have (such as CoglTexture2DSlice, CoglSubTexture and CoglAtlasTexture) called CoglMetaTexture. CoglMetaTexture is an additional interface that lets you iterate a virtual region of a meta texture and get mappings of primitive textures to sub-regions of that virtual region. Internally we already have this kind of abstraction for dealing with sliced texture, sub-textures and atlas textures in a consistent way, so this will just make that abstraction public. The aim here is to clarify that there is a difference between primitive textures (CoglTexture2D/3D) and some of the other high-level textures, and also enable developers to implement primitives that can support meta textures since they can only be used with the cogl_rectangle API currently. The thing that's not so clean-cut with this are the texture constructors we have currently; such as cogl_texture_new_from_file which no longer make sense when CoglTexture is considered to be an interface. These will basically just become convenient factory functions and it's just a bit unusual that they are within the cogl_texture namespace. It's worth noting here that all the texture type APIs will also have their own type specific constructors so these functions will only be used for the convenience of being able to create a texture without really wanting to know the details of what type of texture you need. Longer term for 2.0 we may come up with replacement names for these factory functions or the other thing we are considering is designing some asynchronous factory functions instead since it's so often detrimental to application performance to be blocked waiting for a texture to be uploaded to the GPU. Reviewed-by: Neil Roberts <neil@linux.intel.com>
2011-08-24 16:30:34 -04:00
value->texture = NULL;
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04: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;
/* 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
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04: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;
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
}
key = g_slice_new (CoglPangoGlyphCacheKey);
key->font = g_object_ref (font);
key->glyph = glyph;
g_hash_table_insert (cache->hash_table, key, value);
}
return value;
}
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
static void
_cogl_pango_glyph_cache_set_dirty_glyphs_cb (void *key_ptr,
void *value_ptr,
void *user_data)
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04: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,
GHookFunc func,
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
void *user_data)
{
GHook *hook = g_hook_alloc (&cache->reorganize_callbacks);
hook->func = func;
hook->data = user_data;
g_hook_prepend (&cache->reorganize_callbacks, hook);
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
}
void
_cogl_pango_glyph_cache_remove_reorganize_callback (CoglPangoGlyphCache *cache,
GHookFunc func,
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
void *user_data)
{
GHook *hook = g_hook_find_func_data (&cache->reorganize_callbacks,
FALSE,
func,
user_data);
if (hook)
g_hook_destroy_link (&cache->reorganize_callbacks, hook);
cogl-pango: Use a CoglAtlas to maintain the glyph cache The glyph cache is now stored in a CoglAtlas structure instead of the custom atlasing code. This has the advantage that it can share code with the main texture atlas and that it supports reorganizing the atlas when it becomes full. Unlike the texture atlas, the glyph cache can use multiple atlases which would be neccessary if the maximum texture size is reached and we need to create a second texture. Whenever a display list is created it now has to register a callback with the glyph cache so that the display list can be recreated whenever any of the atlases are reorganized. This is needed because the display list directly stores texture coordinates within the atlas texture and they would become invalid when the texture is moved. The ensure_glyphs_for_layout now works in two steps. First it reserves space in the atlas for all of the glyphs. The atlas is created with the DISABLE_MIGRATION flag so that it won't actually copy any textures if any rearranging is needed. Whenever the position is updated for a glyph then it is marked as dirty. After space for all of the glyphs has been reserved it will iterate over all dirty glyphs and redraw them using Cairo. The rendered glyph is then stored in the texture with a sub texture update. The glyphs need to all be set at the right location before starting to create the display list because the display list stores the texture coordinates of the glyph. If any of the glyphs were moved around then the parts of the display list that was created already would become invalid. To make this work, ensure_glyphs_for_layout is now always called before rendering a layout or a layout line.
2010-08-04 13:05:21 -04:00
}