[gnome-shell/gbsneto/clutter-image-on-texture-cache: 2/3] texture-cache: Avoid creating unnecessary ClutterImages



commit 1847a4f4ccc99194d69135c19a7accfd767ef9cb
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Jan 24 13:57:40 2019 -0200

    texture-cache: Avoid creating unnecessary ClutterImages
    
    After loading the GdkPixbuf, StTextureCache unconditionally
    creates a ClutterImage and, if it's not in the cache, add
    it to the cache. That's a waste of resources when the image
    is already committed to the texture cache.
    
    Fix that by reusing the ClutterImage of the cache if it is
    already there; otherwise, create a new ClutterImage as we
    were previously doing.

 src/st/st-texture-cache.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c
index 337d81869..d0c49960b 100644
--- a/src/st/st-texture-cache.c
+++ b/src/st/st-texture-cache.c
@@ -528,20 +528,30 @@ finish_texture_load (AsyncTextureLoadData *data,
   if (pixbuf == NULL)
     goto out;
 
-  image = pixbuf_to_clutter_image (pixbuf);
-  if (!image)
-    goto out;
-
   if (data->policy != ST_TEXTURE_CACHE_POLICY_NONE)
     {
-      gpointer orig_key, value;
+      gpointer orig_key = NULL, value = NULL;
 
       if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key,
                                          &orig_key, &value))
         {
+          image = pixbuf_to_clutter_image (pixbuf);
+          if (!image)
+            goto out;
+
           g_hash_table_insert (cache->priv->keyed_cache, g_strdup (data->key),
                                g_object_ref (image));
         }
+      else
+        {
+          image = g_object_ref (value);
+        }
+    }
+  else
+    {
+      image = pixbuf_to_clutter_image (pixbuf);
+      if (!image)
+        goto out;
     }
 
   for (iter = data->actors; iter; iter = iter->next)


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