From 9e90760ab054db2234f73374600489fa5584ad7c Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Sat, 17 Oct 2020 15:03:09 -0300 Subject: [PATCH] tests: start to use Weston's default screenshooter in the test suite Until now we had two different protocol extensions: one for the test suite screenshooter and other for the screenshooter client. As they are identical and this won't change, make the test suite use the same protocol that the screenshooter client uses. Besides the cleanup, this change will also allow us to use the DRM writeback screenshooter in the test suite, as the test suite implementation is hardcoded to use a renderer based screenshooter. Signed-off-by: Leandro Ribeiro --- tests/meson.build | 3 ++- tests/weston-test-client-helper.c | 28 +++++++++++++++++--------- tests/weston-test-client-helper.h | 4 +++- tests/weston-test-desktop-shell.c | 2 ++ tests/weston-test-fixture-compositor.c | 3 +++ 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/tests/meson.build b/tests/meson.build index 94e9cdee..de023c95 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -2,7 +2,7 @@ plugin_test_shell_desktop = shared_library( 'weston-test-desktop-shell', 'weston-test-desktop-shell.c', include_directories: common_inc, - dependencies: [ dep_lib_desktop, dep_libweston_public ], + dependencies: [ dep_lib_desktop, dep_libweston_public, dep_libexec_weston ], name_prefix: '', install: false ) @@ -29,6 +29,7 @@ lib_test_client = static_library( 'weston-test-client-helper.c', 'weston-test-fixture-compositor.c', weston_test_client_protocol_h, + weston_screenshooter_protocol_c, weston_test_protocol_c, viewporter_client_protocol_h, viewporter_protocol_c, diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index b58795b5..c52a5736 100644 --- a/tests/weston-test-client-helper.c +++ b/tests/weston-test-client-helper.c @@ -540,17 +540,20 @@ test_handle_pointer_position(void *data, struct weston_test *weston_test, } static void -test_handle_capture_screenshot_done(void *data, struct weston_test *weston_test) +test_handle_capture_screenshot_done(void *data, struct weston_screenshooter *screenshooter) { - struct test *test = data; + struct client *client = data; testlog("Screenshot has been captured\n"); - test->buffer_copy_done = true; + client->buffer_copy_done = true; } +static const struct weston_screenshooter_listener screenshooter_listener = { + test_handle_capture_screenshot_done +}; + static const struct weston_test_listener test_listener = { test_handle_pointer_position, - test_handle_capture_screenshot_done, }; static void @@ -792,6 +795,12 @@ handle_global(void *data, struct wl_registry *registry, &weston_test_interface, version); weston_test_add_listener(test->weston_test, &test_listener, test); client->test = test; + } else if (strcmp(interface, "weston_screenshooter") == 0) { + client->screenshooter = + wl_registry_bind(registry, id, + &weston_screenshooter_interface, 1); + weston_screenshooter_add_listener(client->screenshooter, + &screenshooter_listener, client); } } @@ -1614,17 +1623,18 @@ capture_screenshot_of_output(struct client *client) { struct buffer *buffer; + assert(client->screenshooter); + buffer = create_shm_buffer_a8r8g8b8(client, client->output->width, client->output->height); - client->test->buffer_copy_done = false; - weston_test_capture_screenshot(client->test->weston_test, + client->buffer_copy_done = false; + weston_screenshooter_take_shot(client->screenshooter, client->output->wl_output, buffer->proxy); - while (client->test->buffer_copy_done == false) - if (wl_display_dispatch(client->wl_display) < 0) - break; + while (client->buffer_copy_done == false) + assert(wl_display_dispatch(client->wl_display) >= 0); /* FIXME: Document somewhere the orientation the screenshot is taken * and how the clip coords are interpreted, in case of scaling/transform. diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h index e615964b..90ab3616 100644 --- a/tests/weston-test-client-helper.h +++ b/tests/weston-test-client-helper.h @@ -37,6 +37,7 @@ #include #include "weston-test-runner.h" #include "weston-test-client-protocol.h" +#include "weston-screenshooter-client-protocol.h" #include "viewporter-client-protocol.h" struct client { @@ -58,6 +59,8 @@ struct client { int has_argb; struct wl_list global_list; struct wl_list output_list; /* struct output::link */ + struct weston_screenshooter *screenshooter; + bool buffer_copy_done; }; struct global { @@ -72,7 +75,6 @@ struct test { int pointer_x; int pointer_y; uint32_t n_egl_buffers; - bool buffer_copy_done; }; struct input { diff --git a/tests/weston-test-desktop-shell.c b/tests/weston-test-desktop-shell.c index f5ef9f68..d9c39450 100644 --- a/tests/weston-test-desktop-shell.c +++ b/tests/weston-test-desktop-shell.c @@ -221,6 +221,8 @@ wet_shell_init(struct weston_compositor *ec, if (dts->desktop == NULL) goto out_view; + screenshooter_create(ec); + return 0; out_view: diff --git a/tests/weston-test-fixture-compositor.c b/tests/weston-test-fixture-compositor.c index 693c39da..0cc05083 100644 --- a/tests/weston-test-fixture-compositor.c +++ b/tests/weston-test-fixture-compositor.c @@ -369,6 +369,9 @@ execute_compositor(const struct compositor_setup *setup, return RESULT_FAIL; } + /* Test suite needs the debug protocol to be able to take screenshots */ + prog_args_take(&args, strdup("--debug")); + asprintf(&tmp, "--socket=%s", setup->testset_name); prog_args_take(&args, tmp);