This looks good to land to me:<div><br></div><div>Reviewed-by: Robert Bragg <<a href="mailto:robert@linux.intel.com">robert@linux.intel.com</a>></div><div><br></div><div>thanks,</div><div>- Robert</div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Nov 27, 2012 at 8:11 PM, Neil Roberts <span dir="ltr"><<a href="mailto:neil@linux.intel.com" target="_blank">neil@linux.intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
test-pixel-buffer previously had two tests, one to check filling the<br>
pixel buffer by mapping it and another to fill it by just setting the<br>
data. These tests were set up in a kind of confusing way where it<br>
would try to paint both steps and then validate them together using<br>
colors looked up from a table. This patch separates out the two tests<br>
and gets rid of the tables which hopefully makes them a bit easier to<br>
follow.<br>
<br>
The contents of the bitmap are now set to an image with has a<br>
different colour for each of its four quadrants instead of just a<br>
single colour in the hope that this will be a bit more of an extensive<br>
test.<br>
<br>
The old code had a third test that was commented out. This test has<br>
been removed.<br>
<br>
The textures are now created using cogl_texture_2d_new_* which means<br>
they won't be in the atlas. This exposes a bug where setting the<br>
entire contents of the texture won't handle errors properly and it<br>
will hit an assertion. The previous code using the atlas would end up<br>
only setting a sub-region of the larger atlas texture so the bug<br>
wouldn't be hit. To make sure we still test this code path there is<br>
now a third test which explicitly sets a sub-region of the texture<br>
using the bitmap.<br>
---<br>
 tests/conform/test-conform-main.c |   4 +-<br>
 tests/conform/test-pixel-buffer.c | 409 +++++++++++++++++++-------------------<br>
 2 files changed, 207 insertions(+), 206 deletions(-)<br>
<br>
diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c<br>
index 4b7b698..78eefc3 100644<br>
--- a/tests/conform/test-conform-main.c<br>
+++ b/tests/conform/test-conform-main.c<br>
@@ -67,7 +67,9 @@ main (int argc, char **argv)<br>
   UNPORTED_TEST (test_multitexture);<br>
   UNPORTED_TEST (test_texture_mipmaps);<br>
   ADD_TEST (test_sub_texture, 0, 0);<br>
-  ADD_TEST (test_pixel_buffer, 0, 0);<br>
+  ADD_TEST (test_pixel_buffer_map, 0, TEST_KNOWN_FAILURE);<br>
+  ADD_TEST (test_pixel_buffer_set_data, 0, TEST_KNOWN_FAILURE);<br>
+  ADD_TEST (test_pixel_buffer_sub_region, 0, 0);<br>
   UNPORTED_TEST (test_texture_rectangle);<br>
   ADD_TEST (test_texture_3d, TEST_REQUIREMENT_TEXTURE_3D, 0);<br>
   ADD_TEST (test_wrap_modes, 0, 0);<br>
diff --git a/tests/conform/test-pixel-buffer.c b/tests/conform/test-pixel-buffer.c<br>
index cd0272b..39df4ab 100644<br>
--- a/tests/conform/test-pixel-buffer.c<br>
+++ b/tests/conform/test-pixel-buffer.c<br>
@@ -3,71 +3,64 @@<br>
<br>
 #include "test-utils.h"<br>
<br>
-#define TILE_SIZE        32.0f<br>
+#define BITMAP_SIZE 256<br>
<br>
-enum<br>
-{<br>
-  TILE_MAP,<br>
-  TILE_SET_DATA,<br>
-  NB_TILES,<br>
-  TILE_SET_REGION,<br>
-};<br>
-<br>
-typedef struct test_tile<br>
-{<br>
-  uint8_t color[4];<br>
-  gfloat x, y;<br>
-  CoglBuffer *buffer;<br>
-  CoglTexture *texture;<br>
-} TestTile;<br>
-<br>
-typedef struct _TestState<br>
-{<br>
-  TestTile *tiles;<br>
-  int width;<br>
-  int height;<br>
-} TestState;<br>
-<br>
-static CoglTexture *<br>
-create_texture_from_bitmap (CoglBitmap *bitmap)<br>
+/*<br>
+ * Creates a 256 x 256 with image data split into four quadrants. The<br>
+ * colours of these in reading order will be: blue, green, cyan,<br>
+ * red */<br>
+static void<br>
+generate_bitmap_data (uint8_t *data,<br>
+                      int stride)<br>
 {<br>
-  CoglTexture *texture;<br>
-<br>
-  texture = cogl_texture_new_from_bitmap (bitmap,<br>
-                                          COGL_TEXTURE_NONE,<br>
-                                          COGL_PIXEL_FORMAT_RGBA_8888,<br>
-                                          NULL); /* don't catch errors */<br>
+  int y, x;<br>
<br>
-  g_assert (texture != NULL);<br>
-<br>
-  return texture;<br>
+  for (y = 0; y < BITMAP_SIZE; y++)<br>
+    {<br>
+      for (x = 0; x < BITMAP_SIZE; x++)<br>
+        {<br>
+          int color_num = x / (BITMAP_SIZE / 2) + y / (BITMAP_SIZE / 2) * 2 + 1;<br>
+          *(data++) = (color_num & 4) ? 255 : 0;<br>
+          *(data++) = (color_num & 2) ? 255 : 0;<br>
+          *(data++) = (color_num & 1) ? 255 : 0;<br>
+          *(data++) = 255;<br>
+        }<br>
+      data += stride - BITMAP_SIZE * 4;<br>
+    }<br>
 }<br>
