icontheme: Return textures from load_icon{,_for_scale}
authorTimm Bäder <mail@baedert.org>
Fri, 30 Aug 2019 18:54:16 +0000 (20:54 +0200)
committerTimm Bäder <mail@baedert.org>
Mon, 9 Sep 2019 15:36:26 +0000 (17:36 +0200)
demos/gtk-demo/textview.c
gdk/gdktexture.c
gtk/gtkbuilder.c
gtk/gtkicontheme.c
gtk/gtkicontheme.h
tests/testicontheme.c

index b1306a0ff3ea8263bb0d826c0cd7522af77407d9..a339d37bb7906fc15a2f70b778d8fe9bc1dba6fb 100644 (file)
@@ -128,18 +128,16 @@ insert_text (GtkTextBuffer *buffer)
 {
   GtkTextIter iter;
   GtkTextIter start, end;
-  GdkPixbuf *pixbuf;
   GdkTexture *texture;
   GtkIconTheme *icon_theme;
 
   icon_theme = gtk_icon_theme_get_default ();
-  pixbuf = gtk_icon_theme_load_icon (icon_theme,
-                                     "gtk3-demo",
-                                     32,
-                                     GTK_ICON_LOOKUP_GENERIC_FALLBACK,
-                                     NULL);
-  g_assert (pixbuf);
-  texture = gdk_texture_new_for_pixbuf (pixbuf);
+  texture = GDK_TEXTURE (gtk_icon_theme_load_icon (icon_theme,
+                                                   "gtk3-demo",
+                                                   32,
+                                                   GTK_ICON_LOOKUP_GENERIC_FALLBACK,
+                                                   NULL));
+  g_assert (texture);
 
   /* get start of buffer; each insertion will revalidate the
    * iterator to point to just after the inserted text.
@@ -379,7 +377,6 @@ insert_text (GtkTextBuffer *buffer)
   gtk_text_buffer_get_bounds (buffer, &start, &end);
   gtk_text_buffer_apply_tag_by_name (buffer, "word_wrap", &start, &end);
 
-  g_object_unref (pixbuf);
   g_object_unref (texture);
 }
 
index 73c7f85dbf5e02e32adee2c94903984fc6bf85d3..c939de4a9019e2dff4b8e3499ed327845899a5a2 100644 (file)
@@ -333,7 +333,6 @@ gdk_texture_new_for_pixbuf (GdkPixbuf *pixbuf)
                                       * gdk_pixbuf_get_rowstride (pixbuf),
                                       g_object_unref,
                                       g_object_ref (pixbuf));
-  
   texture = gdk_memory_texture_new (gdk_pixbuf_get_width (pixbuf),
                                     gdk_pixbuf_get_height (pixbuf),
                                     gdk_pixbuf_get_has_alpha (pixbuf)
index 220a51c33cab0743bb42be6a4288b1a45eb67641..d5c4f1954c24818fc44f73fb2ef780541a21fecb 100644 (file)
@@ -2108,7 +2108,7 @@ gtk_builder_value_from_string_type (GtkBuilder   *builder,
     case G_TYPE_OBJECT:
     case G_TYPE_INTERFACE:
       if (G_VALUE_HOLDS (value, GDK_TYPE_PIXBUF) ||
-          G_VALUE_HOLDS (value, GDK_TYPE_PAINTABLE) || 
+          G_VALUE_HOLDS (value, GDK_TYPE_PAINTABLE) ||
           G_VALUE_HOLDS (value, GDK_TYPE_TEXTURE))
         {
           gchar *filename;
@@ -2156,6 +2156,7 @@ gtk_builder_value_from_string_type (GtkBuilder   *builder,
           if (pixbuf == NULL)
             {
               GtkIconTheme *theme;
+              GdkPaintable *texture;
 
               g_warning ("Could not load image '%s': %s",
                          string, tmp_error->message);
@@ -2163,11 +2164,13 @@ gtk_builder_value_from_string_type (GtkBuilder   *builder,
 
               /* fall back to a missing image */
               theme = gtk_icon_theme_get_default ();
-              pixbuf = gtk_icon_theme_load_icon (theme,
+              texture = gtk_icon_theme_load_icon (theme,
                                                  "image-missing",
                                                  16,
                                                  GTK_ICON_LOOKUP_USE_BUILTIN,
                                                  NULL);
+              pixbuf = gdk_pixbuf_get_from_texture (GDK_TEXTURE (texture));
+              g_object_unref (texture);
             }
 
           if (pixbuf)
index 6cf0c82ab9695578d634787292a481fd6bf0d4e0..47469d0780ee2a4fef4ecf50407bdf97b91605e5 100644 (file)
@@ -2264,7 +2264,7 @@ gtk_icon_theme_error_quark (void)
  *     you must not modify the icon. Use g_object_unref() to release
  *     your reference to the icon. %NULL if the icon isn’t found.
  */
-GdkPixbuf *
+GdkPaintable *
 gtk_icon_theme_load_icon (GtkIconTheme         *icon_theme,
                           const gchar          *icon_name,
                           gint                  size,
@@ -2311,7 +2311,7 @@ gtk_icon_theme_load_icon (GtkIconTheme         *icon_theme,
  *     you must not modify the icon. Use g_object_unref() to release
  *     your reference to the icon. %NULL if the icon isn’t found.
  */
-GdkPixbuf *
+GdkPaintable *
 gtk_icon_theme_load_icon_for_scale (GtkIconTheme        *icon_theme,
                                     const gchar         *icon_name,
                                     gint                 size,
@@ -2320,8 +2320,8 @@ gtk_icon_theme_load_icon_for_scale (GtkIconTheme        *icon_theme,
                                     GError             **error)
 {
   GtkIconInfo *icon_info;
-  GdkPixbuf *pixbuf = NULL;
-  
+  GdkTexture *texture = NULL;
+
   g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
   g_return_val_if_fail (icon_name != NULL, NULL);
   g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
@@ -2338,11 +2338,11 @@ gtk_icon_theme_load_icon_for_scale (GtkIconTheme        *icon_theme,
       return NULL;
     }
 
-  pixbuf = gtk_icon_info_load_icon (icon_info, error);
+  texture = gtk_icon_info_load_texture (icon_info, error);
   g_prefix_error (error, "Failed to load %s: ", icon_info->filename);
   g_object_unref (icon_info);
 
-  return pixbuf;
+  return GDK_PAINTABLE (texture);
 }
 
 /**
index 5a98d149a11131aea8e71db5702f3f2a1301c1c2..bf4588ff2bd8d5b879272f71037efb5101cdd48a 100644 (file)
@@ -169,13 +169,13 @@ GtkIconInfo * gtk_icon_theme_choose_icon_for_scale (GtkIconTheme
                                                     gint                         scale,
                                                    GtkIconLookupFlags           flags);
 GDK_AVAILABLE_IN_ALL
-GdkPixbuf *   gtk_icon_theme_load_icon             (GtkIconTheme                *icon_theme,
-                                                   const gchar                 *icon_name,
-                                                   gint                         size,
-                                                   GtkIconLookupFlags           flags,
-                                                   GError                     **error);
+GdkPaintable *gtk_icon_theme_load_icon             (GtkIconTheme                *icon_theme,
+                                                    const char                  *icon_name,
+                                                    int                          size,
+                                                    GtkIconLookupFlags           flags,
+                                                    GError                     **error);
 GDK_AVAILABLE_IN_ALL
-GdkPixbuf *   gtk_icon_theme_load_icon_for_scale   (GtkIconTheme                *icon_theme,
+GdkPaintable *gtk_icon_theme_load_icon_for_scale   (GtkIconTheme                *icon_theme,
                                                     const gchar                 *icon_name,
                                                     gint                         size,
                                                     gint                         scale,
index 02e775dc68f66a1d04132bb44726fa74d2c851c0..44a9599aaff017a391b819e9e2dfcdc4787f92d2 100644 (file)
@@ -93,7 +93,7 @@ main (int argc, char *argv[])
   if (strcmp (argv[1], "display") == 0)
     {
       GError *error;
-      GdkPixbuf *pixbuf;
+      GdkPaintable *paintable;
       GtkWidget *window, *image;
 
       if (argc < 4)
@@ -110,8 +110,8 @@ main (int argc, char *argv[])
        scale = atoi (argv[5]);
 
       error = NULL;
-      pixbuf = gtk_icon_theme_load_icon_for_scale (icon_theme, argv[3], size, scale, flags, &error);
-      if (!pixbuf)
+      paintable = gtk_icon_theme_load_icon_for_scale (icon_theme, argv[3], size, scale, flags, &error);
+      if (!paintable)
         {
           g_print ("%s\n", error->message);
           return 1;
@@ -119,8 +119,8 @@ main (int argc, char *argv[])
 
       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       image = gtk_image_new ();
-      gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
-      g_object_unref (pixbuf);
+      gtk_image_set_from_paintable (GTK_IMAGE (image), paintable);
+      g_object_unref (paintable);
       gtk_container_add (GTK_CONTAINER (window), image);
       g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
       gtk_widget_show (window);