diff --git a/src/core/gcal-shell-search-provider.c b/src/core/gcal-shell-search-provider.c index 9c6fe5ef..ba68df61 100644 --- a/src/core/gcal-shell-search-provider.c +++ b/src/core/gcal-shell-search-provider.c @@ -70,6 +70,39 @@ static GParamSpec* properties[N_PROPS] = { NULL, }; * Auxiliary methods */ +GdkTexture* +paintable_to_texture (GdkPaintable *paintable) +{ + g_autoptr (GtkSnapshot) snapshot = NULL; + g_autoptr (GskRenderNode) node = NULL; + g_autoptr (GskRenderer) renderer = NULL; + g_autoptr (GdkTexture) texture = NULL; + g_autoptr (GError) error = NULL; + graphene_rect_t viewport; + + snapshot = gtk_snapshot_new (); + gdk_paintable_snapshot (paintable, snapshot, + gdk_paintable_get_intrinsic_width (paintable), + gdk_paintable_get_intrinsic_height (paintable)); + node = gtk_snapshot_free_to_node (g_steal_pointer (&snapshot)); + + renderer = gsk_cairo_renderer_new (); + gsk_renderer_realize (renderer, NULL, &error); + if (error) + { + g_warning ("Couldn't realize Cairo renderer: %s", error->message); + return NULL; + } + + viewport = GRAPHENE_RECT_INIT (0, 0, + gdk_paintable_get_intrinsic_width (paintable), + gdk_paintable_get_intrinsic_height (paintable)); + texture = gsk_renderer_render_texture (renderer, node, &viewport); + gsk_renderer_unrealize (renderer); + + return g_steal_pointer (&texture); +} + static gint sort_event_data (GcalEvent *a, GcalEvent *b, @@ -221,8 +254,8 @@ get_result_metas_cb (GcalShellSearchProvider *self, for (i = 0; i < g_strv_length (results); i++) { g_autoptr (GdkPaintable) paintable = NULL; + g_autoptr (GdkTexture) texture = NULL; g_autoptr (GVariant) icon_variant = NULL; - g_autoptr (GdkPixbuf) gicon = NULL; uuid = results[i]; event = g_hash_table_lookup (self->events, uuid); @@ -232,8 +265,8 @@ get_result_metas_cb (GcalShellSearchProvider *self, g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_string (gcal_event_get_summary (event))); paintable = get_circle_paintable_from_color (gcal_event_get_color (event), 96); - gicon = paintable_to_pixbuf (paintable); - icon_variant = g_icon_serialize (G_ICON (gicon)); + texture = paintable_to_texture (paintable); + icon_variant = g_icon_serialize (G_ICON (texture)); g_variant_builder_add (&builder, "{sv}", "icon", icon_variant); local_datetime = g_date_time_to_local (gcal_event_get_date_start (event)); diff --git a/src/utils/gcal-utils.c b/src/utils/gcal-utils.c index ccc8a82a..c9e7b252 100644 --- a/src/utils/gcal-utils.c +++ b/src/utils/gcal-utils.c @@ -183,49 +183,6 @@ get_circle_paintable_from_color (const GdkRGBA *color, return gtk_snapshot_to_paintable (snapshot, &GRAPHENE_SIZE_INIT (size, size)); } -/** - * paintable_to_pixbuf: - * @color: a #GdkRGBA - * @size: the size of the surface - * - * Creates a circular surface filled with @color. The - * surface is always @size x @size. - * - * Returns: (transfer full): a #cairo_surface_t - */ -GdkPixbuf* -paintable_to_pixbuf (GdkPaintable *paintable) -{ - g_autoptr (GtkSnapshot) snapshot = NULL; - g_autoptr (GskRenderNode) node = NULL; - g_autoptr (GskRenderer) renderer = NULL; - g_autoptr (GdkTexture) texture = NULL; - g_autoptr (GError) error = NULL; - graphene_rect_t viewport; - - snapshot = gtk_snapshot_new (); - gdk_paintable_snapshot (paintable, snapshot, - gdk_paintable_get_intrinsic_width (paintable), - gdk_paintable_get_intrinsic_height (paintable)); - node = gtk_snapshot_free_to_node (g_steal_pointer (&snapshot)); - - renderer = gsk_cairo_renderer_new (); - gsk_renderer_realize (renderer, NULL, &error); - if (error) - { - g_warning ("Couldn't realize Cairo renderer: %s", error->message); - return NULL; - } - - viewport = GRAPHENE_RECT_INIT (0, 0, - gdk_paintable_get_intrinsic_width (paintable), - gdk_paintable_get_intrinsic_height (paintable)); - texture = gsk_renderer_render_texture (renderer, node, &viewport); - gsk_renderer_unrealize (renderer); - - return gdk_pixbuf_get_from_texture (texture); -} - /** * get_color_name_from_source: * @source: an #ESource diff --git a/src/utils/gcal-utils.h b/src/utils/gcal-utils.h index c5dd8d24..d7be86d9 100644 --- a/src/utils/gcal-utils.h +++ b/src/utils/gcal-utils.h @@ -59,8 +59,6 @@ GdkPaintable* gcal_get_paintable_from_color (const GdkRGBA GdkPaintable* get_circle_paintable_from_color (const GdkRGBA *color, gint size); -GdkPixbuf* paintable_to_pixbuf (GdkPaintable *paintable); - void get_color_name_from_source (ESource *source, GdkRGBA *out_color);