summaryrefslogtreecommitdiff
path: root/gdk/gdkmemorytexture.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-03-12 17:17:30 +0100
committerBenjamin Otte <otte@redhat.com>2018-03-12 17:21:45 +0100
commit13d943f76353367724d5f6e9d9f5174d73f09a2e (patch)
tree3ef803f3ca8597b0ed2e3df9116fc99f01f6a896 /gdk/gdkmemorytexture.c
parente5813b3ae76c7a75ed42a932cf3b93a15596ff44 (diff)
downloadgtk+-13d943f76353367724d5f6e9d9f5174d73f09a2e.tar.gz
texture: Change download vfunc
A problem with textures is that they can become too big for GPU memory, which would require tiling. But for tiling we only need to download the pixels needed by the tile. Similarly, there might be interest to not upload full textures if a renderer knows it only needs a small part. Both of these methods require the ability to specify an area of the texture to be downloaded. So change the download vfunc to include this parameter now before we add even more textures later. A private gdk_texture_download_area() function has also been added, but nobody is using it yet.
Diffstat (limited to 'gdk/gdkmemorytexture.c')
-rw-r--r--gdk/gdkmemorytexture.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index f44dff2139..7a84e3962f 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -38,6 +38,30 @@ struct _GdkMemoryTextureClass
G_DEFINE_TYPE (GdkMemoryTexture, gdk_memory_texture, GDK_TYPE_TEXTURE)
+static gsize
+gdk_memory_format_bytes_per_pixel (GdkMemoryFormat format)
+{
+ switch (format)
+ {
+ case GDK_MEMORY_B8G8R8A8_PREMULTIPLIED:
+ case GDK_MEMORY_A8R8G8B8_PREMULTIPLIED:
+ case GDK_MEMORY_B8G8R8A8:
+ case GDK_MEMORY_A8R8G8B8:
+ case GDK_MEMORY_R8G8B8A8:
+ case GDK_MEMORY_A8B8G8R8:
+ return 4;
+
+ case GDK_MEMORY_R8G8B8:
+ case GDK_MEMORY_B8G8R8:
+ return 3;
+
+ case GDK_MEMORY_N_FORMATS:
+ default:
+ g_assert_not_reached ();
+ return 4;
+ }
+}
+
static void
gdk_memory_texture_dispose (GObject *object)
{
@@ -49,17 +73,21 @@ gdk_memory_texture_dispose (GObject *object)
}
static void
-gdk_memory_texture_download (GdkTexture *texture,
- guchar *data,
- gsize stride)
+gdk_memory_texture_download (GdkTexture *texture,
+ const GdkRectangle *area,
+ guchar *data,
+ gsize stride)
{
GdkMemoryTexture *self = GDK_MEMORY_TEXTURE (texture);
gdk_memory_convert (data, stride,
GDK_MEMORY_CAIRO_FORMAT_ARGB32,
- g_bytes_get_data (self->bytes, NULL), self->stride,
+ (guchar *) g_bytes_get_data (self->bytes, NULL)
+ + area->x * gdk_memory_format_bytes_per_pixel (self->format)
+ + area->y * self->stride,
+ self->stride,
self->format,
- texture->width, texture->height);
+ area->width, area->height);
}
static void