[gtk/wip/baedert/icontheme2: 3/4] icontheme: Return textures from load_icon{, _for_scale}
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/icontheme2: 3/4] icontheme: Return textures from load_icon{, _for_scale}
- Date: Fri, 30 Aug 2019 19:27:15 +0000 (UTC)
commit 9a4a5198bb976041b5fe4bf84a53b59c8466cd6c
Author: Timm Bäder <mail baedert org>
Date: Fri Aug 30 20:54:16 2019 +0200
icontheme: Return textures from load_icon{,_for_scale}
demos/gtk-demo/textview.c | 15 ++++++---------
gdk/gdktexture.c | 1 -
gtk/gtkbuilder.c | 7 +++++--
gtk/gtkicontheme.c | 12 ++++++------
gtk/gtkicontheme.h | 12 ++++++------
tests/testicontheme.c | 10 +++++-----
6 files changed, 28 insertions(+), 29 deletions(-)
---
diff --git a/demos/gtk-demo/textview.c b/demos/gtk-demo/textview.c
index b1306a0ff3..a339d37bb7 100644
--- a/demos/gtk-demo/textview.c
+++ b/demos/gtk-demo/textview.c
@@ -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);
}
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 73c7f85dbf..c939de4a90 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -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)
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index 220a51c33c..d5c4f1954c 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -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)
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 37b4787e40..46fd37ba84 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -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);
}
/**
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index 5a98d149a1..bf4588ff2b 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -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,
diff --git a/tests/testicontheme.c b/tests/testicontheme.c
index 02e775dc68..44a9599aaf 100644
--- a/tests/testicontheme.c
+++ b/tests/testicontheme.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]