From 4d2ea5dd0b141dfdd11f1849f6e76e27808316b5 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Wed, 8 Jun 2022 14:32:16 +0300 Subject: [PATCH] tests: move set_opaque_rect() to client helpers I will be needing it in a new test, so let's share it. For convenience, this also adds client back-pointer in struct surface so that I don't need to pass client explicitly. Signed-off-by: Pekka Paalanen --- tests/alpha-blending-test.c | 17 ++--------------- tests/weston-test-client-helper.c | 12 ++++++++++++ tests/weston-test-client-helper.h | 5 +++++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/alpha-blending-test.c b/tests/alpha-blending-test.c index 1a315828..58111b8e 100644 --- a/tests/alpha-blending-test.c +++ b/tests/alpha-blending-test.c @@ -80,19 +80,6 @@ fixture_setup(struct weston_test_harness *harness, const struct setup_args *arg) } DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args, meta); -static void -set_opaque_rect(struct client *client, - struct surface *surface, - const struct rectangle *rect) -{ - struct wl_region *region; - - region = wl_compositor_create_region(client->wl_compositor); - wl_region_add(region, rect->x, rect->y, rect->width, rect->height); - wl_surface_set_opaque_region(surface->wl_surface, region); - wl_region_destroy(region); -} - static uint32_t premult_color(uint32_t a, uint32_t r, uint32_t g, uint32_t b) { @@ -400,8 +387,8 @@ TEST(alpha_blend) client->surface->width = width; client->surface->height = height; client->surface->buffer = bg; /* pass ownership */ - set_opaque_rect(client, client->surface, - &(struct rectangle){ 0, 0, width, height }); + surface_set_opaque_rect(client->surface, + &(struct rectangle){ 0, 0, width, height }); /* foreground blended content */ fg = create_shm_buffer_a8r8g8b8(client, width, height); diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index 1b96f8e6..30974d61 100644 --- a/tests/weston-test-client-helper.c +++ b/tests/weston-test-client-helper.c @@ -976,6 +976,7 @@ create_test_surface(struct client *client) surface = xzalloc(sizeof *surface); + surface->client = client; surface->wl_surface = wl_compositor_create_surface(client->wl_compositor); assert(surface->wl_surface); @@ -998,6 +999,17 @@ surface_destroy(struct surface *surface) free(surface); } +void +surface_set_opaque_rect(struct surface *surface, const struct rectangle *rect) +{ + struct wl_region *region; + + region = wl_compositor_create_region(surface->client->wl_compositor); + wl_region_add(region, rect->x, rect->y, rect->width, rect->height); + wl_surface_set_opaque_region(surface->wl_surface, region); + wl_region_destroy(region); +} + struct client * create_client_and_test_surface(int x, int y, int width, int height) { diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h index b30fdb7f..dd20d514 100644 --- a/tests/weston-test-client-helper.h +++ b/tests/weston-test-client-helper.h @@ -172,6 +172,8 @@ struct buffer { }; struct surface { + struct client *client; /* not owned */ + struct wl_surface *wl_surface; struct output *output; /* not owned */ int x; @@ -205,6 +207,9 @@ create_test_surface(struct client *client); void surface_destroy(struct surface *surface); +void +surface_set_opaque_rect(struct surface *surface, const struct rectangle *rect); + struct client * create_client_and_test_surface(int x, int y, int width, int height);