Make it use gdk_memory_texture_from_texture().
Also make gdk_memory_format_alpha() privately available so that we can
detect if an image contains an alpha channel.
else if (G_VALUE_HOLDS (value, GDK_TYPE_TEXTURE))
{
GdkTexture *texture = g_value_get_object (value);
- cairo_surface_t *surface = gdk_texture_download_surface (texture);
- pixbuf = gdk_pixbuf_get_from_surface (surface,
- 0, 0,
- gdk_texture_get_width (texture), gdk_texture_get_height (texture));
- cairo_surface_destroy (surface);
+ pixbuf = gdk_pixbuf_get_from_texture (texture);
}
else
{
typedef struct _GdkMemoryFormatDescription GdkMemoryFormatDescription;
-typedef enum {
- GDK_MEMORY_ALPHA_PREMULTIPLIED,
- GDK_MEMORY_ALPHA_STRAIGHT,
- GDK_MEMORY_ALPHA_OPAQUE
-} GdkMemoryAlpha;
-
#define TYPED_FUNCS(name, T, R, G, B, A, bpp, scale) \
static void \
name ## _to_float (float *dest, \
return memory_formats[format].bytes_per_pixel;
}
+GdkMemoryAlpha
+gdk_memory_format_alpha (GdkMemoryFormat format)
+{
+ return memory_formats[format].alpha;
+}
+
gsize
gdk_memory_format_alignment (GdkMemoryFormat format)
{
G_BEGIN_DECLS
+typedef enum {
+ GDK_MEMORY_ALPHA_PREMULTIPLIED,
+ GDK_MEMORY_ALPHA_STRAIGHT,
+ GDK_MEMORY_ALPHA_OPAQUE
+} GdkMemoryAlpha;
+
gsize gdk_memory_format_alignment (GdkMemoryFormat format) G_GNUC_CONST;
+GdkMemoryAlpha gdk_memory_format_alpha (GdkMemoryFormat format) G_GNUC_CONST;
gsize gdk_memory_format_bytes_per_pixel (GdkMemoryFormat format) G_GNUC_CONST;
gboolean gdk_memory_format_prefers_high_depth(GdkMemoryFormat format) G_GNUC_CONST;
gboolean gdk_memory_format_gl_format (GdkMemoryFormat format,
#include "gdkpixbuf.h"
+#include "gdkmemoryformatprivate.h"
+#include "gdkmemorytextureprivate.h"
#include "gdksurface.h"
#include "gdktextureprivate.h"
return dest;
}
+static void
+pixbuf_texture_unref_cb (guchar *pixels,
+ gpointer texture)
+{
+ g_object_unref (texture);
+}
+
/**
* gdk_pixbuf_get_from_texture:
* @texture: a `GdkTexture`
GdkPixbuf *
gdk_pixbuf_get_from_texture (GdkTexture *texture)
{
- GdkPixbuf *pixbuf;
- cairo_surface_t *surface;
- int width, height;
+ GdkMemoryTexture *memtex;
+ gboolean alpha;
- g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL);
+ alpha = gdk_memory_format_alpha (gdk_texture_get_format (texture)) != GDK_MEMORY_ALPHA_OPAQUE;
- 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);
+ memtex = gdk_memory_texture_from_texture (texture,
+ alpha ? GDK_MEMORY_GDK_PIXBUF_ALPHA
+ : GDK_MEMORY_GDK_PIXBUF_OPAQUE);
- return pixbuf;
+ return gdk_pixbuf_new_from_data (gdk_memory_texture_get_data (memtex),
+ GDK_COLORSPACE_RGB,
+ alpha,
+ 8,
+ gdk_texture_get_width (GDK_TEXTURE (memtex)),
+ gdk_texture_get_height (GDK_TEXTURE (memtex)),
+ gdk_memory_texture_get_stride (memtex),
+ pixbuf_texture_unref_cb,
+ memtex);
}