tests: Support decoration capture for screenshots

It's pretty trivial to make verify_screen_content() and
capture_screenshot_from_output() support decorations, so we can reuse
those in output-decorations tests rather than open-coding.

Signed-off-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
Daniel Stone 2025-10-11 09:08:30 +01:00 committed by Pekka Paalanen
parent fe4cb8a546
commit c00997979c
16 changed files with 55 additions and 45 deletions

View file

@ -353,7 +353,7 @@ TEST(alpha_blend)
/* attach, damage, commit background window */
move_client(client, 0, 0);
shot = capture_screenshot_of_output(client, NULL);
shot = capture_screenshot_of_output(client, NULL, NO_DECORATIONS);
test_assert_ptr_not_null(shot);
match = verify_image(shot->image, "alpha_blend", seq_no, NULL, seq_no);
test_assert_true(check_blend_pattern(bg, fg, shot, space));

View file

@ -151,7 +151,8 @@ TEST_P(buffer_transform, my_buffer_args)
bargs->transform);
move_client(client, 19, 19);
match = verify_screen_content(client, refname, 0, NULL, 0, NULL);
match = verify_screen_content(client, refname, 0, NULL, 0, NULL,
NO_DECORATIONS);
test_assert_true(match);
client_destroy(client);

View file

@ -1667,7 +1667,7 @@ test_client_buffer(const struct client_buffer_case *cb_case,
match = verify_screen_content(client, "client-buffer",
cb_case->ref_seq_no, NULL, 0,
NULL);
NULL, NO_DECORATIONS);
res = match ? RESULT_OK : RESULT_FAIL;
client_buffer_util_destroy_buffer(buf);

View file

@ -149,7 +149,8 @@ TEST(color_effects)
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);
verify_screen_content(client, arg->ref_image_prefix, seq_no, &clip,
seq_no, NULL, NO_DECORATIONS);
buffer_destroy(buffer);
client_destroy(client);

View file

