From 66dcbcdfe76b150673352d97086577c6d60a6265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Wed, 8 May 2019 17:04:25 +0200 Subject: cellrendererpixbuf: Avoid creating expander textures... ... every frame. Create them once when setting the pixbuf instead. --- gtk/gtkcellrendererpixbuf.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/gtk/gtkcellrendererpixbuf.c b/gtk/gtkcellrendererpixbuf.c index f30ccccf97..17ec14018c 100644 --- a/gtk/gtkcellrendererpixbuf.c +++ b/gtk/gtkcellrendererpixbuf.c @@ -94,6 +94,8 @@ struct _GtkCellRendererPixbufPrivate GdkPixbuf *pixbuf_expander_open; GdkPixbuf *pixbuf_expander_closed; + GdkTexture *texture_expander_open; + GdkTexture *texture_expander_closed; }; G_DEFINE_TYPE_WITH_PRIVATE (GtkCellRendererPixbuf, gtk_cell_renderer_pixbuf, GTK_TYPE_CELL_RENDERER) @@ -117,10 +119,10 @@ gtk_cell_renderer_pixbuf_finalize (GObject *object) gtk_image_definition_unref (priv->image_def); - if (priv->pixbuf_expander_open) - g_object_unref (priv->pixbuf_expander_open); - if (priv->pixbuf_expander_closed) - g_object_unref (priv->pixbuf_expander_closed); + g_clear_object (&priv->pixbuf_expander_open); + g_clear_object (&priv->pixbuf_expander_closed); + g_clear_object (&priv->texture_expander_open); + g_clear_object (&priv->texture_expander_closed); G_OBJECT_CLASS (gtk_cell_renderer_pixbuf_parent_class)->finalize (object); } @@ -335,14 +337,16 @@ gtk_cell_renderer_pixbuf_set_property (GObject *object, take_image_definition (cellpixbuf, gtk_image_definition_new_paintable (GDK_PAINTABLE (texture))); break; case PROP_PIXBUF_EXPANDER_OPEN: - if (priv->pixbuf_expander_open) - g_object_unref (priv->pixbuf_expander_open); + g_clear_object (&priv->pixbuf_expander_open); + g_clear_object (&priv->texture_expander_open); priv->pixbuf_expander_open = (GdkPixbuf*) g_value_dup_object (value); + priv->texture_expander_open = gdk_texture_new_for_pixbuf (priv->pixbuf_expander_open); break; case PROP_PIXBUF_EXPANDER_CLOSED: - if (priv->pixbuf_expander_closed) - g_object_unref (priv->pixbuf_expander_closed); + g_clear_object (&priv->pixbuf_expander_closed); + g_clear_object (&priv->texture_expander_closed); priv->pixbuf_expander_closed = (GdkPixbuf*) g_value_dup_object (value); + priv->texture_expander_closed = gdk_texture_new_for_pixbuf (priv->pixbuf_expander_open); break; case PROP_TEXTURE: take_image_definition (cellpixbuf, gtk_image_definition_new_paintable (g_value_get_object (value))); @@ -500,7 +504,6 @@ gtk_cell_renderer_pixbuf_snapshot (GtkCellRenderer *cell, gboolean is_expander; gint xpad, ypad; GtkIconHelper *icon_helper; - GdkTexture *texture; gtk_cell_renderer_pixbuf_get_size (cell, widget, (GdkRectangle *) cell_area, &pix_rect.x, @@ -533,16 +536,12 @@ gtk_cell_renderer_pixbuf_snapshot (GtkCellRenderer *cell, if (is_expanded && priv->pixbuf_expander_open != NULL) { icon_helper = gtk_icon_helper_new (gtk_style_context_get_node (context), widget); - texture = gdk_texture_new_for_pixbuf (priv->pixbuf_expander_open); - _gtk_icon_helper_set_paintable (icon_helper, GDK_PAINTABLE (texture)); - g_object_unref (texture); + _gtk_icon_helper_set_paintable (icon_helper, GDK_PAINTABLE (priv->texture_expander_open)); } else if (!is_expanded && priv->pixbuf_expander_closed != NULL) { icon_helper = gtk_icon_helper_new (gtk_style_context_get_node (context), widget); - texture = gdk_texture_new_for_pixbuf (priv->pixbuf_expander_closed); - _gtk_icon_helper_set_paintable (icon_helper, GDK_PAINTABLE (texture)); - g_object_unref (texture); + _gtk_icon_helper_set_paintable (icon_helper, GDK_PAINTABLE (priv->texture_expander_closed)); } else { -- cgit v1.2.1