Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 674c4b5630c92f29c6d55a4660c1af0615e25215 Mon Sep 17 00:00:00 2001
- From: Neil Roberts <neil@linux.intel.com>
- Date: Thu, 24 Feb 2011 20:30:30 +0000
- Subject: [PATCH] Add a conformance test for atlas migration
- This adds a conformance test which creates a lot of textures with
- increasing size and destroys them again a number of times in order to
- cause a few atlas migrations. The last time the textures are created
- they are all read back and the data is verified to confirm that the
- atlas migration successfully preserved the data.
- ---
- tests/conform/Makefile.am | 1 +
- tests/conform/test-cogl-atlas-migration.c | 133 +++++++++++++++++++++++++++++
- tests/conform/test-conform-main.c | 1 +
- 3 files changed, 135 insertions(+), 0 deletions(-)
- create mode 100644 tests/conform/test-cogl-atlas-migration.c
- diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
- index 5d7e295..b86c9fa 100644
- --- a/tests/conform/Makefile.am
- +++ b/tests/conform/Makefile.am
- @@ -48,6 +48,7 @@ units_sources += \
- test-cogl-texture-mipmaps.c \
- test-cogl-texture-pixmap-x11.c \
- test-cogl-texture-rectangle.c \
- + test-cogl-atlas-migration.c \
- test-cogl-vertex-buffer-contiguous.c \
- test-cogl-vertex-buffer-interleved.c \
- test-cogl-vertex-buffer-mutability.c \
- diff --git a/tests/conform/test-cogl-atlas-migration.c b/tests/conform/test-cogl-atlas-migration.c
- new file mode 100644
- index 0000000..9042e8a
- --- /dev/null
- +++ b/tests/conform/test-cogl-atlas-migration.c
- @@ -0,0 +1,133 @@
- +#include <clutter/clutter.h>
- +
- +#include "test-conform-common.h"
- +
- +#define N_TEXTURES 128
- +
- +#define OPACITY_FOR_ROW(y) \
- + (0xff - ((y) & 0xf) * 0x10)
- +
- +#define COLOR_FOR_SIZE(size) \
- + (colors + (size) % 3)
- +
- +static const ClutterColor colors[] =
- + { { 0xff, 0x00, 0x00, 0xff },
- + { 0x00, 0xff, 0x00, 0xff },
- + { 0x00, 0x00, 0xff, 0xff } };
- +
- +static CoglHandle
- +create_texture (int size)
- +{
- + CoglHandle texture;
- + const ClutterColor *color;
- + guint8 *data, *p;
- + int x, y;
- +
- + /* Create a red, green or blue texture depending on the size */
- + color = COLOR_FOR_SIZE (size);
- +
- + p = data = g_malloc (size * size * 4);
- +
- + /* Fill the data with the color but fade the opacity out with
- + increasing y coordinates so that we can see the blending it the
- + atlas migration accidentally blends with garbage in the
- + texture */
- + for (y = 0; y < size; y++)
- + {
- + int opacity = OPACITY_FOR_ROW (y);
- +
- + for (x = 0; x < size; x++)
- + {
- + /* Store the colors premultiplied */
- + p[0] = color->red * opacity / 255;
- + p[1] = color->green * opacity / 255;
- + p[2] = color->blue * opacity / 255;
- + p[3] = opacity;
- +
- + p += 4;
- + }
- + }
- +
- + texture = cogl_texture_new_from_data (size, /* width */
- + size, /* height */
- + COGL_TEXTURE_NONE, /* flags */
- + /* format */
- + COGL_PIXEL_FORMAT_RGBA_8888,
- + /* internal format */
- + COGL_PIXEL_FORMAT_RGBA_8888,
- + /* rowstride */
- + size * 4,
- + data);
- +
- + g_free (data);
- +
- + return texture;
- +}
- +
- +static void
- +verify_texture (CoglHandle texture, int size)
- +{
- + guint8 *data, *p;
- + int x, y;
- + const ClutterColor *color;
- +
- + color = COLOR_FOR_SIZE (size);
- +
- + p = data = g_malloc (size * size * 4);
- +
- + cogl_texture_get_data (texture,
- + COGL_PIXEL_FORMAT_RGBA_8888,
- + size * 4,
- + data);
- +
- + for (y = 0; y < size; y++)
- + {
- + int opacity = OPACITY_FOR_ROW (y);
- +
- + for (x = 0; x < size; x++)
- + {
- + g_assert_cmpint (p[0], ==, color->red * opacity / 255);
- + g_assert_cmpint (p[1], ==, color->green * opacity / 255);
- + g_assert_cmpint (p[2], ==, color->blue * opacity / 255);
- + g_assert_cmpint (p[3], ==, opacity);
- +
- + p += 4;
- + }
- + }
- +
- + g_free (data);
- +}
- +
- +void
- +test_cogl_atlas_migration (TestConformSimpleFixture *fixture,
- + gconstpointer data)
- +{
- + CoglHandle textures[N_TEXTURES];
- + int i, tex_num;
- +
- + /* Create and destroy all of the textures a few times to increase
- + the chances that we'll end up reusing the buffers for previously
- + discarded atlases */
- + for (i = 0; i < 5; i++)
- + {
- + for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
- + textures[tex_num] = create_texture (tex_num + 1);
- + for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
- + cogl_object_unref (textures[tex_num]);
- + }
- +
- + /* Create all the textures again */
- + for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
- + textures[tex_num] = create_texture (tex_num + 1);
- +
- + /* Verify that they all still have the right data */
- + for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
- + verify_texture (textures[tex_num], tex_num + 1);
- +
- + /* Destroy them all */
- + for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
- + cogl_object_unref (textures[tex_num]);
- +
- + if (g_test_verbose ())
- + g_print ("OK\n");
- +}
- diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
- index fae6a20..7fa1e8d 100644
- --- a/tests/conform/test-conform-main.c
- +++ b/tests/conform/test-conform-main.c
- @@ -230,6 +230,7 @@ main (int argc, char **argv)
- TEST_CONFORM_SIMPLE ("/cogl/texture", test_cogl_wrap_modes);
- TEST_CONFORM_SIMPLE ("/cogl/texture", test_cogl_texture_pixmap_x11);
- TEST_CONFORM_SIMPLE ("/cogl/texture", test_cogl_texture_get_set_data);
- + TEST_CONFORM_SIMPLE ("/cogl/texture", test_cogl_atlas_migration);
- TEST_CONFORM_SIMPLE ("/cogl/vertex-buffer", test_cogl_vertex_buffer_contiguous);
- TEST_CONFORM_SIMPLE ("/cogl/vertex-buffer", test_cogl_vertex_buffer_interleved);
- --
- 1.7.3.16.g9464b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement