diff options
author | Benjamin Otte <otte@redhat.com> | 2018-04-12 13:50:33 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2018-04-12 14:02:59 +0200 |
commit | 770866f265a0dfc03a0ee1bb705e758e76749c8c (patch) | |
tree | 2823a11ff123599e879e1fa6f962d33791d8dfb7 /gdk/gdktexture.c | |
parent | 39d930c065da341999db5e7428c00b7ef5780c0d (diff) | |
download | gtk+-770866f265a0dfc03a0ee1bb705e758e76749c8c.tar.gz |
texture: Add gdk_texture_save_to_png()
It's needed for debugging Timm's code, so better have it here than
hidden in my random-patch vault.
Diffstat (limited to 'gdk/gdktexture.c')
-rw-r--r-- | gdk/gdktexture.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c index c518bac8a4..3e5f0a401a 100644 --- a/gdk/gdktexture.c +++ b/gdk/gdktexture.c @@ -552,3 +552,50 @@ gdk_texture_get_render_data (GdkTexture *self, return self->render_data; } + +/** + * gdk_texture_save_to_png: + * @texture: a #GdkTexture + * @filename: the filename to store to + * + * Store the given @texture to the @filename as a PNG file. + * + * This is a utility function intended for debugging and testing. + * If you want more control over formats, proper error handling or + * want to store to a #GFile or other location, you might want to + * look into using the gdk-pixbuf library. + * + * Returns: %TRUE if saving succeeded, %FALSE on failure. + **/ +gboolean +gdk_texture_save_to_png (GdkTexture *texture, + const char *filename) +{ + cairo_surface_t *surface; + cairo_status_t status; + gboolean result; + + g_return_val_if_fail (GDK_IS_TEXTURE (texture), FALSE); + g_return_val_if_fail (filename != NULL, FALSE); + + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, + gdk_texture_get_width (texture), + gdk_texture_get_height (texture)); + gdk_texture_download (texture, + cairo_image_surface_get_data (surface), + cairo_image_surface_get_stride (surface)); + cairo_surface_mark_dirty (surface); + + status = cairo_surface_write_to_png (surface, filename); + + if (status != CAIRO_STATUS_SUCCESS || + cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) + result = FALSE; + else + result = TRUE; + + cairo_surface_destroy (surface); + + return result; +} + |