[gtk/wip/baedert/icontheme2: 1/2] icontheme: Return a paintable from gtk_icon_info_load_icon
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/icontheme2: 1/2] icontheme: Return a paintable from gtk_icon_info_load_icon
- Date: Sat, 31 Aug 2019 06:52:52 +0000 (UTC)
commit f09448fd2dc0085feaadc603777a6aa2e9341734
Author: Timm Bäder <mail baedert org>
Date: Fri Aug 30 22:20:51 2019 +0200
icontheme: Return a paintable from gtk_icon_info_load_icon
gtk/gtkicontheme.c | 77 ++++++++++++++++++++++++++---------------------
gtk/gtkicontheme.h | 4 +--
tests/testicontheme.c | 10 +++---
testsuite/gtk/icontheme.c | 8 ++---
4 files changed, 53 insertions(+), 46 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 4695dfdfb8..0bade5749e 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]