[gtk+/wip/matthiasc/icon-texture-cache: 1/2] icon theme: Add a texture cache
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/icon-texture-cache: 1/2] icon theme: Add a texture cache
- Date: Mon, 23 Oct 2017 05:57:02 +0000 (UTC)
commit 2494e2719d92811f64f2e2c0fcb43e5d114150ec
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Oct 23 07:51:45 2017 +0200
icon theme: Add a texture cache
Return cached textures for icons. This lets us avoid duplicate
texture uploads for icons whose surfaces we already cache.
docs/reference/gtk/gtk4-sections.txt | 1 +
gtk/gtkicontheme.c | 35 ++++++++++++++++++++++++++++++++++
gtk/gtkicontheme.h | 4 +++
3 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 57cb5e9..3cc5327 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 2a663c5..64842b4 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;
@@ -4005,6 +4006,40 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info,
}
/**
+ * 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()
* @for_window: (allow-none): #GdkWindow to optimize drawing for, or %NULL
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index a76a978..4f69717 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -25,6 +25,7 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdk.h>
#include <gtk/gtkstylecontext.h>
+#include <gsk/gsk.h>
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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]