tests: use pixel-formats.h in create_shm_buffer()

Instead of starting yet another hand-crafted pixel format mapping table,
use the one we have.

Following patches want to be able to create XRGB8888 buffers, and later
even other formats.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
Pekka Paalanen 2022-09-01 16:15:08 +03:00
parent e40a7eae67
commit c93b18ea54
2 changed files with 16 additions and 6 deletions

View file

@ -43,6 +43,8 @@ lib_test_client = static_library(
dep_libshared,
dep_wayland_client,
dep_libexec_weston,
dep_libweston_private,
dep_libdrm_headers,
dep_pixman,
dependency('cairo'),
],

View file

@ -37,6 +37,8 @@
#include <cairo.h>
#include "test-config.h"
#include "pixel-formats.h"
#include "shared/weston-drm-fourcc.h"
#include "shared/os-compatibility.h"
#include "shared/string-helpers.h"
#include "shared/xalloc.h"
@ -445,8 +447,9 @@ static const struct wl_surface_listener surface_listener = {
static struct buffer *
create_shm_buffer(struct client *client, int width, int height,
pixman_format_code_t format, uint32_t wlfmt)
uint32_t drm_format)
{
const struct pixel_format_info *pfmt;
struct wl_shm *shm = client->wl_shm;
struct buffer *buf;
size_t stride_bytes;
@ -458,9 +461,13 @@ create_shm_buffer(struct client *client, int width, int height,
assert(width > 0);
assert(height > 0);
pfmt = pixel_format_get_info(drm_format);
assert(pfmt);
assert(pixel_format_get_plane_count(pfmt) == 1);
buf = xzalloc(sizeof *buf);
bytes_pp = PIXMAN_FORMAT_BPP(format) / 8;
bytes_pp = pfmt->bpp / 8;
stride_bytes = width * bytes_pp;
/* round up to multiple of 4 bytes for Pixman */
stride_bytes = (stride_bytes + 3) & ~3u;
@ -480,11 +487,13 @@ create_shm_buffer(struct client *client, int width, int height,
pool = wl_shm_create_pool(shm, fd, buf->len);
buf->proxy = wl_shm_pool_create_buffer(pool, 0, width, height,
stride_bytes, wlfmt);
stride_bytes,
pixel_format_get_shm_format(pfmt));
wl_shm_pool_destroy(pool);
close(fd);
buf->image = pixman_image_create_bits(format, width, height,
buf->image = pixman_image_create_bits(pfmt->pixman_format,
width, height,
data, stride_bytes);
assert(buf->proxy);
@ -498,8 +507,7 @@ create_shm_buffer_a8r8g8b8(struct client *client, int width, int height)
{
assert(client->has_argb);
return create_shm_buffer(client, width, height,
PIXMAN_a8r8g8b8, WL_SHM_FORMAT_ARGB8888);
return create_shm_buffer(client, width, height, DRM_FORMAT_ARGB8888);
}
void