<br>
-static void<br>
-create_map_tile (CoglContext *context,<br>
-                 TestTile *tile)<br>
+static CoglBitmap *<br>
+create_bitmap (void)<br>
 {<br>
   CoglBitmap *bitmap;<br>
   CoglBuffer *buffer;<br>
-  guchar *map;<br>
-  unsigned int i;<br>
-  unsigned int stride;<br>
-  uint8_t *line;<br>
<br>
-  bitmap = cogl_bitmap_new_with_size (context,<br>
-                                      TILE_SIZE,<br>
-                                      TILE_SIZE,<br>
+  bitmap = cogl_bitmap_new_with_size (test_ctx,<br>
+                                      BITMAP_SIZE,<br>
+                                      BITMAP_SIZE,<br>
                                       COGL_PIXEL_FORMAT_RGBA_8888);<br>
   buffer = COGL_BUFFER (cogl_bitmap_get_buffer (bitmap));<br>
-  stride = cogl_bitmap_get_rowstride (bitmap);<br>
<br>
   g_assert (cogl_is_pixel_buffer (buffer));<br>
   g_assert (cogl_is_buffer (buffer));<br>
<br>
   cogl_buffer_set_update_hint (buffer, COGL_BUFFER_UPDATE_HINT_DYNAMIC);<br>
   g_assert_cmpint (cogl_buffer_get_update_hint (buffer),<br>
-            ==,<br>
-            COGL_BUFFER_UPDATE_HINT_DYNAMIC);<br>
+                   ==,<br>
+                   COGL_BUFFER_UPDATE_HINT_DYNAMIC);<br>
+<br>
+  return bitmap;<br>
+}<br>
+<br>
+static CoglBitmap *<br>
+create_and_fill_bitmap (void)<br>
+{<br>
+  CoglBitmap *bitmap = create_bitmap ();<br>
+  CoglBuffer *buffer = COGL_BUFFER (cogl_bitmap_get_buffer (bitmap));<br>
+  uint8_t *map;<br>
+  unsigned int stride;<br>
+<br>
+  stride = cogl_bitmap_get_rowstride (bitmap);<br>
<br>
   map = cogl_buffer_map (buffer,<br>
                          COGL_BUFFER_ACCESS_WRITE,<br>
@@ -75,202 +68,208 @@ create_map_tile (CoglContext *context,<br>
                          NULL); /* don't catch errors */<br>
   g_assert (map);<br>
<br>
-  line = g_alloca (TILE_SIZE * 4);<br>
-  for (i = 0; i < TILE_SIZE * 4; i += 4)<br>
-    memcpy (line + i, tile->color, 4);<br>
+  generate_bitmap_data (map, stride);<br>
<br>
-  for (i = 0; i < TILE_SIZE; i++)<br>
-    memcpy (map + stride * i, line, TILE_SIZE * 4);<br>
+  cogl_buffer_unmap (COGL_BUFFER (buffer));<br>
<br>
-  cogl_buffer_unmap (buffer);<br>
+  return bitmap;<br>
+}<br>
<br>
-  tile->buffer = cogl_object_ref (buffer);<br>
-  tile->texture = create_texture_from_bitmap (bitmap);<br>
+static CoglTexture *<br>
+create_texture_from_bitmap (CoglBitmap *bitmap)<br>
+{<br>
+  CoglTexture2D *texture;<br>
<br>
-  cogl_object_unref (bitmap);<br>
+  texture = cogl_texture_2d_new_from_bitmap (bitmap,<br>
+                                             COGL_PIXEL_FORMAT_RGBA_8888,<br>
+                                             NULL); /* don't catch errors */<br>
+<br>
+  g_assert (texture != NULL);<br>
+<br>
+  return COGL_TEXTURE (texture);<br>
 }<br>
<br>
-#if 0<br>
-static void<br>
-create_set_region_tile (CoglContext *context,<br>
-                        TestTile *tile)<br>
+static CoglPipeline *<br>
+create_pipeline_from_texture (CoglTexture *texture)<br>
 {<br>
-  CoglBitmap *bitmap;<br>
-  CoglBuffer *buffer;<br>
-  uint8_t bottom_color[4];<br>
-  unsigned int rowstride = 0;<br>
-  guchar *data;<br>
-  unsigned int i;<br>
-<br>
-  bitmap = cogl_bitmap_new_with_size (context,<br>
-                                      TILE_SIZE,<br>
-                                      TILE_SIZE,<br>
-                                      COGL_PIXEL_FORMAT_RGBA_8888);<br>
-  buffer = COGL_BUFFER (cogl_bitmap_get_buffer (bitmap));<br>
-  rowstride = cogl_bitmap_get_rowstride (bitmap);<br>
-<br>
-  g_assert (cogl_is_pixel_buffer (buffer));<br>
-  g_assert (cogl_is_buffer (buffer));<br>
+  CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);<br>
<br>
-  /* while at it, set/get the hint */<br>
-  cogl_buffer_set_update_hint (buffer, COGL_BUFFER_UPDATE_HINT_STATIC);<br>
-  g_assert (cogl_buffer_get_update_hint (buffer) ==<br>
-            COGL_BUFFER_UPDATE_HINT_STATIC);<br>
+  cogl_pipeline_set_layer_texture (pipeline, 0, texture);<br>
+  cogl_pipeline_set_layer_filters (pipeline,<br>
+                                   0, /* layer_num */<br>
+                                   COGL_PIPELINE_FILTER_NEAREST,<br>
+                                   COGL_PIPELINE_FILTER_NEAREST);<br>
<br>
-  data = g_malloc (TILE_SIZE * TILE_SIZE * 4);<br>
-  /* create a buffer with the data we want to copy to the buffer */<br>
-  for (i = 0; i < TILE_SIZE * TILE_SIZE * 4; i += 4)<br>
-      memcpy (data + i, &tile->color, 4);<br>
+  return pipeline;<br>
+}<br>
<br>
-  cogl_pixel_array_set_region (buffer,<br>
-                                data,<br>
-                                TILE_SIZE, TILE_SIZE,<br>
-                                TILE_SIZE,<br>
-                                0, 0);<br>
+static void<br>
+check_colours (uint32_t color0,<br>
+               uint32_t color1,<br>
+               uint32_t color2,<br>
+               uint32_t color3)<br>
+{<br>
+  int fb_width = cogl_framebuffer_get_width (test_fb);<br>
+  int fb_height = cogl_framebuffer_get_height (test_fb);<br>
<br>
-  memcpy (bottom_color, tile->color, 4);<br>
-  for (i = 0; i < TILE_SIZE / 2; i++)<br>
-    memcpy (data + i, bottom_color, 4);<br>
+  test_utils_check_region (test_fb,<br>
+                           1, 1, /* x/y */<br>
+                           fb_width / 2 - 2, /* width */<br>
+                           fb_height / 2 - 2, /* height */<br>
+                           color0);<br>
+  test_utils_check_region (test_fb,<br>
+                           fb_width / 2 + 1, /* x */<br>
+                           1, /* y */<br>
+                           fb_width / 2 - 2, /* width */<br>
+                           fb_height / 2 - 2, /* height */<br>
+                           color1);<br>
+  test_utils_check_region (test_fb,<br>
+                           1, /* x */<br>
+                           fb_height / 2 + 1, /* y */<br>
+                           fb_width / 2 - 2, /* width */<br>
+                           fb_height / 2 - 2, /* height */<br>
+                           color2);<br>
+  test_utils_check_region (test_fb,<br>
+                           fb_width / 2 + 1, /* x */<br>
+                           fb_height / 2 + 1, /* y */<br>
+                           fb_width / 2 - 2, /* width */<br>
+                           fb_height / 2 - 2, /* height */<br>
+                           color3);<br>
+}<br>
<br>
-  cogl_buffer_set_data (buffer, 0, data, TILE_SIZE * TILE_SIZE * 4 / 2);<br>
+void<br>
+test_pixel_buffer_map (void)<br>
+{<br>
+  CoglBitmap *bitmap = create_and_fill_bitmap ();<br>
+  CoglPipeline *pipeline;<br>
+  CoglTexture *texture;<br>
<br>
-  g_free (data);<br>
+  texture = create_texture_from_bitmap (bitmap);<br>
+  pipeline = create_pipeline_from_texture (texture);<br>
<br>
-  tile->buffer = cogl_object_ref (buffer);<br>
-  tile->texture = create_texture_from_bitmap (bitmap);<br>
+  cogl_framebuffer_draw_rectangle (test_fb,<br>
+                                   pipeline,<br>
+                                   -1.0f, 1.0f,<br>
+                                   1.0f, -1.0f);<br>
<br>
   cogl_object_unref (bitmap);<br>
+  cogl_object_unref (texture);<br>
+  cogl_object_unref (pipeline);<br>
+<br>
+  check_colours (0x0000ffff,<br>
+                 0x00ff00ff,<br>
+                 0x00ffffff,<br>
+                 0xff0000ff);<br>
+<br>
+  if (cogl_test_verbose ())<br>
+    g_print ("OK\n");<br>
 }<br>
-#endif<br>
<br>
-static void<br>
-create_set_data_tile (CoglContext *context,<br>
-                      TestTile *tile)<br>
+void<br>
+test_pixel_buffer_set_data (void)<br>
 {<br>
-  CoglBitmap *bitmap;<br>
-  CoglBuffer *buffer;<br>
-  unsigned int rowstride = 0;<br>
-  CoglBool res;<br>
-  guchar *data;<br>
-  unsigned int i;<br>
-<br>
-  bitmap = cogl_bitmap_new_with_size (context,<br>
-                                      TILE_SIZE,<br>
-                                      TILE_SIZE,<br>
-                                      COGL_PIXEL_FORMAT_RGBA_8888);<br>
-  buffer = COGL_BUFFER (cogl_bitmap_get_buffer (bitmap));<br>
-  rowstride = cogl_bitmap_get_rowstride (bitmap);<br>
+  CoglBitmap *bitmap = create_bitmap ();<br>
+  CoglBuffer *buffer = COGL_BUFFER (cogl_bitmap_get_buffer (bitmap));<br>
+  CoglPipeline *pipeline;<br>
+  CoglTexture *texture;<br>
+  uint8_t *data;<br>
+  unsigned int stride;<br>
<br>
-  g_assert (cogl_is_pixel_buffer (buffer));<br>
-  g_assert (cogl_is_buffer (buffer));<br>
-  g_assert_cmpint (cogl_buffer_get_size (buffer), ==, rowstride * TILE_SIZE);<br>
+  stride = cogl_bitmap_get_rowstride (bitmap);<br>
<br>
-  /* create a buffer with the data we want to copy to the buffer */<br>
-  data = g_malloc (TILE_SIZE * TILE_SIZE * 4);<br>
-  for (i = 0; i < TILE_SIZE * TILE_SIZE * 4; i += 4)<br>
-      memcpy (data + i, tile->color, 4);<br>
+  data = g_malloc (stride * BITMAP_SIZE);<br>
<br>
-  /* FIXME: this doesn't consider the rowstride */<br>
-  res = cogl_buffer_set_data (buffer, 0, data, TILE_SIZE * TILE_SIZE * 4, NULL);<br>
-  g_assert (res);<br>
+  generate_bitmap_data (data, stride);<br>
+<br>
+  cogl_buffer_set_data (buffer,<br>
+                        0, /* offset */<br>
+                        data,<br>
+                        stride * (BITMAP_SIZE - 1) +<br>
+                        BITMAP_SIZE * 4,<br>
+                        NULL /* don't catch errors */);<br>
<br>
   g_free (data);<br>
<br>
-  tile->buffer = cogl_object_ref (buffer);<br>
-  tile->texture = create_texture_from_bitmap (bitmap);<br>
+  texture = create_texture_from_bitmap (bitmap);<br>
+  pipeline = create_pipeline_from_texture (texture);<br>
<br>
-  cogl_object_unref (bitmap);<br>
-}<br>
+  cogl_framebuffer_draw_rectangle (test_fb,<br>
+                                   pipeline,<br>
+                                   -1.0f, 1.0f,<br>
+                                   1.0f, -1.0f);<br>
<br>
-static void<br>
-draw_frame (TestState *state)<br>
-{<br>
-  unsigned int i;<br>
+  cogl_object_unref (bitmap);<br>
+  cogl_object_unref (texture);<br>
+  cogl_object_unref (pipeline);<br>
<br>
-  /* Paint the textures */<br>
-  for (i = 0; i < NB_TILES; i++)<br>
-    {<br>
-      CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);<br>
-      cogl_pipeline_set_layer_texture (pipeline, 0, state->tiles[i].texture);<br>
-      cogl_framebuffer_draw_rectangle (test_fb,<br>
-                                       pipeline,<br>
-                                       state->tiles[i].x,<br>
-                                       state->tiles[i].y,<br>
-                                       state->tiles[i].x + TILE_SIZE,<br>
-                                       state->tiles[i].y + TILE_SIZE);<br>
-      cogl_object_unref (pipeline);<br>
-    }<br>
+  check_colours (0x0000ffff,<br>
+                 0x00ff00ff,<br>
+                 0x00ffffff,<br>
+                 0xff0000ff);<br>
<br>
+  if (cogl_test_verbose ())<br>
+    g_print ("OK\n");<br>
 }<br>