@ -502,7 +502,7 @@ TEST(opaque_pixel_conversion)
wl_surface_damage(surface, 0, 0, width, height);
wl_surface_commit(surface);
shot = capture_screenshot_of_output(client, NULL);
shot = capture_screenshot_of_output(client, NULL, NO_DECORATIONS);
test_assert_ptr_not_null(shot);
match = verify_image(shot->image, "shaper_matrix", arg->ref_image_index,
@ -725,7 +725,7 @@ TEST(output_icc_alpha_blend)
/* attach, damage, commit background window */
move_client(client, 0, 0);
shot = capture_screenshot_of_output(client, NULL);
shot = capture_screenshot_of_output(client, NULL, NO_DECORATIONS);
test_assert_ptr_not_null(shot);
match = verify_image(shot->image, "output_icc_alpha_blend", arg->ref_image_index,
NULL, seq_no);
@ -760,23 +760,15 @@ TEST(output_icc_decorations)
int seq_no = get_test_fixture_index();
const struct setup_args *arg = &my_setup_args[seq_no];
struct client *client;
struct buffer *shot;
pixman_image_t *img;
bool match;
client = create_client();
shot = client_capture_output(client, client->output,
WESTON_CAPTURE_V1_SOURCE_FULL_FRAMEBUFFER,
CLIENT_BUFFER_TYPE_SHM);
img = image_convert_to_a8r8g8b8(shot->image);
match = verify_image(img, "output-icc-decorations",
arg->ref_image_index, NULL, seq_no);
match = verify_screen_content(client, "output-icc-decorations",
arg->ref_image_index, NULL, seq_no,
client->output->name, INCLUDE_DECORATIONS);
test_assert_true(match);
pixman_image_unref(img);
buffer_destroy(shot);
client_destroy(client);
return RESULT_OK;

View file

@ -94,7 +94,7 @@ TEST(drm_screenshot_no_damage) {
*/
for (i = 0; i < 5; i++) {
ret = verify_screen_content(client, "drm_screenshot_no_damage",
0, NULL, i, NULL);
0, NULL, i, NULL, NO_DECORATIONS);
test_assert_true(ret);
}

View file

@ -120,7 +120,7 @@ TEST(internal_screenshot)
/* Take a snapshot. Result will be in screenshot->wl_buffer. */
testlog("Taking a screenshot\n");
screenshot = capture_screenshot_of_output(client, NULL);
screenshot = capture_screenshot_of_output(client, NULL, NO_DECORATIONS);
test_assert_ptr_not_null(screenshot);
/* Load good reference image */

View file

@ -224,8 +224,10 @@ TEST(output_damage)
*/
for (i = 1; i < COUNT_BUFS; i++) {
commit_buffer_with_damage(client->surface, buf[i], damages[i]);
if (!verify_screen_content(client, refname, i, NULL, i, NULL))
if (!verify_screen_content(client, refname, i, NULL, i, NULL,
NO_DECORATIONS)) {
match = false;
}
}
test_assert_true(match);

View file

@ -82,22 +82,14 @@ DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args, meta);
TEST(output_decorations)
{
struct client *client;
struct buffer *shot;
pixman_image_t *img;
bool match;
client = create_client();
shot = client_capture_output(client, client->output,
WESTON_CAPTURE_V1_SOURCE_FULL_FRAMEBUFFER,
CLIENT_BUFFER_TYPE_SHM);
img = image_convert_to_a8r8g8b8(shot->image);
match = verify_image(img, "output-decorations", 0, NULL, 0);
match = verify_screen_content(client, "output-decorations", 0, NULL, 0,
client->output->name, INCLUDE_DECORATIONS);
test_assert_true(match);
pixman_image_unref(img);
buffer_destroy(shot);
client_destroy(client);
return RESULT_OK;

View file

@ -151,7 +151,8 @@ TEST_P(output_transform, my_buffer_args)
bargs->transform);
move_client(client, 19, 19);
match = verify_screen_content(client, refname, 0, NULL, 0, NULL);
match = verify_screen_content(client, refname, 0, NULL, 0, NULL,
NO_DECORATIONS);
test_assert_true(match);
client_destroy(client);

View file

@ -155,7 +155,7 @@ TEST(pointer_cursor_retains_committed_buffer_after_reenter)
client->input->pointer->serial,
main_cursor_surface->wl_surface, 0, 0);
match = verify_screen_content(client, "pointer_cursor_reenter", 0,
NULL, 0, NULL);
NULL, 0, NULL, NO_DECORATIONS);
test_assert_true(match);
/* Move the cursor just outside the main surface. */
@ -164,7 +164,7 @@ TEST(pointer_cursor_retains_committed_buffer_after_reenter)
client->input->pointer->serial,
back_cursor_surface->wl_surface, 0, 0);
match = verify_screen_content(client, "pointer_cursor_reenter", 1,
NULL, 1, NULL);
NULL, 1, NULL, NO_DECORATIONS);
test_assert_true(match);
/* And back in the main surface again. */
@ -173,7 +173,7 @@ TEST(pointer_cursor_retains_committed_buffer_after_reenter)
client->input->pointer->serial,
main_cursor_surface->wl_surface, 0, 0);
match = verify_screen_content(client, "pointer_cursor_reenter", 2,
NULL, 2, NULL);
NULL, 2, NULL, NO_DECORATIONS);
test_assert_true(match);
surface_destroy(back_cursor_surface);

View file

@ -100,7 +100,8 @@ TEST(solid_buffer_argb_u32)
wl_surface_commit(client->surface->wl_surface);
frame_callback_wait(client, &done);
match = verify_screen_content(client, "single-pixel-buffer", 0, NULL, 0, NULL);
match = verify_screen_content(client, "single-pixel-buffer", 0,
NULL, 0, NULL, NO_DECORATIONS);
test_assert_true(match);
wl_buffer_destroy(buffer);

View file

