gdk: Add GDK_MEMORY_DEFAULT
authorBenjamin Otte <otte@redhat.com>
Sun, 18 Mar 2018 03:48:06 +0000 (04:48 +0100)
committerBenjamin Otte <otte@redhat.com>
Sun, 18 Mar 2018 04:57:07 +0000 (05:57 +0100)
This is the default memory format.

I added it because it is way better than including a private header and
using GDK_MEMORY_CAIRO_FORMAT_ARGB32.

docs/reference/gdk/gdk4-sections.txt
gdk/gdkmemorytexture.h
gdk/gdkmemorytextureprivate.h
gsk/gskrendernodeimpl.c
gsk/vulkan/gskvulkanimage.c
testsuite/gdk/memorytexture.c

index 6d16ed606dba76826585401ba4708ae2ea7715dd..989c0feae1d5a8cbef3e63afa008135ae0c70401 100644 (file)
@@ -739,6 +739,8 @@ gdk_texture_new_from_file
 gdk_texture_get_width
 gdk_texture_get_height
 gdk_texture_download
+GdkMemoryFormat
+GDK_MEMORY_FORMAT_DEFAULT
 gdk_memory_texture_new
 gdk_gl_texture_new
 gdk_gl_texture_release
index d442c1fbea6dd64267d50ea964bcdac48ca973ab..31d30fbd7fb7fd370bc21dcd9be61445d43a0a03 100644 (file)
@@ -68,6 +68,24 @@ typedef enum {
   GDK_MEMORY_N_FORMATS
 } GdkMemoryFormat;
 
