gdk: Add GDK_MEMORY_DEFAULT

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.
This commit is contained in:
Benjamin Otte 2018-03-18 04:48:06 +01:00
parent ee8e42f19b
commit d54ca3c74f
6 changed files with 27 additions and 22 deletions

View 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

View 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,

View 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 ())

View 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);

View 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);

View 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);