diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 57cb5e9ca1..3cc532780e 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -5446,6 +5446,7 @@ gtk_icon_theme_lookup_by_gicon_for_scale gtk_icon_theme_load_icon gtk_icon_theme_load_icon_for_scale gtk_icon_theme_load_surface +gtk_icon_theme_load_texture gtk_icon_theme_list_contexts gtk_icon_theme_list_icons gtk_icon_theme_get_icon_sizes diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index 2a663c55e8..64842b4ccd 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -225,6 +225,7 @@ struct _GtkIconInfo */ GdkPixbuf *pixbuf; GdkPixbuf *proxy_pixbuf; + GskTexture *texture; GError *load_error; gdouble unscaled_scale; gdouble scale; @@ -4004,6 +4005,40 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info, return icon_info->proxy_pixbuf; } +/** + * gtk_icon_info_load_texture: + * @icon_info: a #GtkIconInfo + * + * Returns a texture object that can be used to render the icon + * with GSK. + * + * Returns: (transfer full): the icon texture; this may be a newly + * created texture or a new reference to an exiting texture, so you must + * not modify the icon. Use g_object_unref() to release your + * reference. + * + * Since: 3.94 + */ +GskTexture * +gtk_icon_info_load_texture (GtkIconInfo *icon_info) +{ + if (!icon_info->texture) + { + GdkPixbuf *pixbuf; + + pixbuf = gtk_icon_info_load_icon (icon_info, NULL); + icon_info->texture = gsk_texture_new_for_pixbuf (pixbuf); + g_object_unref (pixbuf); + + g_object_add_weak_pointer (icon_info->texture, &icon_info->texture); + } + + if (icon_info->in_cache != NULL) + ensure_in_lru_cache (icon_info->in_cache, icon_info); + + return g_object_ref (icon_info->texture); +} + /** * gtk_icon_info_load_surface: * @icon_info: a #GtkIconInfo from gtk_icon_theme_lookup_icon() diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h index a76a97890e..4f69717951 100644 --- a/gtk/gtkicontheme.h +++ b/gtk/gtkicontheme.h @@ -25,6 +25,7 @@ #include #include #include +#include G_BEGIN_DECLS @@ -293,6 +294,9 @@ GDK_AVAILABLE_IN_3_10 cairo_surface_t * gtk_icon_info_load_surface (GtkIconInfo *icon_info, GdkWindow *for_window, GError **error); +GDK_AVAILABLE_IN_3_94 +GskTexture * gtk_icon_info_load_texture (GtkIconInfo *icon_info); + GDK_AVAILABLE_IN_3_8 void gtk_icon_info_load_icon_async (GtkIconInfo *icon_info, GCancellable *cancellable,