From fd16ac4d5ed535bfebf0fbdb3e3e75115038b832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Fri, 30 Aug 2019 21:26:21 +0200 Subject: [PATCH] icontheme: Return paintables from more API --- demos/gtk-demo/foreigndrawing.c | 9 +-- demos/icon-browser/iconbrowserwin.c | 5 +- gtk/gtkicontheme.c | 91 ++++++++++++++++++++--------- gtk/gtkicontheme.h | 56 +++++++++--------- tests/testicontheme.c | 12 ++-- testsuite/gtk/icontheme.c | 29 ++++----- 6 files changed, 118 insertions(+), 84 deletions(-) diff --git a/demos/gtk-demo/foreigndrawing.c b/demos/gtk-demo/foreigndrawing.c index 3f662fde76..98384f19ff 100644 --- a/demos/gtk-demo/foreigndrawing.c +++ b/demos/gtk-demo/foreigndrawing.c @@ -829,7 +829,6 @@ draw_spinbutton (GtkWidget *widget, GtkStyleContext *down_context; GtkIconTheme *icon_theme; GtkIconInfo *icon_info; - GdkPixbuf *pixbuf; GdkTexture *texture; gint icon_width, icon_height, icon_size; gint button_width; @@ -857,26 +856,22 @@ draw_spinbutton (GtkWidget *widget, "min-width", &icon_width, "min-height", &icon_height, NULL); icon_size = MIN (icon_width, icon_height); icon_info = gtk_icon_theme_lookup_icon (icon_theme, "list-add-symbolic", icon_size, 0); - pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, up_context, NULL, NULL); - texture = gdk_texture_new_for_pixbuf (pixbuf); + texture = GDK_TEXTURE (gtk_icon_info_load_symbolic_for_context (icon_info, up_context, NULL, NULL)); g_object_unref (icon_info); draw_style_common (up_context, cr, x + width - button_width, y, button_width, *height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_render_icon (up_context, cr, texture, contents_x, contents_y + (contents_height - icon_size) / 2); - g_object_unref (pixbuf); g_object_unref (texture); gtk_style_context_get (down_context, "min-width", &icon_width, "min-height", &icon_height, NULL); icon_size = MIN (icon_width, icon_height); icon_info = gtk_icon_theme_lookup_icon (icon_theme, "list-remove-symbolic", icon_size, 0); - pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info, down_context, NULL, NULL); - texture = gdk_texture_new_for_pixbuf (pixbuf); + texture = GDK_TEXTURE (gtk_icon_info_load_symbolic_for_context (icon_info, down_context, NULL, NULL)); g_object_unref (icon_info); draw_style_common (down_context, cr, x + width - 2 * button_width, y, button_width, *height, &contents_x, &contents_y, &contents_width, &contents_height); gtk_render_icon (down_context, cr, texture, contents_x, contents_y + (contents_height - icon_size) / 2); - g_object_unref (pixbuf); g_object_unref (texture); g_object_unref (down_context); diff --git a/demos/icon-browser/iconbrowserwin.c b/demos/icon-browser/iconbrowserwin.c index da795cc112..593c8cf917 100644 --- a/demos/icon-browser/iconbrowserwin.c +++ b/demos/icon-browser/iconbrowserwin.c @@ -81,11 +81,14 @@ get_icon (GtkWidget *image, const gchar *name, gint size) { GtkIconInfo *info; GtkStyleContext *context; + GdkTexture *texture; GdkPixbuf *pixbuf; context = gtk_widget_get_style_context (image); info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (), name, size, 0); - pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL); + texture = GDK_TEXTURE (gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL)); + pixbuf = gdk_pixbuf_get_from_texture (texture); + g_object_unref (texture); g_object_unref (info); return pixbuf; diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index 47469d0780..d7182e5feb 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -3942,13 +3942,14 @@ gtk_icon_info_load_icon_async (GtkIconInfo *icon_info, * not modify the icon. Use g_object_unref() to release your reference * to the icon. */ -GdkPixbuf * +GdkPaintable * gtk_icon_info_load_icon_finish (GtkIconInfo *icon_info, GAsyncResult *result, GError **error) { GTask *task = G_TASK (result); GtkIconInfo *dup; + GdkTexture *texture; g_return_val_if_fail (g_task_is_valid (result, icon_info), NULL); @@ -3974,7 +3975,12 @@ gtk_icon_info_load_icon_finish (GtkIconInfo *icon_info, g_assert (icon_info_get_pixbuf_ready (icon_info)); /* This is now guaranteed to not block */ - return gtk_icon_info_load_icon (icon_info, error); + texture = gtk_icon_info_load_texture (icon_info, error); + + if (texture) + return GDK_PAINTABLE (texture); + + return NULL; } static void @@ -4382,7 +4388,7 @@ gtk_icon_info_load_symbolic_internal (GtkIconInfo *icon_info, * * Returns: (transfer full): a #GdkPixbuf representing the loaded icon */ -GdkPixbuf * +GdkPaintable * gtk_icon_info_load_symbolic (GtkIconInfo *icon_info, const GdkRGBA *fg, const GdkRGBA *success_color, @@ -4391,6 +4397,7 @@ gtk_icon_info_load_symbolic (GtkIconInfo *icon_info, gboolean *was_symbolic, GError **error) { + GdkPixbuf *pixbuf; gboolean is_symbolic; g_return_val_if_fail (icon_info != NULL, NULL); @@ -4402,13 +4409,23 @@ gtk_icon_info_load_symbolic (GtkIconInfo *icon_info, *was_symbolic = is_symbolic; if (!is_symbolic) - return gtk_icon_info_load_icon (icon_info, error); + return (GdkPaintable *)gtk_icon_info_load_texture (icon_info, error); - return gtk_icon_info_load_symbolic_internal (icon_info, - fg, success_color, - warning_color, error_color, - TRUE, - error); + pixbuf = gtk_icon_info_load_symbolic_internal (icon_info, + fg, success_color, + warning_color, error_color, + TRUE, + error); + + if (pixbuf) + { + GdkTexture *texture = gdk_texture_new_for_pixbuf (pixbuf); + g_object_unref (pixbuf); + + return GDK_PAINTABLE (texture); + } + + return NULL; } void @@ -4467,7 +4484,7 @@ gtk_icon_theme_lookup_symbolic_colors (GtkCssStyle *style, * * Returns: (transfer full): a #GdkPixbuf representing the loaded icon */ -GdkPixbuf * +GdkPaintable * gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info, GtkStyleContext *context, gboolean *was_symbolic, @@ -4478,6 +4495,7 @@ gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info, GdkRGBA warning_color; GdkRGBA error_color; gboolean is_symbolic; + GdkPixbuf *pixbuf; g_return_val_if_fail (icon_info != NULL, NULL); g_return_val_if_fail (context != NULL, NULL); @@ -4488,17 +4506,27 @@ gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info, *was_symbolic = is_symbolic; if (!is_symbolic) - return gtk_icon_info_load_icon (icon_info, error); + return (GdkPaintable *)gtk_icon_info_load_texture (icon_info, error); gtk_icon_theme_lookup_symbolic_colors (gtk_style_context_lookup_style (context), &fg, &success_color, &warning_color, &error_color); - return gtk_icon_info_load_symbolic_internal (icon_info, - &fg, &success_color, - &warning_color, &error_color, - TRUE, - error); + pixbuf = gtk_icon_info_load_symbolic_internal (icon_info, + &fg, &success_color, + &warning_color, &error_color, + TRUE, + error); + + if (pixbuf) + { + GdkTexture *texture = gdk_texture_new_for_pixbuf (pixbuf); + g_object_unref (pixbuf); + + return GDK_PAINTABLE (texture); + } + + return NULL; } typedef struct { @@ -4530,13 +4558,13 @@ async_load_no_symbolic_cb (GObject *source_object, GtkIconInfo *icon_info = GTK_ICON_INFO (source_object); GTask *task = user_data; GError *error = NULL; - GdkPixbuf *pixbuf; + GdkPaintable *paintable; - pixbuf = gtk_icon_info_load_icon_finish (icon_info, res, &error); - if (pixbuf == NULL) + paintable = gtk_icon_info_load_icon_finish (icon_info, res, &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); } @@ -4669,12 +4697,11 @@ gtk_icon_info_load_symbolic_async (GtkIconInfo *icon_info, * * Finishes an async icon load, see gtk_icon_info_load_symbolic_async(). * - * Returns: (transfer full): 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. + * Returns: (transfer full): the rendered icon; + * Use g_object_unref() to release your reference + * to the icon. */ -GdkPixbuf * +GdkPaintable * gtk_icon_info_load_symbolic_finish (GtkIconInfo *icon_info, GAsyncResult *result, gboolean *was_symbolic, @@ -4684,6 +4711,7 @@ gtk_icon_info_load_symbolic_finish (GtkIconInfo *icon_info, AsyncSymbolicData *data = g_task_get_task_data (task); SymbolicPixbufCache *symbolic_cache; GdkPixbuf *pixbuf; + GdkTexture *texture; if (was_symbolic) *was_symbolic = data->is_symbolic; @@ -4713,10 +4741,17 @@ gtk_icon_info_load_symbolic_finish (GtkIconInfo *icon_info, g_object_unref (pixbuf); - return symbolic_cache_get_proxy (symbolic_cache, icon_info); + pixbuf = symbolic_cache_get_proxy (symbolic_cache, icon_info); + } + else + { + pixbuf = g_task_propagate_pointer (task, error); } - return g_task_propagate_pointer (task, error); + texture = gdk_texture_new_for_pixbuf (pixbuf); + g_object_unref (pixbuf); + + return GDK_PAINTABLE (texture); } /** @@ -4777,7 +4812,7 @@ gtk_icon_info_load_symbolic_for_context_async (GtkIconInfo *icon_info, * not modify the icon. Use g_object_unref() to release your reference * to the icon. */ -GdkPixbuf * +GdkPaintable * gtk_icon_info_load_symbolic_for_context_finish (GtkIconInfo *icon_info, GAsyncResult *result, gboolean *was_symbolic, diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h index bf4588ff2b..ee55cc120c 100644 --- a/gtk/gtkicontheme.h +++ b/gtk/gtkicontheme.h @@ -230,15 +230,15 @@ GdkTexture * gtk_icon_info_load_texture (GtkIconInfo *icon_info GDK_AVAILABLE_IN_ALL void gtk_icon_info_load_icon_async (GtkIconInfo *icon_info, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); GDK_AVAILABLE_IN_ALL -GdkPixbuf * gtk_icon_info_load_icon_finish (GtkIconInfo *icon_info, - GAsyncResult *res, - GError **error); +GdkPaintable * gtk_icon_info_load_icon_finish (GtkIconInfo *icon_info, + GAsyncResult *res, + GError **error); GDK_AVAILABLE_IN_ALL -GdkPixbuf * gtk_icon_info_load_symbolic (GtkIconInfo *icon_info, +GdkPaintable * gtk_icon_info_load_symbolic (GtkIconInfo *icon_info, const GdkRGBA *fg, const GdkRGBA *success_color, const GdkRGBA *warning_color, @@ -247,34 +247,34 @@ GdkPixbuf * gtk_icon_info_load_symbolic (GtkIconInfo *icon_info GError **error); GDK_AVAILABLE_IN_ALL void gtk_icon_info_load_symbolic_async (GtkIconInfo *icon_info, - const GdkRGBA *fg, - const GdkRGBA *success_color, - const GdkRGBA *warning_color, - const GdkRGBA *error_color, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); + const GdkRGBA *fg, + const GdkRGBA *success_color, + const GdkRGBA *warning_color, + const GdkRGBA *error_color, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); GDK_AVAILABLE_IN_ALL -GdkPixbuf * gtk_icon_info_load_symbolic_finish (GtkIconInfo *icon_info, - GAsyncResult *res, - gboolean *was_symbolic, - GError **error); +GdkPaintable * gtk_icon_info_load_symbolic_finish (GtkIconInfo *icon_info, + GAsyncResult *res, + gboolean *was_symbolic, + GError **error); GDK_AVAILABLE_IN_ALL -GdkPixbuf * gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info, +GdkPaintable * gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info, GtkStyleContext *context, gboolean *was_symbolic, GError **error); GDK_AVAILABLE_IN_ALL -void gtk_icon_info_load_symbolic_for_context_async (GtkIconInfo *icon_info, - GtkStyleContext *context, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); +void gtk_icon_info_load_symbolic_for_context_async (GtkIconInfo *icon_info, + GtkStyleContext *context, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); GDK_AVAILABLE_IN_ALL -GdkPixbuf * gtk_icon_info_load_symbolic_for_context_finish (GtkIconInfo *icon_info, - GAsyncResult *res, - gboolean *was_symbolic, - GError **error); +GdkPaintable * gtk_icon_info_load_symbolic_for_context_finish (GtkIconInfo *icon_info, + GAsyncResult *res, + gboolean *was_symbolic, + GError **error); G_END_DECLS diff --git a/tests/testicontheme.c b/tests/testicontheme.c index 44a9599aaf..96cf65c1ff 100644 --- a/tests/testicontheme.c +++ b/tests/testicontheme.c @@ -39,21 +39,21 @@ icon_loaded_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - GdkPixbuf *pixbuf; + GdkPaintable *paintable; GError *error; error = NULL; - pixbuf = gtk_icon_info_load_icon_finish (GTK_ICON_INFO (source_object), - res, &error); + paintable = gtk_icon_info_load_icon_finish (GTK_ICON_INFO (source_object), + res, &error); - if (pixbuf == NULL) + if (paintable == NULL) { g_print ("%s\n", error->message); exit (1); } - gtk_image_set_from_pixbuf (GTK_IMAGE (user_data), pixbuf); - g_object_unref (pixbuf); + gtk_image_set_from_paintable (GTK_IMAGE (user_data), paintable); + g_object_unref (paintable); } diff --git a/testsuite/gtk/icontheme.c b/testsuite/gtk/icontheme.c index 21e482477f..a2d091d56e 100644 --- a/testsuite/gtk/icontheme.c +++ b/testsuite/gtk/icontheme.c @@ -598,12 +598,12 @@ load_icon (GObject *source, { GtkIconInfo *info = (GtkIconInfo *)source; GError *error = NULL; - GdkPixbuf *pixbuf; + GdkPaintable *paintable; - pixbuf = gtk_icon_info_load_icon_finish (info, res, &error); - g_assert (pixbuf != NULL); + paintable = gtk_icon_info_load_icon_finish (info, res, &error); + g_assert (paintable != NULL); g_assert_no_error (error); - g_object_unref (pixbuf); + g_object_unref (paintable); loaded++; } @@ -616,12 +616,12 @@ load_symbolic (GObject *source, GtkIconInfo *info = (GtkIconInfo *)source; GError *error = NULL; gboolean symbolic; - GdkPixbuf *pixbuf; + GdkPaintable *paintable; - pixbuf = gtk_icon_info_load_symbolic_finish (info, res, &symbolic, &error); - g_assert (pixbuf != NULL); + paintable = gtk_icon_info_load_symbolic_finish (info, res, &symbolic, &error); + g_assert (paintable != NULL); g_assert_no_error (error); - g_object_unref (pixbuf); + g_object_unref (paintable); loaded++; } @@ -711,6 +711,7 @@ test_nonsquare_symbolic (void) GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 }; gboolean was_symbolic = FALSE; GError *error = NULL; + GdkTexture *texture; gchar *path = g_build_filename (g_test_get_dir (G_TEST_DIST), "icons", "scalable", @@ -735,20 +736,20 @@ test_nonsquare_symbolic (void) g_assert_nonnull (info); g_object_unref (pixbuf); - pixbuf = gtk_icon_info_load_symbolic (info, &black, NULL, NULL, NULL, - &was_symbolic, &error); + texture = GDK_TEXTURE (gtk_icon_info_load_symbolic (info, &black, NULL, NULL, NULL, + &was_symbolic, &error)); /* we are loaded successfully */ g_assert_no_error (error); - g_assert_nonnull (pixbuf); + g_assert_nonnull (texture); g_assert_true (was_symbolic); /* the original dimensions have been preserved */ - g_assert_cmpint (gdk_pixbuf_get_width (pixbuf), ==, width); - g_assert_cmpint (gdk_pixbuf_get_height (pixbuf), ==, height); + g_assert_cmpint (gdk_texture_get_width (texture), ==, width); + g_assert_cmpint (gdk_texture_get_height (texture), ==, height); g_free (path); - g_object_unref (pixbuf); + g_object_unref (texture); g_object_unref (file); g_object_unref (icon); g_object_unref (info);