Use gdk_cairo_surface_create_from_pixbuf when possible

This commit is contained in:
Alexander Larsson 2013-06-24 12:53:53 +02:00
parent ae43f9facb
commit 6cc5d29792
3 changed files with 4 additions and 29 deletions

View File

@ -142,20 +142,12 @@ _gtk_css_image_surface_new_for_pixbuf (GdkPixbuf *pixbuf)
{ {
GtkCssImage *image; GtkCssImage *image;
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_t *cr;
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf));
cr = cairo_create (surface);
gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
cairo_paint (cr);
cairo_destroy (cr);
image = _gtk_css_image_surface_new (surface); image = _gtk_css_image_surface_new (surface);
cairo_surface_destroy (surface); cairo_surface_destroy (surface);
return image; return image;

View File

@ -766,7 +766,6 @@ pattern_value_parse (GtkCssParser *parser,
GFile *file; GFile *file;
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_pattern_t *pattern; cairo_pattern_t *pattern;
cairo_t *cr;
cairo_matrix_t matrix; cairo_matrix_t matrix;
file = _gtk_css_parser_read_url (parser); file = _gtk_css_parser_read_url (parser);
@ -784,21 +783,15 @@ pattern_value_parse (GtkCssParser *parser,
return FALSE; return FALSE;
} }
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf));
cr = cairo_create (surface);
gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
cairo_paint (cr);
pattern = cairo_pattern_create_for_surface (surface); pattern = cairo_pattern_create_for_surface (surface);
cairo_surface_destroy (surface);
cairo_matrix_init_scale (&matrix, cairo_matrix_init_scale (&matrix,
gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf)); gdk_pixbuf_get_height (pixbuf));
cairo_pattern_set_matrix (pattern, &matrix); cairo_pattern_set_matrix (pattern, &matrix);
cairo_surface_destroy (surface);
cairo_destroy (cr);
g_object_unref (pixbuf); g_object_unref (pixbuf);
g_value_take_boxed (value, pattern); g_value_take_boxed (value, pattern);

View File

@ -196,7 +196,6 @@ draw_from_gicon (GtkNumerableIcon *self)
GtkIconInfo *info; GtkIconInfo *info;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_t *cr;
if (self->priv->style != NULL) if (self->priv->style != NULL)
{ {
@ -220,16 +219,7 @@ draw_from_gicon (GtkNumerableIcon *self)
if (pixbuf == NULL) if (pixbuf == NULL)
return NULL; return NULL;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
gdk_pixbuf_get_width (pixbuf),
gdk_pixbuf_get_height (pixbuf));
cr = cairo_create (surface);
gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
cairo_paint (cr);
cairo_destroy (cr);
g_object_unref (pixbuf); g_object_unref (pixbuf);
return surface; return surface;