2020-12-09 15:14:11 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2020 Collabora, Ltd.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
|
* portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2025-04-07 13:43:31 +02:00
|
|
|
#include <fcntl.h>
|
2025-04-07 13:42:43 +02:00
|
|
|
#include <math.h>
|
2025-04-07 13:43:31 +02:00
|
|
|
#include <sys/ioctl.h>
|
2020-12-09 15:14:11 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
#include "test-config.h"
|
2020-12-09 15:14:11 +02:00
|
|
|
#include "weston-test-client-helper.h"
|
|
|
|
|
#include "weston-test-fixture-compositor.h"
|
2022-06-13 12:29:30 +03:00
|
|
|
#include "image-iter.h"
|
2025-05-12 18:36:34 +02:00
|
|
|
#include "pixel-formats.h"
|
2020-12-09 15:14:11 +02:00
|
|
|
#include "shared/os-compatibility.h"
|
2021-02-04 17:39:45 +02:00
|
|
|
#include "shared/weston-drm-fourcc.h"
|
2020-12-09 15:14:11 +02:00
|
|
|
#include "shared/xalloc.h"
|
|
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
/* Align buffers to 256 bytes - required by e.g. AMD GPUs */
|
|
|
|
|
#define STRIDE_ALIGN_MASK 255
|
|
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
|
get_aligned_stride(size_t width_bytes)
|
|
|
|
|
{
|
|
|
|
|
return (width_bytes + STRIDE_ALIGN_MASK) & ~STRIDE_ALIGN_MASK;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-21 12:47:13 +01:00
|
|
|
/* XXX For formats with more than 8 bit pre component, we should ideally load a
|
|
|
|
|
* 16-bit (or 32-bit) per component image and store into a 16-bit (or 32-bit)
|
|
|
|
|
* per component renderbuffer so that we can ensure the additional precision is
|
|
|
|
|
* correctly handled. */
|
|
|
|
|
|
2025-05-01 18:53:54 +02:00
|
|
|
struct setup_args {
|
|
|
|
|
struct fixture_metadata meta;
|
|
|
|
|
enum weston_renderer_type renderer;
|
|
|
|
|
const char *logging_scopes;
|
2025-05-11 21:50:28 +02:00
|
|
|
|
|
|
|
|
/* Formats in these arrays can be defined per renderer and must be
|
|
|
|
|
* advertised and supported by the renderer.
|
|
|
|
|
* If undefined, all formats checked by the test are considered
|
|
|
|
|
* must pass. */
|
|
|
|
|
const uint32_t *shm_format_must_pass;
|
|
|
|
|
size_t shm_format_num;
|
|
|
|
|
const uint32_t *dmabuf_format_must_pass;
|
|
|
|
|
size_t dmabuf_format_num;
|
2025-05-12 18:36:34 +02:00
|
|
|
|
|
|
|
|
bool gl_force_import_yuv_fallback;
|
2025-05-11 21:50:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Formats supported by llvmpipe as of Mesa 25.0.4 */
|
|
|
|
|
static const uint32_t gl_dmabuf_format_must_pass[] = {
|
|
|
|
|
DRM_FORMAT_RGB565,
|
|
|
|
|
DRM_FORMAT_XRGB8888,
|
|
|
|
|
DRM_FORMAT_ARGB8888,
|
|
|
|
|
DRM_FORMAT_XBGR8888,
|
|
|
|
|
DRM_FORMAT_ABGR8888,
|
|
|
|
|
DRM_FORMAT_XRGB2101010,
|
|
|
|
|
DRM_FORMAT_ARGB2101010,
|
|
|
|
|
DRM_FORMAT_XBGR2101010,
|
|
|
|
|
DRM_FORMAT_ABGR2101010,
|
|
|
|
|
DRM_FORMAT_XBGR16161616,
|
|
|
|
|
DRM_FORMAT_ABGR16161616,
|
|
|
|
|
DRM_FORMAT_XBGR16161616F,
|
|
|
|
|
DRM_FORMAT_ABGR16161616F,
|
|
|
|
|
DRM_FORMAT_YUV420,
|
|
|
|
|
DRM_FORMAT_YVU420,
|
|
|
|
|
DRM_FORMAT_YUV422,
|
|
|
|
|
DRM_FORMAT_YVU422,
|
|
|
|
|
DRM_FORMAT_YUV444,
|
|
|
|
|
DRM_FORMAT_YVU444,
|
|
|
|
|
DRM_FORMAT_NV12,
|
|
|
|
|
DRM_FORMAT_NV21,
|
|
|
|
|
DRM_FORMAT_NV16,
|
|
|
|
|
DRM_FORMAT_YUYV,
|
|
|
|
|
DRM_FORMAT_YVYU,
|
|
|
|
|
DRM_FORMAT_UYVY,
|
|
|
|
|
DRM_FORMAT_VYUY,
|
|
|
|
|
DRM_FORMAT_XYUV8888,
|
|
|
|
|
DRM_FORMAT_P010,
|
|
|
|
|
DRM_FORMAT_P012,
|
|
|
|
|
DRM_FORMAT_P016,
|
2025-05-01 18:53:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct setup_args my_setup_args[] = {
|
|
|
|
|
{
|
|
|
|
|
.meta.name = "GL",
|
|
|
|
|
.renderer = WESTON_RENDERER_GL,
|
|
|
|
|
.logging_scopes = "log,gl-shader-generator",
|
2025-05-11 21:50:28 +02:00
|
|
|
.dmabuf_format_must_pass = gl_dmabuf_format_must_pass,
|
|
|
|
|
.dmabuf_format_num = ARRAY_LENGTH(gl_dmabuf_format_must_pass),
|
2025-05-12 18:36:34 +02:00
|
|
|
.gl_force_import_yuv_fallback = false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.meta.name = "GL force-import-yuv-fallback",
|
|
|
|
|
.renderer = WESTON_RENDERER_GL,
|
|
|
|
|
.logging_scopes = "log,gl-shader-generator",
|
|
|
|
|
.dmabuf_format_must_pass = gl_dmabuf_format_must_pass,
|
|
|
|
|
.dmabuf_format_num = ARRAY_LENGTH(gl_dmabuf_format_must_pass),
|
|
|
|
|
.gl_force_import_yuv_fallback = true,
|
2025-05-01 18:53:54 +02:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-09 15:14:11 +02:00
|
|
|
static enum test_result_code
|
2025-05-01 18:53:54 +02:00
|
|
|
fixture_setup(struct weston_test_harness *harness, const struct setup_args *arg)
|
2020-12-09 15:14:11 +02:00
|
|
|
{
|
|
|
|
|
struct compositor_setup setup;
|
|
|
|
|
|
|
|
|
|
compositor_setup_defaults(&setup);
|
2025-05-01 18:53:54 +02:00
|
|
|
setup.renderer = arg->renderer;
|
2020-12-09 15:14:11 +02:00
|
|
|
setup.width = 324;
|
|
|
|
|
setup.height = 264;
|
|
|
|
|
setup.shell = SHELL_TEST_DESKTOP;
|
2025-05-01 18:53:54 +02:00
|
|
|
setup.logging_scopes = arg->logging_scopes;
|
2024-02-20 21:09:41 +01:00
|
|
|
setup.refresh = HIGHEST_OUTPUT_REFRESH;
|
2025-05-12 18:36:34 +02:00
|
|
|
setup.test_quirks.gl_force_import_yuv_fallback =
|
|
|
|
|
arg->gl_force_import_yuv_fallback;
|
2020-12-09 15:14:11 +02:00
|
|
|
|
|
|
|
|
return weston_test_harness_execute_as_client(harness, &setup);
|
|
|
|
|
}
|
2025-05-01 18:53:54 +02:00
|
|
|
DECLARE_FIXTURE_SETUP_WITH_ARG(fixture_setup, my_setup_args, meta);
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type {
|
|
|
|
|
BUFFER_TYPE_SHM = 1,
|
2025-04-07 13:43:31 +02:00
|
|
|
BUFFER_TYPE_DMABUF,
|
2025-04-07 13:42:43 +02:00
|
|
|
};
|
|
|
|
|
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer {
|
2020-12-09 15:14:11 +02:00
|
|
|
void *data;
|
|
|
|
|
size_t bytes;
|
2025-04-07 13:42:43 +02:00
|
|
|
struct wl_buffer *wl_buffer;
|
|
|
|
|
int fd;
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct client_buffer_create_data {
|
|
|
|
|
uint32_t drm_format;
|
|
|
|
|
enum buffer_type type;
|
|
|
|
|
size_t bytes;
|
|
|
|
|
size_t strides[3];
|
|
|
|
|
size_t offsets[3];
|
|
|
|
|
int n_planes;
|
2020-12-09 15:14:11 +02:00
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer_case {
|
2020-12-09 15:14:11 +02:00
|
|
|
uint32_t drm_format;
|
|
|
|
|
const char *drm_format_name;
|
2024-11-21 12:47:13 +01:00
|
|
|
int ref_seq_no;
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *(*create_buffer)(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2025-04-23 13:47:28 +02:00
|
|
|
pixman_image_t *rgb_image);
|
2020-12-09 15:14:11 +02:00
|
|
|
};
|
|
|
|
|
|
2025-04-07 13:43:31 +02:00
|
|
|
#define UDMABUF_CREATE _IOW('u', 0x42, struct udmabuf_create)
|
|
|
|
|
#define UDMABUF_FLAGS_CLOEXEC 0x01
|
|
|
|
|
|
|
|
|
|
struct udmabuf_create {
|
|
|
|
|
uint32_t memfd;
|
|
|
|
|
uint32_t flags;
|
|
|
|
|
uint64_t offset;
|
|
|
|
|
uint64_t size;
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
static struct client_buffer_create_data
|
|
|
|
|
create_init(uint32_t drm_format, enum buffer_type type,
|
|
|
|
|
const struct image_header *ih)
|
|
|
|
|
{
|
|
|
|
|
return (struct client_buffer_create_data){
|
|
|
|
|
.drm_format = drm_format,
|
|
|
|
|
.type = type,
|
|
|
|
|
.width = ih->width,
|
|
|
|
|
.height = ih->height,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2024-11-13 16:33:09 +01:00
|
|
|
shm_buffer_create(struct client *client,
|
2020-12-09 15:14:11 +02:00
|
|
|
size_t bytes,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
int stride_bytes,
|
|
|
|
|
uint32_t drm_format)
|
|
|
|
|
{
|
|
|
|
|
struct wl_shm_pool *pool;
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-14 08:33:09 +01:00
|
|
|
uint32_t shm_format;
|
2020-12-09 15:14:11 +02:00
|
|
|
int fd;
|
|
|
|
|
|
2024-11-14 08:33:09 +01:00
|
|
|
if (drm_format == DRM_FORMAT_ARGB8888)
|
|
|
|
|
shm_format = WL_SHM_FORMAT_ARGB8888;
|
|
|
|
|
else if (drm_format == DRM_FORMAT_XRGB8888)
|
|
|
|
|
shm_format = WL_SHM_FORMAT_XRGB8888;
|
|
|
|
|
else
|
|
|
|
|
shm_format = drm_format;
|
|
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
if (!support_shm_format(client, shm_format)) {
|
|
|
|
|
testlog("%s: Skipped: format not supported by compositor for SHM\n",
|
|
|
|
|
get_test_name());
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2024-11-13 14:32:11 +01:00
|
|
|
|
2020-12-09 15:14:11 +02:00
|
|
|
buf = xzalloc(sizeof *buf);
|
2025-04-07 13:42:43 +02:00
|
|
|
buf->fd = -1;
|
2020-12-09 15:14:11 +02:00
|
|
|
buf->bytes = bytes;
|
|
|
|
|
buf->width = width;
|
|
|
|
|
buf->height = height;
|
|
|
|
|
|
|
|
|
|
fd = os_create_anonymous_file(buf->bytes);
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_int_ge(fd, 0);
|
2020-12-09 15:14:11 +02:00
|
|
|
|
|
|
|
|
buf->data = mmap(NULL, buf->bytes,
|
|
|
|
|
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
|
|
|
if (buf->data == MAP_FAILED) {
|
|
|
|
|
close(fd);
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_not_reached("mmap() failed");
|
2020-12-09 15:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pool = wl_shm_create_pool(client->wl_shm, fd, buf->bytes);
|
2025-04-07 13:42:43 +02:00
|
|
|
buf->wl_buffer = wl_shm_pool_create_buffer(pool, 0, buf->width,
|
|
|
|
|
buf->height, stride_bytes,
|
|
|
|
|
shm_format);
|
2020-12-09 15:14:11 +02:00
|
|
|
wl_shm_pool_destroy(pool);
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-07 13:43:31 +02:00
|
|
|
static void
|
|
|
|
|
create_succeeded(void *data,
|
|
|
|
|
struct zwp_linux_buffer_params_v1 *params,
|
|
|
|
|
struct wl_buffer *new_buffer)
|
|
|
|
|
{
|
|
|
|
|
struct client_buffer *buf = data;
|
|
|
|
|
|
|
|
|
|
buf->wl_buffer = new_buffer;
|
|
|
|
|
wl_proxy_set_queue ((struct wl_proxy *) buf->wl_buffer, NULL);
|
|
|
|
|
|
|
|
|
|
zwp_linux_buffer_params_v1_destroy(params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
create_failed(void *data, struct zwp_linux_buffer_params_v1 *params)
|
|
|
|
|
{
|
|
|
|
|
zwp_linux_buffer_params_v1_destroy(params);
|
|
|
|
|
test_assert_not_reached("buffer creation failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct zwp_linux_buffer_params_v1_listener params_listener = {
|
|
|
|
|
create_succeeded,
|
|
|
|
|
create_failed
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct client_buffer *
|
|
|
|
|
dmabuf_buffer_create(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
|
|
|
|
size_t bytes,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
int n_planes,
|
|
|
|
|
size_t *strides_bytes,
|
|
|
|
|
size_t *offsets_bytes)
|
|
|
|
|
{
|
|
|
|
|
struct zwp_linux_buffer_params_v1 *params;
|
|
|
|
|
struct wl_event_queue *event_queue;
|
|
|
|
|
struct client_buffer *buf;
|
|
|
|
|
struct udmabuf_create create;
|
|
|
|
|
int udmabuf_fd;
|
|
|
|
|
int fd, orig_fd;
|
|
|
|
|
|
|
|
|
|
if (!support_drm_format(client, drm_format, DRM_FORMAT_MOD_LINEAR)) {
|
|
|
|
|
testlog("%s: Skipped: format not supported by compositor for DMABUF\n",
|
|
|
|
|
get_test_name());
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
udmabuf_fd = open ("/dev/udmabuf", O_RDWR | O_CLOEXEC, 0);
|
|
|
|
|
if (udmabuf_fd < 0) {
|
|
|
|
|
testlog("%s: Skipped: udmabuf not supported\n", get_test_name());
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
orig_fd = memfd_create ("udmabuf", MFD_CLOEXEC | MFD_ALLOW_SEALING);
|
|
|
|
|
if (orig_fd < 0) {
|
|
|
|
|
testlog("memfd_create() failed: %s", strerror (errno));
|
|
|
|
|
test_assert_not_reached("udmabuf creation failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ftruncate (orig_fd, bytes) < 0) {
|
|
|
|
|
testlog("ftruncate failed: %s", strerror (errno));
|
|
|
|
|
close (orig_fd);
|
|
|
|
|
test_assert_not_reached("udmabuf creation failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fcntl (orig_fd, F_ADD_SEALS, F_SEAL_SHRINK) < 0) {
|
|
|
|
|
testlog("adding seals failed: %s", strerror (errno));
|
|
|
|
|
close (orig_fd);
|
|
|
|
|
test_assert_not_reached("udmabuf creation failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
create.memfd = orig_fd;
|
|
|
|
|
create.flags = UDMABUF_FLAGS_CLOEXEC;
|
|
|
|
|
create.offset = 0;
|
|
|
|
|
create.size = bytes;
|
|
|
|
|
|
|
|
|
|
fd = ioctl (udmabuf_fd, UDMABUF_CREATE, &create);
|
|
|
|
|
if (fd < 0) {
|
|
|
|
|
testlog("creating udmabuf failed: %s", strerror (errno));
|
|
|
|
|
close (orig_fd);
|
|
|
|
|
test_assert_not_reached("udmabuf creation failed");
|
|
|
|
|
}
|
|
|
|
|
/* The underlying memfd is kept as as a reference in the kernel. */
|
|
|
|
|
close (orig_fd);
|
|
|
|
|
close (udmabuf_fd);
|
|
|
|
|
|
|
|
|
|
test_assert_int_ge(fd, 0);
|
|
|
|
|
|
|
|
|
|
buf = xzalloc(sizeof *buf);
|
|
|
|
|
buf->bytes = bytes;
|
|
|
|
|
buf->fd = fd;
|
|
|
|
|
buf->width = width;
|
|
|
|
|
buf->height = height;
|
|
|
|
|
|
|
|
|
|
buf->data = mmap(NULL, buf->bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
|
|
|
if (buf->data == MAP_FAILED) {
|
|
|
|
|
testlog("mmap() failed: %s\n", strerror (errno));
|
|
|
|
|
close(fd);
|
|
|
|
|
test_assert_not_reached("udmabuf creation failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
params = zwp_linux_dmabuf_v1_create_params(client->dmabuf);
|
|
|
|
|
event_queue = wl_display_create_queue (client->wl_display);
|
|
|
|
|
wl_proxy_set_queue ((struct wl_proxy *) params, event_queue);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < n_planes; i++) {
|
|
|
|
|
zwp_linux_buffer_params_v1_add(params,
|
|
|
|
|
buf->fd,
|
|
|
|
|
i /* plane id */,
|
|
|
|
|
offsets_bytes[i],
|
|
|
|
|
strides_bytes[i],
|
|
|
|
|
DRM_FORMAT_MOD_LINEAR >> 32,
|
|
|
|
|
DRM_FORMAT_MOD_LINEAR & 0xffffffff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
zwp_linux_buffer_params_v1_add_listener(params,
|
|
|
|
|
¶ms_listener,
|
|
|
|
|
buf);
|
|
|
|
|
|
|
|
|
|
zwp_linux_buffer_params_v1_create(params,
|
|
|
|
|
buf->width,
|
|
|
|
|
buf->height,
|
|
|
|
|
drm_format,
|
|
|
|
|
0 /* flags */);
|
|
|
|
|
|
|
|
|
|
while (!buf->wl_buffer) {
|
|
|
|
|
if (wl_display_dispatch_queue(client->wl_display, event_queue) == -1)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
test_assert_true(buf->wl_buffer);
|
|
|
|
|
|
|
|
|
|
wl_event_queue_destroy(event_queue);
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
2025-04-07 13:42:43 +02:00
|
|
|
|
|
|
|
|
static struct client_buffer *
|
|
|
|
|
client_buffer_create(struct client *client,
|
|
|
|
|
struct client_buffer_create_data *create_data)
|
|
|
|
|
{
|
|
|
|
|
switch (create_data->type) {
|
|
|
|
|
case BUFFER_TYPE_SHM:
|
|
|
|
|
return shm_buffer_create(client, create_data->bytes,
|
|
|
|
|
create_data->width,
|
|
|
|
|
create_data->height,
|
|
|
|
|
create_data->strides[0],
|
|
|
|
|
create_data->drm_format);
|
2025-04-07 13:43:31 +02:00
|
|
|
case BUFFER_TYPE_DMABUF:
|
|
|
|
|
return dmabuf_buffer_create(client, create_data->drm_format,
|
|
|
|
|
create_data->bytes,
|
|
|
|
|
create_data->width,
|
|
|
|
|
create_data->height,
|
|
|
|
|
create_data->n_planes,
|
|
|
|
|
create_data->strides,
|
|
|
|
|
create_data->offsets);
|
2025-04-07 13:42:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test_assert_not_reached("Unknown buffer type");
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 15:14:11 +02:00
|
|
|
static void
|
2025-04-23 13:47:28 +02:00
|
|
|
client_buffer_destroy(struct client_buffer *buf)
|
2020-12-09 15:14:11 +02:00
|
|
|
{
|
2025-04-07 13:42:43 +02:00
|
|
|
wl_buffer_destroy(buf->wl_buffer);
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_int_eq(munmap(buf->data, buf->bytes), 0);
|
2025-04-07 13:42:43 +02:00
|
|
|
if (buf->fd > -1)
|
|
|
|
|
close(buf->fd);
|
2020-12-09 15:14:11 +02:00
|
|
|
free(buf);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-14 08:33:09 +01:00
|
|
|
/*
|
|
|
|
|
* 16 bpp RGB
|
|
|
|
|
*
|
|
|
|
|
* RGBX4444: [15:0] R:G:B:x 4:4:4:4 little endian
|
|
|
|
|
* RGBA4444: [15:0] R:G:B:A 4:4:4:4 little endian
|
|
|
|
|
*
|
|
|
|
|
* BGRX4444: [15:0] B:G:R:x 4:4:4:4 little endian
|
|
|
|
|
* BGRA4444: [15:0] B:G:R:A 4:4:4:4 little endian
|
|
|
|
|
*
|
|
|
|
|
* XRGB4444: [15:0] x:R:G:B 4:4:4:4 little endian
|
|
|
|
|
* ARGB4444: [15:0] A:R:G:B 4:4:4:4 little endian
|
|
|
|
|
*
|
|
|
|
|
* XBGR4444: [15:0] x:B:G:R 4:4:4:4 little endian
|
|
|
|
|
* ABGR4444: [15:0] A:B:G:R 4:4:4:4 little endian
|
|
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2024-11-14 08:33:09 +01:00
|
|
|
rgba4444_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2024-11-14 08:33:09 +01:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
|
|
|
|
static const int swizzles[][4] = {
|
|
|
|
|
{ 3, 2, 1, 0 }, /* RGBX4444, RGBA4444 */
|
|
|
|
|
{ 1, 2, 3, 0 }, /* BGRX4444, BGRA4444 */
|
|
|
|
|
{ 2, 1, 0, 3 }, /* XRGB4444, ARGB4444 */
|
|
|
|
|
{ 0, 1, 2, 3 }, /* XBGR4444, ABGR4444 */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct image_header src = image_header_from(rgb_image);
|
2025-04-07 13:42:43 +02:00
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-14 08:33:09 +01:00
|
|
|
bool is_opaque;
|
|
|
|
|
int idx, x, y;
|
|
|
|
|
uint16_t a;
|
|
|
|
|
|
|
|
|
|
switch (drm_format) {
|
|
|
|
|
case DRM_FORMAT_RGBX4444:
|
|
|
|
|
is_opaque = true;
|
|
|
|
|
idx = 0;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_RGBA4444:
|
|
|
|
|
is_opaque = false;
|
|
|
|
|
idx = 0;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_BGRX4444:
|
|
|
|
|
is_opaque = true;
|
|
|
|
|
idx = 1;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_BGRA4444:
|
|
|
|
|
is_opaque = false;
|
|
|
|
|
idx = 1;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_XRGB4444:
|
|
|
|
|
is_opaque = true;
|
|
|
|
|
idx = 2;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_ARGB4444:
|
|
|
|
|
is_opaque = false;
|
|
|
|
|
idx = 2;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_XBGR4444:
|
|
|
|
|
is_opaque = true;
|
|
|
|
|
idx = 3;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_ABGR4444:
|
|
|
|
|
is_opaque = false;
|
|
|
|
|
idx = 3;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_not_reached("Invalid format!");
|
2024-11-14 08:33:09 +01:00
|
|
|
};
|
|
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
args.n_planes = 1;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width * 2);
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.bytes = args.strides[0] * src.height;
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2024-11-14 08:33:09 +01:00
|
|
|
|
|
|
|
|
/* Store alpha as 0x0 to ensure the compositor correctly replaces it
|
|
|
|
|
* with 0xf. */
|
|
|
|
|
a = is_opaque ? 0x0 : 0xf;
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < src.height; y++) {
|
2025-04-07 13:42:43 +02:00
|
|
|
uint16_t *dst_row =
|
|
|
|
|
(uint16_t*) buf->data + (args.strides[0] / sizeof(uint16_t)) * y;
|
2024-11-14 08:33:09 +01:00
|
|
|
uint32_t *src_row = image_header_get_row_u32(&src, y);
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < src.width; x++) {
|
|
|
|
|
uint16_t r = (src_row[x] >> 20) & 0xf;
|
|
|
|
|
uint16_t g = (src_row[x] >> 12) & 0xf;
|
|
|
|
|
uint16_t b = (src_row[x] >> 4) & 0xf;
|
|
|
|
|
|
|
|
|
|
dst_row[x] =
|
|
|
|
|
r << (swizzles[idx][0] * 4) |
|
|
|
|
|
g << (swizzles[idx][1] * 4) |
|
|
|
|
|
b << (swizzles[idx][2] * 4) |
|
|
|
|
|
a << (swizzles[idx][3] * 4);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 16 bpp RGB
|
|
|
|
|
*
|
|
|
|
|
* RGBX5551: [15:0] R:G:B:x 5:5:5:1 little endian
|
|
|
|
|
* RGBA5551: [15:0] R:G:B:A 5:5:5:1 little endian
|
|
|
|
|
*
|
|
|
|
|
* BGRX5551: [15:0] B:G:R:x 5:5:5:1 little endian
|
|
|
|
|
* BGRA5551: [15:0] B:G:R:A 5:5:5:1 little endian
|
|
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2024-11-14 08:33:09 +01:00
|
|
|
rgba5551_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2024-11-14 08:33:09 +01:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
|
|
|
|
struct image_header src = image_header_from(rgb_image);
|
2025-04-07 13:42:43 +02:00
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2025-04-07 13:42:43 +02:00
|
|
|
|
2024-11-14 08:33:09 +01:00
|
|
|
int x, y;
|
|
|
|
|
uint16_t a;
|
|
|
|
|
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_true(drm_format == DRM_FORMAT_RGBX5551 ||
|
|
|
|
|
drm_format == DRM_FORMAT_RGBA5551 ||
|
|
|
|
|
drm_format == DRM_FORMAT_BGRX5551 ||
|
|
|
|
|
drm_format == DRM_FORMAT_BGRA5551);
|
2024-11-14 08:33:09 +01:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
args.n_planes = 1;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width * 2);
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.bytes = args.strides[0] * src.height;
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2024-11-14 08:33:09 +01:00
|
|
|
|
|
|
|
|
/* Store alpha as 0x0 to ensure the compositor correctly replaces it
|
|
|
|
|
* with 0x1. */
|
|
|
|
|
a = drm_format == DRM_FORMAT_RGBX5551 ||
|
|
|
|
|
drm_format == DRM_FORMAT_RGBX5551 ? 0x0 : 0x1;
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < src.height; y++) {
|
2025-04-07 13:42:43 +02:00
|
|
|
uint16_t *dst_row =
|
|
|
|
|
(uint16_t*) buf->data + (args.strides[0] / sizeof(uint16_t)) * y;
|
2024-11-14 08:33:09 +01:00
|
|
|
uint32_t *src_row = image_header_get_row_u32(&src, y);
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < src.width; x++) {
|
|
|
|
|
uint16_t r = (src_row[x] >> 19) & 0x1f;
|
|
|
|
|
uint16_t g = (src_row[x] >> 11) & 0x1f;
|
|
|
|
|
uint16_t b = (src_row[x] >> 3) & 0x1f;
|
|
|
|
|
|
|
|
|
|
if (drm_format == DRM_FORMAT_RGBX5551 ||
|
|
|
|
|
drm_format == DRM_FORMAT_RGBA5551)
|
|
|
|
|
dst_row[x] = r << 11 | g << 6 | b << 1 | a;
|
|
|
|
|
else
|
|
|
|
|
dst_row[x] = b << 11 | g << 6 | r << 1 | a;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 16 bpp RGB
|
|
|
|
|
*
|
|
|
|
|
* RGB565: [15:0] R:G:B 5:6:5 little endian
|
|
|
|
|
* BGR565: [15:0] B:G:R 5:6:5 little endian
|
|
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2024-11-14 08:33:09 +01:00
|
|
|
rgb565_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2024-11-14 08:33:09 +01:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
|
|
|
|
struct image_header src = image_header_from(rgb_image);
|
2025-04-07 13:42:43 +02:00
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-14 08:33:09 +01:00
|
|
|
int x, y;
|
|
|
|
|
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_true(drm_format == DRM_FORMAT_RGB565 ||
|
|
|
|
|
drm_format == DRM_FORMAT_BGR565);
|
2024-11-14 08:33:09 +01:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
args.n_planes = 1;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width * 2);
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.bytes = args.strides[0] * src.height;
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2024-11-14 08:33:09 +01:00
|
|
|
|
|
|
|
|
for (y = 0; y < src.height; y++) {
|
2025-04-07 13:42:43 +02:00
|
|
|
uint16_t *dst_row =
|
|
|
|
|
(uint16_t*) buf->data + (args.strides[0] / sizeof(uint16_t)) * y;
|
2024-11-14 08:33:09 +01:00
|
|
|
uint32_t *src_row = image_header_get_row_u32(&src, y);
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < src.width; x++) {
|
|
|
|
|
uint16_t r = (src_row[x] >> 19) & 0x1f;
|
|
|
|
|
uint16_t g = (src_row[x] >> 10) & 0x3f;
|
|
|
|
|
uint16_t b = (src_row[x] >> 3) & 0x1f;
|
|
|
|
|
|
|
|
|
|
if (drm_format == DRM_FORMAT_RGB565)
|
|
|
|
|
dst_row[x] = r << 11 | g << 5 | b;
|
|
|
|
|
else
|
|
|
|
|
dst_row[x] = b << 11 | g << 5 | r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 24 bpp RGB
|
|
|
|
|
*
|
|
|
|
|
* RGB888: [23:0] R:G:B 8:8:8 little endian
|
|
|
|
|
* BGR888: [23:0] B:G:R 8:8:8 little endian
|
|
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2024-11-14 08:33:09 +01:00
|
|
|
rgb888_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2024-11-14 08:33:09 +01:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
|
|
|
|
struct image_header src = image_header_from(rgb_image);
|
2025-04-07 13:42:43 +02:00
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-14 08:33:09 +01:00
|
|
|
int x, y;
|
|
|
|
|
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_true(drm_format == DRM_FORMAT_RGB888 ||
|
|
|
|
|
drm_format == DRM_FORMAT_BGR888);
|
2024-11-14 08:33:09 +01:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
args.n_planes = 1;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width * 3);
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.bytes = args.strides[0] * src.height;
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2024-11-14 08:33:09 +01:00
|
|
|
|
|
|
|
|
for (y = 0; y < src.height; y++) {
|
|
|
|
|
uint8_t *dst_row = (uint8_t*) buf->data + src.width * 3 * y;
|
|
|
|
|
uint32_t *src_row = image_header_get_row_u32(&src, y);
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < src.width; x++) {
|
|
|
|
|
uint8_t r = src_row[x] >> 16;
|
|
|
|
|
uint8_t g = src_row[x] >> 8;
|
|
|
|
|
uint8_t b = src_row[x];
|
|
|
|
|
|
|
|
|
|
if (drm_format == DRM_FORMAT_RGB888) {
|
|
|
|
|
dst_row[x * 3 + 2] = r;
|
|
|
|
|
dst_row[x * 3 + 1] = g;
|
|
|
|
|
dst_row[x * 3 + 0] = b;
|
2025-04-01 12:00:14 +02:00
|
|
|
} else {
|
|
|
|
|
dst_row[x * 3 + 2] = b;
|
|
|
|
|
dst_row[x * 3 + 1] = g;
|
|
|
|
|
dst_row[x * 3 + 0] = r;
|
2024-11-14 08:33:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 32 bpp RGB
|
|
|
|
|
*
|
|
|
|
|
* RGBX8888: [31:0] R:G:B:x 8:8:8:8 little endian
|
|
|
|
|
* RGBA8888: [31:0] R:G:B:A 8:8:8:8 little endian
|
|
|
|
|
*
|
|
|
|
|
* BGRX8888: [31:0] B:G:R:x 8:8:8:8 little endian
|
|
|
|
|
* BGRA8888: [31:0] B:G:R:A 8:8:8:8 little endian
|
|
|
|
|
*
|
|
|
|
|
* XRGB8888: [31:0] x:R:G:B 8:8:8:8 little endian
|
|
|
|
|
* ARGB8888: [31:0] A:R:G:B 8:8:8:8 little endian
|
|
|
|
|
*
|
|
|
|
|
* XBGR8888: [31:0] x:B:G:R 8:8:8:8 little endian
|
|
|
|
|
* ABGR8888: [31:0] A:B:G:R 8:8:8:8 little endian
|
|
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2024-11-14 08:33:09 +01:00
|
|
|
rgba8888_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2024-11-14 08:33:09 +01:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
|
|
|
|
static const int swizzles[][4] = {
|
|
|
|
|
{ 3, 2, 1, 0 }, /* RGBX8888, RGBA8888 */
|
|
|
|
|
{ 1, 2, 3, 0 }, /* BGRX8888, BGRA8888 */
|
|
|
|
|
{ 2, 1, 0, 3 }, /* XRGB8888, ARGB8888 */
|
|
|
|
|
{ 0, 1, 2, 3 }, /* XBGR8888, ABGR8888 */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct image_header src = image_header_from(rgb_image);
|
2025-04-07 13:42:43 +02:00
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-14 08:33:09 +01:00
|
|
|
bool is_opaque;
|
|
|
|
|
int idx, x, y;
|
|
|
|
|
uint32_t a;
|
|
|
|
|
|
|
|
|
|
switch (drm_format) {
|
|
|
|
|
case DRM_FORMAT_RGBX8888:
|
|
|
|
|
is_opaque = true;
|
|
|
|
|
idx = 0;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_RGBA8888:
|
|
|
|
|
is_opaque = false;
|
|
|
|
|
idx = 0;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_BGRX8888:
|
|
|
|
|
is_opaque = true;
|
|
|
|
|
idx = 1;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_BGRA8888:
|
|
|
|
|
is_opaque = false;
|
|
|
|
|
idx = 1;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_XRGB8888:
|
|
|
|
|
is_opaque = true;
|
|
|
|
|
idx = 2;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_ARGB8888:
|
|
|
|
|
is_opaque = false;
|
|
|
|
|
idx = 2;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_XBGR8888:
|
|
|
|
|
is_opaque = true;
|
|
|
|
|
idx = 3;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_ABGR8888:
|
|
|
|
|
is_opaque = false;
|
|
|
|
|
idx = 3;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_not_reached("Invalid format!");
|
2024-11-14 08:33:09 +01:00
|
|
|
};
|
|
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
args.n_planes = 1;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width * 4);
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.bytes = args.strides[0] * src.height;
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2024-11-14 08:33:09 +01:00
|
|
|
|
|
|
|
|
/* Store alpha as 0x00 to ensure the compositor correctly replaces it
|
|
|
|
|
* with 0xff. */
|
|
|
|
|
a = is_opaque ? 0x00 : 0xff;
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < src.height; y++) {
|
2025-04-07 13:42:43 +02:00
|
|
|
uint32_t *dst_row =
|
|
|
|
|
(uint32_t*) buf->data + (args.strides[0] / sizeof(uint32_t)) * y;
|
2024-11-14 08:33:09 +01:00
|
|
|
uint32_t *src_row = image_header_get_row_u32(&src, y);
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < src.width; x++) {
|
|
|
|
|
uint32_t r = (src_row[x] >> 16) & 0xff;
|
|
|
|
|
uint32_t g = (src_row[x] >> 8) & 0xff;
|
|
|
|
|
uint32_t b = (src_row[x] >> 0) & 0xff;
|
|
|
|
|
|
|
|
|
|
dst_row[x] =
|
|
|
|
|
r << (swizzles[idx][0] * 8) |
|
|
|
|
|
g << (swizzles[idx][1] * 8) |
|
|
|
|
|
b << (swizzles[idx][2] * 8) |
|
|
|
|
|
a << (swizzles[idx][3] * 8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 32 bpp RGB
|
|
|
|
|
*
|
|
|
|
|
* XRGB2101010: [31:0] x:R:G:B 2:10:10:10 little endian
|
|
|
|
|
* ARGB2101010: [31:0] A:R:G:B 2:10:10:10 little endian
|
|
|
|
|
*
|
|
|
|
|
* XBGR2101010: [31:0] x:B:G:R 2:10:10:10 little endian
|
|
|
|
|
* ABGR2101010: [31:0] A:B:G:R 2:10:10:10 little endian
|
|
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2024-11-14 08:33:09 +01:00
|
|
|
rgba2101010_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2024-11-14 08:33:09 +01:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
|
|
|
|
struct image_header src = image_header_from(rgb_image);
|
2025-04-07 13:42:43 +02:00
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-14 08:33:09 +01:00
|
|
|
int x, y;
|
|
|
|
|
uint32_t a;
|
|
|
|
|
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_true(drm_format == DRM_FORMAT_XRGB2101010 ||
|
|
|
|
|
drm_format == DRM_FORMAT_ARGB2101010 ||
|
|
|
|
|
drm_format == DRM_FORMAT_XBGR2101010 ||
|
|
|
|
|
drm_format == DRM_FORMAT_ABGR2101010);
|
2024-11-14 08:33:09 +01:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
args.n_planes = 1;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width * 4);
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.bytes = args.strides[0] * src.height;
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2024-11-14 08:33:09 +01:00
|
|
|
|
|
|
|
|
/* Store alpha as 0x0 to ensure the compositor correctly replaces it
|
|
|
|
|
* with 0x3. */
|
|
|
|
|
a = drm_format == DRM_FORMAT_XRGB2101010 ||
|
|
|
|
|
drm_format == DRM_FORMAT_XRGB2101010 ? 0x0 : 0x3;
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < src.height; y++) {
|
2025-04-07 13:42:43 +02:00
|
|
|
uint32_t *dst_row =
|
|
|
|
|
(uint32_t*) buf->data + (args.strides[0] / sizeof(uint32_t)) * y;
|
2024-11-14 08:33:09 +01:00
|
|
|
uint32_t *src_row = image_header_get_row_u32(&src, y);
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < src.width; x++) {
|
|
|
|
|
uint32_t r = ((src_row[x] >> 16) & 0xff) << 2;
|
|
|
|
|
uint32_t g = ((src_row[x] >> 8) & 0xff) << 2;
|
|
|
|
|
uint32_t b = ((src_row[x] >> 0) & 0xff) << 2;
|
|
|
|
|
|
|
|
|
|
if (drm_format == DRM_FORMAT_XRGB2101010 ||
|
|
|
|
|
drm_format == DRM_FORMAT_ARGB2101010)
|
|
|
|
|
dst_row[x] = a << 30 | r << 20 | g << 10 | b;
|
|
|
|
|
else
|
|
|
|
|
dst_row[x] = a << 30 | b << 20 | g << 10 | r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 64 bpp RGB
|
|
|
|
|
*
|
|
|
|
|
* XRGB16161616: [63:0] x:R:G:B 16:16:16:16 little endian
|
|
|
|
|
* ARGB16161616: [63:0] A:R:G:B 16:16:16:16 little endian
|
|
|
|
|
*
|
|
|
|
|
* XBGR16161616: [63:0] x:B:G:R 16:16:16:16 little endian
|
|
|
|
|
* ABGR16161616: [63:0] A:B:G:R 16:16:16:16 little endian
|
|
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2024-11-14 08:33:09 +01:00
|
|
|
rgba16161616_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2024-11-14 08:33:09 +01:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
|
|
|
|
static const int swizzles[][4] = {
|
|
|
|
|
{ 2, 1, 0, 3 }, /* XRGB16161616, ARGB16161616 */
|
|
|
|
|
{ 0, 1, 2, 3 }, /* XBGR16161616, ABGR16161616 */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct image_header src = image_header_from(rgb_image);
|
2025-04-07 13:42:43 +02:00
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-14 08:33:09 +01:00
|
|
|
bool is_opaque;
|
|
|
|
|
int idx, x, y;
|
|
|
|
|
uint64_t a;
|
|
|
|
|
|
|
|
|
|
switch (drm_format) {
|
|
|
|
|
case DRM_FORMAT_XRGB16161616:
|
|
|
|
|
is_opaque = true;
|
|
|
|
|
idx = 0;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_ARGB16161616:
|
|
|
|
|
is_opaque = false;
|
|
|
|
|
idx = 0;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_XBGR16161616:
|
|
|
|
|
is_opaque = true;
|
|
|
|
|
idx = 1;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_ABGR16161616:
|
|
|
|
|
is_opaque = false;
|
|
|
|
|
idx = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_not_reached("Invalid format!");
|
2024-11-14 08:33:09 +01:00
|
|
|
};
|
|
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
args.n_planes = 1;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width * 8);
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.bytes = args.strides[0] * src.height;
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2024-11-14 08:33:09 +01:00
|
|
|
|
|
|
|
|
/* Store alpha as 0x0000 to ensure the compositor correctly replaces it
|
|
|
|
|
* with 0xffff. */
|
|
|
|
|
a = is_opaque ? 0x0000 : 0xffff;
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < src.height; y++) {
|
2025-04-07 13:42:43 +02:00
|
|
|
uint64_t *dst_row =
|
|
|
|
|
(uint64_t*) buf->data + (args.strides[0] / sizeof(uint64_t)) * y;
|
2024-11-14 08:33:09 +01:00
|
|
|
uint32_t *src_row = image_header_get_row_u32(&src, y);
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < src.width; x++) {
|
|
|
|
|
uint64_t r = ((src_row[x] >> 16) & 0xff) << 8;
|
|
|
|
|
uint64_t g = ((src_row[x] >> 8) & 0xff) << 8;
|
|
|
|
|
uint64_t b = ((src_row[x] >> 0) & 0xff) << 8;
|
|
|
|
|
|
|
|
|
|
dst_row[x] =
|
|
|
|
|
r << (swizzles[idx][0] * 16) |
|
|
|
|
|
g << (swizzles[idx][1] * 16) |
|
|
|
|
|
b << (swizzles[idx][2] * 16) |
|
|
|
|
|
a << (swizzles[idx][3] * 16);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Convert an IEEE 754-2008 binary32 value to binary16 bits. Doesn't bother
|
|
|
|
|
* supporting Inf, Nan or subnormal numbers. Simply return signed 0 if there's
|
|
|
|
|
* an underflow due to the loss of precision. */
|
|
|
|
|
static uint16_t
|
|
|
|
|
binary16_from_binary32(float binary32)
|
|
|
|
|
{
|
|
|
|
|
uint32_t bits;
|
|
|
|
|
uint16_t sign, significand, exponent;
|
|
|
|
|
|
|
|
|
|
memcpy(&bits, &binary32, 4);
|
|
|
|
|
|
|
|
|
|
sign = bits >> 31;
|
|
|
|
|
exponent = (bits >> 23) & 0xff;
|
|
|
|
|
significand = (bits >> 13) & 0x3ff;
|
|
|
|
|
|
|
|
|
|
if (exponent >= 103)
|
|
|
|
|
return sign << 15 | (exponent - 112) << 10 | significand;
|
|
|
|
|
else
|
|
|
|
|
return sign << 15;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Floating point 64bpp RGB
|
|
|
|
|
* IEEE 754-2008 binary16 half-precision float
|
|
|
|
|
* [15:0] sign:exponent:mantissa 1:5:10
|
|
|
|
|
*
|
|
|
|
|
* XRGB16161616F: [63:0] x:R:G:B 16:16:16:16 little endian
|
|
|
|
|
* ARGB16161616F: [63:0] A:R:G:B 16:16:16:16 little endian
|
|
|
|
|
*
|
|
|
|
|
* XBGR16161616F: [63:0] x:B:G:R 16:16:16:16 little endian
|
|
|
|
|
* ABGR16161616F: [63:0] A:B:G:R 16:16:16:16 little endian
|
|
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2024-11-14 08:33:09 +01:00
|
|
|
rgba16161616f_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2024-11-14 08:33:09 +01:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
|
|
|
|
static const int swizzles[][4] = {
|
|
|
|
|
{ 2, 1, 0, 3 }, /* XRGB16161616F, ARGB16161616F */
|
|
|
|
|
{ 0, 1, 2, 3 }, /* XBGR16161616F, ABGR16161616F */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct image_header src = image_header_from(rgb_image);
|
2025-04-07 13:42:43 +02:00
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-14 08:33:09 +01:00
|
|
|
bool is_opaque;
|
|
|
|
|
int idx, x, y;
|
|
|
|
|
uint64_t a;
|
|
|
|
|
|
|
|
|
|
switch (drm_format) {
|
|
|
|
|
case DRM_FORMAT_XRGB16161616F:
|
|
|
|
|
is_opaque = true;
|
|
|
|
|
idx = 0;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_ARGB16161616F:
|
|
|
|
|
is_opaque = false;
|
|
|
|
|
idx = 0;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_XBGR16161616F:
|
|
|
|
|
is_opaque = true;
|
|
|
|
|
idx = 1;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_ABGR16161616F:
|
|
|
|
|
is_opaque = false;
|
|
|
|
|
idx = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_not_reached("Invalid format!");
|
2024-11-14 08:33:09 +01:00
|
|
|
};
|
|
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
args.n_planes = 1;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width * 8);
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.bytes = args.strides[0] * src.height;
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2024-11-14 08:33:09 +01:00
|
|
|
|
|
|
|
|
/* Store alpha as 0.0 to ensure the compositor correctly replaces it
|
|
|
|
|
* with 1.0. */
|
|
|
|
|
a = is_opaque ?
|
|
|
|
|
binary16_from_binary32(0.0f) :
|
|
|
|
|
binary16_from_binary32(1.0f);
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < src.height; y++) {
|
2025-04-07 13:42:43 +02:00
|
|
|
uint64_t *dst_row =
|
|
|
|
|
(uint64_t*) buf->data + (args.strides[0] / sizeof(uint64_t)) * y;
|
2024-11-14 08:33:09 +01:00
|
|
|
uint32_t *src_row = image_header_get_row_u32(&src, y);
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < src.width; x++) {
|
|
|
|
|
uint64_t r = ((src_row[x] >> 16) & 0xff) << 8;
|
|
|
|
|
uint64_t g = ((src_row[x] >> 8) & 0xff) << 8;
|
|
|
|
|
uint64_t b = ((src_row[x] >> 0) & 0xff) << 8;
|
|
|
|
|
r = binary16_from_binary32(r / 65535.0f);
|
|
|
|
|
g = binary16_from_binary32(g / 65535.0f);
|
|
|
|
|
b = binary16_from_binary32(b / 65535.0f);
|
|
|
|
|
|
|
|
|
|
dst_row[x] =
|
|
|
|
|
r << (swizzles[idx][0] * 16) |
|
|
|
|
|
g << (swizzles[idx][1] * 16) |
|
|
|
|
|
b << (swizzles[idx][2] * 16) |
|
|
|
|
|
a << (swizzles[idx][3] * 16);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 15:14:11 +02:00
|
|
|
/*
|
2025-01-06 14:52:47 +01:00
|
|
|
* Based on Rec. ITU-R BT.709-6
|
2020-12-09 15:14:11 +02:00
|
|
|
*
|
|
|
|
|
* This is intended to be obvious and accurate, not fast.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2025-01-06 14:52:47 +01:00
|
|
|
x8r8g8b8_to_ycbcr8_bt709(uint32_t xrgb,
|
2020-12-09 15:14:11 +02:00
|
|
|
uint8_t *y_out, uint8_t *cb_out, uint8_t *cr_out)
|
|
|
|
|
{
|
|
|
|
|
double y, cb, cr;
|
|
|
|
|
double r = (xrgb >> 16) & 0xff;
|
|
|
|
|
double g = (xrgb >> 8) & 0xff;
|
|
|
|
|
double b = (xrgb >> 0) & 0xff;
|
|
|
|
|
|
|
|
|
|
/* normalize to [0.0, 1.0] */
|
|
|
|
|
r /= 255.0;
|
|
|
|
|
g /= 255.0;
|
|
|
|
|
b /= 255.0;
|
|
|
|
|
|
|
|
|
|
/* Y normalized to [0.0, 1.0], Cb and Cr [-0.5, 0.5] */
|
2025-01-06 14:52:47 +01:00
|
|
|
y = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
|
|
|
cr = (r - y) / 1.5748;
|
|
|
|
|
cb = (b - y) / 1.8556;
|
2020-12-09 15:14:11 +02:00
|
|
|
|
|
|
|
|
/* limited range quantization to 8 bit */
|
|
|
|
|
*y_out = round(219.0 * y + 16.0);
|
|
|
|
|
if (cr_out)
|
|
|
|
|
*cr_out = round(224.0 * cr + 128.0);
|
|
|
|
|
if (cb_out)
|
|
|
|
|
*cb_out = round(224.0 * cb + 128.0);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-21 12:47:13 +01:00
|
|
|
/*
|
|
|
|
|
* Same as above but for conversion to 16-bit Y'CbCr formats. 'depth' can be set
|
|
|
|
|
* to any value in the range [9, 16]. If 'depth' is less than 16, components are
|
|
|
|
|
* aligned to the most significant bit with the least significant bits set to 0.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
x8r8g8b8_to_ycbcr16_bt709(uint32_t xrgb, int depth,
|
|
|
|
|
uint16_t *y_out, uint16_t *cb_out, uint16_t *cr_out)
|
|
|
|
|
{
|
|
|
|
|
uint16_t d;
|
|
|
|
|
double y, cb, cr;
|
|
|
|
|
double r = (xrgb >> 16) & 0xff;
|
|
|
|
|
double g = (xrgb >> 8) & 0xff;
|
|
|
|
|
double b = (xrgb >> 0) & 0xff;
|
|
|
|
|
|
|
|
|
|
/* Rec. ITU-R BT.709-6 defines D as 1 or 4 for 8-bit or 10-bit
|
|
|
|
|
* quantization respectively. We extrapolate here to [9, 16]-bit depths
|
|
|
|
|
* by setting D to 2^(depth - 8). */
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_int_ge(depth, 9);
|
|
|
|
|
test_assert_int_le(depth, 16);
|
2024-11-21 12:47:13 +01:00
|
|
|
d = 1 << (depth - 8);
|
|
|
|
|
|
|
|
|
|
/* normalize to [0.0, 1.0] */
|
|
|
|
|
r /= 255.0;
|
|
|
|
|
g /= 255.0;
|
|
|
|
|
b /= 255.0;
|
|
|
|
|
|
|
|
|
|
/* Y normalized to [0.0, 1.0], Cb and Cr [-0.5, 0.5] */
|
|
|
|
|
y = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
|
|
|
cr = (r - y) / 1.5748;
|
|
|
|
|
cb = (b - y) / 1.8556;
|
|
|
|
|
|
|
|
|
|
/* limited range quantization to [9, 16]-bit aligned to the MSB */
|
|
|
|
|
*y_out = (uint16_t) round((219.0 * y + 16.0) * d) << (16 - depth);
|
|
|
|
|
if (cr_out)
|
|
|
|
|
*cr_out = (uint16_t)
|
|
|
|
|
round((224.0 * cr + 128.0) * d) << (16 - depth);
|
|
|
|
|
if (cb_out)
|
|
|
|
|
*cb_out = (uint16_t)
|
|
|
|
|
round((224.0 * cb + 128.0) * d) << (16 - depth);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 15:14:11 +02:00
|
|
|
/*
|
|
|
|
|
* 3 plane YCbCr
|
|
|
|
|
* plane 0: Y plane, [7:0] Y
|
|
|
|
|
* plane 1: Cb plane, [7:0] Cb
|
|
|
|
|
* plane 2: Cr plane, [7:0] Cr
|
2024-11-13 15:09:59 +01:00
|
|
|
*
|
2022-04-28 01:21:15 +01:00
|
|
|
* YUV420: 2x2 subsampled Cb (1) and Cr (2) planes
|
2024-11-13 15:09:59 +01:00
|
|
|
*
|
|
|
|
|
* YVU420: 2x2 subsampled Cr (1) and Cb (2) planes
|
|
|
|
|
*
|
|
|
|
|
* YUV444: no subsampling Cb (1) and Cr (2) planes
|
|
|
|
|
|
|
|
|
|
* YVU444: no subsampling Cr (1) and Cb (2) planes
|
2020-12-09 15:14:11 +02:00
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2022-04-28 01:21:15 +01:00
|
|
|
y_u_v_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2022-04-28 01:21:15 +01:00
|
|
|
pixman_image_t *rgb_image)
|
2020-12-09 15:14:11 +02:00
|
|
|
{
|
2025-04-07 13:42:43 +02:00
|
|
|
struct image_header src = image_header_from(rgb_image);
|
|
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2020-12-09 15:14:11 +02:00
|
|
|
int x, y;
|
|
|
|
|
uint32_t *rgb_row;
|
|
|
|
|
uint8_t *y_base;
|
|
|
|
|
uint8_t *u_base;
|
|
|
|
|
uint8_t *v_base;
|
|
|
|
|
uint8_t *y_row;
|
|
|
|
|
uint8_t *u_row;
|
|
|
|
|
uint8_t *v_row;
|
|
|
|
|
uint32_t argb;
|
2025-04-07 13:42:43 +02:00
|
|
|
int sub_x;
|
|
|
|
|
int sub_y;
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
switch (drm_format) {
|
|
|
|
|
case DRM_FORMAT_YUV420:
|
|
|
|
|
case DRM_FORMAT_YVU420:
|
|
|
|
|
sub_x = 2;
|
|
|
|
|
sub_y = 2;
|
|
|
|
|
break;
|
2025-04-25 00:53:28 +02:00
|
|
|
case DRM_FORMAT_YUV422:
|
|
|
|
|
case DRM_FORMAT_YVU422:
|
|
|
|
|
sub_x = 2;
|
|
|
|
|
sub_y = 1;
|
|
|
|
|
break;
|
2025-04-07 13:42:43 +02:00
|
|
|
case DRM_FORMAT_YUV444:
|
|
|
|
|
case DRM_FORMAT_YVU444:
|
|
|
|
|
sub_x = 1;
|
|
|
|
|
sub_y = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
test_assert_not_reached("Invalid format!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case BUFFER_TYPE_SHM:
|
|
|
|
|
args.strides[0] = src.width;
|
|
|
|
|
args.strides[1] = args.strides[2] = src.width / sub_x;
|
|
|
|
|
break;
|
2025-04-07 13:43:31 +02:00
|
|
|
case BUFFER_TYPE_DMABUF:
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width);
|
|
|
|
|
args.strides[1] = args.strides[2] = get_aligned_stride(src.width / sub_x);
|
|
|
|
|
break;
|
2025-04-07 13:42:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args.n_planes = 3;
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.offsets[1] = args.strides[0] * src.height;
|
|
|
|
|
args.offsets[2] = args.offsets[1] + args.strides[1] * (src.height / sub_y);
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2022-04-28 01:21:15 +01:00
|
|
|
/* Full size Y plus quarter U and V */
|
2025-04-07 13:42:43 +02:00
|
|
|
args.bytes =
|
|
|
|
|
args.strides[0] * src.height +
|
|
|
|
|
args.strides[1] * (src.height / sub_y) * 2;
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
y_base = buf->data + args.offsets[0];
|
|
|
|
|
switch (drm_format) {
|
|
|
|
|
case DRM_FORMAT_YUV420:
|
2025-04-25 00:53:28 +02:00
|
|
|
case DRM_FORMAT_YUV422:
|
2025-04-07 13:42:43 +02:00
|
|
|
case DRM_FORMAT_YUV444:
|
|
|
|
|
u_base = buf->data + args.offsets[1];
|
|
|
|
|
v_base = buf->data + args.offsets[2];
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_YVU420:
|
2025-04-25 00:53:28 +02:00
|
|
|
case DRM_FORMAT_YVU422:
|
2025-04-07 13:42:43 +02:00
|
|
|
case DRM_FORMAT_YVU444:
|
|
|
|
|
v_base = buf->data + args.offsets[1];
|
|
|
|
|
u_base = buf->data + args.offsets[2];
|
|
|
|
|
break;
|
2024-11-13 15:09:59 +01:00
|
|
|
}
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
for (y = 0; y < src.height; y++) {
|
|
|
|
|
rgb_row = image_header_get_row_u32(&src, y / 2 * 2);
|
|
|
|
|
y_row = y_base + y * args.strides[0];
|
|
|
|
|
|
|
|
|
|
switch (drm_format) {
|
|
|
|
|
case DRM_FORMAT_YUV420:
|
2025-04-25 00:53:28 +02:00
|
|
|
case DRM_FORMAT_YUV422:
|
2025-04-07 13:42:43 +02:00
|
|
|
case DRM_FORMAT_YUV444:
|
|
|
|
|
u_row = u_base + (y / sub_y) * args.strides[1];
|
|
|
|
|
v_row = v_base + (y / sub_y) * args.strides[2];
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_YVU420:
|
2025-04-25 00:53:28 +02:00
|
|
|
case DRM_FORMAT_YVU422:
|
2025-04-07 13:42:43 +02:00
|
|
|
case DRM_FORMAT_YVU444:
|
|
|
|
|
v_row = v_base + (y / sub_y) * args.strides[1];
|
|
|
|
|
u_row = u_base + (y / sub_y) * args.strides[2];
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
for (x = 0; x < src.width; x++) {
|
2020-12-09 15:14:11 +02:00
|
|
|
/*
|
|
|
|
|
* Sub-sample the source image instead, so that U and V
|
|
|
|
|
* sub-sampling does not require proper
|
|
|
|
|
* filtering/averaging/siting.
|
|
|
|
|
*/
|
|
|
|
|
argb = *(rgb_row + x / 2 * 2);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A stupid way of "sub-sampling" chroma. This does not
|
|
|
|
|
* do the necessary filtering/averaging/siting or
|
|
|
|
|
* alternate Cb/Cr rows.
|
|
|
|
|
*/
|
2025-04-07 13:42:43 +02:00
|
|
|
if ((y & (sub_y - 1)) == 0 && (x & (sub_x - 1)) == 0) {
|
2025-01-06 14:52:47 +01:00
|
|
|
x8r8g8b8_to_ycbcr8_bt709(argb, y_row + x,
|
2025-04-07 13:42:43 +02:00
|
|
|
u_row + x / sub_x,
|
|
|
|
|
v_row + x / sub_x);
|
2020-12-09 15:14:11 +02:00
|
|
|
} else {
|
2025-01-06 14:52:47 +01:00
|
|
|
x8r8g8b8_to_ycbcr8_bt709(argb, y_row + x,
|
2020-12-09 15:14:11 +02:00
|
|
|
NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 2 plane YCbCr
|
2024-11-13 15:09:59 +01:00
|
|
|
*
|
|
|
|
|
* NV12: plane 0 = Y plane, [7:0] Y
|
|
|
|
|
* plane 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
|
|
|
|
|
* 2x2 subsampled Cr:Cb plane
|
|
|
|
|
*
|
|
|
|
|
* NV21: plane 0 = Y plane, [7:0] Y
|
|
|
|
|
* plane 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
|
|
|
|
|
* 2x2 subsampled Cb:Cr plane
|
2020-12-09 15:14:11 +02:00
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2020-12-09 15:14:11 +02:00
|
|
|
nv12_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2020-12-09 15:14:11 +02:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
2024-11-13 15:09:59 +01:00
|
|
|
static const int swizzles[][2] = {
|
|
|
|
|
{ 0, 1 }, /* NV12 */
|
|
|
|
|
{ 1, 0 } /* NV21 */
|
|
|
|
|
};
|
2025-04-07 13:42:43 +02:00
|
|
|
struct image_header src = image_header_from(rgb_image);
|
|
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-13 15:09:59 +01:00
|
|
|
int idx, x, y;
|
2020-12-09 15:14:11 +02:00
|
|
|
uint32_t *rgb_row;
|
|
|
|
|
uint8_t *y_base;
|
|
|
|
|
uint16_t *uv_base;
|
|
|
|
|
uint8_t *y_row;
|
|
|
|
|
uint16_t *uv_row;
|
|
|
|
|
uint32_t argb;
|
|
|
|
|
uint8_t cr;
|
|
|
|
|
uint8_t cb;
|
2025-04-07 13:42:43 +02:00
|
|
|
int sub_x;
|
|
|
|
|
int sub_y;
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2024-11-13 15:09:59 +01:00
|
|
|
switch (drm_format) {
|
|
|
|
|
case DRM_FORMAT_NV12:
|
|
|
|
|
idx = 0;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_NV21:
|
|
|
|
|
idx = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_not_reached("Invalid format!");
|
2024-11-13 15:09:59 +01:00
|
|
|
};
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
sub_x = sub_y = 2;
|
|
|
|
|
|
|
|
|
|
args.n_planes = 2;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width);
|
|
|
|
|
args.strides[1] = get_aligned_stride(src.width / sub_x * sizeof(uint16_t));
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.offsets[1] = args.strides[0] * src.height;
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
/* Full size Y plus quarter U and V */
|
|
|
|
|
args.bytes =
|
|
|
|
|
args.strides[0] * src.height +
|
|
|
|
|
args.strides[1] * (src.height / sub_y);
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
y_base = buf->data + args.offsets[0];
|
|
|
|
|
uv_base = (uint16_t *)(buf->data + args.offsets[1]);
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < src.height; y++) {
|
|
|
|
|
rgb_row = image_header_get_row_u32(&src, y / 2 * 2);
|
|
|
|
|
y_row = y_base + y * args.strides[0];
|
|
|
|
|
uv_row = uv_base + (y / 2) * (args.strides[1] / sizeof(uint16_t));
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < src.width; x++) {
|
2020-12-09 15:14:11 +02:00
|
|
|
/*
|
|
|
|
|
* Sub-sample the source image instead, so that U and V
|
|
|
|
|
* sub-sampling does not require proper
|
|
|
|
|
* filtering/averaging/siting.
|
|
|
|
|
*/
|
|
|
|
|
argb = *(rgb_row + x / 2 * 2);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A stupid way of "sub-sampling" chroma. This does not
|
|
|
|
|
* do the necessary filtering/averaging/siting.
|
|
|
|
|
*/
|
|
|
|
|
if ((y & 1) == 0 && (x & 1) == 0) {
|
2025-01-06 14:52:47 +01:00
|
|
|
x8r8g8b8_to_ycbcr8_bt709(argb, y_row + x,
|
2020-12-09 15:14:11 +02:00
|
|
|
&cb, &cr);
|
2024-11-13 15:09:59 +01:00
|
|
|
*(uv_row + x / 2) =
|
|
|
|
|
((uint16_t) cr << (swizzles[idx][1] * 8)) |
|
|
|
|
|
((uint16_t) cb << (swizzles[idx][0] * 8));
|
2020-12-09 15:14:11 +02:00
|
|
|
} else {
|
2025-01-06 14:52:47 +01:00
|
|
|
x8r8g8b8_to_ycbcr8_bt709(argb, y_row + x,
|
2020-12-09 15:14:11 +02:00
|
|
|
NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 12:06:35 +08:00
|
|
|
/*
|
|
|
|
|
* 2 plane YCbCr
|
2024-11-13 15:09:59 +01:00
|
|
|
*
|
|
|
|
|
* NV16: plane 0 = Y plane, [7:0] Y
|
|
|
|
|
* plane 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
|
|
|
|
|
* 2x1 subsampled Cr:Cb plane
|
|
|
|
|
*
|
|
|
|
|
* NV61: plane 0 = Y plane, [7:0] Y
|
|
|
|
|
* plane 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
|
|
|
|
|
* 2x1 subsampled Cb:Cr plane
|
2019-11-22 12:06:35 +08:00
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2019-11-22 12:06:35 +08:00
|
|
|
nv16_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2019-11-22 12:06:35 +08:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
2024-11-13 15:09:59 +01:00
|
|
|
static const int swizzles[][2] = {
|
|
|
|
|
{ 0, 1 }, /* NV16 */
|
|
|
|
|
{ 1, 0 } /* NV61 */
|
|
|
|
|
};
|
2025-04-07 13:42:43 +02:00
|
|
|
struct image_header src = image_header_from(rgb_image);
|
|
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-13 15:09:59 +01:00
|
|
|
int idx, x, y;
|
2019-11-22 12:06:35 +08:00
|
|
|
uint32_t *rgb_row;
|
|
|
|
|
uint8_t *y_base;
|
|
|
|
|
uint16_t *uv_base;
|
|
|
|
|
uint8_t *y_row;
|
|
|
|
|
uint16_t *uv_row;
|
|
|
|
|
uint32_t argb;
|
|
|
|
|
uint8_t cr;
|
|
|
|
|
uint8_t cb;
|
2025-04-07 13:42:43 +02:00
|
|
|
int sub_x;
|
|
|
|
|
int sub_y;
|
2019-11-22 12:06:35 +08:00
|
|
|
|
2024-11-13 15:09:59 +01:00
|
|
|
switch (drm_format) {
|
|
|
|
|
case DRM_FORMAT_NV16:
|
|
|
|
|
idx = 0;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_NV61:
|
|
|
|
|
idx = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_not_reached("Invalid format!");
|
2024-11-13 15:09:59 +01:00
|
|
|
};
|
2019-11-22 12:06:35 +08:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
sub_x = 2;
|
|
|
|
|
sub_y = 1;
|
|
|
|
|
|
|
|
|
|
args.n_planes = 2;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width);
|
|
|
|
|
args.strides[1] = get_aligned_stride(src.width / sub_x * sizeof(uint16_t));
|
|
|
|
|
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.offsets[1] = args.strides[0] * src.height;
|
|
|
|
|
|
2019-11-22 12:06:35 +08:00
|
|
|
/* Full size Y, horizontally subsampled UV */
|
2025-04-07 13:42:43 +02:00
|
|
|
args.bytes =
|
|
|
|
|
args.strides[0] * src.height +
|
|
|
|
|
args.strides[1] * (src.height / sub_y);
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2019-11-22 12:06:35 +08:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
y_base = buf->data + args.offsets[0];
|
|
|
|
|
uv_base = (uint16_t *)(buf->data + args.offsets[1]);
|
2019-11-22 12:06:35 +08:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
for (y = 0; y < src.height; y++) {
|
|
|
|
|
rgb_row = image_header_get_row_u32(&src, y / 2 * 2);
|
|
|
|
|
y_row = y_base + y * args.strides[0];
|
|
|
|
|
uv_row = uv_base + y * (args.strides[1] / sizeof(uint16_t));
|
2019-11-22 12:06:35 +08:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
for (x = 0; x < src.width; x++) {
|
2019-11-22 12:06:35 +08:00
|
|
|
/*
|
|
|
|
|
* 2x2 sub-sample the source image to get the same
|
|
|
|
|
* result as the other YUV variants, so we can use the
|
|
|
|
|
* same reference image for checking.
|
|
|
|
|
*/
|
|
|
|
|
argb = *(rgb_row + x / 2 * 2);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A stupid way of "sub-sampling" chroma. This does not
|
|
|
|
|
* do the necessary filtering/averaging/siting.
|
|
|
|
|
*/
|
|
|
|
|
if ((x & 1) == 0) {
|
2025-01-06 14:52:47 +01:00
|
|
|
x8r8g8b8_to_ycbcr8_bt709(argb, y_row + x,
|
2019-11-22 12:06:35 +08:00
|
|
|
&cb, &cr);
|
2024-11-13 15:09:59 +01:00
|
|
|
*(uv_row + x / 2) =
|
|
|
|
|
((uint16_t) cr << (swizzles[idx][1] * 8)) |
|
|
|
|
|
((uint16_t) cb << (swizzles[idx][0] * 8));
|
2019-11-22 12:06:35 +08:00
|
|
|
} else {
|
2025-01-06 14:52:47 +01:00
|
|
|
x8r8g8b8_to_ycbcr8_bt709(argb, y_row + x,
|
2019-11-22 12:06:35 +08:00
|
|
|
NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 16:27:01 +08:00
|
|
|
/*
|
|
|
|
|
* 2 plane YCbCr
|
2024-11-13 15:09:59 +01:00
|
|
|
*
|
|
|
|
|
* NV24: plane 0 = Y plane, [7:0] Y
|
|
|
|
|
* plane 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
|
|
|
|
|
* non-subsampled Cr:Cb plane
|
|
|
|
|
*
|
|
|
|
|
* NV42: plane 0 = Y plane, [7:0] Y
|
|
|
|
|
* plane 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
|
|
|
|
|
* non-subsampled Cb:Cr plane
|
2024-03-29 16:27:01 +08:00
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2024-03-29 16:27:01 +08:00
|
|
|
nv24_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2024-03-29 16:27:01 +08:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
2024-11-13 15:09:59 +01:00
|
|
|
static const int swizzles[][2] = {
|
|
|
|
|
{ 0, 1 }, /* NV24 */
|
|
|
|
|
{ 1, 0 } /* NV42 */
|
|
|
|
|
};
|
2025-04-07 13:42:43 +02:00
|
|
|
struct image_header src = image_header_from(rgb_image);
|
|
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-13 15:09:59 +01:00
|
|
|
int idx, x, y;
|
2024-03-29 16:27:01 +08:00
|
|
|
uint32_t *rgb_row;
|
|
|
|
|
uint8_t *y_base;
|
|
|
|
|
uint16_t *uv_base;
|
|
|
|
|
uint8_t *y_row;
|
|
|
|
|
uint16_t *uv_row;
|
|
|
|
|
uint32_t argb;
|
|
|
|
|
uint8_t cr;
|
|
|
|
|
uint8_t cb;
|
2025-04-07 13:42:43 +02:00
|
|
|
int sub_x;
|
|
|
|
|
int sub_y;
|
2024-03-29 16:27:01 +08:00
|
|
|
|
2024-11-13 15:09:59 +01:00
|
|
|
switch (drm_format) {
|
|
|
|
|
case DRM_FORMAT_NV24:
|
|
|
|
|
idx = 0;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_NV42:
|
|
|
|
|
idx = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_not_reached("Invalid format!");
|
2024-11-13 15:09:59 +01:00
|
|
|
};
|
2024-03-29 16:27:01 +08:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
sub_x = 1;
|
|
|
|
|
sub_y = 1;
|
|
|
|
|
|
|
|
|
|
args.n_planes = 2;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width);
|
|
|
|
|
args.strides[1] = get_aligned_stride(src.width / sub_x * sizeof(uint16_t));
|
|
|
|
|
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.offsets[1] = args.strides[0] * src.height;
|
|
|
|
|
|
2024-03-29 16:27:01 +08:00
|
|
|
/* Full size Y, non-subsampled UV */
|
2025-04-07 13:42:43 +02:00
|
|
|
args.bytes =
|
|
|
|
|
args.strides[0] * src.height +
|
|
|
|
|
args.strides[1] * (src.height / sub_y);
|
2024-03-29 16:27:01 +08:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2024-03-29 16:27:01 +08:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
y_base = buf->data + args.offsets[0];
|
|
|
|
|
uv_base = (uint16_t *)(buf->data + args.offsets[1]);
|
2024-03-29 16:27:01 +08:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
for (y = 0; y < src.height; y++) {
|
|
|
|
|
rgb_row = image_header_get_row_u32(&src, y / 2 * 2);
|
|
|
|
|
y_row = y_base + y * args.strides[0];
|
|
|
|
|
uv_row = uv_base + y * (args.strides[1] / sizeof(uint16_t));
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < src.width; x++) {
|
2024-03-29 16:27:01 +08:00
|
|
|
/*
|
|
|
|
|
* 2x2 sub-sample the source image to get the same
|
|
|
|
|
* result as the other YUV variants, so we can use the
|
|
|
|
|
* same reference image for checking.
|
|
|
|
|
*/
|
|
|
|
|
argb = *(rgb_row + x / 2 * 2);
|
|
|
|
|
|
2025-01-06 14:52:47 +01:00
|
|
|
x8r8g8b8_to_ycbcr8_bt709(argb, y_row + x,
|
2024-03-29 16:27:01 +08:00
|
|
|
&cb, &cr);
|
2024-11-13 15:09:59 +01:00
|
|
|
*(uv_row + x) =
|
|
|
|
|
((uint16_t) cr << (swizzles[idx][1] * 8)) |
|
|
|
|
|
((uint16_t) cb << (swizzles[idx][0] * 8));
|
2024-03-29 16:27:01 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 15:14:11 +02:00
|
|
|
/*
|
|
|
|
|
* Packed YCbCr
|
|
|
|
|
*
|
2024-11-13 15:09:59 +01:00
|
|
|
* YUYV: [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian
|
|
|
|
|
* 2x1 subsampled Cr:Cb plane
|
|
|
|
|
*
|
|
|
|
|
* YVYU: [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian
|
|
|
|
|
* 2x1 subsampled Cb:Cr plane
|
|
|
|
|
*
|
|
|
|
|
* UYVY: [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian
|
|
|
|
|
* 2x1 subsampled Cr:Cb plane
|
|
|
|
|
*
|
|
|
|
|
* VYUY: [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian
|
|
|
|
|
* 2x1 subsampled Cb:Cr plane
|
2020-12-09 15:14:11 +02:00
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2020-12-09 15:14:11 +02:00
|
|
|
yuyv_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2020-12-09 15:14:11 +02:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
2024-11-13 15:09:59 +01:00
|
|
|
static const int swizzles[][4] = {
|
|
|
|
|
{ 0, 1, 2, 3 }, /* YUYV */
|
|
|
|
|
{ 0, 3, 2, 1 }, /* YVYU */
|
|
|
|
|
{ 1, 0, 3, 2 }, /* UYVY */
|
|
|
|
|
{ 1, 2, 3, 0 } /* VYUY */
|
|
|
|
|
};
|
2025-04-07 13:42:43 +02:00
|
|
|
struct image_header src = image_header_from(rgb_image);
|
|
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-13 15:09:59 +01:00
|
|
|
int idx, x, y;
|
2020-12-09 15:14:11 +02:00
|
|
|
uint32_t *rgb_row;
|
|
|
|
|
uint32_t *yuv_base;
|
|
|
|
|
uint32_t *yuv_row;
|
|
|
|
|
uint8_t cr;
|
|
|
|
|
uint8_t cb;
|
|
|
|
|
uint8_t y0;
|
|
|
|
|
|
2024-11-13 15:09:59 +01:00
|
|
|
switch (drm_format) {
|
|
|
|
|
case DRM_FORMAT_YUYV:
|
|
|
|
|
idx = 0;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_YVYU:
|
|
|
|
|
idx = 1;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_UYVY:
|
|
|
|
|
idx = 2;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_VYUY:
|
|
|
|
|
idx = 3;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_not_reached("Invalid format!");
|
2024-11-13 15:09:59 +01:00
|
|
|
};
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
args.n_planes = 1;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width / 2 * sizeof(uint32_t));
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
|
2020-12-09 15:14:11 +02:00
|
|
|
/* Full size Y, horizontally subsampled UV, 2 pixels in 32 bits */
|
2025-04-07 13:42:43 +02:00
|
|
|
args.bytes = args.strides[0] * src.height;
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2020-12-09 15:14:11 +02:00
|
|
|
|
|
|
|
|
yuv_base = buf->data;
|
|
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
for (y = 0; y < src.height; y++) {
|
|
|
|
|
rgb_row = image_header_get_row_u32(&src, y / 2 * 2);
|
|
|
|
|
yuv_row = yuv_base + y * (args.strides[0] / sizeof(uint32_t));
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
for (x = 0; x < src.width; x += 2) {
|
2020-12-09 15:14:11 +02:00
|
|
|
/*
|
|
|
|
|
* Sub-sample the source image instead, so that U and V
|
|
|
|
|
* sub-sampling does not require proper
|
|
|
|
|
* filtering/averaging/siting.
|
|
|
|
|
*/
|
2025-01-06 14:52:47 +01:00
|
|
|
x8r8g8b8_to_ycbcr8_bt709(*(rgb_row + x), &y0, &cb, &cr);
|
2020-12-09 15:14:11 +02:00
|
|
|
*(yuv_row + x / 2) =
|
2024-11-13 15:09:59 +01:00
|
|
|
((uint32_t)cr << (swizzles[idx][3] * 8)) |
|
|
|
|
|
((uint32_t)y0 << (swizzles[idx][2] * 8)) |
|
|
|
|
|
((uint32_t)cb << (swizzles[idx][1] * 8)) |
|
|
|
|
|
((uint32_t)y0 << (swizzles[idx][0] * 8));
|
2020-12-09 15:14:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 16:30:22 +02:00
|
|
|
/*
|
|
|
|
|
* Packed YCbCr
|
|
|
|
|
*
|
2024-11-13 15:09:59 +01:00
|
|
|
* XYUV8888: [31:0] X:Y:Cb:Cr 8:8:8:8 little endian
|
|
|
|
|
* full resolution chroma
|
2021-02-05 16:30:22 +02:00
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2021-02-05 16:30:22 +02:00
|
|
|
xyuv8888_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2021-02-05 16:30:22 +02:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
2025-04-07 13:42:43 +02:00
|
|
|
struct image_header src = image_header_from(rgb_image);
|
|
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2021-02-05 16:30:22 +02:00
|
|
|
int x, y;
|
|
|
|
|
uint32_t *rgb_row;
|
|
|
|
|
uint32_t *yuv_base;
|
|
|
|
|
uint32_t *yuv_row;
|
|
|
|
|
uint8_t cr;
|
|
|
|
|
uint8_t cb;
|
|
|
|
|
uint8_t y0;
|
|
|
|
|
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_enum(drm_format, DRM_FORMAT_XYUV8888);
|
2021-02-05 16:30:22 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
args.n_planes = 1;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width * sizeof(uint32_t));
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
|
2021-02-05 16:30:22 +02:00
|
|
|
/* Full size, 32 bits per pixel */
|
2025-04-07 13:42:43 +02:00
|
|
|
args.bytes = args.strides[0] * src.height;
|
|
|
|
|
|
|
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2021-02-05 16:30:22 +02:00
|
|
|
|
|
|
|
|
yuv_base = buf->data;
|
|
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
for (y = 0; y < src.height; y++) {
|
|
|
|
|
rgb_row = image_header_get_row_u32(&src, y / 2 * 2);
|
|
|
|
|
yuv_row = yuv_base + y * (args.strides[0] / sizeof(uint32_t));
|
2021-02-05 16:30:22 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
for (x = 0; x < src.width; x++) {
|
2021-02-05 16:30:22 +02:00
|
|
|
/*
|
|
|
|
|
* 2x2 sub-sample the source image to get the same
|
|
|
|
|
* result as the other YUV variants, so we can use the
|
|
|
|
|
* same reference image for checking.
|
|
|
|
|
*/
|
2025-01-06 14:52:47 +01:00
|
|
|
x8r8g8b8_to_ycbcr8_bt709(*(rgb_row + x / 2 * 2), &y0, &cb, &cr);
|
2021-02-05 16:30:22 +02:00
|
|
|
/*
|
|
|
|
|
* The unused byte is intentionally set to "garbage"
|
|
|
|
|
* to catch any accidental use of it in the compositor.
|
|
|
|
|
*/
|
|
|
|
|
*(yuv_row + x) =
|
|
|
|
|
((uint32_t)x << 24) |
|
|
|
|
|
((uint32_t)y0 << 16) |
|
|
|
|
|
((uint32_t)cb << 8) |
|
|
|
|
|
((uint32_t)cr << 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-21 12:47:13 +01:00
|
|
|
/*
|
|
|
|
|
* 2 plane YCbCr MSB aligned
|
|
|
|
|
*
|
|
|
|
|
* P016: index 0 = Y plane, [15:0] Y little endian
|
|
|
|
|
* index 1 = Cr:Cb plane, [31:0] Cr:Cb [16:16] little endian
|
|
|
|
|
* 2x2 subsampled Cr:Cb plane 16 bits per channel
|
|
|
|
|
*
|
|
|
|
|
* P012: index 0 = Y plane, [15:0] Y:x [12:4] little endian
|
|
|
|
|
* index 1 = Cr:Cb plane, [31:0] Cr:x:Cb:x [12:4:12:4] little endian
|
|
|
|
|
* 2x2 subsampled Cr:Cb plane 12 bits per channel
|
|
|
|
|
*
|
|
|
|
|
* P010: index 0 = Y plane, [15:0] Y:x [10:6] little endian
|
|
|
|
|
* index 1 = Cr:Cb plane, [31:0] Cr:x:Cb:x [10:6:10:6] little endian
|
|
|
|
|
* 2x2 subsampled Cr:Cb plane 10 bits per channel
|
|
|
|
|
*/
|
2025-04-23 13:47:28 +02:00
|
|
|
static struct client_buffer *
|
2024-11-21 12:47:13 +01:00
|
|
|
p016_create_buffer(struct client *client,
|
|
|
|
|
uint32_t drm_format,
|
2025-04-07 13:42:43 +02:00
|
|
|
enum buffer_type type,
|
2024-11-21 12:47:13 +01:00
|
|
|
pixman_image_t *rgb_image)
|
|
|
|
|
{
|
2025-04-07 13:42:43 +02:00
|
|
|
struct image_header src = image_header_from(rgb_image);
|
|
|
|
|
struct client_buffer_create_data args = create_init(drm_format, type, &src);
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2024-11-21 12:47:13 +01:00
|
|
|
int depth, x, y;
|
|
|
|
|
uint32_t *rgb_row;
|
|
|
|
|
uint16_t *y_base;
|
|
|
|
|
uint32_t *uv_base;
|
|
|
|
|
uint16_t *y_row;
|
|
|
|
|
uint32_t *uv_row;
|
|
|
|
|
uint32_t argb;
|
|
|
|
|
uint16_t cr;
|
|
|
|
|
uint16_t cb;
|
2025-04-07 13:42:43 +02:00
|
|
|
int sub_x;
|
|
|
|
|
int sub_y;
|
2024-11-21 12:47:13 +01:00
|
|
|
|
|
|
|
|
switch (drm_format) {
|
|
|
|
|
case DRM_FORMAT_P016:
|
|
|
|
|
depth = 16;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_P012:
|
|
|
|
|
depth = 12;
|
|
|
|
|
break;
|
|
|
|
|
case DRM_FORMAT_P010:
|
|
|
|
|
depth = 10;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_not_reached("Invalid format!");
|
2024-11-21 12:47:13 +01:00
|
|
|
};
|
|
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
sub_x = sub_y = 2;
|
|
|
|
|
|
|
|
|
|
args.n_planes = 2;
|
|
|
|
|
args.strides[0] = get_aligned_stride(src.width * sizeof(uint16_t));
|
|
|
|
|
args.strides[1] = get_aligned_stride(src.width / sub_x * sizeof(uint32_t));
|
|
|
|
|
|
|
|
|
|
args.offsets[0] = 0;
|
|
|
|
|
args.offsets[1] = args.strides[0] * src.height;
|
|
|
|
|
|
2024-11-21 12:47:13 +01:00
|
|
|
/* Full size Y, quarter UV */
|
2025-04-07 13:42:43 +02:00
|
|
|
args.bytes =
|
|
|
|
|
args.strides[0] * src.height +
|
|
|
|
|
args.strides[1] * (src.height / sub_y);
|
2024-11-21 12:47:13 +01:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
buf = client_buffer_create(client, &args);
|
|
|
|
|
if (!buf)
|
|
|
|
|
return NULL;
|
2024-11-21 12:47:13 +01:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
y_base = (uint16_t *)(buf->data + args.offsets[0]);
|
|
|
|
|
uv_base = (uint32_t *)(buf->data + args.offsets[1]);
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < src.height; y++) {
|
|
|
|
|
rgb_row = image_header_get_row_u32(&src, y / 2 * 2);
|
|
|
|
|
y_row = y_base + y * (args.strides[0] / sizeof(uint16_t));
|
|
|
|
|
uv_row = uv_base + (y / 2) * (args.strides[1] / sizeof(uint32_t));
|
2024-11-21 12:47:13 +01:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
for (x = 0; x < src.width; x++) {
|
2024-11-21 12:47:13 +01:00
|
|
|
/*
|
|
|
|
|
* Sub-sample the source image instead, so that U and V
|
|
|
|
|
* sub-sampling does not require proper
|
|
|
|
|
* filtering/averaging/siting.
|
|
|
|
|
*/
|
|
|
|
|
argb = *(rgb_row + x / 2 * 2);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A stupid way of "sub-sampling" chroma. This does not
|
|
|
|
|
* do the necessary filtering/averaging/siting.
|
|
|
|
|
*/
|
|
|
|
|
if ((x & 1) == 0 && (y & 1) == 0) {
|
|
|
|
|
x8r8g8b8_to_ycbcr16_bt709(argb, depth,
|
|
|
|
|
y_row + x, &cb, &cr);
|
|
|
|
|
*(uv_row + x / 2) =
|
|
|
|
|
((uint32_t) cr << 16) |
|
|
|
|
|
((uint32_t) cb << 0);
|
|
|
|
|
} else {
|
|
|
|
|
x8r8g8b8_to_ycbcr16_bt709(argb, depth,
|
|
|
|
|
y_row + x, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 15:14:11 +02:00
|
|
|
static void
|
2025-04-23 13:47:28 +02:00
|
|
|
show_window_with_client_buffer(struct client *client, struct client_buffer *buf)
|
2020-12-09 15:14:11 +02:00
|
|
|
{
|
|
|
|
|
struct surface *surface = client->surface;
|
|
|
|
|
int done;
|
|
|
|
|
|
|
|
|
|
weston_test_move_surface(client->test->weston_test, surface->wl_surface,
|
|
|
|
|
4, 4);
|
2025-04-07 13:42:43 +02:00
|
|
|
wl_surface_attach(surface->wl_surface, buf->wl_buffer, 0, 0);
|
2020-12-09 15:14:11 +02:00
|
|
|
wl_surface_damage(surface->wl_surface, 0, 0, buf->width,
|
|
|
|
|
buf->height);
|
|
|
|
|
frame_callback_set(surface->wl_surface, &done);
|
|
|
|
|
wl_surface_commit(surface->wl_surface);
|
|
|
|
|
frame_callback_wait(client, &done);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-23 13:47:28 +02:00
|
|
|
static const struct client_buffer_case client_buffer_cases[] = {
|
2020-12-09 15:14:11 +02:00
|
|
|
#define FMT(x) DRM_FORMAT_ ##x, #x
|
2024-11-14 08:33:09 +01:00
|
|
|
/* RGB */
|
|
|
|
|
{ FMT(RGBX4444), 0, rgba4444_create_buffer },
|
|
|
|
|
{ FMT(RGBA4444), 0, rgba4444_create_buffer },
|
|
|
|
|
{ FMT(BGRX4444), 0, rgba4444_create_buffer },
|
|
|
|
|
{ FMT(BGRA4444), 0, rgba4444_create_buffer },
|
|
|
|
|
{ FMT(XRGB4444), 0, rgba4444_create_buffer },
|
|
|
|
|
{ FMT(ARGB4444), 0, rgba4444_create_buffer },
|
|
|
|
|
{ FMT(XBGR4444), 0, rgba4444_create_buffer },
|
|
|
|
|
{ FMT(ABGR4444), 0, rgba4444_create_buffer },
|
|
|
|
|
{ FMT(RGBX5551), 1, rgba5551_create_buffer },
|
|
|
|
|
{ FMT(RGBA5551), 1, rgba5551_create_buffer },
|
|
|
|
|
{ FMT(BGRX5551), 1, rgba5551_create_buffer },
|
|
|
|
|
{ FMT(BGRA5551), 1, rgba5551_create_buffer },
|
|
|
|
|
{ FMT(RGB565), 2, rgb565_create_buffer },
|
|
|
|
|
{ FMT(BGR565), 2, rgb565_create_buffer },
|
|
|
|
|
{ FMT(RGB888), 3, rgb888_create_buffer },
|
|
|
|
|
{ FMT(BGR888), 3, rgb888_create_buffer },
|
|
|
|
|
{ FMT(RGBX8888), 3, rgba8888_create_buffer },
|
|
|
|
|
{ FMT(RGBA8888), 3, rgba8888_create_buffer },
|
|
|
|
|
{ FMT(BGRX8888), 3, rgba8888_create_buffer },
|
|
|
|
|
{ FMT(BGRA8888), 3, rgba8888_create_buffer },
|
|
|
|
|
{ FMT(XRGB8888), 3, rgba8888_create_buffer },
|
|
|
|
|
{ FMT(ARGB8888), 3, rgba8888_create_buffer },
|
|
|
|
|
{ FMT(XBGR8888), 3, rgba8888_create_buffer },
|
|
|
|
|
{ FMT(ABGR8888), 3, rgba8888_create_buffer },
|
|
|
|
|
{ FMT(XRGB2101010), 3, rgba2101010_create_buffer },
|
|
|
|
|
{ FMT(ARGB2101010), 3, rgba2101010_create_buffer },
|
|
|
|
|
{ FMT(XBGR2101010), 3, rgba2101010_create_buffer },
|
|
|
|
|
{ FMT(ABGR2101010), 3, rgba2101010_create_buffer },
|
|
|
|
|
{ FMT(XRGB16161616), 3, rgba16161616_create_buffer },
|
|
|
|
|
{ FMT(ARGB16161616), 3, rgba16161616_create_buffer },
|
|
|
|
|
{ FMT(XBGR16161616), 3, rgba16161616_create_buffer },
|
|
|
|
|
{ FMT(ABGR16161616), 3, rgba16161616_create_buffer },
|
|
|
|
|
{ FMT(XRGB16161616F), 3, rgba16161616f_create_buffer },
|
|
|
|
|
{ FMT(ARGB16161616F), 3, rgba16161616f_create_buffer },
|
|
|
|
|
{ FMT(XBGR16161616F), 3, rgba16161616f_create_buffer },
|
|
|
|
|
{ FMT(ABGR16161616F), 3, rgba16161616f_create_buffer },
|
|
|
|
|
/* YUV */
|
|
|
|
|
{ FMT(YUV420), 4, y_u_v_create_buffer },
|
|
|
|
|
{ FMT(YVU420), 4, y_u_v_create_buffer },
|
2025-04-25 00:53:28 +02:00
|
|
|
{ FMT(YUV422), 4, y_u_v_create_buffer },
|
|
|
|
|
{ FMT(YVU422), 4, y_u_v_create_buffer },
|
2024-11-14 08:33:09 +01:00
|
|
|
{ FMT(YUV444), 4, y_u_v_create_buffer },
|
|
|
|
|
{ FMT(YVU444), 4, y_u_v_create_buffer },
|
|
|
|
|
{ FMT(NV12), 4, nv12_create_buffer },
|
|
|
|
|
{ FMT(NV21), 4, nv12_create_buffer },
|
|
|
|
|
{ FMT(NV16), 4, nv16_create_buffer },
|
|
|
|
|
{ FMT(NV61), 4, nv16_create_buffer },
|
|
|
|
|
{ FMT(NV24), 4, nv24_create_buffer },
|
|
|
|
|
{ FMT(NV42), 4, nv24_create_buffer },
|
|
|
|
|
{ FMT(YUYV), 4, yuyv_create_buffer },
|
|
|
|
|
{ FMT(YVYU), 4, yuyv_create_buffer },
|
|
|
|
|
{ FMT(UYVY), 4, yuyv_create_buffer },
|
|
|
|
|
{ FMT(VYUY), 4, yuyv_create_buffer },
|
|
|
|
|
{ FMT(XYUV8888), 4, xyuv8888_create_buffer },
|
|
|
|
|
{ FMT(P010), 5, p016_create_buffer },
|
2025-04-07 13:42:43 +02:00
|
|
|
{ FMT(P012), 5, p016_create_buffer },
|
|
|
|
|
{ FMT(P016), 5, p016_create_buffer },
|
2020-12-09 15:14:11 +02:00
|
|
|
#undef FMT
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-30 15:31:53 +02:00
|
|
|
static enum test_result_code
|
|
|
|
|
test_client_buffer(const struct client_buffer_case *cb_case,
|
|
|
|
|
enum buffer_type type)
|
2020-12-09 15:14:11 +02:00
|
|
|
{
|
2025-04-30 15:31:53 +02:00
|
|
|
enum test_result_code res = RESULT_SKIP;
|
2020-12-09 15:14:11 +02:00
|
|
|
char *fname;
|
|
|
|
|
pixman_image_t *img;
|
|
|
|
|
struct client *client;
|
2025-04-23 13:47:28 +02:00
|
|
|
struct client_buffer *buf;
|
2020-12-09 15:14:11 +02:00
|
|
|
bool match;
|
|
|
|
|
|
|
|
|
|
/*
|
2024-11-14 08:33:09 +01:00
|
|
|
* Note for YUV formats:
|
|
|
|
|
*
|
2020-12-09 15:14:11 +02:00
|
|
|
* This test image is 256 x 256 pixels.
|
|
|
|
|
*
|
|
|
|
|
* Therefore this test does NOT exercise:
|
|
|
|
|
* - odd image dimensions
|
|
|
|
|
* - non-square image
|
|
|
|
|
* - row padding
|
|
|
|
|
* - unaligned row stride
|
|
|
|
|
* - different alignments or padding in sub-sampled planes
|
|
|
|
|
*
|
|
|
|
|
* The reason to not test these is that GL-renderer seems to be more
|
|
|
|
|
* or less broken.
|
|
|
|
|
*
|
|
|
|
|
* The source image is effectively further downscaled to 128 x 128
|
|
|
|
|
* before sampled and converted to 256 x 256 YUV, so that
|
|
|
|
|
* sub-sampling for U and V does not require proper algorithms.
|
|
|
|
|
* Therefore, this test also does not test:
|
|
|
|
|
* - chroma siting (chroma sample positioning)
|
|
|
|
|
*/
|
|
|
|
|
fname = image_filename("chocolate-cake");
|
|
|
|
|
img = load_image_from_png(fname);
|
|
|
|
|
free(fname);
|
2025-01-27 14:28:39 +01:00
|
|
|
test_assert_ptr_not_null(img);
|
2020-12-09 15:14:11 +02:00
|
|
|
|
|
|
|
|
client = create_client();
|
|
|
|
|
client->surface = create_test_surface(client);
|
|
|
|
|
|
2025-04-30 15:31:53 +02:00
|
|
|
buf = cb_case->create_buffer(client, cb_case->drm_format, type, img);
|
2025-04-07 13:42:43 +02:00
|
|
|
if (buf) {
|
|
|
|
|
show_window_with_client_buffer(client, buf);
|
2020-12-09 15:14:11 +02:00
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
match = verify_screen_content(client, "client-buffer",
|
2025-04-30 15:31:53 +02:00
|
|
|
cb_case->ref_seq_no, NULL, 0,
|
2025-04-07 13:42:43 +02:00
|
|
|
NULL);
|
2025-04-30 15:31:53 +02:00
|
|
|
res = match ? RESULT_OK : RESULT_FAIL;
|
2025-04-07 13:42:43 +02:00
|
|
|
|
|
|
|
|
client_buffer_destroy(buf);
|
|
|
|
|
}
|
2025-04-30 15:31:53 +02:00
|
|
|
|
|
|
|
|
pixman_image_unref(img);
|
|
|
|
|
client_destroy(client);
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-07 13:42:43 +02:00
|
|
|
#if WESTON_TEST_SKIP_IS_FAILURE
|
2025-04-30 15:31:53 +02:00
|
|
|
static bool
|
|
|
|
|
format_must_pass(uint32_t drm_format, const uint32_t *must_pass, const size_t num)
|
|
|
|
|
{
|
2025-05-15 15:49:23 +03:00
|
|
|
if (!must_pass || num == 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
2025-04-30 15:31:53 +02:00
|
|
|
for (size_t i = 0; i < num; i++)
|
|
|
|
|
if (must_pass[i] == drm_format)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Test that various SHM pixel formats result in correct coloring on screen.
|
|
|
|
|
*/
|
|
|
|
|
TEST_P(client_buffer_shm, client_buffer_cases)
|
|
|
|
|
{
|
|
|
|
|
const struct client_buffer_case *cb_case = data;
|
2025-05-12 18:36:34 +02:00
|
|
|
const struct setup_args *args = &my_setup_args[get_test_fixture_index()];
|
2025-04-30 15:31:53 +02:00
|
|
|
enum test_result_code res;
|
|
|
|
|
|
2025-05-12 18:36:34 +02:00
|
|
|
if (args->gl_force_import_yuv_fallback)
|
|
|
|
|
#if WESTON_TEST_SKIP_IS_FAILURE
|
|
|
|
|
return RESULT_OK;
|
|
|
|
|
#else
|
|
|
|
|
return RESULT_SKIP;
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-04-30 15:31:53 +02:00
|
|
|
testlog("%s: format %s\n", get_test_name(), cb_case->drm_format_name);
|
|
|
|
|
|
|
|
|
|
res = test_client_buffer(cb_case, BUFFER_TYPE_SHM);
|
|
|
|
|
#if WESTON_TEST_SKIP_IS_FAILURE
|
|
|
|
|
if (res == RESULT_SKIP) {
|
2025-05-15 15:49:23 +03:00
|
|
|
test_assert_false(format_must_pass(cb_case->drm_format,
|
|
|
|
|
args->shm_format_must_pass,
|
|
|
|
|
args->shm_format_num));
|
|
|
|
|
res = RESULT_OK;
|
2025-04-07 13:42:43 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
2024-11-13 14:32:11 +01:00
|
|
|
|
2025-04-30 15:31:53 +02:00
|
|
|
return res;
|
|
|
|
|
}
|
2025-04-07 13:43:31 +02:00
|
|
|
|
2025-04-30 15:31:53 +02:00
|
|
|
/*
|
|
|
|
|
* Test that various DRM pixel formats result in correct coloring on screen.
|
|
|
|
|
*/
|
|
|
|
|
TEST_P(client_buffer_drm, client_buffer_cases)
|
|
|
|
|
{
|
|
|
|
|
const struct client_buffer_case *cb_case = data;
|
2025-05-12 18:36:34 +02:00
|
|
|
const struct setup_args *args = &my_setup_args[get_test_fixture_index()];
|
2025-04-30 15:31:53 +02:00
|
|
|
enum test_result_code res;
|
2025-04-07 13:43:31 +02:00
|
|
|
|
2025-05-12 18:36:34 +02:00
|
|
|
if (args->gl_force_import_yuv_fallback) {
|
|
|
|
|
const struct pixel_format_info *info;
|
|
|
|
|
|
|
|
|
|
info = pixel_format_get_info(cb_case->drm_format);
|
|
|
|
|
if (info->color_model != COLOR_MODEL_YUV)
|
|
|
|
|
#if WESTON_TEST_SKIP_IS_FAILURE
|
|
|
|
|
return RESULT_OK;
|
|
|
|
|
#else
|
|
|
|
|
return RESULT_SKIP;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-30 15:31:53 +02:00
|
|
|
testlog("%s: format %s\n", get_test_name(), cb_case->drm_format_name);
|
2025-04-07 13:43:31 +02:00
|
|
|
|
2025-04-30 15:31:53 +02:00
|
|
|
res = test_client_buffer(cb_case, BUFFER_TYPE_DMABUF);
|
2025-04-07 13:43:31 +02:00
|
|
|
#if WESTON_TEST_SKIP_IS_FAILURE
|
2025-04-30 15:31:53 +02:00
|
|
|
if (res == RESULT_SKIP) {
|
2025-05-15 15:49:23 +03:00
|
|
|
test_assert_false(format_must_pass(cb_case->drm_format,
|
|
|
|
|
args->dmabuf_format_must_pass,
|
|
|
|
|
args->dmabuf_format_num));
|
|
|
|
|
res = RESULT_OK;
|
2025-04-07 13:43:31 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-04-30 15:31:53 +02:00
|
|
|
return res;
|
2020-12-09 15:14:11 +02:00
|
|
|
}
|