gdk: Add gtk_pixbuf_get_from_texture
authorTimm Bäder <mail@baedert.org>
Fri, 30 Aug 2019 18:51:47 +0000 (20:51 +0200)
committerTimm Bäder <mail@baedert.org>
Mon, 9 Sep 2019 15:36:26 +0000 (17:36 +0200)
gdk/gdkpixbuf-drawable.c
gdk/gdkpixbuf.h

index fd4fa5a97a063c1d5b787575d7fdfbec3668ceb4..8bc31ba4beeaa8fe78d4597c39879598de5adf05 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "gdksurface.h"
 #include "gdkinternals.h"
+#include "gdktextureprivate.h"
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
@@ -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;
+}
index 215c2773fb786edf41fc8084d3e3e3ac64f7c92c..65e49348c274706de1fb9c5f087c0d2df63a3958 100644 (file)
@@ -33,6 +33,8 @@
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gdk/gdktypes.h>
 #include <gdk/gdkversionmacros.h>
+#include <gdk/gdktexture.h>
+
 
 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