<br>
-static void<br>
-validate_tile (TestState *state,<br>
-               TestTile  *tile)<br>
+static CoglTexture *<br>
+create_white_texture (void)<br>
 {<br>
-  test_utils_check_region (test_fb,<br>
-                           tile->x, tile->y,<br>
-                           TILE_SIZE, TILE_SIZE,<br>
-                           (tile->color[0] << 24) |<br>
-                           (tile->color[1] << 16) |<br>
-                           (tile->color[2] << 8) |<br>
-                           0xff);<br>
-}<br>
+  CoglTexture2D *texture;<br>
+  uint8_t *data = g_malloc (BITMAP_SIZE * BITMAP_SIZE * 4);<br>
<br>
-static void<br>
-validate_result (TestState *state)<br>
-{<br>
-  unsigned int i;<br>
+  memset (data, 255, BITMAP_SIZE * BITMAP_SIZE * 4);<br>
+<br>
+  texture = cogl_texture_2d_new_from_data (test_ctx,<br>
+                                           BITMAP_SIZE,<br>
+                                           BITMAP_SIZE,<br>
+                                           COGL_PIXEL_FORMAT_RGBA_8888,<br>
+                                           COGL_PIXEL_FORMAT_ANY,<br>
+                                           BITMAP_SIZE * 4, /* rowstride */<br>
+                                           data,<br>
+                                           NULL); /* don't catch errors */<br>
+<br>
+  g_free (data);<br>
<br>
-  for (i = 0; i < NB_TILES; i++)<br>
-    validate_tile (state, &state->tiles[i]);<br>
+  return COGL_TEXTURE (texture);<br>
 }<br>
