[gnome-shell] st-texture-cache: Use StContentImage to create actor contents



commit aaf69b28989f3206779617e4e0761bb8ef71af9b
Author: Marco Trevisan (Treviño) <mail 3v1n0 net>
Date:   Wed Feb 27 03:18:39 2019 +0100

    st-texture-cache: Use StContentImage to create actor contents
    
    This will allow to use resource-scale aware content that will use a preferred
    size that takes in account the icon scaling and the resource scaling.
    
    If no size is passed we should just divide the actual resource size by the
    resource scale, as we assume that it's loaded with such scaling applied.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/5
    https://bugzilla.gnome.org/show_bug.cgi?id=765011

 src/st/st-texture-cache.c | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)
---
diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c
index 0075845f8..402130770 100644
--- a/src/st/st-texture-cache.c
+++ b/src/st/st-texture-cache.c
@@ -21,6 +21,7 @@
 
 #include "config.h"
 
+#include "st-image-content.h"
 #include "st-texture-cache.h"
 #include "st-private.h"
 #include "st-settings.h"
@@ -486,12 +487,26 @@ load_pixbuf_async_finish (StTextureCache *cache, GAsyncResult *result, GError **
 }
 
 static ClutterContent *
-pixbuf_to_clutter_image (GdkPixbuf *pixbuf)
+pixbuf_to_st_content_image (GdkPixbuf *pixbuf,
+                            int        width,
+                            int        height,
+                            int        paint_scale,
+                            float      resource_scale)
 {
   ClutterContent *image;
   g_autoptr(GError) error = NULL;
 
-  image = clutter_image_new ();
+  if (width < 0)
+    width = ceilf (gdk_pixbuf_get_width (pixbuf) / resource_scale);
+  else
+    width *= paint_scale;
+
+  if (height < 0)
+    height = ceilf (gdk_pixbuf_get_width (pixbuf) / resource_scale);
+  else
+    height *= paint_scale;
+
+  image = st_image_content_new_with_preferred_size (width, height);
   clutter_image_set_data (CLUTTER_IMAGE (image),
                           gdk_pixbuf_get_pixels (pixbuf),
                           gdk_pixbuf_get_has_alpha (pixbuf) ?
@@ -553,7 +568,10 @@ finish_texture_load (AsyncTextureLoadData *data,
       if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key,
                                          &orig_key, &value))
         {
-          image = pixbuf_to_clutter_image (pixbuf);
+          image = pixbuf_to_st_content_image (pixbuf,
+                                              data->width, data->height,
+                                              data->paint_scale,
+                                              data->resource_scale);
           if (!image)
             goto out;
 
@@ -567,7 +585,10 @@ finish_texture_load (AsyncTextureLoadData *data,
     }
   else
     {
-      image = pixbuf_to_clutter_image (pixbuf);
+      image = pixbuf_to_st_content_image (pixbuf,
+                                          data->width, data->height,
+                                          data->paint_scale,
+                                          data->resource_scale);
       if (!image)
         goto out;
     }
@@ -994,7 +1015,7 @@ load_from_pixbuf (GdkPixbuf *pixbuf)
   int width = gdk_pixbuf_get_width (pixbuf);
   int height = gdk_pixbuf_get_height (pixbuf);
 
-  image = pixbuf_to_clutter_image (pixbuf);
+  image = pixbuf_to_st_content_image (pixbuf, width, height, 1, 1.0f);
 
   actor = clutter_actor_new ();
   clutter_actor_set_size (actor, width, height);
@@ -1326,7 +1347,9 @@ st_texture_cache_load_file_sync_to_cogl_texture (StTextureCache *cache,
       if (!pixbuf)
         goto out;
 
-      image = pixbuf_to_clutter_image (pixbuf);
+      image = pixbuf_to_st_content_image (pixbuf,
+                                          available_height, available_width,
+                                          paint_scale, resource_scale);
       g_object_unref (pixbuf);
 
       if (!image)


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