[nautilus/wip/antoniof/hidpi-and-icons-cleanup: 2/12] xicon-info: Take a paintables instead of pixbufs




commit 314fc335dce1ee733d3607c908f9091fcd8d19eb
Author: António Fernandes <antoniof gnome org>
Date:   Sun Aug 7 22:52:26 2022 +0100

    xicon-info: Take a paintables instead of pixbufs
    
    This is more generic and is going to allow HiDPI icons and GPU usage.
    
    GdkPixbuf can be easily converted into GdkTexture, which is a GdkPaintable.

 src/nautilus-file.c      | 22 ++++------------------
 src/nautilus-icon-info.c | 31 ++++++++++++++-----------------
 src/nautilus-icon-info.h |  2 +-
 3 files changed, 19 insertions(+), 36 deletions(-)
---
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index 96ececa4c..a2c02f690 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -5150,11 +5150,9 @@ nautilus_file_get_thumbnail_icon (NautilusFile          *file,
     GdkPixbuf *pixbuf;
     int w, h, s;
     double thumb_scale;
-    GIcon *gicon;
     NautilusIconInfo *icon;
 
     icon = NULL;
-    gicon = NULL;
     pixbuf = NULL;
 
     modified_size = size * scale;
@@ -5221,25 +5219,13 @@ nautilus_file_get_thumbnail_icon (NautilusFile          *file,
 
     if (pixbuf != NULL)
     {
-        gicon = G_ICON (g_object_ref (pixbuf));
+        g_autoptr (GdkTexture) texture = gdk_texture_new_for_pixbuf (pixbuf);
+        icon = nautilus_icon_info_new_for_paintable (GDK_PAINTABLE (texture), scale);
     }
     else if (file->details->is_thumbnailing)
     {
-        gicon = g_themed_icon_new (ICON_NAME_THUMBNAIL_LOADING);
-    }
-
-    if (gicon != NULL)
-    {
-        if (g_icon_equal (gicon, G_ICON (pixbuf)))
-        {
-            icon = nautilus_icon_info_new_for_pixbuf (pixbuf, scale);
-        }
-        else
-        {
-            icon = nautilus_icon_info_lookup (gicon, size, scale);
-        }
-
-        g_object_unref (gicon);
+        g_autoptr (GIcon) gicon = g_themed_icon_new (ICON_NAME_THUMBNAIL_LOADING);
+        icon = nautilus_icon_info_lookup (gicon, size, scale);
     }
 
     return icon;
diff --git a/src/nautilus-icon-info.c b/src/nautilus-icon-info.c
index 0831ae168..b5754518c 100644
--- a/src/nautilus-icon-info.c
+++ b/src/nautilus-icon-info.c
@@ -28,8 +28,6 @@ struct _NautilusIconInfo
     GdkPaintable *paintable;
 
     char *icon_name;
-
-    gint orig_scale;
 };
 
 static void schedule_reap_cache (void);
@@ -103,20 +101,18 @@ nautilus_icon_info_class_init (NautilusIconInfoClass *icon_info_class)
 }
 
 NautilusIconInfo *
-nautilus_icon_info_new_for_pixbuf (GdkPixbuf *pixbuf,
-                                   gint       scale)
+nautilus_icon_info_new_for_paintable (GdkPaintable *paintable,
+                                      gint          scale)
 {
     NautilusIconInfo *icon;
 
     icon = g_object_new (NAUTILUS_TYPE_ICON_INFO, NULL);
 
-    if (pixbuf)
+    if (paintable != NULL)
     {
-        icon->paintable = GDK_PAINTABLE (gdk_texture_new_for_pixbuf (pixbuf));
+        icon->paintable = g_object_ref (paintable);
     }
 
-    icon->orig_scale = scale;
-
     return icon;
 }
 
@@ -128,9 +124,7 @@ nautilus_icon_info_new_for_icon_paintable (GtkIconPaintable *icon_paintable,
     g_autoptr (GFile) file = NULL;
     char *basename, *p;
 
-    icon = g_object_new (NAUTILUS_TYPE_ICON_INFO, NULL);
-
-    icon->paintable = GDK_PAINTABLE (g_object_ref (icon_paintable));
+    icon = nautilus_icon_info_new_for_paintable (GDK_PAINTABLE (icon_paintable), scale);
 
     file = gtk_icon_paintable_get_file (icon_paintable);
     if (file != NULL)
@@ -148,8 +142,6 @@ nautilus_icon_info_new_for_icon_paintable (GtkIconPaintable *icon_paintable,
         icon->icon_name = g_strdup (gtk_icon_paintable_get_icon_name (icon_paintable));
     }
 
-    icon->orig_scale = scale;
-
     return icon;
 }
 
@@ -344,7 +336,8 @@ nautilus_icon_info_lookup (GIcon *icon,
 
     if (G_IS_LOADABLE_ICON (icon))
     {
-        GdkPixbuf *pixbuf;
+        g_autoptr (GdkPixbuf) pixbuf = NULL;
+        g_autoptr (GdkTexture) texture = NULL;
         LoadableIconKey lookup_key;
         LoadableIconKey *key;
         GInputStream *stream;
@@ -368,7 +361,6 @@ nautilus_icon_info_lookup (GIcon *icon,
             return g_object_ref (icon_info);
         }
 
-        pixbuf = NULL;
         stream = g_loadable_icon_load (G_LOADABLE_ICON (icon),
                                        size * scale,
                                        NULL, NULL, NULL);
@@ -382,7 +374,12 @@ nautilus_icon_info_lookup (GIcon *icon,
             g_object_unref (stream);
         }
 
-        icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf, scale);
+        if (pixbuf != NULL)
+        {
+            texture = gdk_texture_new_for_pixbuf (pixbuf);
+        }
+
+        icon_info = nautilus_icon_info_new_for_paintable (GDK_PAINTABLE (texture), scale);
 
         key = loadable_icon_key_new (icon, scale, size);
         g_hash_table_insert (loadable_icon_cache, key, icon_info);
@@ -394,7 +391,7 @@ nautilus_icon_info_lookup (GIcon *icon,
                                                      icon, size, scale, GTK_TEXT_DIR_NONE, 0);
     if (icon_paintable == NULL)
     {
-        return nautilus_icon_info_new_for_pixbuf (NULL, scale);
+        return nautilus_icon_info_new_for_paintable (NULL, scale);
     }
 
     if (G_IS_THEMED_ICON (icon))
diff --git a/src/nautilus-icon-info.h b/src/nautilus-icon-info.h
index 074789fda..727d3b226 100644
--- a/src/nautilus-icon-info.h
+++ b/src/nautilus-icon-info.h
@@ -14,7 +14,7 @@ G_BEGIN_DECLS
 #define NAUTILUS_TYPE_ICON_INFO (nautilus_icon_info_get_type ())
 G_DECLARE_FINAL_TYPE (NautilusIconInfo, nautilus_icon_info, NAUTILUS, ICON_INFO, GObject)
 
-NautilusIconInfo *    nautilus_icon_info_new_for_pixbuf               (GdkPixbuf         *pixbuf,
+NautilusIconInfo *    nautilus_icon_info_new_for_paintable            (GdkPaintable      *paintable,
                                                                       int                scale);
 NautilusIconInfo *    nautilus_icon_info_lookup                       (GIcon             *icon,
                                                                       int                size,


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