[gnome-shell] Add st_texture_cache_load



commit 176487834a803d3060809718b3691f020a355d20
Author: Colin Walters <walters verbum org>
Date:   Tue Feb 9 16:53:59 2010 -0500

    Add st_texture_cache_load
    
    Function for caching texture data from an arbitrary origin.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=607500

 src/st/st-texture-cache.c |   39 +++++++++++++++++++++++++++++++++++++++
 src/st/st-texture-cache.h |    9 +++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c
index 84e2a9b..ad33e52 100644
--- a/src/st/st-texture-cache.c
+++ b/src/st/st-texture-cache.c
@@ -831,6 +831,45 @@ st_texture_cache_bind_pixbuf_property (StTextureCache    *cache,
 }
 
 /**
+ * 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:
  * @key: A cache key
diff --git a/src/st/st-texture-cache.h b/src/st/st-texture-cache.h
index 2e6dfd1..bfbfabb 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__ */



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