mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2026-05-05 05:18:01 +02:00
tests: improvements to color effects tests
This fixes a huge bug: we were ignoring the return value from verify_screen_content(), which meant that tests were always passing. Also, this adds tests for single-pixel solid color buffers, which are useful to verify that color effects are actually applied in such cases. Renderers (as the GL-renderer) may simply use glClear() instead of going through the full rendering pipeline when drawing solid colors, and we need to ensure that color effects are applied in those cases as well. Besides that, some refactoring was done to improve the code. Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
parent
d3fee82090
commit
82a832ef38
6 changed files with 120 additions and 24 deletions
|
|
@ -31,6 +31,24 @@
|
|||
static const int WINDOW_WIDTH = 320;
|
||||
static const int WINDOW_HEIGHT = 240;
|
||||
|
||||
static const int CAT_WIDTH = 220;
|
||||
static const int CAT_HEIGHT = 220;
|
||||
|
||||
static const int SOLID_BUFFER_WIDTH = 20;
|
||||
static const int SOLID_BUFFER_HEIGHT = 15;
|
||||
|
||||
static const struct solid_buffer_color {
|
||||
uint32_t r;
|
||||
uint32_t g;
|
||||
uint32_t b;
|
||||
uint32_t a;
|
||||
} SOLID_BUFFER_COLOR = {
|
||||
.r = 0xcfffffff,
|
||||
.g = 0x8fffffff,
|
||||
.b = 0x4fffffff,
|
||||
.a = 0xffffffff,
|
||||
};
|
||||
|
||||
enum effect_type {
|
||||
EFFECT_TYPE_NONE = 0,
|
||||
EFFECT_TYPE_INVERSION,
|
||||
|
|
@ -43,6 +61,9 @@ struct setup_args {
|
|||
struct fixture_metadata meta;
|
||||
enum effect_type type;
|
||||
const char *ref_image_prefix;
|
||||
uint32_t object_width;
|
||||
uint32_t object_height;
|
||||
bool solid_color;
|
||||
};
|
||||
|
||||
static const struct setup_args my_setup_args[] = {
|
||||
|
|
@ -50,26 +71,81 @@ static const struct setup_args my_setup_args[] = {
|
|||
.meta.name = "normal-cat",
|
||||
.ref_image_prefix = "color-effects",
|
||||
.type = EFFECT_TYPE_NONE,
|
||||
.solid_color = false,
|
||||
.object_width = CAT_WIDTH,
|
||||
.object_height = CAT_HEIGHT,
|
||||
},
|
||||
{
|
||||
.meta.name = "inversion-cat",
|
||||
.ref_image_prefix = "color-effects",
|
||||
.type = EFFECT_TYPE_INVERSION,
|
||||
.solid_color = false,
|
||||
.object_width = CAT_WIDTH,
|
||||
.object_height = CAT_HEIGHT,
|
||||
},
|
||||
{
|
||||
.meta.name = "deuteranopia-cat",
|
||||
.ref_image_prefix = "color-effects",
|
||||
.type = EFFECT_TYPE_DEUTERANOPIA,
|
||||
.solid_color = false,
|
||||
.object_width = CAT_WIDTH,
|
||||
.object_height = CAT_HEIGHT,
|
||||
},
|
||||
{
|
||||
.meta.name = "protanopia-cat",
|
||||
.ref_image_prefix = "color-effects",
|
||||
.type = EFFECT_TYPE_PROTANOPIA,
|
||||
.solid_color = false,
|
||||
.object_width = CAT_WIDTH,
|
||||
.object_height = CAT_HEIGHT,
|
||||
},
|
||||
{
|
||||
.meta.name = "tritanopia-cat",
|
||||
.ref_image_prefix = "color-effects",
|
||||
.type = EFFECT_TYPE_TRITANOPIA,
|
||||
.solid_color = false,
|
||||
.object_width = CAT_WIDTH,
|
||||
.object_height = CAT_HEIGHT,
|
||||
},
|
||||
{
|
||||
.meta.name = "normal-solid-color",
|
||||
.ref_image_prefix = "color-effects",
|
||||
.type = EFFECT_TYPE_NONE,
|
||||
.solid_color = true,
|
||||
.object_width = SOLID_BUFFER_WIDTH,
|
||||
.object_height = SOLID_BUFFER_HEIGHT,
|
||||
},
|
||||
{
|
||||
.meta.name = "inversion-solid-color",
|
||||
.ref_image_prefix = "color-effects",
|
||||
.type = EFFECT_TYPE_INVERSION,
|
||||
.solid_color = true,
|
||||
.object_width = SOLID_BUFFER_WIDTH,
|
||||
.object_height = SOLID_BUFFER_HEIGHT,
|
||||
},
|
||||
{
|
||||
.meta.name = "deuteranopia-solid-color",
|
||||
.ref_image_prefix = "color-effects",
|
||||
.type = EFFECT_TYPE_DEUTERANOPIA,
|
||||
.solid_color = true,
|
||||
.object_width = SOLID_BUFFER_WIDTH,
|
||||
.object_height = SOLID_BUFFER_HEIGHT,
|
||||
},
|
||||
{
|
||||
.meta.name = "protanopia-solid-color",
|
||||
.ref_image_prefix = "color-effects",
|
||||
.type = EFFECT_TYPE_PROTANOPIA,
|
||||
.solid_color = true,
|
||||
.object_width = SOLID_BUFFER_WIDTH,
|
||||
.object_height = SOLID_BUFFER_HEIGHT,
|
||||
},
|
||||
{
|
||||
.meta.name = "tritanopia-solid-color",
|
||||
.ref_image_prefix = "color-effects",
|
||||
.type = EFFECT_TYPE_TRITANOPIA,
|
||||
.solid_color = true,
|
||||
.object_width = SOLID_BUFFER_WIDTH,
|
||||
.object_height = SOLID_BUFFER_HEIGHT,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -118,42 +194,62 @@ TEST(color_effects)
|
|||
int seq_no = get_test_fixture_index();
|
||||
const struct setup_args *arg = &my_setup_args[seq_no];
|
||||
struct client *client;
|
||||
struct buffer *buffer;
|
||||
struct wl_surface *surface;
|
||||
const uint32_t width = WINDOW_WIDTH;
|
||||
const uint32_t height = WINDOW_HEIGHT;
|
||||
struct surface *surface;
|
||||
struct rectangle clip;
|
||||
struct wl_buffer *buf;
|
||||
struct buffer *buffer = NULL;
|
||||
struct wp_viewport *viewport;
|
||||
int frame;
|
||||
bool res;
|
||||
|
||||
client = create_client_and_test_surface(0, 0, width, height);
|
||||
client = create_client_and_test_surface(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
test_assert_ptr_not_null(client);
|
||||
surface = client->surface->wl_surface;
|
||||
surface = client->surface;
|
||||
|
||||
viewport = client_create_viewport(client);
|
||||
|
||||
if (!arg->solid_color) {
|
||||
buffer = client_buffer_from_image_file(client, "colorful-cat", 1);
|
||||
test_assert_ptr_not_null(buffer);
|
||||
buf = buffer->proxy;
|
||||
} else {
|
||||
buf = wp_single_pixel_buffer_manager_v1_create_u32_rgba_buffer(client->single_pixel_manager,
|
||||
SOLID_BUFFER_COLOR.r,
|
||||
SOLID_BUFFER_COLOR.g,
|
||||
SOLID_BUFFER_COLOR.b,
|
||||
SOLID_BUFFER_COLOR.a);
|
||||
wp_viewport_set_source(viewport, wl_fixed_from_int(0), wl_fixed_from_int(0),
|
||||
wl_fixed_from_int(1), wl_fixed_from_int(1));
|
||||
wp_viewport_set_destination(viewport, arg->object_width, arg->object_height);
|
||||
}
|
||||
|
||||
/* move pointer away so it does not interfere */
|
||||
weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 0, 0);
|
||||
|
||||
/* buffer with cat image */
|
||||
buffer = client_buffer_from_image_file(client, "colorful-cat", 1);
|
||||
test_assert_ptr_not_null(buffer);
|
||||
|
||||
/* commit buffer */
|
||||
wl_surface_attach(surface, buffer->proxy, 0, 0);
|
||||
wl_surface_damage_buffer(surface, 0, 0, INT32_MAX, INT32_MAX);
|
||||
frame_callback_set(surface, &frame);
|
||||
wl_surface_commit(surface);
|
||||
wl_surface_attach(surface->wl_surface, buf, 0, 0);
|
||||
wl_surface_damage_buffer(surface->wl_surface, 0, 0, arg->object_width, arg->object_height);
|
||||
frame_callback_set(surface->wl_surface, &frame);
|
||||
wl_surface_commit(surface->wl_surface);
|
||||
frame_callback_wait(client, &frame);
|
||||
|
||||
/* compare screenshot to reference image, ignoring background (which also
|
||||
* changes with color effects, but let's make the test run faster) */
|
||||
clip.x = 0;
|
||||
clip.y = 0;
|
||||
clip.width = buffer->buf->width;
|
||||
clip.height = buffer->buf->height;
|
||||
verify_screen_content(client, arg->ref_image_prefix, seq_no, &clip,
|
||||
seq_no, NULL, NO_DECORATIONS);
|
||||
/* take screenshot and compare to reference image; ignore background */
|
||||
clip = (struct rectangle) {
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = arg->object_width,
|
||||
.height = arg->object_height,
|
||||
};
|
||||
res = verify_screen_content(client, arg->ref_image_prefix, seq_no, &clip,
|
||||
seq_no, NULL, NO_DECORATIONS);
|
||||
|
||||
buffer_destroy(buffer);
|
||||
if (buffer) {
|
||||
buffer_destroy(buffer);
|
||||
} else {
|
||||
wl_buffer_destroy(buf);
|
||||
}
|
||||
wp_viewport_destroy(viewport);
|
||||
client_destroy(client);
|
||||
|
||||
return RESULT_OK;
|
||||
return res ? RESULT_OK : RESULT_FAIL;
|
||||
}
|
||||
|
|
|
|||
BIN
tests/reference/color-effects-05.png
Normal file
BIN
tests/reference/color-effects-05.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 816 B |
BIN
tests/reference/color-effects-06.png
Normal file
BIN
tests/reference/color-effects-06.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 816 B |
BIN
tests/reference/color-effects-07.png
Normal file
BIN
tests/reference/color-effects-07.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 816 B |
BIN
tests/reference/color-effects-08.png
Normal file
BIN
tests/reference/color-effects-08.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 816 B |
BIN
tests/reference/color-effects-09.png
Normal file
BIN
tests/reference/color-effects-09.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 816 B |
Loading…
Add table
Reference in a new issue