diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c index 84e2a9b24..ad33e52b4 100644 --- a/src/st/st-texture-cache.c +++ b/src/st/st-texture-cache.c @@ -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: diff --git a/src/st/st-texture-cache.h b/src/st/st-texture-cache.h index 2e6dfd12d..bfbfabbac 100644 --- a/src/st/st-texture-cache.h +++ b/src/st/st-texture-cache.h @@ -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__ */