diff options
author | Benjamin Otte <otte@redhat.com> | 2018-03-14 04:45:25 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2018-03-16 06:04:44 +0100 |
commit | 7844320f1031cf83f69b3c15e19c7e49d038d0bb (patch) | |
tree | da46cf466cee33af39d083b32c5899816a5adeee /gtk/gtkimage.c | |
parent | c9557c207f3ca927af216723e88bfec22a37999e (diff) | |
download | gtk+-7844320f1031cf83f69b3c15e19c7e49d038d0bb.tar.gz |
image: Load resources and files into textures
Instead of loading them into surfaces (which we want to get rid of), we
load into textures.
In fact, we introduce a new paintable subclass called a GtkScaler that
takes care of tracking scaling.
This also ideally gets rid of an extra conversion once renderers learn
to render textures directly.
Diffstat (limited to 'gtk/gtkimage.c')
-rw-r--r-- | gtk/gtkimage.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c index 3013a93a29..fbddabd930 100644 --- a/gtk/gtkimage.c +++ b/gtk/gtkimage.c @@ -31,6 +31,7 @@ #include "gtkicontheme.h" #include "gtkintl.h" #include "gtkprivate.h" +#include "gtkscalerprivate.h" #include "gtksnapshot.h" #include "gtktypebuiltins.h" #include "gtkwidgetprivate.h" @@ -729,7 +730,8 @@ gtk_image_set_from_file (GtkImage *image, GtkImagePrivate *priv = gtk_image_get_instance_private (image); GdkPixbufAnimation *anim; gint scale_factor; - cairo_surface_t *surface; + GdkTexture *texture; + GdkPaintable *scaler; g_return_if_fail (GTK_IS_IMAGE (image)); @@ -753,11 +755,13 @@ gtk_image_set_from_file (GtkImage *image, return; } - surface = gdk_cairo_surface_create_from_pixbuf (gdk_pixbuf_animation_get_static_image (anim), - scale_factor, _gtk_widget_get_window (GTK_WIDGET (image))); - gtk_image_set_from_surface (image, surface); - cairo_surface_destroy (surface); + texture = gdk_texture_new_for_pixbuf (gdk_pixbuf_animation_get_static_image (anim)); + scaler = gtk_scaler_new (GDK_PAINTABLE (texture), scale_factor); + gtk_image_set_from_paintable (image, scaler); + + g_object_unref (scaler); + g_object_unref (texture); g_object_unref (anim); priv->filename = g_strdup (filename); @@ -809,7 +813,8 @@ gtk_image_set_from_resource (GtkImage *image, GtkImagePrivate *priv = gtk_image_get_instance_private (image); GdkPixbufAnimation *animation; gint scale_factor = 1; - cairo_surface_t *surface; + GdkTexture *texture; + GdkPaintable *scaler; g_return_if_fail (GTK_IS_IMAGE (image)); @@ -840,10 +845,13 @@ gtk_image_set_from_resource (GtkImage *image, return; } - surface = gdk_cairo_surface_create_from_pixbuf (gdk_pixbuf_animation_get_static_image (animation), - scale_factor, _gtk_widget_get_window (GTK_WIDGET (image))); - gtk_image_set_from_surface (image, surface); - cairo_surface_destroy (surface); + texture = gdk_texture_new_for_pixbuf (gdk_pixbuf_animation_get_static_image (animation)); + scaler = gtk_scaler_new (GDK_PAINTABLE (texture), scale_factor); + + gtk_image_set_from_paintable (image, scaler); + + g_object_unref (scaler); + g_object_unref (texture); priv->resource_path = g_strdup (resource_path); |