From: Timm Bäder Date: Fri, 30 Aug 2019 18:51:47 +0000 (+0200) Subject: gdk: Add gtk_pixbuf_get_from_texture X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~20^2~896 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=37f8e6aabd8d6953dc197e75a7e8fdf9f4da6fda;p=gtk4.git gdk: Add gtk_pixbuf_get_from_texture --- diff --git a/gdk/gdkpixbuf-drawable.c b/gdk/gdkpixbuf-drawable.c index fd4fa5a97a..8bc31ba4be 100644 --- a/gdk/gdkpixbuf-drawable.c +++ b/gdk/gdkpixbuf-drawable.c @@ -26,6 +26,7 @@ #include "gdksurface.h" #include "gdkinternals.h" +#include "gdktextureprivate.h" #include @@ -222,3 +223,31 @@ gdk_pixbuf_get_from_surface (cairo_surface_t *surface, cairo_surface_destroy (surface); return dest; } + +/** + * gdk_pixbuf_get_from_texture: + * @texture: a #GdkTexture + * + * Creates a new pixbuf from @texture. This should generally not be used + * in newly written code as later stages will almost certainly convert + * the pixbuf back into a texture to draw it on screen. + * + * returns: a new #GdkPixbuf + */ +GdkPixbuf * +gdk_pixbuf_get_from_texture (GdkTexture *texture) +{ + GdkPixbuf *pixbuf; + cairo_surface_t *surface; + int width, height; + + g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL); + + width = gdk_texture_get_width (texture); + height = gdk_texture_get_height (texture); + surface = gdk_texture_download_surface (texture); + pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height); + cairo_surface_destroy (surface); + + return pixbuf; +} diff --git a/gdk/gdkpixbuf.h b/gdk/gdkpixbuf.h index 215c2773fb..65e49348c2 100644 --- a/gdk/gdkpixbuf.h +++ b/gdk/gdkpixbuf.h @@ -33,6 +33,8 @@ #include #include #include +#include + G_BEGIN_DECLS @@ -42,6 +44,8 @@ GdkPixbuf *gdk_pixbuf_get_from_surface (cairo_surface_t *surface, gint src_y, gint width, gint height); +GDK_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_get_from_texture (GdkTexture *texture); G_END_DECLS