css style funcs: Avoid pixbufs

We can get what we need with GdkTexture.
This commit is contained in:
Matthias Clasen 2017-11-30 17:40:41 -05:00
parent dc15978ac8
commit eb32a2c228

View File

@ -35,6 +35,7 @@
#include "gtkstylecontextprivate.h" #include "gtkstylecontextprivate.h"
#include "gtktypebuiltins.h" #include "gtktypebuiltins.h"
#include "gtkcsswin32sizevalueprivate.h" #include "gtkcsswin32sizevalueprivate.h"
#include <gdk/gdktextureprivate.h>
/* this is in case round() is not provided by the compiler, /* this is in case round() is not provided by the compiler,
@ -403,8 +404,7 @@ pattern_value_parse (GtkCssParser *parser,
else else
{ {
GError *error = NULL; GError *error = NULL;
gchar *path; GdkTexture *texture;
GdkPixbuf *pixbuf;
GFile *file; GFile *file;
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_pattern_t *pattern; cairo_pattern_t *pattern;
@ -414,27 +414,24 @@ pattern_value_parse (GtkCssParser *parser,
if (file == NULL) if (file == NULL)
return FALSE; return FALSE;
path = g_file_get_path (file); texture = gdk_texture_new_from_file (file, &error);
g_object_unref (file);
pixbuf = gdk_pixbuf_new_from_file (path, &error); if (texture == NULL)
g_free (path);
if (pixbuf == NULL)
{ {
_gtk_css_parser_take_error (parser, error); _gtk_css_parser_take_error (parser, error);
return FALSE; return FALSE;
} }
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL); surface = gdk_texture_download_surface (texture);
pattern = cairo_pattern_create_for_surface (surface); pattern = cairo_pattern_create_for_surface (surface);
cairo_surface_destroy (surface); cairo_surface_destroy (surface);
cairo_matrix_init_scale (&matrix, cairo_matrix_init_scale (&matrix,
gdk_pixbuf_get_width (pixbuf), gdk_texture_get_width (texture),
gdk_pixbuf_get_height (pixbuf)); gdk_texture_get_height (texture));
cairo_pattern_set_matrix (pattern, &matrix); cairo_pattern_set_matrix (pattern, &matrix);
g_object_unref (pixbuf); g_object_unref (texture);
g_value_take_boxed (value, pattern); g_value_take_boxed (value, pattern);
} }