[gtk/wip/otte/colorspace: 8/10] texture: Make ::download() take a colorspace
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/colorspace: 8/10] texture: Make ::download() take a colorspace
- Date: Sun, 17 Oct 2021 08:02:24 +0000 (UTC)
commit b625a452427584b59d4a06b2f25fa14fbef08532
Author: Benjamin Otte <otte redhat com>
Date: Sun Oct 17 06:30:33 2021 +0200
texture: Make ::download() take a colorspace
By passing the colorspace down into the download function, we allow an
immediate conversion in the backend. This will make it possible for GL
renderers to do the conversion in a shader instead of having to use the
CPU.
gdk/gdkgltexture.c | 9 +++++++--
gdk/gdkmemorytexture.c | 5 +++--
gdk/gdktexture.c | 6 +++++-
gdk/gdktextureprivate.h | 2 ++
4 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/gdk/gdkgltexture.c b/gdk/gdkgltexture.c
index ed5977ca41..fd77cb9293 100644
--- a/gdk/gdkgltexture.c
+++ b/gdk/gdkgltexture.c
@@ -115,6 +115,7 @@ typedef struct _Download Download;
struct _Download
{
GdkMemoryFormat format;
+ GdkColorSpace *color_space;
guchar *data;
gsize stride;
};
@@ -157,6 +158,7 @@ gdk_gl_texture_do_download (gpointer texture_,
expected_stride = texture->width * gdk_memory_format_bytes_per_pixel (download->format);
if (download->stride == expected_stride &&
+ download->color_space == texture->color_space &&
!gdk_gl_context_get_use_es (self->context) &&
gdk_memory_format_gl_format (download->format, TRUE, &gl_internal_format, &gl_format, &gl_type))
{
@@ -181,6 +183,7 @@ gdk_gl_texture_do_download (gpointer texture_,
actual_format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED; /* pray */
if (download->format == actual_format &&
+ download->color_space == texture->color_space &&
(download->stride == expected_stride))
{
glReadPixels (0, 0,
@@ -203,7 +206,7 @@ gdk_gl_texture_do_download (gpointer texture_,
gdk_memory_convert (download->data,
download->stride,
download->format,
- gdk_color_space_get_srgb (),
+ download->color_space,
pixels,
texture->width * actual_bpp,
actual_format,
@@ -221,6 +224,7 @@ gdk_gl_texture_do_download (gpointer texture_,
static void
gdk_gl_texture_download (GdkTexture *texture,
GdkMemoryFormat format,
+ GdkColorSpace *color_space,
guchar *data,
gsize stride)
{
@@ -229,11 +233,12 @@ gdk_gl_texture_download (GdkTexture *texture,
if (self->saved)
{
- gdk_texture_do_download (self->saved, format, data, stride);
+ gdk_texture_do_download (self->saved, format, color_space, data, stride);
return;
}
download.format = format;
+ download.color_space = color_space;
download.data = data;
download.stride = stride;
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index e4f0893f10..0d4700886b 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -59,6 +59,7 @@ gdk_memory_texture_dispose (GObject *object)
static void
gdk_memory_texture_download (GdkTexture *texture,
GdkMemoryFormat format,
+ GdkColorSpace *color_space,
guchar *data,
gsize stride)
{
@@ -66,7 +67,7 @@ gdk_memory_texture_download (GdkTexture *texture,
gdk_memory_convert (data, stride,
format,
- gdk_color_space_get_srgb (),
+ color_space,
(guchar *) g_bytes_get_data (self->bytes, NULL),
self->stride,
texture->format,
@@ -269,7 +270,7 @@ gdk_memory_texture_from_texture (GdkTexture *texture,
stride = texture->width * gdk_memory_format_bytes_per_pixel (format);
data = g_malloc_n (stride, texture->height);
- gdk_texture_do_download (texture, format, data, stride);
+ gdk_texture_do_download (texture, format, gdk_color_space_get_srgb (), data, stride);
bytes = g_bytes_new_take (data, stride);
result = gdk_memory_texture_new (texture->width,
texture->height,
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index bff9737440..1f128379ed 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -231,6 +231,7 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkTexture, gdk_texture, G_TYPE_OBJECT,
static void
gdk_texture_default_download (GdkTexture *texture,
GdkMemoryFormat format,
+ GdkColorSpace *color_space,
guchar *data,
gsize stride)
{
@@ -724,10 +725,11 @@ gdk_texture_get_color_space (GdkTexture *texture)
void
gdk_texture_do_download (GdkTexture *texture,
GdkMemoryFormat format,
+ GdkColorSpace *color_space,
guchar *data,
gsize stride)
{
- GDK_TEXTURE_GET_CLASS (texture)->download (texture, format, data,stride);
+ GDK_TEXTURE_GET_CLASS (texture)->download (texture, format, color_space, data, stride);
}
cairo_surface_t *
@@ -793,6 +795,7 @@ gdk_texture_download (GdkTexture *texture,
gdk_texture_do_download (texture,
GDK_MEMORY_DEFAULT,
+ gdk_color_space_get_srgb (),
data,
stride);
}
@@ -838,6 +841,7 @@ gdk_texture_download_float (GdkTexture *texture,
gdk_texture_do_download (texture,
GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED,
+ gdk_color_space_get_srgb (),
(guchar *) data,
stride);
}
diff --git a/gdk/gdktextureprivate.h b/gdk/gdktextureprivate.h
index 57171adeb8..d4172f0cb1 100644
--- a/gdk/gdktextureprivate.h
+++ b/gdk/gdktextureprivate.h
@@ -29,6 +29,7 @@ struct _GdkTextureClass {
/* mandatory: Download in the given format into data */
void (* download) (GdkTexture *texture,
GdkMemoryFormat format,
+ GdkColorSpace *color_space,
guchar *data,
gsize stride);
};
@@ -40,6 +41,7 @@ cairo_surface_t * gdk_texture_download_surface (GdkTexture
void gdk_texture_do_download (GdkTexture *texture,
GdkMemoryFormat format,
+ GdkColorSpace *color_space,
guchar *data,
gsize stride);
GdkMemoryFormat gdk_texture_get_format (GdkTexture *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]