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 <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 2 years ago committed by Marius Vlad
parent b878357dfd
commit 4d2ea5dd0b
  1. 17
      tests/alpha-blending-test.c
  2. 12
      tests/weston-test-client-helper.c
  3. 5
      tests/weston-test-client-helper.h

@ -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);

@ -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)
{

@ -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);

Loading…
Cancel
Save