forked from enlightenment/enlightenment
e_comp_wl_dmabuf: Format this file properly
NB: No functional changes (yet), just formatting to make this code remotely readable.
This commit is contained in:
parent
bc28793796
commit
dc013b8626
|
@ -49,7 +49,8 @@ linux_dmabuf_buffer_destroy(struct linux_dmabuf_buffer *buffer)
|
|||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < buffer->attributes.n_planes; i++) {
|
||||
for (i = 0; i < buffer->attributes.n_planes; i++)
|
||||
{
|
||||
close(buffer->attributes.fd[i]);
|
||||
buffer->attributes.fd[i] = -1;
|
||||
}
|
||||
|
@ -65,8 +66,7 @@ destroy_params(struct wl_resource *params_resource)
|
|||
|
||||
buffer = wl_resource_get_user_data(params_resource);
|
||||
|
||||
if (!buffer)
|
||||
return;
|
||||
if (!buffer) return;
|
||||
|
||||
linux_dmabuf_buffer_destroy(buffer);
|
||||
}
|
||||
|
@ -78,19 +78,15 @@ params_destroy(struct wl_client *client, struct wl_resource *resource)
|
|||
}
|
||||
|
||||
static void
|
||||
params_add(struct wl_client *client,
|
||||
struct wl_resource *params_resource,
|
||||
int32_t name_fd,
|
||||
uint32_t plane_idx,
|
||||
uint32_t offset,
|
||||
uint32_t stride,
|
||||
uint32_t modifier_hi,
|
||||
uint32_t modifier_lo)
|
||||
params_add(struct wl_client *client, struct wl_resource *params_resource,
|
||||
int32_t name_fd, uint32_t plane_idx, uint32_t offset,
|
||||
uint32_t stride, uint32_t modifier_hi, uint32_t modifier_lo)
|
||||
{
|
||||
struct linux_dmabuf_buffer *buffer;
|
||||
|
||||
buffer = wl_resource_get_user_data(params_resource);
|
||||
if (!buffer) {
|
||||
if (!buffer)
|
||||
{
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED,
|
||||
"params was already used to create a wl_buffer");
|
||||
|
@ -101,7 +97,8 @@ params_add(struct wl_client *client,
|
|||
assert(buffer->params_resource == params_resource);
|
||||
assert(!buffer->buffer_resource);
|
||||
|
||||
if (plane_idx >= MAX_DMABUF_PLANES) {
|
||||
if (plane_idx >= MAX_DMABUF_PLANES)
|
||||
{
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX,
|
||||
"plane index %u is too high", plane_idx);
|
||||
|
@ -109,7 +106,8 @@ params_add(struct wl_client *client,
|
|||
return;
|
||||
}
|
||||
|
||||
if (buffer->attributes.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",
|
||||
|
@ -124,19 +122,20 @@ params_add(struct wl_client *client,
|
|||
if (wl_resource_get_version(params_resource) < ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION)
|
||||
buffer->attributes.modifier[plane_idx] = DRM_FORMAT_MOD_INVALID;
|
||||
else
|
||||
buffer->attributes.modifier[plane_idx] = ((uint64_t)modifier_hi << 32) |
|
||||
modifier_lo;
|
||||
{
|
||||
buffer->attributes.modifier[plane_idx] =
|
||||
((uint64_t)modifier_hi << 32) | modifier_lo;
|
||||
buffer->attributes.n_planes++;
|
||||
}
|
||||
|
||||
static void
|
||||
linux_dmabuf_wl_buffer_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource)
|
||||
linux_dmabuf_wl_buffer_destroy(struct wl_client *client, struct wl_resource *resource)
|
||||
{
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static const struct wl_buffer_interface linux_dmabuf_buffer_implementation = {
|
||||
static const struct wl_buffer_interface linux_dmabuf_buffer_implementation =
|
||||
{
|
||||
linux_dmabuf_wl_buffer_destroy
|
||||
};
|
||||
|
||||
|
@ -156,20 +155,17 @@ destroy_linux_dmabuf_wl_buffer(struct wl_resource *resource)
|
|||
}
|
||||
|
||||
static void
|
||||
params_create_common(struct wl_client *client,
|
||||
struct wl_resource *params_resource,
|
||||
uint32_t buffer_id,
|
||||
int32_t width,
|
||||
int32_t height,
|
||||
uint32_t format,
|
||||
uint32_t flags)
|
||||
params_create_common(struct wl_client *client, struct wl_resource *params_resource,
|
||||
uint32_t buffer_id, int32_t width, int32_t height,
|
||||
uint32_t format, uint32_t flags)
|
||||
{
|
||||
struct linux_dmabuf_buffer *buffer;
|
||||
int i;
|
||||
|
||||
buffer = wl_resource_get_user_data(params_resource);
|
||||
|
||||
if (!buffer) {
|
||||
if (!buffer)
|
||||
{
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED,
|
||||
"params was already used to create a wl_buffer");
|
||||
|
@ -185,7 +181,8 @@ params_create_common(struct wl_client *client,
|
|||
wl_resource_set_user_data(buffer->params_resource, NULL);
|
||||
buffer->params_resource = NULL;
|
||||
|
||||
if (!buffer->attributes.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");
|
||||
|
@ -193,8 +190,10 @@ params_create_common(struct wl_client *client,
|
|||
}
|
||||
|
||||
/* Check for holes in the dmabufs set (e.g. [0, 1, 3]) */
|
||||
for (i = 0; i < buffer->attributes.n_planes; i++) {
|
||||
if (buffer->attributes.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);
|
||||
|
@ -208,14 +207,16 @@ params_create_common(struct wl_client *client,
|
|||
buffer->attributes.format = format;
|
||||
buffer->attributes.flags = flags;
|
||||
|
||||
if (width < 1 || height < 1) {
|
||||
if (width < 1 || height < 1)
|
||||
{
|
||||
wl_resource_post_error(params_resource,
|
||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS,
|
||||
"invalid width %d or height %d", width, height);
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
for (i = 0; i < buffer->attributes.n_planes; i++) {
|
||||
for (i = 0; i < buffer->attributes.n_planes; i++)
|
||||
{
|
||||
off_t size;
|
||||
|
||||
if ((uint64_t) buffer->attributes.offset[i] + buffer->attributes.stride[i] > UINT32_MAX) {
|
||||
|
@ -227,7 +228,8 @@ params_create_common(struct wl_client *client,
|
|||
|
||||
if (i == 0 &&
|
||||
(uint64_t) buffer->attributes.offset[i] +
|
||||
(uint64_t) buffer->attributes.stride[i] * height > UINT32_MAX) {
|
||||
(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);
|
||||
|
@ -237,10 +239,10 @@ params_create_common(struct wl_client *client,
|
|||
/* Don't report an error as it might be caused
|
||||
* by the kernel not supporting seeking on dmabuf */
|
||||
size = lseek(buffer->attributes.fd[i], 0, SEEK_END);
|
||||
if (size == -1)
|
||||
continue;
|
||||
if (size == -1) continue;
|
||||
|
||||
if (buffer->attributes.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",
|
||||
|
@ -248,7 +250,8 @@ params_create_common(struct wl_client *client,
|
|||
goto err_out;
|
||||
}
|
||||
|
||||
if (buffer->attributes.offset[i] + buffer->attributes.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",
|
||||
|
@ -259,7 +262,8 @@ params_create_common(struct wl_client *client,
|
|||
/* Only valid for first plane as other planes might be
|
||||
* sub-sampled according to fourcc format */
|
||||
if (i == 0 &&
|
||||
buffer->attributes.offset[i] + buffer->attributes.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);
|
||||
|
@ -273,13 +277,12 @@ params_create_common(struct wl_client *client,
|
|||
* checks (e.g. drm_format_num_planes).
|
||||
*/
|
||||
|
||||
if (!e_pixmap_dmabuf_test(buffer))
|
||||
goto err_failed;
|
||||
if (!e_pixmap_dmabuf_test(buffer)) goto err_failed;
|
||||
|
||||
buffer->buffer_resource = wl_resource_create(client,
|
||||
&wl_buffer_interface,
|
||||
1, buffer_id);
|
||||
if (!buffer->buffer_resource) {
|
||||
buffer->buffer_resource =
|
||||
wl_resource_create(client, &wl_buffer_interface, 1, buffer_id);
|
||||
if (!buffer->buffer_resource)
|
||||
{
|
||||
wl_resource_post_no_memory(params_resource);
|
||||
goto err_buffer;
|
||||
}
|
||||
|
@ -297,8 +300,7 @@ params_create_common(struct wl_client *client,
|
|||
return;
|
||||
|
||||
err_buffer:
|
||||
if (buffer->user_data_destroy_func)
|
||||
buffer->user_data_destroy_func(buffer);
|
||||
if (buffer->user_data_destroy_func) buffer->user_data_destroy_func(buffer);
|
||||
|
||||
err_failed:
|
||||
if (buffer_id == 0)
|
||||
|
@ -319,32 +321,24 @@ err_out:
|
|||
}
|
||||
|
||||
static void
|
||||
params_create(struct wl_client *client,
|
||||
struct wl_resource *params_resource,
|
||||
int32_t width,
|
||||
int32_t height,
|
||||
uint32_t format,
|
||||
uint32_t flags)
|
||||
params_create(struct wl_client *client, struct wl_resource *params_resource,
|
||||
int32_t width, int32_t height, uint32_t format, uint32_t flags)
|
||||
{
|
||||
params_create_common(client, params_resource, 0, width, height, format,
|
||||
flags);
|
||||
params_create_common(client, params_resource, 0, width, height, format, flags);
|
||||
}
|
||||
|
||||
static void
|
||||
params_create_immed(struct wl_client *client,
|
||||
struct wl_resource *params_resource,
|
||||
uint32_t buffer_id,
|
||||
int32_t width,
|
||||
int32_t height,
|
||||
uint32_t format,
|
||||
uint32_t flags)
|
||||
params_create_immed(struct wl_client *client, struct wl_resource *params_resource,
|
||||
uint32_t buffer_id, int32_t width, int32_t height,
|
||||
uint32_t format, uint32_t flags)
|
||||
{
|
||||
params_create_common(client, params_resource, buffer_id, width, height,
|
||||
format, flags);
|
||||
}
|
||||
|
||||
static const struct zwp_linux_buffer_params_v1_interface
|
||||
zwp_linux_buffer_params_implementation = {
|
||||
zwp_linux_buffer_params_implementation =
|
||||
{
|
||||
params_destroy,
|
||||
params_add,
|
||||
params_create,
|
||||
|
@ -371,16 +365,14 @@ linux_dmabuf_create_params(struct wl_client *client,
|
|||
compositor = wl_resource_get_user_data(linux_dmabuf_resource);
|
||||
|
||||
buffer = calloc(1, sizeof *buffer);
|
||||
if (!buffer)
|
||||
goto err_out;
|
||||
if (!buffer) goto err_out;
|
||||
|
||||
for (i = 0; i < MAX_DMABUF_PLANES; i++)
|
||||
buffer->attributes.fd[i] = -1;
|
||||
|
||||
buffer->compositor = compositor;
|
||||
buffer->params_resource =
|
||||
wl_resource_create(client,
|
||||
&zwp_linux_buffer_params_v1_interface,
|
||||
wl_resource_create(client, &zwp_linux_buffer_params_v1_interface,
|
||||
version, params_id);
|
||||
if (!buffer->params_resource)
|
||||
goto err_dealloc;
|
||||
|
@ -412,8 +404,7 @@ linux_dmabuf_buffer_get(struct wl_resource *resource)
|
|||
{
|
||||
struct linux_dmabuf_buffer *buffer;
|
||||
|
||||
if (!resource)
|
||||
return NULL;
|
||||
if (!resource) return NULL;
|
||||
|
||||
if (!wl_resource_instance_of(resource, &wl_buffer_interface,
|
||||
&linux_dmabuf_buffer_implementation))
|
||||
|
@ -445,8 +436,7 @@ linux_dmabuf_buffer_get(struct wl_resource *resource)
|
|||
* \sa weston_compositor_import_dmabuf
|
||||
*/
|
||||
EINTERN void
|
||||
linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer,
|
||||
void *data,
|
||||
linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer, void *data,
|
||||
dmabuf_user_data_destroy_func func)
|
||||
{
|
||||
assert(data == NULL || buffer->user_data == NULL);
|
||||
|
@ -470,14 +460,14 @@ linux_dmabuf_buffer_get_user_data(struct linux_dmabuf_buffer *buffer)
|
|||
return buffer->user_data;
|
||||
}
|
||||
|
||||
static const struct zwp_linux_dmabuf_v1_interface linux_dmabuf_implementation = {
|
||||
static const struct zwp_linux_dmabuf_v1_interface linux_dmabuf_implementation =
|
||||
{
|
||||
linux_dmabuf_destroy,
|
||||
linux_dmabuf_create_params
|
||||
};
|
||||
|
||||
static void
|
||||
bind_linux_dmabuf(struct wl_client *client,
|
||||
void *data, uint32_t version, uint32_t id)
|
||||
bind_linux_dmabuf(struct wl_client *client, void *data, uint32_t version, uint32_t id)
|
||||
{
|
||||
void *compositor = data;
|
||||
struct wl_resource *resource;
|
||||
|
@ -487,9 +477,10 @@ bind_linux_dmabuf(struct wl_client *client,
|
|||
uint64_t modifier_invalid = DRM_FORMAT_MOD_INVALID;
|
||||
int i, j;
|
||||
|
||||
resource = wl_resource_create(client, &zwp_linux_dmabuf_v1_interface,
|
||||
version, id);
|
||||
if (resource == NULL) {
|
||||
resource =
|
||||
wl_resource_create(client, &zwp_linux_dmabuf_v1_interface, version, id);
|
||||
if (resource == NULL)
|
||||
{
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
|
@ -499,36 +490,40 @@ bind_linux_dmabuf(struct wl_client *client,
|
|||
|
||||
if (version < ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Use EGL_EXT_image_dma_buf_import_modifiers to query and advertise
|
||||
* format/modifier codes.
|
||||
*/
|
||||
e_pixmap_dmabuf_formats_query(&formats,
|
||||
&num_formats);
|
||||
e_pixmap_dmabuf_formats_query(&formats, &num_formats);
|
||||
|
||||
for (i = 0; i < num_formats; i++) {
|
||||
e_pixmap_dmabuf_modifiers_query(
|
||||
formats[i],
|
||||
&modifiers,
|
||||
&num_modifiers);
|
||||
for (i = 0; i < num_formats; i++)
|
||||
{
|
||||
e_pixmap_dmabuf_modifiers_query(formats[i], &modifiers, &num_modifiers);
|
||||
|
||||
/* send DRM_FORMAT_MOD_INVALID token when no modifiers are supported
|
||||
* for this format */
|
||||
if (num_modifiers == 0) {
|
||||
if (num_modifiers == 0)
|
||||
{
|
||||
num_modifiers = 1;
|
||||
modifiers = &modifier_invalid;
|
||||
}
|
||||
for (j = 0; j < num_modifiers; j++) {
|
||||
if (version >= ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION) {
|
||||
|
||||
for (j = 0; j < num_modifiers; j++)
|
||||
{
|
||||
if (version >= ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION)
|
||||
{
|
||||
uint32_t modifier_lo = modifiers[j] & 0xFFFFFFFF;
|
||||
uint32_t modifier_hi = modifiers[j] >> 32;
|
||||
|
||||
zwp_linux_dmabuf_v1_send_modifier(resource, formats[i],
|
||||
modifier_hi,
|
||||
modifier_lo);
|
||||
} else if (modifiers[j] == DRM_FORMAT_MOD_LINEAR ||
|
||||
modifiers == &modifier_invalid) {
|
||||
zwp_linux_dmabuf_v1_send_format(resource,
|
||||
formats[i]);
|
||||
}
|
||||
else if (modifiers[j] == DRM_FORMAT_MOD_LINEAR ||
|
||||
modifiers == &modifier_invalid)
|
||||
{
|
||||
zwp_linux_dmabuf_v1_send_format(resource, formats[i]);
|
||||
}
|
||||
}
|
||||
if (modifiers != &modifier_invalid)
|
||||
|
@ -551,8 +546,7 @@ bind_linux_dmabuf(struct wl_client *client,
|
|||
EINTERN int
|
||||
linux_dmabuf_setup(struct wl_display *display)
|
||||
{
|
||||
if (!wl_global_create(display,
|
||||
&zwp_linux_dmabuf_v1_interface, 3,
|
||||
if (!wl_global_create(display, &zwp_linux_dmabuf_v1_interface, 3,
|
||||
NULL, bind_linux_dmabuf))
|
||||
return -1;
|
||||
|
||||
|
@ -589,8 +583,7 @@ linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer,
|
|||
display_resource = wl_client_get_object(client, 1);
|
||||
|
||||
assert(display_resource);
|
||||
wl_resource_post_error(display_resource,
|
||||
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
||||
wl_resource_post_error(display_resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
|
||||
"linux_dmabuf server error with "
|
||||
"wl_buffer@%u: %s", id, msg);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue