diff options
author | Alexander Larsson <alexl@redhat.com> | 2017-10-23 14:47:50 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2017-10-23 15:28:33 +0200 |
commit | 2b194089dd525b74c532fdd95c0ab654ac88d295 (patch) | |
tree | a50d83a1288ac22eb431dda63985b5f9909ea898 /gtk/gtktoolbutton.c | |
parent | 7ee2ab32b89e34d312cb4138a2832522a28ce9f1 (diff) | |
download | gtk+-2b194089dd525b74c532fdd95c0ab654ac88d295.tar.gz |
GtkImage: Drop support for storing pixbufs
This drops the pixbuf property and the pixbuf getters. We keep
gtk_image_new/set_from_pixbuf, but these are small helpers that
immediately convert to a surface, and there is no way to later get
back the pixbuf you passed in.
The from file/resource codepaths are also changed to load a surface
instead of a pixbuf.
Diffstat (limited to 'gtk/gtktoolbutton.c')
-rw-r--r-- | gtk/gtktoolbutton.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/gtk/gtktoolbutton.c b/gtk/gtktoolbutton.c index c94e1fd226..a3c019e496 100644 --- a/gtk/gtktoolbutton.c +++ b/gtk/gtktoolbutton.c @@ -723,21 +723,32 @@ clone_image_menu_size (GtkImage *image) gtk_image_get_gicon (image, &icon, NULL); return gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU); } - else if (storage_type == GTK_IMAGE_PIXBUF) + else if (storage_type == GTK_IMAGE_SURFACE) { gint width, height; - - if (gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height)) - { - GdkPixbuf *src_pixbuf, *dest_pixbuf; - GtkWidget *cloned_image; - src_pixbuf = gtk_image_get_pixbuf (image); - dest_pixbuf = gdk_pixbuf_scale_simple (src_pixbuf, width, height, - GDK_INTERP_BILINEAR); - - cloned_image = gtk_image_new_from_pixbuf (dest_pixbuf); - g_object_unref (dest_pixbuf); + if (gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height)) + { + cairo_surface_t *src_surface, *dest_surface; + GtkWidget *cloned_image; + gint scale = gtk_widget_get_scale_factor (GTK_WIDGET (image)); + cairo_t *cr; + + src_surface = gtk_image_get_surface (image); + dest_surface = + gdk_window_create_similar_image_surface (gtk_widget_get_window (GTK_WIDGET(image)), + CAIRO_FORMAT_ARGB32, + width * scale, height * scale, scale); + cr = cairo_create (dest_surface); + cairo_set_source_surface (cr, src_surface, 0, 0); + cairo_scale (cr, + width / cairo_image_surface_get_width (src_surface), + height / cairo_image_surface_get_height (src_surface)); + cairo_paint (cr); + cairo_destroy (cr); + + cloned_image = gtk_image_new_from_surface (dest_surface); + cairo_surface_destroy (dest_surface); return cloned_image; } |