This looks good 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><br><div class="gmail_quote">
On Fri, Nov 9, 2012 at 4:56 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">
This updates the npot-texture test to use Cogl directly instead of<br>
relying on Clutter.<br>
<br>
Note that this currently fails when Cogl ends up using sliced<br>
textures. It looks like there is some bug with the meta texture<br>
function to iterate the primitive textures. This happens when<br>
COGL_DEBUG=disable-npot-textures is set.<br>
---<br>
tests/conform/Makefile.am | 1 +<br>
tests/conform/test-conform-main.c | 2 +-<br>
tests/conform/test-npot-texture.c | 210 +++++++++++++-------------------------<br>
3 files changed, 74 insertions(+), 139 deletions(-)<br>
<br>
diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am<br>
index 9bf7987..b6430e2 100644<br>
--- a/tests/conform/Makefile.am<br>
+++ b/tests/conform/Makefile.am<br>
@@ -58,6 +58,7 @@ test_sources = \<br>
test-layer-remove.c \<br>
test-alpha-test.c \<br>
test-map-buffer-range.c \<br>
+ test-npot-texture.c \<br>
$(NULL)<br>
<br>
test_conformance_SOURCES = $(common_sources) $(test_sources)<br>
diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c<br>
index 701581c..4e2c8bb 100644<br>
--- a/tests/conform/test-conform-main.c<br>
+++ b/tests/conform/test-conform-main.c<br>
@@ -63,7 +63,7 @@ main (int argc, char **argv)<br>
<br>
ADD_TEST (test_sparse_pipeline, 0);<br>
<br>
- UNPORTED_TEST (test_npot_texture);<br>
+ ADD_TEST (test_npot_texture, TEST_REQUIREMENT_NPOT);<br>
UNPORTED_TEST (test_multitexture);<br>
UNPORTED_TEST (test_texture_mipmaps);<br>
ADD_TEST (test_sub_texture, 0);<br>
diff --git a/tests/conform/test-npot-texture.c b/tests/conform/test-npot-texture.c<br>
index 8aca4df..a2bbd9f 100644<br>
--- a/tests/conform/test-npot-texture.c<br>
+++ b/tests/conform/test-npot-texture.c<br>
@@ -1,10 +1,8 @@<br>
-#include <clutter/clutter.h><br>
#include <cogl/cogl.h><br>
-#include <string.h><br>
<br>
-#include "test-conform-common.h"<br>
+#include <string.h><br>
<br>
-static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };<br>
+#include "test-utils.h"<br>
<br>
/* Non-power-of-two sized texture that should cause slicing */<br>
#define TEXTURE_SIZE 384<br>
@@ -22,111 +20,44 @@ static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };<br>
/* The size of a part once rendered */<br>
#define PART_RENDER_SIZE (TEXTURE_RENDER_SIZE / PARTS)<br>
<br>
-static const ClutterColor corner_colors[PARTS * PARTS] =<br>
+static const uint32_t corner_colors[PARTS * PARTS] =<br>
{<br>
- /* Top left - red */ { 255, 0, 0, 255 },<br>
- /* Top right - green */ { 0, 255, 0, 255 },<br>
- /* Bottom left - blue */ { 0, 0, 255, 255 },<br>
- /* Bottom right - yellow */ { 255, 255, 0, 255 }<br>
+ /* Top left - red */ 0xff0000ff,<br>
+ /* Top right - green */ 0x00ff00ff,<br>
+ /* Bottom left - blue */ 0x0000ffff,<br>
+ /* Bottom right - yellow */ 0xffff00ff<br>
};<br>
<br>
-typedef struct _TestState<br>
-{<br>
- unsigned int frame;<br>
- CoglHandle texture;<br>
-} TestState;<br>
-<br>
-static CoglBool<br>
-validate_part (int xnum, int ynum, const ClutterColor *color)<br>
+static void<br>
+validate_part (int xnum,<br>
+ int ynum,<br>
+ uint32_t color)<br>
{<br>
- guchar *pixels, *p;<br>
- ClutterActor *stage = clutter_stage_get_default ();<br>
- CoglBool ret = TRUE;<br>
-<br>
- /* Read the appropriate part but skip out a few pixels around the<br>
- edges */<br>
- pixels = clutter_stage_read_pixels (CLUTTER_STAGE (stage),<br>
- xnum * PART_RENDER_SIZE + TEST_INSET,<br>
- ynum * PART_RENDER_SIZE + TEST_INSET,<br>
- PART_RENDER_SIZE - TEST_INSET * 2,<br>
- PART_RENDER_SIZE - TEST_INSET * 2);<br>
-<br>
- /* Make sure every pixels is the appropriate color */<br>
- for (p = pixels;<br>
- p < pixels + ((PART_RENDER_SIZE - TEST_INSET * 2)<br>
- * (PART_RENDER_SIZE - TEST_INSET * 2));<br>
- p += 4)<br>
- {<br>
- if (p[0] != color->red)<br>
- ret = FALSE;<br>
- if (p[1] != color->green)<br>
- ret = FALSE;<br>
- if (p[2] != color->blue)<br>
- ret = FALSE;<br>
- }<br>
-<br>
- g_free (pixels);<br>
-<br>
- return ret;<br>
+ test_utils_check_region (test_fb,<br>
+ xnum * PART_RENDER_SIZE + TEST_INSET,<br>
+ ynum * PART_RENDER_SIZE + TEST_INSET,<br>
+ PART_RENDER_SIZE - TEST_INSET * 2,<br>
+ PART_RENDER_SIZE - TEST_INSET * 2,<br>
+ color);<br>
}<br>
<br>
static void<br>
-validate_result (TestState *state)<br>
+validate_result (void)<br>
{<br>
/* Validate that all four corners of the texture are drawn in the<br>
right color */<br>
- g_assert (validate_part (0, 0, corner_colors + 0));<br>
- g_assert (validate_part (1, 0, corner_colors + 1));<br>
- g_assert (validate_part (0, 1, corner_colors + 2));<br>
- g_assert (validate_part (1, 1, corner_colors + 3));<br>
-<br>
- /* Comment this out if you want visual feedback of what this test<br>
- * paints.<br>
- */<br>
- clutter_main_quit ();<br>
-}<br>
-<br>
-static void<br>
-on_paint (ClutterActor *actor, TestState *state)<br>
-{<br>
- int frame_num;<br>
- int y, x;<br>
-<br>
- /* Just render the texture in the top left corner */<br>
- cogl_set_source_texture (state->texture);<br>
- /* Render the texture using four separate rectangles */<br>
- for (y = 0; y < 2; y++)<br>
- for (x = 0; x < 2; x++)<br>
- cogl_rectangle_with_texture_coords (x * TEXTURE_RENDER_SIZE / 2,<br>
- y * TEXTURE_RENDER_SIZE / 2,<br>
- (x + 1) * TEXTURE_RENDER_SIZE / 2,<br>
- (y + 1) * TEXTURE_RENDER_SIZE / 2,<br>
- x / 2.0f,<br>
- y / 2.0f,<br>
- (x + 1) / 2.0f,<br>
- (y + 1) / 2.0f);<br>
-<br>
- /* XXX: validate_result calls clutter_stage_read_pixels which will result in<br>
- * another paint run so to avoid infinite recursion we only aim to validate<br>
- * the first frame. */<br>
- frame_num = state->frame++;<br>
- if (frame_num == 1)<br>
- validate_result (state);<br>
-}<br>
-<br>
-static CoglBool<br>
-queue_redraw (void *stage)<br>
-{<br>
- clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));<br>
-<br>
- return TRUE;<br>
+ validate_part (0, 0, corner_colors[0]);<br>
+ validate_part (1, 0, corner_colors[1]);<br>
+ validate_part (0, 1, corner_colors[2]);<br>
+ validate_part (1, 1, corner_colors[3]);<br>
}<br>
<br>
-static CoglHandle<br>
+static CoglTexture *<br>
make_texture (void)<br>
{<br>
- guchar *tex_data, *p;<br>
- CoglHandle tex;<br>
+ void *tex_data;<br>
+ uint32_t *p;<br>
+ CoglTexture *tex;<br>
int partx, party, width, height;<br>
<br>
p = tex_data = g_malloc (TEXTURE_SIZE * TEXTURE_SIZE * 4);<br>
@@ -140,31 +71,26 @@ make_texture (void)<br>
<br>
for (partx = 0; partx < PARTS; partx++)<br>
{<br>
- const ClutterColor *color = corner_colors + party * PARTS + partx;<br>
+ uint32_t color = corner_colors[party * PARTS + partx];<br>
width = (partx < PARTS - 1<br>
? PART_SIZE<br>
: TEXTURE_SIZE - PART_SIZE * (PARTS - 1));<br>
<br>
while (width-- > 0)<br>
- {<br>
- *(p++) = color->red;<br>
- *(p++) = color->green;<br>
- *(p++) = color->blue;<br>
- *(p++) = color->alpha;<br>
- }<br>
+ *(p++) = GUINT32_TO_BE (color);<br>
}<br>
<br>
while (--height > 0)<br>
{<br>
- memcpy (p, p - TEXTURE_SIZE * 4, TEXTURE_SIZE * 4);<br>
- p += TEXTURE_SIZE * 4;<br>
+ memcpy (p, p - TEXTURE_SIZE, TEXTURE_SIZE * 4);<br>
+ p += TEXTURE_SIZE;<br>
}<br>
}<br>
<br>
tex = cogl_texture_new_from_data (TEXTURE_SIZE,<br>
TEXTURE_SIZE,<br>
COGL_TEXTURE_NO_ATLAS,<br>
- COGL_PIXEL_FORMAT_RGBA_8888,<br>
+ COGL_PIXEL_FORMAT_RGBA_8888_PRE,<br>
COGL_PIXEL_FORMAT_ANY,<br>
TEXTURE_SIZE * 4,<br>
tex_data);<br>
@@ -180,55 +106,63 @@ make_texture (void)<br>
}<br>
<br>
/* The texture should be sliced unless NPOTs are supported */<br>
- g_assert (cogl_features_available (COGL_FEATURE_TEXTURE_NPOT)<br>
+ g_assert (cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_NPOT)<br>
? !cogl_texture_is_sliced (tex)<br>
: cogl_texture_is_sliced (tex));<br>
<br>
return tex;<br>
}<br>
<br>
-void<br>
-test_npot_texture (TestUtilsGTestFixture *fixture,<br>
- void *data)<br>
+static void<br>
+paint (void)<br>
{<br>
- TestState state;<br>
- ClutterActor *stage;<br>
- ClutterActor *group;<br>
- unsigned int idle_source;<br>
+ CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);<br>
+ CoglTexture *texture = make_texture ();<br>
+ int y, x;<br>
+<br>
+ cogl_pipeline_set_layer_texture (pipeline, 0, texture);<br>
+<br>
+ /* Just render the texture in the top left corner */<br>
+ /* Render the texture using four separate rectangles */<br>
+ for (y = 0; y < 2; y++)<br>
+ for (x = 0; x < 2; x++)<br>
+ cogl_framebuffer_draw_textured_rectangle (test_fb,<br>
+ pipeline,<br>
+ x * TEXTURE_RENDER_SIZE / 2,<br>
+ y * TEXTURE_RENDER_SIZE / 2,<br>
+ (x + 1) *<br>
+ TEXTURE_RENDER_SIZE / 2,<br>
+ (y + 1) *<br>
+ TEXTURE_RENDER_SIZE / 2,<br>
+ x / 2.0f,<br>
+ y / 2.0f,<br>
+ (x + 1) / 2.0f,<br>
+ (y + 1) / 2.0f);<br>
+<br>
+ cogl_object_unref (pipeline);<br>
+ cogl_object_unref (texture);<br>
+}<br>
<br>
+void<br>
+test_npot_texture (void)<br>
+{<br>
if (cogl_test_verbose ())<br>
{<br>
- if (cogl_features_available (COGL_FEATURE_TEXTURE_NPOT))<br>
+ if (cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_NPOT))<br>
g_print ("NPOT textures are supported\n");<br>
else<br>
g_print ("NPOT textures are not supported\n");<br>
}<br>
<br>
- state.frame = 0;<br>
-<br>
- state.texture = make_texture ();<br>
-<br>
- stage = clutter_stage_get_default ();<br>
-<br>
- clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);<br>
-<br>
- group = clutter_group_new ();<br>
- clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);<br>
-<br>
- /* We force continuous redrawing of the stage, since we need to skip<br>
- * the first few frames, and we wont be doing anything else that<br>
- * will trigger redrawing. */<br>
- idle_source = g_idle_add (queue_redraw, stage);<br>
-<br>
- g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);<br>
-<br>
- clutter_actor_show_all (stage);<br>
-<br>
- clutter_main ();<br>
-<br>
- g_source_remove (idle_source);<br>
+ cogl_framebuffer_orthographic (test_fb,<br>
+ 0, 0,<br>
+ cogl_framebuffer_get_width (test_fb),<br>
+ cogl_framebuffer_get_height (test_fb),<br>
+ -1,<br>
+ 100);<br>
<br>
- cogl_handle_unref (state.texture);<br>
+ paint ();<br>
+ validate_result ();<br>
<br>
if (cogl_test_verbose ())<br>
g_print ("OK\n");<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>