[gtk/gamma-shenanigans] texture: Generalize download_16bit
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gamma-shenanigans] texture: Generalize download_16bit
- Date: Mon, 6 Sep 2021 23:52:24 +0000 (UTC)
commit 94ff25c7ff73d1d4db2a5fb10fed6b91c858bc52
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Sep 6 19:48:47 2021 -0400
texture: Generalize download_16bit
Pass a format, so we can use this vfunc for both
16bit and floating point formats.
gdk/gdkgltexture.c | 41 ++++++++++++++++++++++++++++++-----------
gdk/gdkmemorytexture.c | 7 ++++---
gdk/gdktexture.c | 12 +++++++-----
gdk/gdktextureprivate.h | 7 +++++--
4 files changed, 46 insertions(+), 21 deletions(-)
---
diff --git a/gdk/gdkgltexture.c b/gdk/gdkgltexture.c
index 974545f576..704b39cb17 100644
--- a/gdk/gdkgltexture.c
+++ b/gdk/gdkgltexture.c
@@ -112,12 +112,13 @@ gdk_gl_texture_download (GdkTexture *texture,
}
static GBytes *
-gdk_gl_texture_download_16bit (GdkTexture *texture)
+gdk_gl_texture_download_format (GdkTexture *texture,
+ GdkMemoryFormat format)
{
GdkGLTexture *self = GDK_GL_TEXTURE (texture);
GdkSurface *surface;
GdkGLContext *context;
- int format = 0;
+ int internal_format = 0;
gpointer data;
gsize size;
@@ -126,18 +127,36 @@ gdk_gl_texture_download_16bit (GdkTexture *texture)
gdk_gl_context_make_current (context);
glBindTexture (GL_TEXTURE_2D, self->id);
- glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &format);
+ glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &internal_format);
- if (format != GL_RGBA16)
- return NULL;
+ if (format == GDK_MEMORY_R16G16B16A16_PREMULTIPLIED)
+ {
+ if (format != GL_RGBA16)
+ return NULL;
+
+ size = texture->width * texture->height * 4 * sizeof (guint16);
+ data = malloc (size);
+
+ glReadPixels (0, 0, texture->width, texture->height,
+ GL_RGBA16, GL_UNSIGNED_SHORT, data);
+
+ return g_bytes_new_take (data, size);
+ }
+ else if (format == GDK_MEMORY_R32G32B32_FLOAT)
+ {
+ if (format != GL_RGB32F)
+ return NULL;
- size = texture->width * texture->height * 4 * sizeof (guint16);
- data = malloc (size);
+ size = texture->width * texture->height * 3 * sizeof (float);
+ data = malloc (size);
- glReadPixels (0, 0, texture->width, texture->height,
- GL_RGBA16, GL_UNSIGNED_SHORT, data);
+ glReadPixels (0, 0, texture->width, texture->height,
+ GL_RGBA32F, GL_FLOAT, data);
- return g_bytes_new_take (data, size);
+ return g_bytes_new_take (data, size);
+ }
+ else
+ return NULL;
}
static void
@@ -147,7 +166,7 @@ gdk_gl_texture_class_init (GdkGLTextureClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
texture_class->download = gdk_gl_texture_download;
- texture_class->download_16bit = gdk_gl_texture_download_16bit;
+ texture_class->download_format = gdk_gl_texture_download_format;
gobject_class->dispose = gdk_gl_texture_dispose;
}
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index b2bdd1d50e..dd112dfb30 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -108,11 +108,12 @@ gdk_memory_texture_download (GdkTexture *texture,
}
static GBytes *
-gdk_memory_texture_download_16bit (GdkTexture *texture)
+gdk_memory_texture_download_format (GdkTexture *texture,
+ GdkMemoryFormat format)
{
GdkMemoryTexture *self = GDK_MEMORY_TEXTURE (texture);
- if (self->format == GDK_MEMORY_R16G16B16A16_PREMULTIPLIED)
+ if (self->format == format)
return g_bytes_ref (self->bytes);
return NULL;
@@ -125,7 +126,7 @@ gdk_memory_texture_class_init (GdkMemoryTextureClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
texture_class->download = gdk_memory_texture_download;
- texture_class->download_16bit = gdk_memory_texture_download_16bit;
+ texture_class->download_format = gdk_memory_texture_download_format;
gobject_class->dispose = gdk_memory_texture_dispose;
}
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index e158b62068..d12c5af02b 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -126,7 +126,8 @@ gdk_texture_real_download (GdkTexture *self,
}
static GBytes *
-gdk_texture_real_download_16bit (GdkTexture *self)
+gdk_texture_real_download_format (GdkTexture *self,
+ GdkMemoryFormat format)
{
return NULL;
}
@@ -195,7 +196,7 @@ gdk_texture_class_init (GdkTextureClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
klass->download = gdk_texture_real_download;
- klass->download_16bit = gdk_texture_real_download_16bit;
+ klass->download_format = gdk_texture_real_download_format;
gobject_class->set_property = gdk_texture_set_property;
gobject_class->get_property = gdk_texture_get_property;
@@ -572,9 +573,10 @@ gdk_texture_download (GdkTexture *texture,
}
GBytes *
-gdk_texture_download_16bit (GdkTexture *texture)
+gdk_texture_download_format (GdkTexture *texture,
+ GdkMemoryFormat format)
{
- return GDK_TEXTURE_GET_CLASS (texture)->download_16bit (texture);
+ return GDK_TEXTURE_GET_CLASS (texture)->download_format (texture, format);
}
gboolean
@@ -647,7 +649,7 @@ gdk_texture_save_to_png (GdkTexture *texture,
image.width = gdk_texture_get_width (texture);
image.height = gdk_texture_get_height (texture);
- bytes = gdk_texture_download_16bit (texture);
+ bytes = gdk_texture_download_format (texture, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED);
if (bytes)
{
image.format = PNG_FORMAT_LINEAR_RGB_ALPHA;
diff --git a/gdk/gdktextureprivate.h b/gdk/gdktextureprivate.h
index e0b7b842a6..f00d712d08 100644
--- a/gdk/gdktextureprivate.h
+++ b/gdk/gdktextureprivate.h
@@ -2,6 +2,7 @@
#define __GDK_TEXTURE_PRIVATE_H__
#include "gdktexture.h"
+#include "gdkmemorytexture.h"
G_BEGIN_DECLS
@@ -28,7 +29,8 @@ struct _GdkTextureClass {
const GdkRectangle *area,
guchar *data,
gsize stride);
- GBytes * (* download_16bit) (GdkTexture *texture);
+ GBytes * (* download_format) (GdkTexture *texture,
+ GdkMemoryFormat format);
};
gpointer gdk_texture_new (const GdkTextureClass *klass,
@@ -49,7 +51,8 @@ void gdk_texture_clear_render_data (GdkTexture
gpointer gdk_texture_get_render_data (GdkTexture *self,
gpointer key);
-GBytes * gdk_texture_download_16bit (GdkTexture *texture);
+GBytes * gdk_texture_download_format (GdkTexture *texture,
+ GdkMemoryFormat format);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]