+ task = g_task_new (icon_info, cancellable, callback, user_data);
+
+ if (icon_info_get_pixbuf_ready (icon_info))
+ {
+ pixbuf = gtk_icon_info_load_icon (icon_info, &error);
+ if (pixbuf == NULL)
+ g_task_return_error (task, error);
+ else
+ g_task_return_pointer (task, pixbuf, g_object_unref);
+ g_object_unref (task);
+ }
+ else
+ {
+ dup = icon_info_dup (icon_info);
+ g_task_set_task_data (task, dup, g_object_unref);
+ g_task_run_in_thread (task, load_icon_thread);
+ g_object_unref (task);
+ }
+}
+
+/**
+ * gtk_icon_info_load_icon_finish:
+ * @icon_info: a #GtkIconInfo structure from gtk_icon_theme_lookup_icon()
+ * @res: a #GAsyncResult
+ * @error: (allow-none): location to store error information on failure,
+ * or %NULL.
+ *
+ * Finishes an async icon load, see gtk_icon_info_load_icon_async().
+ *
+ * Return value: (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.
+ *
+ * Since: 3.8
+ **/
+GdkPixbuf *
+gtk_icon_info_load_icon_finish (GtkIconInfo *icon_info,
+ GAsyncResult *result,
+ GError **error)
+{
+ GTask *task = G_TASK (result);
+ GtkIconInfo *dup;
+
+ g_return_val_if_fail (g_task_is_valid (result, icon_info), NULL);
+
+ dup = g_task_get_task_data (task);
+ if (dup == NULL || g_task_had_error (task))
+ return g_task_propagate_pointer (task, error);
+
+ /* We ran the thread and it was not cancelled */
+
+ /* Check if someone else updated the icon_info in between */
+ if (!icon_info_get_pixbuf_ready (icon_info))
+ {
+ /* If not, copy results from dup back to icon_info */
+
+ icon_info->emblems_applied = dup->emblems_applied;
+ icon_info->scale = dup->scale;
+ g_clear_object (&icon_info->pixbuf);
+ if (dup->pixbuf)
+ icon_info->pixbuf = g_object_ref (dup->pixbuf);
+ g_clear_error (&icon_info->load_error);
+ if (dup->load_error)
+ icon_info->load_error = g_error_copy (dup->load_error);
+ }
+
+ 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);
+}
+
+static gchar *
+gdk_color_to_css (GdkColor *color)
+{
+ return g_strdup_printf ("rgb(%d,%d,%d)",
+ color->red >> 8,
+ color->green >> 8,
+ color->blue >> 8);
+}
+
+static gchar *
+gdk_rgba_to_css (const GdkRGBA *color)
+{
+ /* drop alpha for now, since librsvg does not understand rgba() */
+ return g_strdup_printf ("rgb(%d,%d,%d)",
+ (gint)(color->red * 255),
+ (gint)(color->green * 255),
+ (gint)(color->blue * 255));
+}
+
+static void
+proxy_symbolic_pixbuf_destroy (guchar *pixels, gpointer data)
+{
+ GtkIconInfo *icon_info = data;
+ GtkIconTheme *icon_theme = icon_info->in_cache;
+ SymbolicPixbufCache *symbolic_cache;
+
+ for (symbolic_cache = icon_info->symbolic_pixbuf_cache;
+ symbolic_cache != NULL;
+ symbolic_cache = symbolic_cache->next)
+ {
+ if (symbolic_cache->proxy_pixbuf != NULL &&
+ gdk_pixbuf_get_pixels (symbolic_cache->proxy_pixbuf) == pixels)
+ break;
+ }
+
+ g_assert (symbolic_cache != NULL);
+ g_assert (symbolic_cache->proxy_pixbuf != NULL);
+
+ symbolic_cache->proxy_pixbuf = NULL;
+
+ /* Keep it alive a bit longer */
+ if (icon_theme != NULL)
+ ensure_in_lru_cache (icon_theme, icon_info);
+
+ g_object_unref (icon_info);
+}
+
+static GdkPixbuf *
+symbolic_cache_get_proxy (SymbolicPixbufCache *symbolic_cache,
+ GtkIconInfo *icon_info)
+{
+ if (symbolic_cache->proxy_pixbuf)
+ return g_object_ref (symbolic_cache->proxy_pixbuf);
+
+ symbolic_cache->proxy_pixbuf =
+ gdk_pixbuf_new_from_data (gdk_pixbuf_get_pixels (symbolic_cache->pixbuf),
+ gdk_pixbuf_get_colorspace (symbolic_cache->pixbuf),
+ gdk_pixbuf_get_has_alpha (symbolic_cache->pixbuf),
+ gdk_pixbuf_get_bits_per_sample (symbolic_cache->pixbuf),
+ gdk_pixbuf_get_width (symbolic_cache->pixbuf),
+ gdk_pixbuf_get_height (symbolic_cache->pixbuf),
+ gdk_pixbuf_get_rowstride (symbolic_cache->pixbuf),
+ proxy_symbolic_pixbuf_destroy,
+ g_object_ref (icon_info));
+
+ return symbolic_cache->proxy_pixbuf;
+}
+
+static GdkPixbuf *
+_gtk_icon_info_load_symbolic_internal (GtkIconInfo *icon_info,
+ const GdkRGBA *fg,
+ const GdkRGBA *success_color,
+ const GdkRGBA *warning_color,
+ const GdkRGBA *error_color,
+ gboolean use_cache,
+ GError **error)
+{
+ GInputStream *stream;
+ GdkPixbuf *pixbuf;
+ gchar *css_fg;
+ gchar *css_success;
+ gchar *css_warning;
+ gchar *css_error;
+ gchar *data;
+ gchar *width, *height, *uri;
+ SymbolicPixbufCache *symbolic_cache;
+
+ if (use_cache)
+ {
+ symbolic_cache = symbolic_pixbuf_cache_matches (icon_info->symbolic_pixbuf_cache,
+ fg, success_color, warning_color, error_color);
+ if (symbolic_cache)
+ return symbolic_cache_get_proxy (symbolic_cache, icon_info);
+ }
+
+ /* css_fg can't possibly have failed, otherwise
+ * that would mean we have a broken style */
+ g_return_val_if_fail (fg != NULL, NULL);
+
+ css_fg = gdk_rgba_to_css (fg);
+
+ css_success = css_warning = css_error = NULL;
+
+ if (warning_color)
+ css_warning = gdk_rgba_to_css (warning_color);
+
+ if (error_color)
+ css_error = gdk_rgba_to_css (error_color);
+
+ if (success_color)
+ css_success = gdk_rgba_to_css (success_color);