diff options
author | Alexander Larsson <alexl@redhat.com> | 2013-06-24 12:12:43 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2013-07-03 14:34:13 +0200 |
commit | 8524e0c1507043c6c230828493e52ce666e67a5a (patch) | |
tree | 07eb8a99576fb27b0aaa9cd7d878515e6486c0bf /gdk/gdkcairo.c | |
parent | 04f83a56a2080f8c6947ff42535363331b16c39a (diff) | |
download | gtk+-8524e0c1507043c6c230828493e52ce666e67a5a.tar.gz |
gdk: Add gdk_cairo_surface_create_from_pixbuf
Diffstat (limited to 'gdk/gdkcairo.c')
-rw-r--r-- | gdk/gdkcairo.c | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/gdk/gdkcairo.c b/gdk/gdkcairo.c index 2e1d8dc3f8..74bc63611a 100644 --- a/gdk/gdkcairo.c +++ b/gdk/gdkcairo.c @@ -176,24 +176,20 @@ gdk_cairo_region (cairo_t *cr, } /** - * gdk_cairo_set_source_pixbuf: - * @cr: a cairo context + * gdk_cairo_surface_create_from_pixbuf: * @pixbuf: a #GdkPixbuf - * @pixbuf_x: X coordinate of location to place upper left corner of @pixbuf - * @pixbuf_y: Y coordinate of location to place upper left corner of @pixbuf - * - * Sets the given pixbuf as the source pattern for @cr. + * @scale: the scale of the new surface, or 0 to use same as @window + * @for_window: The window this will be drawn to, on %NULL. * - * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned - * so that the origin of @pixbuf is @pixbuf_x, @pixbuf_y. + * Creates an image surface with the same contents as + * the pixbuf. * - * Since: 2.8 + * Since: 3.10 */ -void -gdk_cairo_set_source_pixbuf (cairo_t *cr, - const GdkPixbuf *pixbuf, - gdouble pixbuf_x, - gdouble pixbuf_y) +cairo_surface_t * +gdk_cairo_surface_create_from_pixbuf (const GdkPixbuf *pixbuf, + int scale, + GdkWindow *for_window) { gint width = gdk_pixbuf_get_width (pixbuf); gint height = gdk_pixbuf_get_height (pixbuf); @@ -204,7 +200,6 @@ gdk_cairo_set_source_pixbuf (cairo_t *cr, guchar *cairo_pixels; cairo_format_t format; cairo_surface_t *surface; - static const cairo_user_data_key_t key; int j; if (n_channels == 3) @@ -212,14 +207,13 @@ gdk_cairo_set_source_pixbuf (cairo_t *cr, else format = CAIRO_FORMAT_ARGB32; - cairo_stride = cairo_format_stride_for_width (format, width); - cairo_pixels = g_malloc_n (height, cairo_stride); - surface = cairo_image_surface_create_for_data ((unsigned char *)cairo_pixels, - format, - width, height, cairo_stride); - - cairo_surface_set_user_data (surface, &key, - cairo_pixels, (cairo_destroy_func_t)g_free); + surface = + gdk_window_create_similar_image_surface (for_window, + format, + width, height, + scale); + cairo_stride = cairo_image_surface_get_stride (surface); + cairo_pixels = cairo_image_surface_get_data (surface); for (j = height; j; j--) { @@ -277,6 +271,33 @@ gdk_cairo_set_source_pixbuf (cairo_t *cr, cairo_pixels += cairo_stride; } + cairo_surface_mark_dirty (surface); + return surface; +} + +/** + * gdk_cairo_set_source_pixbuf: + * @cr: a cairo context + * @pixbuf: a #GdkPixbuf + * @pixbuf_x: X coordinate of location to place upper left corner of @pixbuf + * @pixbuf_y: Y coordinate of location to place upper left corner of @pixbuf + * + * Sets the given pixbuf as the source pattern for @cr. + * + * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned + * so that the origin of @pixbuf is @pixbuf_x, @pixbuf_y. + * + * Since: 2.8 + */ +void +gdk_cairo_set_source_pixbuf (cairo_t *cr, + const GdkPixbuf *pixbuf, + gdouble pixbuf_x, + gdouble pixbuf_y) +{ + cairo_surface_t *surface; + + surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL); cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y); cairo_surface_destroy (surface); } |