From: Timm Bäder Date: Fri, 30 Aug 2019 20:20:51 +0000 (+0200) Subject: icontheme: Return a paintable from gtk_icon_info_load_icon X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~20^2~893 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=590e70d4d1f3c3d95b2d96b67aa4b0e5639e1547;p=gtk4.git icontheme: Return a paintable from gtk_icon_info_load_icon --- diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index d7182e5feb..202d2b435c 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -3740,37 +3740,10 @@ proxy_pixbuf_destroy (guchar *pixels, gpointer data) g_object_unref (icon_info); } -/** - * gtk_icon_info_load_icon: - * @icon_info: a #GtkIconInfo from gtk_icon_theme_lookup_icon() - * @error: (allow-none): location to store error information on failure, - * or %NULL. - * - * Renders an icon previously looked up in an icon theme using - * gtk_icon_theme_lookup_icon(); the size will be based on the size - * passed to gtk_icon_theme_lookup_icon(). Note that the resulting - * pixbuf may not be exactly this size; an icon theme may have icons - * that differ slightly from their nominal sizes, and in addition GTK+ - * will avoid scaling icons that it considers sufficiently close to the - * requested size or for which the source image would have to be scaled - * up too far. (This maintains sharpness.). This behaviour can be changed - * by passing the %GTK_ICON_LOOKUP_FORCE_SIZE flag when obtaining - * the #GtkIconInfo. If this flag has been specified, the pixbuf - * returned by this function will be scaled to the exact size. - * - * Returns: (transfer full) (nullable): the rendered icon; this may be a newly - * created icon or a new reference to an internal icon, so you must - * not modify the icon. Use g_object_unref() to release your reference - * to the icon. - * If the icon could not be loaded, %NULL is returned and @error is set. - */ -GdkPixbuf * -gtk_icon_info_load_icon (GtkIconInfo *icon_info, - GError **error) +static GdkPixbuf * +icon_info_load_pixbuf (GtkIconInfo *icon_info, + GError **error) { - g_return_val_if_fail (icon_info != NULL, NULL); - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - if (!icon_info_ensure_scale_and_pixbuf (icon_info)) { if (icon_info->load_error) @@ -3812,6 +3785,40 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info, return icon_info->proxy_pixbuf; } +/** + * gtk_icon_info_load_icon: + * @icon_info: a #GtkIconInfo from gtk_icon_theme_lookup_icon() + * @error: (allow-none): location to store error information on failure, + * or %NULL. + * + * Renders an icon previously looked up in an icon theme using + * gtk_icon_theme_lookup_icon(); the size will be based on the size + * passed to gtk_icon_theme_lookup_icon(). Note that the resulting + * pixbuf may not be exactly this size; an icon theme may have icons + * that differ slightly from their nominal sizes, and in addition GTK+ + * will avoid scaling icons that it considers sufficiently close to the + * requested size or for which the source image would have to be scaled + * up too far. (This maintains sharpness.). This behaviour can be changed + * by passing the %GTK_ICON_LOOKUP_FORCE_SIZE flag when obtaining + * the #GtkIconInfo. If this flag has been specified, the pixbuf + * returned by this function will be scaled to the exact size. + * + * Returns: (transfer full) (nullable): the rendered icon; this may be a newly + * created icon or a new reference to an internal icon, so you must + * not modify the icon. Use g_object_unref() to release your reference + * to the icon. + * If the icon could not be loaded, %NULL is returned and @error is set. + */ +GdkPaintable * +gtk_icon_info_load_icon (GtkIconInfo *icon_info, + GError **error) +{ + g_return_val_if_fail (icon_info != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + return (GdkPaintable *)gtk_icon_info_load_texture (icon_info, error); +} + /** * gtk_icon_info_load_texture: * @icon_info: a #GtkIconInfo @@ -3837,7 +3844,7 @@ gtk_icon_info_load_texture (GtkIconInfo *icon_info, { GdkPixbuf *pixbuf; - pixbuf = gtk_icon_info_load_icon (icon_info, NULL); + pixbuf = icon_info_load_pixbuf (icon_info, NULL); if (!pixbuf) { @@ -3904,7 +3911,6 @@ gtk_icon_info_load_icon_async (GtkIconInfo *icon_info, gpointer user_data) { GTask *task; - GdkPixbuf *pixbuf; GtkIconInfo *dup; GError *error = NULL; @@ -3912,11 +3918,12 @@ gtk_icon_info_load_icon_async (GtkIconInfo *icon_info, if (icon_info_get_pixbuf_ready (icon_info)) { - pixbuf = gtk_icon_info_load_icon (icon_info, &error); - if (pixbuf == NULL) + GdkPaintable *paintable = gtk_icon_info_load_icon (icon_info, &error); + + if (paintable == NULL) g_task_return_error (task, error); else - g_task_return_pointer (task, pixbuf, g_object_unref); + g_task_return_pointer (task, paintable, g_object_unref); g_object_unref (task); } else diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h index ee55cc120c..ba1c830ae4 100644 --- a/gtk/gtkicontheme.h +++ b/gtk/gtkicontheme.h @@ -222,8 +222,8 @@ const gchar * gtk_icon_info_get_filename (GtkIconInfo *icon_info GDK_AVAILABLE_IN_ALL gboolean gtk_icon_info_is_symbolic (GtkIconInfo *icon_info); GDK_AVAILABLE_IN_ALL -GdkPixbuf * gtk_icon_info_load_icon (GtkIconInfo *icon_info, - GError **error); +GdkPaintable * gtk_icon_info_load_icon (GtkIconInfo *icon_info, + GError **error); GDK_AVAILABLE_IN_ALL GdkTexture * gtk_icon_info_load_texture (GtkIconInfo *icon_info, GError **error); diff --git a/tests/testicontheme.c b/tests/testicontheme.c index 96cf65c1ff..18bb84ec8b 100644 --- a/tests/testicontheme.c +++ b/tests/testicontheme.c @@ -211,15 +211,15 @@ main (int argc, char *argv[]) if (icon_info) { - GdkPixbuf *pixbuf; + GdkTexture *texture; g_print ("Base size: %d, Scale: %d\n", gtk_icon_info_get_base_size (icon_info), gtk_icon_info_get_base_scale (icon_info)); - pixbuf = gtk_icon_info_load_icon (icon_info, NULL); - if (pixbuf != NULL) + texture = GDK_TEXTURE (gtk_icon_info_load_icon (icon_info, NULL)); + if (texture != NULL) { - g_print ("Pixbuf size: %dx%d\n", gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf)); - g_object_unref (pixbuf); + g_print ("texture size: %dx%d\n", gdk_texture_get_width (texture), gdk_texture_get_height (texture)); + g_object_unref (texture); } g_object_unref (icon_info); diff --git a/testsuite/gtk/icontheme.c b/testsuite/gtk/icontheme.c index a2d091d56e..0260e1625c 100644 --- a/testsuite/gtk/icontheme.c +++ b/testsuite/gtk/icontheme.c @@ -82,13 +82,13 @@ assert_icon_lookup_size (const char *icon_name, if (pixbuf_size > 0) { - GdkPixbuf *pixbuf; + GdkTexture *texture; GError *error = NULL; - pixbuf = gtk_icon_info_load_icon (info, &error); + texture = GDK_TEXTURE (gtk_icon_info_load_icon (info, &error)); g_assert_no_error (error); - g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, pixbuf_size); - g_object_unref (pixbuf); + g_assert_cmpint (gdk_texture_get_width (texture), ==, pixbuf_size); + g_object_unref (texture); } g_object_unref (info);