Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.90 KB | None | 0 0
  1. From 674c4b5630c92f29c6d55a4660c1af0615e25215 Mon Sep 17 00:00:00 2001
  2. From: Neil Roberts <neil@linux.intel.com>
  3. Date: Thu, 24 Feb 2011 20:30:30 +0000
  4. Subject: [PATCH] Add a conformance test for atlas migration
  5.  
  6. This adds a conformance test which creates a lot of textures with
  7. increasing size and destroys them again a number of times in order to
  8. cause a few atlas migrations. The last time the textures are created
  9. they are all read back and the data is verified to confirm that the
  10. atlas migration successfully preserved the data.
  11. ---
  12. tests/conform/Makefile.am | 1 +
  13. tests/conform/test-cogl-atlas-migration.c | 133 +++++++++++++++++++++++++++++
  14. tests/conform/test-conform-main.c | 1 +
  15. 3 files changed, 135 insertions(+), 0 deletions(-)
  16. create mode 100644 tests/conform/test-cogl-atlas-migration.c
  17.  
  18. diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
  19. index 5d7e295..b86c9fa 100644
  20. --- a/tests/conform/Makefile.am
  21. +++ b/tests/conform/Makefile.am
  22. @@ -48,6 +48,7 @@ units_sources += \
  23. test-cogl-texture-mipmaps.c \
  24. test-cogl-texture-pixmap-x11.c \
  25. test-cogl-texture-rectangle.c \
  26. + test-cogl-atlas-migration.c \
  27. test-cogl-vertex-buffer-contiguous.c \
  28. test-cogl-vertex-buffer-interleved.c \
  29. test-cogl-vertex-buffer-mutability.c \
  30. diff --git a/tests/conform/test-cogl-atlas-migration.c b/tests/conform/test-cogl-atlas-migration.c
  31. new file mode 100644
  32. index 0000000..9042e8a
  33. --- /dev/null
  34. +++ b/tests/conform/test-cogl-atlas-migration.c
  35. @@ -0,0 +1,133 @@
  36. +#include <clutter/clutter.h>
  37. +
  38. +#include "test-conform-common.h"
  39. +
  40. +#define N_TEXTURES 128
  41. +
  42. +#define OPACITY_FOR_ROW(y) \
  43. + (0xff - ((y) & 0xf) * 0x10)
  44. +
  45. +#define COLOR_FOR_SIZE(size) \
  46. + (colors + (size) % 3)
  47. +
  48. +static const ClutterColor colors[] =
  49. + { { 0xff, 0x00, 0x00, 0xff },
  50. + { 0x00, 0xff, 0x00, 0xff },
  51. + { 0x00, 0x00, 0xff, 0xff } };
  52. +
  53. +static CoglHandle
  54. +create_texture (int size)
  55. +{
  56. + CoglHandle texture;
  57. + const ClutterColor *color;
  58. + guint8 *data, *p;
  59. + int x, y;
  60. +
  61. + /* Create a red, green or blue texture depending on the size */
  62. + color = COLOR_FOR_SIZE (size);
  63. +
  64. + p = data = g_malloc (size * size * 4);
  65. +
  66. + /* Fill the data with the color but fade the opacity out with
  67. + increasing y coordinates so that we can see the blending it the
  68. + atlas migration accidentally blends with garbage in the
  69. + texture */
  70. + for (y = 0; y < size; y++)
  71. + {
  72. + int opacity = OPACITY_FOR_ROW (y);
  73. +
  74. + for (x = 0; x < size; x++)
  75. + {
  76. + /* Store the colors premultiplied */
  77. + p[0] = color->red * opacity / 255;
  78. + p[1] = color->green * opacity / 255;
  79. + p[2] = color->blue * opacity / 255;
  80. + p[3] = opacity;
  81. +
  82. + p += 4;
  83. + }
  84. + }
  85. +
  86. + texture = cogl_texture_new_from_data (size, /* width */
  87. + size, /* height */
  88. + COGL_TEXTURE_NONE, /* flags */
  89. + /* format */
  90. + COGL_PIXEL_FORMAT_RGBA_8888,
  91. + /* internal format */
  92. + COGL_PIXEL_FORMAT_RGBA_8888,
  93. + /* rowstride */
  94. + size * 4,
  95. + data);
  96. +
  97. + g_free (data);
  98. +
  99. + return texture;
  100. +}
  101. +
  102. +static void
  103. +verify_texture (CoglHandle texture, int size)
  104. +{
  105. + guint8 *data, *p;
  106. + int x, y;
  107. + const ClutterColor *color;
  108. +
  109. + color = COLOR_FOR_SIZE (size);
  110. +
  111. + p = data = g_malloc (size * size * 4);
  112. +
  113. + cogl_texture_get_data (texture,
  114. + COGL_PIXEL_FORMAT_RGBA_8888,
  115. + size * 4,
  116. + data);
  117. +
  118. + for (y = 0; y < size; y++)
  119. + {
  120. + int opacity = OPACITY_FOR_ROW (y);
  121. +
  122. + for (x = 0; x < size; x++)
  123. + {
  124. + g_assert_cmpint (p[0], ==, color->red * opacity / 255);
  125. + g_assert_cmpint (p[1], ==, color->green * opacity / 255);
  126. + g_assert_cmpint (p[2], ==, color->blue * opacity / 255);
  127. + g_assert_cmpint (p[3], ==, opacity);
  128. +
  129. + p += 4;
  130. + }
  131. + }
  132. +
  133. + g_free (data);
  134. +}
  135. +
  136. +void
  137. +test_cogl_atlas_migration (TestConformSimpleFixture *fixture,
  138. + gconstpointer data)
  139. +{
  140. + CoglHandle textures[N_TEXTURES];
  141. + int i, tex_num;
  142. +
  143. + /* Create and destroy all of the textures a few times to increase
  144. + the chances that we'll end up reusing the buffers for previously
  145. + discarded atlases */
  146. + for (i = 0; i < 5; i++)
  147. + {
  148. + for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
  149. + textures[tex_num] = create_texture (tex_num + 1);
  150. + for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
  151. + cogl_object_unref (textures[tex_num]);
  152. + }
  153. +
  154. + /* Create all the textures again */
  155. + for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
  156. + textures[tex_num] = create_texture (tex_num + 1);
  157. +
  158. + /* Verify that they all still have the right data */
  159. + for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
  160. + verify_texture (textures[tex_num], tex_num + 1);
  161. +
  162. + /* Destroy them all */
  163. + for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
  164. + cogl_object_unref (textures[tex_num]);
  165. +
  166. + if (g_test_verbose ())
  167. + g_print ("OK\n");
  168. +}
  169. diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
  170. index fae6a20..7fa1e8d 100644
  171. --- a/tests/conform/test-conform-main.c
  172. +++ b/tests/conform/test-conform-main.c
  173. @@ -230,6 +230,7 @@ main (int argc, char **argv)
  174. TEST_CONFORM_SIMPLE ("/cogl/texture", test_cogl_wrap_modes);
  175. TEST_CONFORM_SIMPLE ("/cogl/texture", test_cogl_texture_pixmap_x11);
  176. TEST_CONFORM_SIMPLE ("/cogl/texture", test_cogl_texture_get_set_data);
  177. + TEST_CONFORM_SIMPLE ("/cogl/texture", test_cogl_atlas_migration);
  178.  
  179. TEST_CONFORM_SIMPLE ("/cogl/vertex-buffer", test_cogl_vertex_buffer_contiguous);
  180. TEST_CONFORM_SIMPLE ("/cogl/vertex-buffer", test_cogl_vertex_buffer_interleved);
  181. --
  182. 1.7.3.16.g9464b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement