mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-28 06:21:14 +00:00
pixbuf: Use GdkTextureDownloader when downloading pixbufs
This commit is contained in:
parent
51ed1442a2
commit
4afec951c7
@ -28,6 +28,7 @@
|
|||||||
#include "gdkmemorytextureprivate.h"
|
#include "gdkmemorytextureprivate.h"
|
||||||
#include "gdksurface.h"
|
#include "gdksurface.h"
|
||||||
#include "gdktextureprivate.h"
|
#include "gdktextureprivate.h"
|
||||||
|
#include "gdktexturedownloaderprivate.h"
|
||||||
|
|
||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
|
|
||||||
@ -218,9 +219,9 @@ gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
pixbuf_texture_unref_cb (guchar *pixels,
|
pixbuf_texture_unref_cb (guchar *pixels,
|
||||||
gpointer texture)
|
gpointer bytes)
|
||||||
{
|
{
|
||||||
g_object_unref (texture);
|
g_bytes_unref (bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -238,22 +239,27 @@ pixbuf_texture_unref_cb (guchar *pixels,
|
|||||||
GdkPixbuf *
|
GdkPixbuf *
|
||||||
gdk_pixbuf_get_from_texture (GdkTexture *texture)
|
gdk_pixbuf_get_from_texture (GdkTexture *texture)
|
||||||
{
|
{
|
||||||
GdkMemoryTexture *memtex;
|
GdkTextureDownloader downloader;
|
||||||
|
GBytes *bytes;
|
||||||
|
gsize stride;
|
||||||
gboolean alpha;
|
gboolean alpha;
|
||||||
|
|
||||||
alpha = gdk_memory_format_alpha (gdk_texture_get_format (texture)) != GDK_MEMORY_ALPHA_OPAQUE;
|
alpha = gdk_memory_format_alpha (gdk_texture_get_format (texture)) != GDK_MEMORY_ALPHA_OPAQUE;
|
||||||
|
|
||||||
memtex = gdk_memory_texture_from_texture (texture,
|
gdk_texture_downloader_init (&downloader, texture);
|
||||||
|
gdk_texture_downloader_set_format (&downloader,
|
||||||
alpha ? GDK_MEMORY_GDK_PIXBUF_ALPHA
|
alpha ? GDK_MEMORY_GDK_PIXBUF_ALPHA
|
||||||
: GDK_MEMORY_GDK_PIXBUF_OPAQUE);
|
: GDK_MEMORY_GDK_PIXBUF_OPAQUE);
|
||||||
|
bytes = gdk_texture_downloader_download_bytes (&downloader, &stride);
|
||||||
|
gdk_texture_downloader_finish (&downloader);
|
||||||
|
|
||||||
return gdk_pixbuf_new_from_data (gdk_memory_texture_get_data (memtex),
|
return gdk_pixbuf_new_from_data (g_bytes_get_data (bytes, NULL),
|
||||||
GDK_COLORSPACE_RGB,
|
GDK_COLORSPACE_RGB,
|
||||||
alpha,
|
alpha,
|
||||||
8,
|
8,
|
||||||
gdk_texture_get_width (GDK_TEXTURE (memtex)),
|
gdk_texture_get_width (texture),
|
||||||
gdk_texture_get_height (GDK_TEXTURE (memtex)),
|
gdk_texture_get_height (texture),
|
||||||
gdk_memory_texture_get_stride (memtex),
|
stride,
|
||||||
pixbuf_texture_unref_cb,
|
pixbuf_texture_unref_cb,
|
||||||
memtex);
|
bytes);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user