tests/alpha-blending: refactor into get_middle_row()
Refactor the alpha-blending test to allow using all three images foreground, background, and screenshot in a future new verification function. This is a pure refactoring, no change in behavior. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
parent
7c13c4a476
commit
129bef50db
@ -155,26 +155,32 @@ pixels_monotonic(const uint32_t *row, int x)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *
|
||||||
|
get_middle_row(struct buffer *buf)
|
||||||
|
{
|
||||||
|
const int y = (BLOCK_WIDTH - 1) / 2; /* middle row */
|
||||||
|
void *pixels;
|
||||||
|
int stride_bytes;
|
||||||
|
|
||||||
|
assert(pixman_image_get_width(buf->image) >= BLOCK_WIDTH * ALPHA_STEPS);
|
||||||
|
assert(pixman_image_get_height(buf->image) >= BLOCK_WIDTH);
|
||||||
|
|
||||||
|
pixels = pixman_image_get_data(buf->image);
|
||||||
|
stride_bytes = pixman_image_get_stride(buf->image);
|
||||||
|
return pixels + y * stride_bytes;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
check_blend_pattern(struct buffer *shot)
|
check_blend_pattern(struct buffer *shot)
|
||||||
{
|
{
|
||||||
|
uint32_t *shot_row = get_middle_row(shot);
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
const int y = (BLOCK_WIDTH - 1) / 2; /* middle row */
|
|
||||||
int x;
|
int x;
|
||||||
void *pixels;
|
|
||||||
int stride_bytes;
|
|
||||||
uint32_t *row;
|
|
||||||
|
|
||||||
assert(pixman_image_get_width(shot->image) >= BLOCK_WIDTH * ALPHA_STEPS);
|
for (x = 0; x < BLOCK_WIDTH * ALPHA_STEPS - 1; x++) {
|
||||||
assert(pixman_image_get_height(shot->image) >= BLOCK_WIDTH);
|
if (!pixels_monotonic(shot_row, x))
|
||||||
|
|
||||||
pixels = pixman_image_get_data(shot->image);
|
|
||||||
stride_bytes = pixman_image_get_stride(shot->image);
|
|
||||||
row = pixels + y * stride_bytes;
|
|
||||||
|
|
||||||
for (x = 0; x < BLOCK_WIDTH * ALPHA_STEPS - 1; x++)
|
|
||||||
if (!pixels_monotonic(row, x))
|
|
||||||
ret = false;
|
ret = false;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -208,7 +214,8 @@ TEST(alpha_blend_monotonic)
|
|||||||
.alpha = 0xffff
|
.alpha = 0xffff
|
||||||
};
|
};
|
||||||
struct client *client;
|
struct client *client;
|
||||||
struct buffer *buf;
|
struct buffer *bg;
|
||||||
|
struct buffer *fg;
|
||||||
struct wl_subcompositor *subco;
|
struct wl_subcompositor *subco;
|
||||||
struct wl_surface *surf;
|
struct wl_surface *surf;
|
||||||
struct wl_subsurface *sub;
|
struct wl_subsurface *sub;
|
||||||
@ -219,26 +226,26 @@ TEST(alpha_blend_monotonic)
|
|||||||
subco = bind_to_singleton_global(client, &wl_subcompositor_interface, 1);
|
subco = bind_to_singleton_global(client, &wl_subcompositor_interface, 1);
|
||||||
|
|
||||||
/* background window content */
|
/* background window content */
|
||||||
buf = create_shm_buffer_a8r8g8b8(client, width, height);
|
bg = create_shm_buffer_a8r8g8b8(client, width, height);
|
||||||
fill_image_with_color(buf->image, &background_color);
|
fill_image_with_color(bg->image, &background_color);
|
||||||
|
|
||||||
/* background window, main surface */
|
/* background window, main surface */
|
||||||
client->surface = create_test_surface(client);
|
client->surface = create_test_surface(client);
|
||||||
client->surface->width = width;
|
client->surface->width = width;
|
||||||
client->surface->height = height;
|
client->surface->height = height;
|
||||||
client->surface->buffer = buf; /* pass ownership */
|
client->surface->buffer = bg; /* pass ownership */
|
||||||
set_opaque_rect(client, client->surface,
|
set_opaque_rect(client, client->surface,
|
||||||
&(struct rectangle){ 0, 0, width, height });
|
&(struct rectangle){ 0, 0, width, height });
|
||||||
|
|
||||||
/* foreground blended content */
|
/* foreground blended content */
|
||||||
buf = create_shm_buffer_a8r8g8b8(client, width, height);
|
fg = create_shm_buffer_a8r8g8b8(client, width, height);
|
||||||
fill_alpha_pattern(buf);
|
fill_alpha_pattern(fg);
|
||||||
|
|
||||||
/* foreground window, sub-surface */
|
/* foreground window, sub-surface */
|
||||||
surf = wl_compositor_create_surface(client->wl_compositor);
|
surf = wl_compositor_create_surface(client->wl_compositor);
|
||||||
sub = wl_subcompositor_get_subsurface(subco, surf, client->surface->wl_surface);
|
sub = wl_subcompositor_get_subsurface(subco, surf, client->surface->wl_surface);
|
||||||
/* sub-surface defaults to position 0, 0, top-most, synchronized */
|
/* sub-surface defaults to position 0, 0, top-most, synchronized */
|
||||||
wl_surface_attach(surf, buf->proxy, 0, 0);
|
wl_surface_attach(surf, fg->proxy, 0, 0);
|
||||||
wl_surface_damage(surf, 0, 0, width, height);
|
wl_surface_damage(surf, 0, 0, width, height);
|
||||||
wl_surface_commit(surf);
|
wl_surface_commit(surf);
|
||||||
|
|
||||||
@ -255,7 +262,7 @@ TEST(alpha_blend_monotonic)
|
|||||||
|
|
||||||
wl_subsurface_destroy(sub);
|
wl_subsurface_destroy(sub);
|
||||||
wl_surface_destroy(surf);
|
wl_surface_destroy(surf);
|
||||||
buffer_destroy(buf);
|
buffer_destroy(fg);
|
||||||
wl_subcompositor_destroy(subco);
|
wl_subcompositor_destroy(subco);
|
||||||
client_destroy(client);
|
client_destroy(client); /* destroys bg */
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user