mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 10:00:45 -05:00
tests: Port blend-strings to test both the legacy and the new API
https://bugzilla.gnome.org/show_bug.cgi?id=660617 Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
parent
0a70a159c6
commit
bdfaf94afb
@ -11,7 +11,6 @@ common_sources = \
|
|||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
unported_test_sources = \
|
unported_test_sources = \
|
||||||
test-blend-strings.c \
|
|
||||||
test-fixed.c \
|
test-fixed.c \
|
||||||
test-materials.c \
|
test-materials.c \
|
||||||
test-viewport.c \
|
test-viewport.c \
|
||||||
@ -38,6 +37,7 @@ unported_test_sources = \
|
|||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
test_sources = \
|
test_sources = \
|
||||||
|
test-blend-strings.c \
|
||||||
test-depth-test.c \
|
test-depth-test.c \
|
||||||
test-color-mask.c \
|
test-color-mask.c \
|
||||||
test-backface-culling.c \
|
test-backface-culling.c \
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
|
|
||||||
#include <clutter/clutter.h>
|
|
||||||
#include <cogl/cogl.h>
|
#include <cogl/cogl.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "test-conform-common.h"
|
#include "test-utils.h"
|
||||||
|
|
||||||
static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
|
|
||||||
|
|
||||||
#define QUAD_WIDTH 20
|
#define QUAD_WIDTH 20
|
||||||
|
|
||||||
@ -24,30 +21,28 @@ static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
|
|||||||
|
|
||||||
typedef struct _TestState
|
typedef struct _TestState
|
||||||
{
|
{
|
||||||
ClutterGeometry stage_geom;
|
int dummy;
|
||||||
} TestState;
|
} TestState;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
check_pixel (GLubyte *pixel, guint32 color)
|
check_pixel (int x, int y, guint32 expected_pixel)
|
||||||
{
|
{
|
||||||
guint8 r = MASK_RED (color);
|
guint32 pixel;
|
||||||
guint8 g = MASK_GREEN (color);
|
char *screen_pixel;
|
||||||
guint8 b = MASK_BLUE (color);
|
char *intended_pixel;
|
||||||
guint8 a = MASK_ALPHA (color);
|
|
||||||
|
|
||||||
if (g_test_verbose ())
|
cogl_read_pixels (x, y, 1, 1, COGL_READ_PIXELS_COLOR_BUFFER,
|
||||||
g_print (" expected = %x, %x, %x, %x\n",
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
||||||
r, g, b, a);
|
(guint8 *) &pixel);
|
||||||
/* FIXME - allow for hardware in-precision */
|
|
||||||
g_assert_cmpint (pixel[RED], ==, r);
|
|
||||||
g_assert_cmpint (pixel[GREEN], ==, g);
|
|
||||||
g_assert_cmpint (pixel[BLUE], ==, b);
|
|
||||||
|
|
||||||
/* FIXME
|
screen_pixel = g_strdup_printf ("#%06x", GUINT32_FROM_BE (pixel) >> 8);
|
||||||
* We ignore the alpha, since we don't know if our render target is
|
intended_pixel = g_strdup_printf ("#%06x", expected_pixel >> 8);
|
||||||
* RGB or RGBA */
|
|
||||||
/* g_assert (pixel[ALPHA] == a); */
|
g_assert_cmpstr (screen_pixel, ==, intended_pixel);
|
||||||
|
|
||||||
|
g_free (screen_pixel);
|
||||||
|
g_free (intended_pixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -78,11 +73,84 @@ test_blend (TestState *state,
|
|||||||
CoglColor blend_const_color;
|
CoglColor blend_const_color;
|
||||||
|
|
||||||
CoglHandle material;
|
CoglHandle material;
|
||||||
|
CoglPipeline *pipeline;
|
||||||
gboolean status;
|
gboolean status;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GLubyte pixel[4];
|
int y_off;
|
||||||
GLint y_off;
|
int x_off;
|
||||||
GLint x_off;
|
|
||||||
|
/* First write out the destination color without any blending... */
|
||||||
|
pipeline = cogl_pipeline_new ();
|
||||||
|
cogl_pipeline_set_color4ub (pipeline, Dr, Dg, Db, Da);
|
||||||
|
cogl_pipeline_set_blend (pipeline, "RGBA = ADD (SRC_COLOR, 0)", NULL);
|
||||||
|
cogl_set_source (pipeline);
|
||||||
|
cogl_rectangle (x * QUAD_WIDTH,
|
||||||
|
y * QUAD_WIDTH,
|
||||||
|
x * QUAD_WIDTH + QUAD_WIDTH,
|
||||||
|
y * QUAD_WIDTH + QUAD_WIDTH);
|
||||||
|
cogl_object_unref (pipeline);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now blend a rectangle over our well defined destination:
|
||||||
|
*/
|
||||||
|
|
||||||
|
pipeline = cogl_pipeline_new ();
|
||||||
|
cogl_pipeline_set_color4ub (pipeline, Sr, Sg, Sb, Sa);
|
||||||
|
|
||||||
|
status = cogl_pipeline_set_blend (pipeline, blend_string, &error);
|
||||||
|
if (!status)
|
||||||
|
{
|
||||||
|
/* It's not strictly a test failure; you need a more capable GPU or
|
||||||
|
* driver to test this blend string. */
|
||||||
|
if (g_test_verbose ())
|
||||||
|
{
|
||||||
|
g_debug ("Failed to test blend string %s: %s",
|
||||||
|
blend_string, error->message);
|
||||||
|
g_print ("Skipping\n");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cogl_color_init_from_4ub (&blend_const_color, Br, Bg, Bb, Ba);
|
||||||
|
cogl_pipeline_set_blend_constant (pipeline, &blend_const_color);
|
||||||
|
|
||||||
|
cogl_set_source (pipeline);
|
||||||
|
cogl_rectangle (x * QUAD_WIDTH,
|
||||||
|
y * QUAD_WIDTH,
|
||||||
|
x * QUAD_WIDTH + QUAD_WIDTH,
|
||||||
|
y * QUAD_WIDTH + QUAD_WIDTH);
|
||||||
|
cogl_object_unref (pipeline);
|
||||||
|
|
||||||
|
/* See what we got... */
|
||||||
|
|
||||||
|
y_off = y * QUAD_WIDTH + (QUAD_WIDTH / 2);
|
||||||
|
x_off = x * QUAD_WIDTH + (QUAD_WIDTH / 2);
|
||||||
|
|
||||||
|
if (g_test_verbose ())
|
||||||
|
{
|
||||||
|
g_print ("test_blend (%d, %d):\n%s\n", x, y, blend_string);
|
||||||
|
g_print (" src color = %02x, %02x, %02x, %02x\n", Sr, Sg, Sb, Sa);
|
||||||
|
g_print (" dst color = %02x, %02x, %02x, %02x\n", Dr, Dg, Db, Da);
|
||||||
|
if (blend_constant != BLEND_CONSTANT_UNUSED)
|
||||||
|
g_print (" blend constant = %02x, %02x, %02x, %02x\n",
|
||||||
|
Br, Bg, Bb, Ba);
|
||||||
|
else
|
||||||
|
g_print (" blend constant = UNUSED\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
check_pixel (x_off, y_off, expected_result);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test with legacy API
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Clear previous work */
|
||||||
|
cogl_set_source_color4ub (0, 0, 0, 0xff);
|
||||||
|
cogl_rectangle (x * QUAD_WIDTH,
|
||||||
|
y * QUAD_WIDTH,
|
||||||
|
x * QUAD_WIDTH + QUAD_WIDTH,
|
||||||
|
y * QUAD_WIDTH + QUAD_WIDTH);
|
||||||
|
|
||||||
/* First write out the destination color without any blending... */
|
/* First write out the destination color without any blending... */
|
||||||
material = cogl_material_new ();
|
material = cogl_material_new ();
|
||||||
@ -105,10 +173,10 @@ test_blend (TestState *state,
|
|||||||
status = cogl_material_set_blend (material, blend_string, &error);
|
status = cogl_material_set_blend (material, blend_string, &error);
|
||||||
if (!status)
|
if (!status)
|
||||||
{
|
{
|
||||||
/* It's not strictly a test failure; you need a more capable GPU or
|
/* This is a failure as it must be equivalent to the new API */
|
||||||
* driver to test this blend string. */
|
g_warning ("Error setting blend string %s: %s",
|
||||||
g_debug ("Failed to test blend string %s: %s",
|
blend_string, error->message);
|
||||||
blend_string, error->message);
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
|
|
||||||
cogl_color_init_from_4ub (&blend_const_color, Br, Bg, Bb, Ba);
|
cogl_color_init_from_4ub (&blend_const_color, Br, Bg, Bb, Ba);
|
||||||
@ -123,28 +191,7 @@ test_blend (TestState *state,
|
|||||||
|
|
||||||
/* See what we got... */
|
/* See what we got... */
|
||||||
|
|
||||||
y_off = y * QUAD_WIDTH + (QUAD_WIDTH / 2);
|
check_pixel (x_off, y_off, expected_result);
|
||||||
x_off = x * QUAD_WIDTH + (QUAD_WIDTH / 2);
|
|
||||||
|
|
||||||
cogl_read_pixels (x_off, y_off, 1, 1,
|
|
||||||
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
||||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
||||||
pixel);
|
|
||||||
if (g_test_verbose ())
|
|
||||||
{
|
|
||||||
g_print ("test_blend (%d, %d):\n%s\n", x, y, blend_string);
|
|
||||||
g_print (" src color = %02x, %02x, %02x, %02x\n", Sr, Sg, Sb, Sa);
|
|
||||||
g_print (" dst color = %02x, %02x, %02x, %02x\n", Dr, Dg, Db, Da);
|
|
||||||
if (blend_constant != BLEND_CONSTANT_UNUSED)
|
|
||||||
g_print (" blend constant = %02x, %02x, %02x, %02x\n",
|
|
||||||
Br, Bg, Bb, Ba);
|
|
||||||
else
|
|
||||||
g_print (" blend constant = UNUSED\n");
|
|
||||||
g_print (" result = %x, %x, %x, %x\n",
|
|
||||||
pixel[RED], pixel[GREEN], pixel[BLUE], pixel[ALPHA]);
|
|
||||||
}
|
|
||||||
|
|
||||||
check_pixel (pixel, expected_result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static CoglHandle
|
static CoglHandle
|
||||||
@ -204,9 +251,8 @@ test_tex_combine (TestState *state,
|
|||||||
CoglHandle material;
|
CoglHandle material;
|
||||||
gboolean status;
|
gboolean status;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GLubyte pixel[4];
|
int y_off;
|
||||||
GLint y_off;
|
int x_off;
|
||||||
GLint x_off;
|
|
||||||
|
|
||||||
|
|
||||||
tex0 = make_texture (tex0_color);
|
tex0 = make_texture (tex0_color);
|
||||||
@ -250,10 +296,6 @@ test_tex_combine (TestState *state,
|
|||||||
y_off = y * QUAD_WIDTH + (QUAD_WIDTH / 2);
|
y_off = y * QUAD_WIDTH + (QUAD_WIDTH / 2);
|
||||||
x_off = x * QUAD_WIDTH + (QUAD_WIDTH / 2);
|
x_off = x * QUAD_WIDTH + (QUAD_WIDTH / 2);
|
||||||
|
|
||||||
cogl_read_pixels (x_off, y_off, 1, 1,
|
|
||||||
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
||||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
||||||
pixel);
|
|
||||||
if (g_test_verbose ())
|
if (g_test_verbose ())
|
||||||
{
|
{
|
||||||
g_print ("test_tex_combine (%d, %d):\n%s\n", x, y, combine_string);
|
g_print ("test_tex_combine (%d, %d):\n%s\n", x, y, combine_string);
|
||||||
@ -264,15 +306,13 @@ test_tex_combine (TestState *state,
|
|||||||
Cr, Cg, Cb, Ca);
|
Cr, Cg, Cb, Ca);
|
||||||
else
|
else
|
||||||
g_print (" combine constant = UNUSED\n");
|
g_print (" combine constant = UNUSED\n");
|
||||||
g_print (" result = %02x, %02x, %02x, %02x\n",
|
|
||||||
pixel[RED], pixel[GREEN], pixel[BLUE], pixel[ALPHA]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_pixel (pixel, expected_result);
|
check_pixel (x_off, y_off, expected_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_paint (ClutterActor *actor, TestState *state)
|
paint (TestState *state)
|
||||||
{
|
{
|
||||||
test_blend (state, 0, 0, /* position */
|
test_blend (state, 0, 0, /* position */
|
||||||
0xff0000ff, /* src */
|
0xff0000ff, /* src */
|
||||||
@ -385,48 +425,20 @@ on_paint (ClutterActor *actor, TestState *state)
|
|||||||
"RGB = DOT3_RGBA (PREVIOUS, TEXTURE)"
|
"RGB = DOT3_RGBA (PREVIOUS, TEXTURE)"
|
||||||
"A = REPLACE (PREVIOUS)",
|
"A = REPLACE (PREVIOUS)",
|
||||||
0x2a2a2abb); /* expected */
|
0x2a2a2abb); /* expected */
|
||||||
|
|
||||||
/* Comment this out if you want visual feedback for what this test paints */
|
|
||||||
clutter_main_quit ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
queue_redraw (gpointer stage)
|
|
||||||
{
|
|
||||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
test_cogl_blend_strings (TestUtilsGTestFixture *fixture,
|
test_cogl_blend_strings (TestUtilsGTestFixture *fixture,
|
||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
|
TestUtilsSharedState *shared_state = data;
|
||||||
TestState state;
|
TestState state;
|
||||||
ClutterActor *stage;
|
|
||||||
ClutterActor *group;
|
|
||||||
unsigned int idle_source;
|
|
||||||
|
|
||||||
stage = clutter_stage_get_default ();
|
cogl_ortho (0, cogl_framebuffer_get_width (shared_state->fb), /* left, right */
|
||||||
|
cogl_framebuffer_get_height (shared_state->fb), 0, /* bottom, top */
|
||||||
|
-1, 100 /* z near, far */);
|
||||||
|
|
||||||
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
|
paint (&state);
|
||||||
clutter_actor_get_geometry (stage, &state.stage_geom);
|
|
||||||
|
|
||||||
group = clutter_group_new ();
|
|
||||||
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
|
|
||||||
|
|
||||||
/* We force continuous redrawing incase someone comments out the
|
|
||||||
* clutter_main_quit and wants visual feedback for the test since we
|
|
||||||
* wont be doing anything else that will trigger redrawing. */
|
|
||||||
idle_source = g_idle_add (queue_redraw, stage);
|
|
||||||
|
|
||||||
g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
|
|
||||||
|
|
||||||
clutter_actor_show_all (stage);
|
|
||||||
|
|
||||||
clutter_main ();
|
|
||||||
|
|
||||||
g_source_remove (idle_source);
|
|
||||||
|
|
||||||
if (g_test_verbose ())
|
if (g_test_verbose ())
|
||||||
g_print ("OK\n");
|
g_print ("OK\n");
|
||||||
|
@ -134,7 +134,7 @@ main (int argc, char **argv)
|
|||||||
UNPORTED_TEST ("/cogl", test_cogl_fixed);
|
UNPORTED_TEST ("/cogl", test_cogl_fixed);
|
||||||
UNPORTED_TEST ("/cogl", test_cogl_materials);
|
UNPORTED_TEST ("/cogl", test_cogl_materials);
|
||||||
ADD_TEST ("/cogl", test_cogl_pipeline_user_matrix);
|
ADD_TEST ("/cogl", test_cogl_pipeline_user_matrix);
|
||||||
UNPORTED_TEST ("/cogl", test_cogl_blend_strings);
|
ADD_TEST ("/cogl", test_cogl_blend_strings);
|
||||||
UNPORTED_TEST ("/cogl", test_cogl_premult);
|
UNPORTED_TEST ("/cogl", test_cogl_premult);
|
||||||
UNPORTED_TEST ("/cogl", test_cogl_readpixels);
|
UNPORTED_TEST ("/cogl", test_cogl_readpixels);
|
||||||
UNPORTED_TEST ("/cogl", test_cogl_path);
|
UNPORTED_TEST ("/cogl", test_cogl_path);
|
||||||
|
Loading…
Reference in New Issue
Block a user