Add st_texture_cache_load

Function for caching texture data from an arbitrary origin.

https://bugzilla.gnome.org/show_bug.cgi?id=607500
This commit is contained in:
Colin Walters 2010-02-09 16:53:59 -05:00
parent 394e01850b
commit 176487834a
2 changed files with 48 additions and 0 deletions

View File

@ -830,6 +830,45 @@ st_texture_cache_bind_pixbuf_property (StTextureCache *cache,
return CLUTTER_ACTOR(texture);
}
/**
* st_texture_cache_load:
* @cache: A #StTextureCache
* @key: Arbitrary string used to refer to item
* @policy: Caching policy
* @load: Function to create the texture, if not already cached
* @data: User data passed to @load
* @error: A #GError
*
* Load an arbitrary texture, caching it. The string chosen for @key
* should be of the form "type-prefix:type-uuid". For example,
* "url:file:///usr/share/icons/hicolor/48x48/apps/firefox.png", or
* "stock-icon:gtk-ok".
*
* Returns: (transfer full): A newly-referenced handle to the texture
*/
CoglHandle
st_texture_cache_load (StTextureCache *cache,
const char *key,
StTextureCachePolicy policy,
StTextureCacheLoader load,
void *data,
GError **error)
{
CoglHandle texture;
texture = g_hash_table_lookup (cache->priv->keyed_cache, key);
if (!texture)
{
texture = load (cache, key, data, error);
if (texture)
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texture);
else
return COGL_INVALID_HANDLE;
}
cogl_texture_ref (texture);
return texture;
}
/**
* create_texture_and_ensure_request:
* @cache:

View File

@ -101,6 +101,15 @@ ClutterActor *st_texture_cache_load_from_raw (StTextureCache *cache,
int size,
GError **error);
typedef CoglHandle (*StTextureCacheLoader) (StTextureCache *cache, const char *key, void *data, GError **error);
CoglHandle st_texture_cache_load (StTextureCache *cache,
const char *key,
StTextureCachePolicy policy,
StTextureCacheLoader load,
void *data,
GError **error);
gboolean st_texture_cache_pixbuf_equal (StTextureCache *cache, GdkPixbuf *a, GdkPixbuf *b);
#endif /* __ST_TEXTURE_CACHE_H__ */