[gtk/wip/otte/float-textures: 3/7] texture: Add GdkMemoryConversion private enum




commit f61a75f645b362641051d9525cf240c73eaa9b12
Author: Benjamin Otte <otte redhat com>
Date:   Thu Sep 9 02:05:08 2021 +0200

    texture: Add GdkMemoryConversion private enum
    
    Now gdk_memory_convert() converts to one of these conversions instead of
    re(ab)using parts of the GdkMemoryFormat enum.

 gdk/gdkglcontext.c            |  4 ++--
 gdk/gdkmemorytexture.c        | 20 ++++++++++----------
 gdk/gdkmemorytextureprivate.h | 32 +++++++++++++++++++++++---------
 gdk/gdktexture.c              |  2 +-
 gsk/ngl/gsknglglyphlibrary.c  |  2 +-
 gsk/ngl/gskngliconlibrary.c   |  2 +-
 6 files changed, 38 insertions(+), 24 deletions(-)
---
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index 58dba198ab..f957d9c1c5 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -242,7 +242,7 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
         {
           copy = g_malloc (width * height * 4);
           gdk_memory_convert (copy, width * 4,
-                              GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
+                              GDK_MEMORY_CONVERT_GLES_RGBA,
                               data, stride, data_format,
                               width, height);
           stride = width * 4;
@@ -277,7 +277,7 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
         {
           copy = g_malloc (width * height * 4);
           gdk_memory_convert (copy, width * 4,
-                              GDK_MEMORY_DEFAULT,
+                              GDK_MEMORY_CONVERT_DOWNLOAD,
                               data, stride, data_format,
                               width, height);
           stride = width * 4;
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index a8d8bbd834..ab117a01ff 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -87,7 +87,7 @@ gdk_memory_texture_download (GdkTexture *texture,
   GdkMemoryTexture *self = GDK_MEMORY_TEXTURE (texture);
 
   gdk_memory_convert (data, stride,
-                      GDK_MEMORY_CAIRO_FORMAT_ARGB32,
+                      GDK_MEMORY_CONVERT_DOWNLOAD,
                       (guchar *) g_bytes_get_data (self->bytes, NULL),
                       self->stride,
                       self->format,
@@ -288,7 +288,7 @@ typedef void (* ConversionFunc) (guchar       *dest_data,
                                  gsize         width,
                                  gsize         height);
 
-static ConversionFunc converters[GDK_MEMORY_N_FORMATS][3] =
+static ConversionFunc converters[GDK_MEMORY_N_FORMATS][GDK_MEMORY_N_CONVERSIONS] =
 {
   { convert_memcpy, convert_swizzle3210, convert_swizzle2103 },
   { convert_swizzle3210, convert_memcpy, convert_swizzle3012 },
@@ -302,14 +302,14 @@ static ConversionFunc converters[GDK_MEMORY_N_FORMATS][3] =
 };
 
 void
-gdk_memory_convert (guchar          *dest_data,
-                    gsize            dest_stride,
-                    GdkMemoryFormat  dest_format,
-                    const guchar    *src_data,
-                    gsize            src_stride,
-                    GdkMemoryFormat  src_format,
-                    gsize            width,
-                    gsize            height)
+gdk_memory_convert (guchar              *dest_data,
+                    gsize                dest_stride,
+                    GdkMemoryConversion  dest_format,
+                    const guchar        *src_data,
+                    gsize                src_stride,
+                    GdkMemoryFormat      src_format,
+                    gsize                width,
+                    gsize                height)
 {
   g_assert (dest_format < 3);
   g_assert (src_format < GDK_MEMORY_N_FORMATS);
diff --git a/gdk/gdkmemorytextureprivate.h b/gdk/gdkmemorytextureprivate.h
index 740a59da6e..a450a9a139 100644
--- a/gdk/gdkmemorytextureprivate.h
+++ b/gdk/gdkmemorytextureprivate.h
@@ -29,7 +29,21 @@ G_BEGIN_DECLS
 #define GDK_MEMORY_GDK_PIXBUF_OPAQUE GDK_MEMORY_R8G8B8
 #define GDK_MEMORY_GDK_PIXBUF_ALPHA GDK_MEMORY_R8G8B8A8
 
-#define GDK_MEMORY_CAIRO_FORMAT_ARGB32 GDK_MEMORY_DEFAULT
+typedef enum {
+  GDK_MEMORY_CONVERT_DOWNLOAD_LITTLE_ENDIAN,
+  GDK_MEMORY_CONVERT_DOWNLOAD_BIT_ENDIAN,
+  GDK_MEMORY_CONVERT_GLES_RGBA,
+
+  GDK_MEMORY_N_CONVERSIONS
+} GdkMemoryConversion;
+
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+#define GDK_MEMORY_CONVERT_DOWNLOAD GDK_MEMORY_CONVERT_DOWNLOAD_LITTLE_ENDIAN
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+#define GDK_MEMORY_CONVERT_DOWNLOAD GDK_MEMORY_CONVERT_DOWNLOAD_BIG_ENDIAN
+#else
+#error "Unknown byte order for GDK_MEMORY_CONVERT_DOWNLOAD"
+#endif
 
 gsize                   gdk_memory_format_bytes_per_pixel   (GdkMemoryFormat    format);
 
@@ -37,14 +51,14 @@ GdkMemoryFormat         gdk_memory_texture_get_format       (GdkMemoryTexture  *
 const guchar *          gdk_memory_texture_get_data         (GdkMemoryTexture  *self);
 gsize                   gdk_memory_texture_get_stride       (GdkMemoryTexture  *self);
 
-void                    gdk_memory_convert                  (guchar            *dest_data,
-                                                             gsize              dest_stride,
-                                                             GdkMemoryFormat    dest_format,
-                                                             const guchar      *src_data,
-                                                             gsize              src_stride,
-                                                             GdkMemoryFormat    src_format,
-                                                             gsize              width,
-                                                             gsize              height);
+void                    gdk_memory_convert                  (guchar                     *dest_data,
+                                                             gsize                       dest_stride,
+                                                             GdkMemoryConversion         dest_format,
+                                                             const guchar               *src_data,
+                                                             gsize                       src_stride,
+                                                             GdkMemoryFormat             src_format,
+                                                             gsize                       width,
+                                                             gsize                       height);
 
 
 G_END_DECLS
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 1f262909e0..9ae9f80944 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -262,7 +262,7 @@ gdk_texture_new_for_surface (cairo_surface_t *surface)
   
   texture = gdk_memory_texture_new (cairo_image_surface_get_width (surface),
                                     cairo_image_surface_get_height (surface),
-                                    GDK_MEMORY_CAIRO_FORMAT_ARGB32,
+                                    GDK_MEMORY_DEFAULT,
                                     bytes,
                                     cairo_image_surface_get_stride (surface));
 
diff --git a/gsk/ngl/gsknglglyphlibrary.c b/gsk/ngl/gsknglglyphlibrary.c
index 9f269d8643..8ddf1ab265 100644
--- a/gsk/ngl/gsknglglyphlibrary.c
+++ b/gsk/ngl/gsknglglyphlibrary.c
@@ -235,7 +235,7 @@ gsk_ngl_glyph_library_upload_glyph (GskNglGlyphLibrary     *self,
       pixel_data = free_data = g_malloc (width * height * 4);
       gdk_memory_convert (pixel_data,
                           width * 4,
-                          GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
+                          GDK_MEMORY_CONVERT_GLES_RGBA,
                           cairo_image_surface_get_data (surface),
                           width * 4,
                           GDK_MEMORY_DEFAULT,
diff --git a/gsk/ngl/gskngliconlibrary.c b/gsk/ngl/gskngliconlibrary.c
index 977c201051..ab4d1b4d6f 100644
--- a/gsk/ngl/gskngliconlibrary.c
+++ b/gsk/ngl/gskngliconlibrary.c
@@ -115,7 +115,7 @@ gsk_ngl_icon_library_add (GskNglIconLibrary     *self,
     {
       pixel_data = free_data = g_malloc (width * height * 4);
       gdk_memory_convert (pixel_data, width * 4,
-                          GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
+                          GDK_MEMORY_CONVERT_GLES_RGBA,
                           surface_data, cairo_image_surface_get_stride (surface),
                           GDK_MEMORY_DEFAULT, width, height);
       gl_format = GL_RGBA;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]