diff options
author | Benjamin Otte <otte@redhat.com> | 2021-09-12 04:34:42 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2021-09-12 05:54:37 +0200 |
commit | 416763bf2d31edc21608dd20cc6cf125ea3d6563 (patch) | |
tree | 5bda24a08d97f05e1de5f03775d25f7ad2529a3d | |
parent | 9179ebb28e8140c91282b6df482934e70746e98b (diff) | |
download | gtk+-wip/otte/float-textures.tar.gz |
testsuite: Add tests for gdk_texture_download_float()wip/otte/float-textures
-rw-r--r-- | testsuite/gdk/memorytexture.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/testsuite/gdk/memorytexture.c b/testsuite/gdk/memorytexture.c index 4146d476ee..021a7ad11b 100644 --- a/testsuite/gdk/memorytexture.c +++ b/testsuite/gdk/memorytexture.c @@ -353,6 +353,50 @@ compare_textures (GdkTexture *expected, g_free (test_data); } +static void +compare_textures_float (GdkTexture *expected, + GdkTexture *test, + float eps, + gboolean has_alpha) +{ + static int R = 0; + static int G = 1; + static int B = 2; + static int A = 3; + float *expected_data, *test_data; + int width, height; + int x, y; + + g_assert_cmpint (gdk_texture_get_width (expected), ==, gdk_texture_get_width (test)); + g_assert_cmpint (gdk_texture_get_height (expected), ==, gdk_texture_get_height (test)); + + width = gdk_texture_get_width (expected); + height = gdk_texture_get_height (expected); + + expected_data = g_new (float, width * height * 4); + gdk_texture_download_float (expected, expected_data, width * 4); + + test_data = g_new (float, width * height * 4); + gdk_texture_download_float (test, test_data, width * 4); + + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + g_assert_cmpfloat_with_epsilon (expected_data[y * width + 4 * x + R], test_data[y * width + 4 * x + R], eps); + g_assert_cmpfloat_with_epsilon (expected_data[y * width + 4 * x + G], test_data[y * width + 4 * x + G], eps); + g_assert_cmpfloat_with_epsilon (expected_data[y * width + 4 * x + B], test_data[y * width + 4 * x + B], eps); + if (has_alpha) + g_assert_cmpfloat_with_epsilon (expected_data[y * width + 4 * x + A], test_data[y * width + 4 * x + A], eps); + else + g_assert_cmpfloat (1.0, ==, test_data[y * width + 4 * x + A]); + } + } + + g_free (expected_data); + g_free (test_data); +} + static GdkTexture * upload_to_gl (GdkTexture *texture) { @@ -474,6 +518,59 @@ test_download_4x4 (gconstpointer data) } static void +test_download_float_1x1 (gconstpointer data) +{ + GdkMemoryFormat format; + TextureMethod method; + GdkTexture *expected, *test; + gsize i; + + decode (data, &format, &method); + + for (i = 0; i < N; i++) + { + GdkRGBA color; + + create_random_color (&color); + expected = create_texture (GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED, TEXTURE_METHOD_LOCAL, 1, 1, &color); + test = create_texture (format, method, 1, 1, &color); + + compare_textures_float (expected, test, + G_MINFLOAT, + gdk_memory_format_has_alpha (format)); + + g_object_unref (expected); + g_object_unref (test); + } +} + +static void +test_download_float_4x4 (gconstpointer data) +{ + GdkMemoryFormat format; + TextureMethod method; + GdkTexture *expected, *test; + gsize i; + + decode (data, &format, &method); + + for (i = 0; i < N; i++) + { + GdkRGBA color; + + create_random_color (&color); + expected = create_texture (GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED, TEXTURE_METHOD_LOCAL, 4, 4, &color); + test = create_texture (format, method, 4, 4, &color); + + compare_textures_float (expected, test, G_MINFLOAT, gdk_memory_format_has_alpha (format)); + + g_object_unref (expected); + g_object_unref (test); + } +} + + +static void add_test (const char *name, GTestDataFunc func) { @@ -508,6 +605,8 @@ main (int argc, char *argv[]) add_test ("/memorytexture/download_1x1", test_download_1x1); add_test ("/memorytexture/download_4x4", test_download_4x4); + add_test ("/memorytexture/download_float_1x1", test_download_float_1x1); + add_test ("/memorytexture/download_float_4x4", test_download_float_4x4); surface = gdk_surface_new_toplevel (gdk_display_get_default()); gl_renderer = gsk_ngl_renderer_new (); |