linux-dmabuf: Move the attributes part of linux_dmabuf_buffer into its own struct
This allows renderers to use that struct to create their own dmabufs,
in case they can’t import the one provided by the client directly but
know how to convert it into a format they can render.
Signed-off-by: Emmanuel Gil Peyrot <emmanuel.peyrot@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Differential Revision: https://phabricator.freedesktop.org/D332
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 4f9bbaf..ea6f3cd 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -983,14 +983,14 @@
* support a mix of gbm_bos and drmfbs.
*/
struct gbm_import_fd_data gbm_dmabuf = {
- .fd = dmabuf->dmabuf_fd[0],
- .width = dmabuf->width,
- .height = dmabuf->height,
- .stride = dmabuf->stride[0],
- .format = dmabuf->format
+ .fd = dmabuf->attributes.fd[0],
+ .width = dmabuf->attributes.width,
+ .height = dmabuf->attributes.height,
+ .stride = dmabuf->attributes.stride[0],
+ .format = dmabuf->attributes.format
};
- if (dmabuf->n_planes != 1 || dmabuf->offset[0] != 0)
+ if (dmabuf->attributes.n_planes != 1 || dmabuf->attributes.offset[0] != 0)
return NULL;
bo = gbm_bo_import(b->gbm, GBM_BO_IMPORT_FD, &gbm_dmabuf,
diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index ae72f32..d5356b6 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -1446,38 +1446,38 @@
*/
attribs[atti++] = EGL_WIDTH;
- attribs[atti++] = dmabuf->width;
+ attribs[atti++] = dmabuf->attributes.width;
attribs[atti++] = EGL_HEIGHT;
- attribs[atti++] = dmabuf->height;
+ attribs[atti++] = dmabuf->attributes.height;
attribs[atti++] = EGL_LINUX_DRM_FOURCC_EXT;
- attribs[atti++] = dmabuf->format;
+ attribs[atti++] = dmabuf->attributes.format;
/* XXX: Add modifier here when supported */
- if (dmabuf->n_planes > 0) {
+ if (dmabuf->attributes.n_planes > 0) {
attribs[atti++] = EGL_DMA_BUF_PLANE0_FD_EXT;
- attribs[atti++] = dmabuf->dmabuf_fd[0];
+ attribs[atti++] = dmabuf->attributes.fd[0];
attribs[atti++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT;
- attribs[atti++] = dmabuf->offset[0];
+ attribs[atti++] = dmabuf->attributes.offset[0];
attribs[atti++] = EGL_DMA_BUF_PLANE0_PITCH_EXT;
- attribs[atti++] = dmabuf->stride[0];
+ attribs[atti++] = dmabuf->attributes.stride[0];
}
- if (dmabuf->n_planes > 1) {
+ if (dmabuf->attributes.n_planes > 1) {
attribs[atti++] = EGL_DMA_BUF_PLANE1_FD_EXT;
- attribs[atti++] = dmabuf->dmabuf_fd[1];
+ attribs[atti++] = dmabuf->attributes.fd[1];
attribs[atti++] = EGL_DMA_BUF_PLANE1_OFFSET_EXT;
- attribs[atti++] = dmabuf->offset[1];
+ attribs[atti++] = dmabuf->attributes.offset[1];
attribs[atti++] = EGL_DMA_BUF_PLANE1_PITCH_EXT;
- attribs[atti++] = dmabuf->stride[1];
+ attribs[atti++] = dmabuf->attributes.stride[1];
}
- if (dmabuf->n_planes > 2) {
+ if (dmabuf->attributes.n_planes > 2) {
attribs[atti++] = EGL_DMA_BUF_PLANE2_FD_EXT;
- attribs[atti++] = dmabuf->dmabuf_fd[2];
+ attribs[atti++] = dmabuf->attributes.fd[2];
attribs[atti++] = EGL_DMA_BUF_PLANE2_OFFSET_EXT;
- attribs[atti++] = dmabuf->offset[2];
+ attribs[atti++] = dmabuf->attributes.offset[2];
attribs[atti++] = EGL_DMA_BUF_PLANE2_PITCH_EXT;
- attribs[atti++] = dmabuf->stride[2];
+ attribs[atti++] = dmabuf->attributes.stride[2];
}
attribs[atti++] = EGL_NONE;
@@ -1507,14 +1507,14 @@
assert(gr->has_dmabuf_import);
- for (i = 0; i < dmabuf->n_planes; i++) {
+ for (i = 0; i < dmabuf->attributes.n_planes; i++) {
/* EGL import does not have modifiers */
- if (dmabuf->modifier[i] != 0)
+ if (dmabuf->attributes.modifier[i] != 0)
return false;
}
/* reject all flags we do not recognize or handle */
- if (dmabuf->flags & ~ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT)
+ if (dmabuf->attributes.flags & ~ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT)
return false;
image = import_dmabuf(gr, dmabuf);
@@ -1528,12 +1528,12 @@
}
static GLenum
-choose_texture_target(struct linux_dmabuf_buffer *dmabuf)
+choose_texture_target(struct dmabuf_attributes *attributes)
{
- if (dmabuf->n_planes > 1)
+ if (attributes->n_planes > 1)
return GL_TEXTURE_EXTERNAL_OES;
- switch (dmabuf->format & ~DRM_FORMAT_BIG_ENDIAN) {
+ switch (attributes->format & ~DRM_FORMAT_BIG_ENDIAN) {
case DRM_FORMAT_YUYV:
case DRM_FORMAT_YVYU:
case DRM_FORMAT_UYVY:
@@ -1560,16 +1560,16 @@
return;
}
- buffer->width = dmabuf->width;
- buffer->height = dmabuf->height;
+ buffer->width = dmabuf->attributes.width;
+ buffer->height = dmabuf->attributes.height;
buffer->y_inverted =
- !!(dmabuf->flags & ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT);
+ !!(dmabuf->attributes.flags & ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT);
for (i = 0; i < gs->num_images; i++)
egl_image_unref(gs->images[i]);
gs->num_images = 0;
- gs->target = choose_texture_target(dmabuf);
+ gs->target = choose_texture_target(&dmabuf->attributes);
switch (gs->target) {
case GL_TEXTURE_2D:
gs->shader = &gr->texture_shader_rgba;
diff --git a/src/linux-dmabuf.c b/src/linux-dmabuf.c
index 53768bf..8c6337c 100644
--- a/src/linux-dmabuf.c
+++ b/src/linux-dmabuf.c
@@ -35,12 +35,12 @@
{
int i;
- for (i = 0; i < buffer->n_planes; i++) {
- close(buffer->dmabuf_fd[i]);
- buffer->dmabuf_fd[i] = -1;
+ for (i = 0; i < buffer->attributes.n_planes; i++) {
+ close(buffer->attributes.fd[i]);
+ buffer->attributes.fd[i] = -1;
}
- buffer->n_planes = 0;
+ buffer->attributes.n_planes = 0;
free(buffer);
}
@@ -95,7 +95,7 @@
return;
}
- if (buffer->dmabuf_fd[plane_idx] != -1) {
+ if (buffer->attributes.fd[plane_idx] != -1) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET,
"a dmabuf has already been added for plane %u",
@@ -104,12 +104,12 @@
return;
}
- buffer->dmabuf_fd[plane_idx] = name_fd;
- buffer->offset[plane_idx] = offset;
- buffer->stride[plane_idx] = stride;
- buffer->modifier[plane_idx] = ((uint64_t)modifier_hi << 32) |
- modifier_lo;
- buffer->n_planes++;
+ buffer->attributes.fd[plane_idx] = name_fd;
+ buffer->attributes.offset[plane_idx] = offset;
+ buffer->attributes.stride[plane_idx] = stride;
+ buffer->attributes.modifier[plane_idx] = ((uint64_t)modifier_hi << 32) |
+ modifier_lo;
+ buffer->attributes.n_planes++;
}
static void
@@ -167,7 +167,7 @@
wl_resource_set_user_data(buffer->params_resource, NULL);
buffer->params_resource = NULL;
- if (!buffer->n_planes) {
+ if (!buffer->attributes.n_planes) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE,
"no dmabuf has been added to the params");
@@ -175,8 +175,8 @@
}
/* Check for holes in the dmabufs set (e.g. [0, 1, 3]) */
- for (i = 0; i < buffer->n_planes; i++) {
- if (buffer->dmabuf_fd[i] == -1) {
+ for (i = 0; i < buffer->attributes.n_planes; i++) {
+ if (buffer->attributes.fd[i] == -1) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE,
"no dmabuf has been added for plane %i", i);
@@ -184,10 +184,10 @@
}
}
- buffer->width = width;
- buffer->height = height;
- buffer->format = format;
- buffer->flags = flags;
+ buffer->attributes.width = width;
+ buffer->attributes.height = height;
+ buffer->attributes.format = format;
+ buffer->attributes.flags = flags;
if (width < 1 || height < 1) {
wl_resource_post_error(params_resource,
@@ -196,10 +196,10 @@
goto err_out;
}
- for (i = 0; i < buffer->n_planes; i++) {
+ for (i = 0; i < buffer->attributes.n_planes; i++) {
off_t size;
- if ((uint64_t) buffer->offset[i] + buffer->stride[i] > UINT32_MAX) {
+ if ((uint64_t) buffer->attributes.offset[i] + buffer->attributes.stride[i] > UINT32_MAX) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
"size overflow for plane %i", i);
@@ -207,8 +207,8 @@
}
if (i == 0 &&
- (uint64_t) buffer->offset[i] +
- (uint64_t) buffer->stride[i] * height > UINT32_MAX) {
+ (uint64_t) buffer->attributes.offset[i] +
+ (uint64_t) buffer->attributes.stride[i] * height > UINT32_MAX) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
"size overflow for plane %i", i);
@@ -217,30 +217,30 @@
/* Don't report an error as it might be caused
* by the kernel not supporting seeking on dmabuf */
- size = lseek(buffer->dmabuf_fd[i], 0, SEEK_END);
+ size = lseek(buffer->attributes.fd[i], 0, SEEK_END);
if (size == -1)
break;
- if (buffer->offset[i] >= size) {
+ if (buffer->attributes.offset[i] >= size) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
"invalid offset %i for plane %i",
- buffer->offset[i], i);
+ buffer->attributes.offset[i], i);
goto err_out;
}
- if (buffer->offset[i] + buffer->stride[i] > size) {
+ if (buffer->attributes.offset[i] + buffer->attributes.stride[i] > size) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
"invalid stride %i for plane %i",
- buffer->stride[i], i);
+ buffer->attributes.stride[i], i);
goto err_out;
}
/* Only valid for first plane as other planes might be
* sub-sampled according to fourcc format */
if (i == 0 &&
- buffer->offset[i] + buffer->stride[i] * height > size) {
+ buffer->attributes.offset[i] + buffer->attributes.stride[i] * height > size) {
wl_resource_post_error(params_resource,
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
"invalid buffer stride or height for plane %i", i);
@@ -316,7 +316,7 @@
goto err_out;
for (i = 0; i < MAX_DMABUF_PLANES; i++)
- buffer->dmabuf_fd[i] = -1;
+ buffer->attributes.fd[i] = -1;
buffer->compositor = compositor;
buffer->params_resource =
diff --git a/src/linux-dmabuf.h b/src/linux-dmabuf.h
index 162ff58..cd30f91 100644
--- a/src/linux-dmabuf.h
+++ b/src/linux-dmabuf.h
@@ -31,19 +31,23 @@
typedef void (*dmabuf_user_data_destroy_func)(
struct linux_dmabuf_buffer *buffer);
-struct linux_dmabuf_buffer {
- struct wl_resource *buffer_resource;
- struct wl_resource *params_resource;
- struct weston_compositor *compositor;
+struct dmabuf_attributes {
int32_t width;
int32_t height;
uint32_t format;
uint32_t flags; /* enum zlinux_buffer_params_flags */
int n_planes;
- int dmabuf_fd[MAX_DMABUF_PLANES];
+ int fd[MAX_DMABUF_PLANES];
uint32_t offset[MAX_DMABUF_PLANES];
uint32_t stride[MAX_DMABUF_PLANES];
uint64_t modifier[MAX_DMABUF_PLANES];
+};
+
+struct linux_dmabuf_buffer {
+ struct wl_resource *buffer_resource;
+ struct wl_resource *params_resource;
+ struct weston_compositor *compositor;
+ struct dmabuf_attributes attributes;
void *user_data;
dmabuf_user_data_destroy_func user_data_destroy_func;