From 4ebb06a94f0767af9ddfe34278064444d793bdab Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Sat, 11 Oct 2025 08:53:24 +0100 Subject: [PATCH] tests: Add helper to create solid-filled buffer At the moment this is only replacing two clear calls with one. However, when client_buffer starts using properly-bracketed CPU access, this will become much more tedious. Introduce a helper now to make it easier. Signed-off-by: Daniel Stone --- tests/alpha-blending-test.c | 3 +-- tests/color-icc-output-test.c | 3 +-- tests/drm-smoke-test.c | 4 +-- tests/event-test.c | 9 ++++--- tests/ivi-layout-test-client.c | 4 ++- tests/linux-explicit-synchronization-test.c | 28 ++++++++++++++++----- tests/output-damage-test.c | 6 ++--- tests/paint-node-test.c | 3 +-- tests/pointer-shot-test.c | 6 ++--- tests/subsurface-shot-test.c | 3 +-- tests/viewporter-shot-test.c | 3 +-- tests/weston-test-client-helper.c | 17 +++++++++++-- tests/weston-test-client-helper.h | 4 +++ tests/xdg-client-helper.c | 8 +++--- 14 files changed, 63 insertions(+), 38 deletions(-) diff --git a/tests/alpha-blending-test.c b/tests/alpha-blending-test.c index d45c29672..346178d73 100644 --- a/tests/alpha-blending-test.c +++ b/tests/alpha-blending-test.c @@ -327,8 +327,7 @@ TEST(alpha_blend) subco = bind_to_singleton_global(client, &wl_subcompositor_interface, 1); /* background window content */ - bg = create_shm_buffer_a8r8g8b8(client, width, height); - fill_image_with_color(bg->image, &background_color); + bg = create_shm_buffer_solid(client, width, height, &background_color); /* background window, main surface */ client->surface = create_test_surface(client); diff --git a/tests/color-icc-output-test.c b/tests/color-icc-output-test.c index a5c857910..d43585345 100644 --- a/tests/color-icc-output-test.c +++ b/tests/color-icc-output-test.c @@ -699,8 +699,7 @@ TEST(output_icc_alpha_blend) subco = bind_to_singleton_global(client, &wl_subcompositor_interface, 1); /* background window content */ - bg = create_shm_buffer_a8r8g8b8(client, width, height); - fill_image_with_color(bg->image, &background_color); + bg = create_shm_buffer_solid(client, width, height, &background_color); /* background window, main surface */ client->surface = create_test_surface(client); diff --git a/tests/drm-smoke-test.c b/tests/drm-smoke-test.c index bb5bed1e6..6171c1229 100644 --- a/tests/drm-smoke-test.c +++ b/tests/drm-smoke-test.c @@ -57,9 +57,7 @@ TEST(drm_smoke) { test_assert_ptr_not_null(client); surface = client->surface->wl_surface; - buffer = create_shm_buffer_a8r8g8b8(client, 200, 200); - - fill_image_with_color(buffer->image, &red); + buffer = create_shm_buffer_solid(client, 200, 200, &red); for (i = 0; i < 5; i++) { wl_surface_attach(surface, buffer->proxy, 0, 0); diff --git a/tests/event-test.c b/tests/event-test.c index 99ac96b67..d503f0c31 100644 --- a/tests/event-test.c +++ b/tests/event-test.c @@ -136,22 +136,25 @@ TEST(buffer_release) struct buffer *buf1; struct buffer *buf2; struct buffer *buf3; + pixman_color_t black; int buf1_released = 0; int buf2_released = 0; int buf3_released = 0; int frame; + color_rgb888(&black, 0, 0, 0); + client = create_client_and_test_surface(100, 100, 100, 100); test_assert_ptr_not_null(client); surface = client->surface->wl_surface; - buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100); + buf1 = create_shm_buffer_solid(client, 100, 100, &black); wl_buffer_add_listener(buf1->proxy, &buffer_listener, &buf1_released); - buf2 = create_shm_buffer_a8r8g8b8(client, 100, 100); + buf2 = create_shm_buffer_solid(client, 100, 100, &black); wl_buffer_add_listener(buf2->proxy, &buffer_listener, &buf2_released); - buf3 = create_shm_buffer_a8r8g8b8(client, 100, 100); + buf3 = create_shm_buffer_solid(client, 100, 100, &black); wl_buffer_add_listener(buf3->proxy, &buffer_listener, &buf3_released); /* diff --git a/tests/ivi-layout-test-client.c b/tests/ivi-layout-test-client.c index a624976ac..31b4b6b2d 100644 --- a/tests/ivi-layout-test-client.c +++ b/tests/ivi-layout-test-client.c @@ -463,6 +463,7 @@ TEST(ivi_layout_surface_configure_notification) struct ivi_application *iviapp; struct ivi_window *wind; struct buffer *buffer; + pixman_color_t black; client = create_client(); runner = client_create_runner(client); @@ -472,7 +473,8 @@ TEST(ivi_layout_surface_configure_notification) wind = client_create_ivi_window(client, iviapp, IVI_TEST_SURFACE_ID(0)); - buffer = create_shm_buffer_a8r8g8b8(client, 200, 300); + color_rgb888(&black, 0, 0, 0); + buffer = create_shm_buffer_solid(client, 200, 300, &black); wl_surface_attach(wind->wl_surface, buffer->proxy, 0, 0); wl_surface_damage(wind->wl_surface, 0, 0, 20, 30); diff --git a/tests/linux-explicit-synchronization-test.c b/tests/linux-explicit-synchronization-test.c index 0c23a568b..cfd68a196 100644 --- a/tests/linux-explicit-synchronization-test.c +++ b/tests/linux-explicit-synchronization-test.c @@ -273,10 +273,13 @@ TEST(get_release_after_commit_succeeds) struct zwp_linux_surface_synchronization_v1 *surface_sync = zwp_linux_explicit_synchronization_v1_get_synchronization( sync, surface); - struct buffer *buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100); + struct buffer *buf1; + pixman_color_t black; struct zwp_linux_buffer_release_v1 *buffer_release1; struct zwp_linux_buffer_release_v1 *buffer_release2; + color_rgb888(&black, 0, 0, 0); + buf1 = create_shm_buffer_solid(client, 100, 100, &black); buffer_release1 = zwp_linux_surface_synchronization_v1_get_release(surface_sync); client_roundtrip(client); @@ -335,8 +338,9 @@ TEST(get_release_events_are_emitted_for_different_buffers) struct zwp_linux_surface_synchronization_v1 *surface_sync = zwp_linux_explicit_synchronization_v1_get_synchronization( sync, client->surface->wl_surface); - struct buffer *buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100); - struct buffer *buf2 = create_shm_buffer_a8r8g8b8(client, 100, 100); + struct buffer *buf1; + struct buffer *buf2; + pixman_color_t black; struct wl_surface *surface = client->surface->wl_surface; struct zwp_linux_buffer_release_v1 *buffer_release1; struct zwp_linux_buffer_release_v1 *buffer_release2; @@ -344,6 +348,10 @@ TEST(get_release_events_are_emitted_for_different_buffers) int buf_released2 = 0; int frame; + color_rgb888(&black, 0, 0, 0); + buf1 = create_shm_buffer_solid(client, 100, 100, &black); + buf2 = create_shm_buffer_solid(client, 100, 100, &black); + buffer_release1 = zwp_linux_surface_synchronization_v1_get_release(surface_sync); zwp_linux_buffer_release_v1_add_listener(buffer_release1, @@ -399,7 +407,8 @@ TEST(get_release_events_are_emitted_for_same_buffer_on_surface) struct zwp_linux_surface_synchronization_v1 *surface_sync = zwp_linux_explicit_synchronization_v1_get_synchronization( sync, client->surface->wl_surface); - struct buffer *buf = create_shm_buffer_a8r8g8b8(client, 100, 100); + struct buffer *buf; + pixman_color_t black; struct wl_surface *surface = client->surface->wl_surface; struct zwp_linux_buffer_release_v1 *buffer_release1; struct zwp_linux_buffer_release_v1 *buffer_release2; @@ -407,6 +416,8 @@ TEST(get_release_events_are_emitted_for_same_buffer_on_surface) int buf_released2 = 0; int frame; + color_rgb888(&black, 0, 0, 0); + buf = create_shm_buffer_solid(client, 100, 100, &black); buffer_release1 = zwp_linux_surface_synchronization_v1_get_release(surface_sync); zwp_linux_buffer_release_v1_add_listener(buffer_release1, @@ -467,14 +478,19 @@ TEST(get_release_events_are_emitted_for_same_buffer_on_different_surfaces) struct zwp_linux_surface_synchronization_v1 *surface_sync2 = zwp_linux_explicit_synchronization_v1_get_synchronization( sync, surface2); - struct buffer *buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100); - struct buffer *buf2 = create_shm_buffer_a8r8g8b8(client, 100, 100); + struct buffer *buf1; + struct buffer *buf2; + pixman_color_t black; struct zwp_linux_buffer_release_v1 *buffer_release1; struct zwp_linux_buffer_release_v1 *buffer_release2; int buf_released1 = 0; int buf_released2 = 0; int frame; + color_rgb888(&black, 0, 0, 0); + buf1 = create_shm_buffer_solid(client, 100, 100, &black); + buf2 = create_shm_buffer_solid(client, 100, 100, &black); + weston_test_move_surface(client->test->weston_test, surface2, 0, 0); /* Attach buf1 to both surface1 and surface2. */ diff --git a/tests/output-damage-test.c b/tests/output-damage-test.c index ed54f2966..55af7129c 100644 --- a/tests/output-damage-test.c +++ b/tests/output-damage-test.c @@ -210,10 +210,8 @@ TEST(output_damage) client->surface->width = width; client->surface->height = height; - for (i = 0; i < COUNT_BUFS; i++) { - buf[i] = create_shm_buffer_a8r8g8b8(client, width, height); - fill_image_with_color(buf[i]->image, &colors[i]); - } + for (i = 0; i < COUNT_BUFS; i++) + buf[i] = create_shm_buffer_solid(client, width, height, &colors[i]); client->surface->buffer = buf[0]; move_client_frame_sync(client, 19, 19); diff --git a/tests/paint-node-test.c b/tests/paint-node-test.c index b080a4c01..b20789da3 100644 --- a/tests/paint-node-test.c +++ b/tests/paint-node-test.c @@ -57,8 +57,7 @@ surface_commit_color(struct client *client, struct wl_surface *surface, { struct buffer *buf; - buf = create_shm_buffer_a8r8g8b8(client, width, height); - fill_image_with_color(buf->image, color); + buf = create_shm_buffer_solid(client, width, height, color); wl_surface_attach(surface, buf->proxy, 0, 0); wl_surface_damage_buffer(surface, 0, 0, width, height); wl_surface_commit(surface); diff --git a/tests/pointer-shot-test.c b/tests/pointer-shot-test.c index 166449be4..ce027b183 100644 --- a/tests/pointer-shot-test.c +++ b/tests/pointer-shot-test.c @@ -92,8 +92,7 @@ surface_commit_color(struct client *client, struct surface *surface, { struct buffer *buf; - buf = create_shm_buffer_a8r8g8b8(client, width, height); - fill_image_with_color(buf->image, color); + buf = create_shm_buffer_solid(client, width, height, color); wl_surface_attach(surface->wl_surface, buf->proxy, 0, 0); wl_surface_damage(surface->wl_surface, 0, 0, width, height); wl_surface_commit(surface->wl_surface); @@ -145,8 +144,7 @@ TEST(pointer_cursor_retains_committed_buffer_after_reenter) /* Set up the main surface. */ client->surface = main_surface; - client->surface->buffer = create_shm_buffer_a8r8g8b8(client, 100, 100); - fill_image_with_color(client->surface->buffer->image, &red); + client->surface->buffer = create_shm_buffer_solid(client, 100, 100, &red); move_client_frame_sync(client, 50, 50); /* Move the pointer into the main surface. */ diff --git a/tests/subsurface-shot-test.c b/tests/subsurface-shot-test.c index 905a98f0f..5da72ec38 100644 --- a/tests/subsurface-shot-test.c +++ b/tests/subsurface-shot-test.c @@ -120,8 +120,7 @@ surface_commit_color(struct client *client, struct wl_surface *surface, { struct buffer *buf; - buf = create_shm_buffer_a8r8g8b8(client, width, height); - fill_image_with_color(buf->image, color); + buf = create_shm_buffer_solid(client, width, height, color); wl_surface_attach(surface, buf->proxy, 0, 0); wl_surface_damage_buffer(surface, 0, 0, width, height); wl_surface_commit(surface); diff --git a/tests/viewporter-shot-test.c b/tests/viewporter-shot-test.c index b25225f03..5dfbef374 100644 --- a/tests/viewporter-shot-test.c +++ b/tests/viewporter-shot-test.c @@ -84,8 +84,7 @@ TEST(viewport_upscale_solid) client->surface = create_test_surface(client); viewport = client_create_viewport(client); - client->surface->buffer = create_shm_buffer_a8r8g8b8(client, 2, 2); - fill_image_with_color(client->surface->buffer->image, &color); + client->surface->buffer = create_shm_buffer_solid(client, 2, 2, &color); /* Needs output scale != buffer scale to hit bilinear filter. */ wl_surface_set_buffer_scale(client->surface->wl_surface, 2); diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index aef0ca83d..c0296c61a 100644 --- a/tests/weston-test-client-helper.c +++ b/tests/weston-test-client-helper.c @@ -1188,8 +1188,7 @@ create_client_and_test_surface(int x, int y, int width, int height) surface->width = width; surface->height = height; - surface->buffer = create_shm_buffer_a8r8g8b8(client, width, height); - fill_image_with_color(surface->buffer->image, &color); + surface->buffer = create_shm_buffer_solid(client, width, height, &color); move_client_frame_sync(client, x, y); @@ -2351,6 +2350,20 @@ fill_image_with_color(pixman_image_t *image, const pixman_color_t *color) pixman_image_unref(solid); } +struct buffer * +create_shm_buffer_solid(struct client *client, int width, int height, + const pixman_color_t *color) +{ + struct buffer *buffer; + + buffer = create_shm_buffer_a8r8g8b8(client, width, height); + if (!buffer) + return NULL; + fill_image_with_color(buffer->image, color); + + return buffer; +} + /** * Convert 8-bit RGB to opaque Pixman color * diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h index ad0713a40..7de02ebc1 100644 --- a/tests/weston-test-client-helper.h +++ b/tests/weston-test-client-helper.h @@ -244,6 +244,10 @@ create_shm_buffer(struct client *client, int width, int height, struct buffer * create_shm_buffer_a8r8g8b8(struct client *client, int width, int height); +struct buffer * +create_shm_buffer_solid(struct client *client, int width, int height, + const pixman_color_t *solid); + bool support_drm_format(struct client *client, uint32_t format, uint64_t modifier); diff --git a/tests/xdg-client-helper.c b/tests/xdg-client-helper.c index 88a7dbd32..8d4676295 100644 --- a/tests/xdg-client-helper.c +++ b/tests/xdg-client-helper.c @@ -190,14 +190,12 @@ xdg_surface_commit_solid(struct xdg_surface_data *xdg_surface, width = xdg_surface->configure.width; height = xdg_surface->configure.height; - buf = create_shm_buffer_a8r8g8b8(xdg_surface->surface->client, - width, height); + color_rgb888(&color, r, g, b); + buf = create_shm_buffer_solid(xdg_surface->surface->client, + width, height, &color); test_assert_ptr_not_null(buf); xdg_surface->surface->buffer = buf; - color_rgb888(&color, r, g, b); - fill_image_with_color(buf->image, &color); - wl_surface_attach(xdg_surface->surface->wl_surface, buf->proxy, 0, 0); wl_surface_damage_buffer(xdg_surface->surface->wl_surface, 0, 0, width, height);