@ -109,7 +109,7 @@ check_screen(struct client *client,
bool match;
match = verify_screen_content(client, ref_image, ref_seq_no, clip,
seq_no, NULL);
seq_no, NULL, NO_DECORATIONS);
return match ? 0 : -1;
}

View file

@ -97,7 +97,7 @@ TEST(viewport_upscale_solid)
move_client(client, 19, 19);
match = verify_screen_content(client, "viewport_upscale_solid", 0,
NULL, 0, NULL);
NULL, 0, NULL, NO_DECORATIONS);
test_assert_true(match);
wp_viewport_destroy(viewport);

View file

@ -2037,16 +2037,21 @@ client_capture_output(struct client *client,
* is ensured to be PIXMAN_a8r8g8b8.
*
* @param client a client instance, as created by create_client()
* @param output_name the name of the output, as specified by wl_output.name
* @param output_name the name of the output, as specified by wl_output.name,
* or NULL to use the client-defined output
* @param include_decorations true if the screenshot should include output
* decorations, or false if it should include just the client content
* @returns A new buffer object, that should be freed with buffer_destroy().
*/
struct buffer *
capture_screenshot_of_output(struct client *client, const char *output_name)
capture_screenshot_of_output(struct client *client, const char *output_name,
enum screenshot_decoration_mode include_decorations)
{
struct image_header ih;
struct buffer *shm;
struct buffer *buf;
struct output *output = NULL;
enum weston_capture_v1_source source;
if (output_name) {
struct output *output_iter;
@ -2063,8 +2068,12 @@ capture_screenshot_of_output(struct client *client, const char *output_name)
output = client->output;
}
shm = client_capture_output(client, output,
WESTON_CAPTURE_V1_SOURCE_FRAMEBUFFER,
if (include_decorations == INCLUDE_DECORATIONS)
source = WESTON_CAPTURE_V1_SOURCE_FULL_FRAMEBUFFER;
else
source = WESTON_CAPTURE_V1_SOURCE_FRAMEBUFFER;
shm = client_capture_output(client, output, source,
CLIENT_BUFFER_TYPE_SHM);
ih = image_header_from(shm->image);
@ -2182,6 +2191,8 @@ verify_image(pixman_image_t *shot,
* \param seq_no See verify_image().
* \param output_name the output name as specified by wl_output.name. If NULL,
* this is the last wl_output advertised by wl_registry.
* \param include_decorations true if the screenshot should include output
* decorations, or false if it should include just the client content
* \return True if the screen contents matches the reference image,
* false otherwise.
*/
@ -2190,12 +2201,14 @@ verify_screen_content(struct client *client,
const char *ref_image,
int ref_seq_no,
const struct rectangle *clip,
int seq_no, const char *output_name)
int seq_no, const char *output_name,
enum screenshot_decoration_mode include_decorations)
{
struct buffer *shot;
bool match;
shot = capture_screenshot_of_output(client, output_name);
shot = capture_screenshot_of_output(client, output_name,
include_decorations);
test_assert_ptr_not_null(shot);
match = verify_image(shot->image, ref_image, ref_seq_no, clip, seq_no);
buffer_destroy(shot);

View file

@ -207,6 +207,11 @@ struct range {
int b;
};
enum screenshot_decoration_mode {
INCLUDE_DECORATIONS,
NO_DECORATIONS,
};
struct client *
create_client(void);
@ -318,7 +323,8 @@ pixman_image_t *
load_image_from_png(const char *fname);
struct buffer *
capture_screenshot_of_output(struct client *client, const char *output_name);
capture_screenshot_of_output(struct client *client, const char *output_name,
enum screenshot_decoration_mode include_decorations);
struct buffer *
client_capture_output(struct client *client,
@ -341,7 +347,8 @@ verify_screen_content(struct client *client,
const char *ref_image,
int ref_seq_no,
const struct rectangle *clip,
int seq_no, const char *output_name);
int seq_no, const char *output_name,
enum screenshot_decoration_mode include_decorations);
struct buffer *
client_buffer_from_image_file(struct client *client,