<br>
 void<br>
-test_pixel_buffer (void)<br>
+test_pixel_buffer_sub_region (void)<br>
 {<br>
-  TestState state;<br>
-  int i;<br>
-  static TestTile tiles[NB_TILES] =<br>
-    {<br>
-        /*         color             x  y buffer tex */<br>
-<br>
-        /* MAP */<br>
-        { { 0xff, 0x00, 0x00, 0xff }, 0.0f, 0.0f, NULL, NULL },<br>
-#if 0<br>
-        /* SET_REGION */<br>
-        { { 0x7e, 0x7e, 0xff, 0x7e }, 0.0f, TILE_SIZE, NULL, NULL },<br>
-#endif<br>
-        /* SET_DATA */<br>
-        { { 0x7e, 0xff, 0x7e, 0xff }, 0.0f, TILE_SIZE, NULL, NULL }<br>
-    };<br>
-<br>
-  state.width = cogl_framebuffer_get_width (test_fb);<br>
-  state.height = cogl_framebuffer_get_height (test_fb);<br>
-  cogl_framebuffer_orthographic (test_fb,<br>
-                                 0, 0,<br>
-                                 state.width,<br>
-                                 state.height,<br>
-                                 -1,<br>
-                                 100);<br>
-<br>
-  create_map_tile (test_ctx, &tiles[TILE_MAP]);<br>
-#if 0<br>
-  create_set_region_tile (test_ctx, &tiles[TILE_SET_REGION]);<br>
-#endif<br>
-  create_set_data_tile (test_ctx, &tiles[TILE_SET_DATA]);<br>
-<br>
-  state.tiles = tiles;<br>
-<br>
-  draw_frame (&state);<br>
-  validate_result (&state);<br>
-<br>
-  for (i = 0; i < NB_TILES; i++)<br>
-    {<br>
-      cogl_object_unref (state.tiles[i].buffer);<br>
-      cogl_object_unref (state.tiles[i].texture);<br>
-    }<br>
+  CoglBitmap *bitmap = create_and_fill_bitmap ();<br>
+  CoglPipeline *pipeline;<br>
+  CoglTexture *texture;<br>
+<br>
+  texture = create_white_texture ();<br>
+<br>
+  /* Replace the top-right quadrant of the texture with the red part<br>
+   * of the bitmap */<br>
+  cogl_texture_set_region_from_bitmap (texture,<br>
+                                       BITMAP_SIZE / 2, /* src_x */<br>
+                                       BITMAP_SIZE / 2, /* src_y */<br>
+                                       BITMAP_SIZE / 2, /* dst_x */<br>
+                                       0, /* dst_y */<br>
+                                       BITMAP_SIZE / 2, /* dst_width */<br>
+                                       BITMAP_SIZE / 2, /* dst_height */<br>
+                                       bitmap,<br>
+                                       NULL /* don't catch errors */);<br>
+<br>
+  pipeline = create_pipeline_from_texture (texture);<br>
+<br>
+  cogl_framebuffer_draw_rectangle (test_fb,<br>
+                                   pipeline,<br>
+                                   -1.0f, 1.0f,<br>
+                                   1.0f, -1.0f);<br>
+<br>
+  cogl_object_unref (bitmap);<br>
+  cogl_object_unref (texture);<br>
+  cogl_object_unref (pipeline);<br>
+<br>
+  check_colours (0xffffffff,<br>
+                 0xff0000ff,<br>
+                 0xffffffff,<br>
+                 0xffffffff);<br>
<br>
   if (cogl_test_verbose ())<br>
     g_print ("OK\n");<br>
 }<br>
-<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.11.3.g3c3efa5<br>
<br>
_______________________________________________<br>
Cogl mailing list<br>
<a href="mailto:Cogl@lists.freedesktop.org">Cogl@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/cogl" target="_blank">http://lists.freedesktop.org/mailman/listinfo/cogl</a><br>
</font></span></blockquote></div><br></div>