+/**
+ * GDK_MEMORY_DEFAULT:
+ *
+ * This is the default memory format used by GTK and is the format
+ * provided by gdk_texture_download(). It is equal to
+ * %CAIRO_FORMAT_ARGB32.
+ *
+ * Be aware that unlike the #GdkMemoryFormat values, this format is
+ * different for different endianness.
+ */
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+#define GDK_MEMORY_DEFAULT GDK_MEMORY_B8G8R8A8_PREMULTIPLIED
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+#define GDK_MEMORY_DEFAULT GDK_MEMORY_A8R8G8B8_PREMULTIPLIED
+#else
+#error "Unknown byte order for GDK_MEMORY_DEFAULT"
+#endif
+
 GDK_AVAILABLE_IN_ALL
 GdkTexture *            gdk_memory_texture_new              (int                width,
                                                              int                height,
index bb39690790c66a62f1f211ab77da911512c28eaf..9634b1ccf39853c1aef13f13977a1b3019a2fb32 100644 (file)
@@ -29,13 +29,7 @@ G_BEGIN_DECLS
 #define GDK_MEMORY_GDK_PIXBUF_OPAQUE GDK_MEMORY_R8G8B8
 #define GDK_MEMORY_GDK_PIXBUF_ALPHA GDK_MEMORY_R8G8B8A8
 
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-#define GDK_MEMORY_CAIRO_FORMAT_ARGB32 GDK_MEMORY_B8G8R8A8_PREMULTIPLIED
-#elif G_BYTE_ORDER == G_BIG_ENDIAN
-#define GDK_MEMORY_CAIRO_FORMAT_ARGB32 GDK_MEMORY_A8R8G8B8_PREMULTIPLIED
-#else
-#error "Unknown byte order."
-#endif
+#define GDK_MEMORY_CAIRO_FORMAT_ARGB32 GDK_MEMORY_DEFAULT
 
 #define GDK_TYPE_MEMORY_TEXTURE (gdk_memory_texture_get_type ())
 
index 6df5cc0d977ad44326071a2888b7c0b3efa48684..f7e552ac099a6deb116584aa8e7bed0770f338e7 100644 (file)
@@ -25,7 +25,6 @@
 #include "gskrendererprivate.h"
 #include "gskroundedrectprivate.h"
 
-#include "gdk/gdkmemorytextureprivate.h"
 #include "gdk/gdktextureprivate.h"
 
 static gboolean
@@ -755,7 +754,7 @@ gsk_texture_node_deserialize (GVariant  *variant,
     }
 
   texture = gdk_memory_texture_new (width, height,
-                                    GDK_MEMORY_CAIRO_FORMAT_ARGB32,
+                                    GDK_MEMORY_DEFAULT,
                                     bytes,
                                     width * 4);
 
index 729d99326267f6b77334b2b95ea46477cde502b3..03d76c2d057ef8f3ed472352e6f57778c798f217 100644 (file)
@@ -6,8 +6,6 @@
 #include "gskvulkanmemoryprivate.h"
 #include "gskvulkanpipelineprivate.h"
 
-#include "gdk/gdkmemorytextureprivate.h"
-
 #include <string.h>
 
 struct _GskVulkanUploader
@@ -676,7 +674,7 @@ gsk_vulkan_image_download (GskVulkanImage    *self,
   mem = gsk_vulkan_buffer_map (buffer);
   bytes = g_bytes_new (mem, self->width * self->height * 4);
   texture = gdk_memory_texture_new (self->width, self->height,
-                                    GDK_MEMORY_CAIRO_FORMAT_ARGB32,
+                                    GDK_MEMORY_DEFAULT,
                                     bytes,
                                     self->width * 4);
   gsk_vulkan_buffer_unmap (buffer);
index e4cf45117487d782eb5d6ebbfcea956bf21ec1cc..65d159068020523de6ee692a011522da3c0fc18d 100644 (file)
@@ -4,12 +4,6 @@
 /* maximum bytes per pixel */
 #define MAX_BPP 4
 
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-#define GDK_MEMORY_CAIRO_FORMAT_ARGB32 GDK_MEMORY_B8G8R8A8_PREMULTIPLIED
-#elif G_BYTE_ORDER == G_BIG_ENDIAN
-#define GDK_MEMORY_CAIRO_FORMAT_ARGB32 GDK_MEMORY_A8R8G8B8_PREMULTIPLIED
-#endif
-
 typedef enum {
   BLUE,
   GREEN,
@@ -124,7 +118,7 @@ test_download_1x1 (gconstpointer data)
   const TestData *test_data = data;
   GdkTexture *expected, *test;
 
-  expected = create_texture (GDK_MEMORY_CAIRO_FORMAT_ARGB32, test_data->color, 1, 1, tests[test_data->format].bytes_per_pixel);
+  expected = create_texture (GDK_MEMORY_DEFAULT, test_data->color, 1, 1, tests[test_data->format].bytes_per_pixel);
   test = create_texture (test_data->format, test_data->color, 1, 1, tests[test_data->format].bytes_per_pixel);
 
   compare_textures (expected, test, tests[test_data->format].opaque);
@@ -139,7 +133,7 @@ test_download_1x1_with_stride (gconstpointer data)
   const TestData *test_data = data;
   GdkTexture *expected, *test;
 
-  expected = create_texture (GDK_MEMORY_CAIRO_FORMAT_ARGB32, test_data->color, 1, 1, 4);
+  expected = create_texture (GDK_MEMORY_DEFAULT, test_data->color, 1, 1, 4);
   test = create_texture (test_data->format, test_data->color, 1, 1, 2 * MAX_BPP);
 
   compare_textures (expected, test, tests[test_data->format].opaque);
@@ -154,7 +148,7 @@ test_download_4x4 (gconstpointer data)
   const TestData *test_data = data;
   GdkTexture *expected, *test;
 
-  expected = create_texture (GDK_MEMORY_CAIRO_FORMAT_ARGB32, test_data->color, 4, 4, 16);
+  expected = create_texture (GDK_MEMORY_DEFAULT, test_data->color, 4, 4, 16);
   test = create_texture (test_data->format, test_data->color, 4, 4, 4 * tests[test_data->format].bytes_per_pixel);
 
   compare_textures (expected, test, tests[test_data->format].opaque);
@@ -169,7 +163,7 @@ test_download_4x4_with_stride (gconstpointer data)
   const TestData *test_data = data;
   GdkTexture *expected, *test;
 
-  expected = create_texture (GDK_MEMORY_CAIRO_FORMAT_ARGB32, test_data->color, 4, 4, 16);
+  expected = create_texture (GDK_MEMORY_DEFAULT, test_data->color, 4, 4, 16);
   test = create_texture (test_data->format, test_data->color, 4, 4, 4 * MAX_BPP);
 
   compare_textures (expected, test, tests[test_data->format].opaque);