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
|
@ -47,314 +47,308 @@
|
||||||
static void
|
static void
|
||||||
linux_dmabuf_buffer_destroy(struct linux_dmabuf_buffer *buffer)
|
linux_dmabuf_buffer_destroy(struct linux_dmabuf_buffer *buffer)
|
||||||
{
|
{
|
||||||
int i;
|
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;
|
close(buffer->attributes.fd[i]);
|
||||||
}
|
buffer->attributes.fd[i] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
buffer->attributes.n_planes = 0;
|
buffer->attributes.n_planes = 0;
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_params(struct wl_resource *params_resource)
|
destroy_params(struct wl_resource *params_resource)
|
||||||
{
|
{
|
||||||
struct linux_dmabuf_buffer *buffer;
|
struct linux_dmabuf_buffer *buffer;
|
||||||
|
|
||||||
buffer = wl_resource_get_user_data(params_resource);
|
buffer = wl_resource_get_user_data(params_resource);
|
||||||
|
|
||||||
if (!buffer)
|
if (!buffer) return;
|
||||||
return;
|
|
||||||
|
|
||||||
linux_dmabuf_buffer_destroy(buffer);
|
linux_dmabuf_buffer_destroy(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
params_destroy(struct wl_client *client, struct wl_resource *resource)
|
params_destroy(struct wl_client *client, struct wl_resource *resource)
|
||||||
{
|
{
|
||||||
wl_resource_destroy(resource);
|
wl_resource_destroy(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
params_add(struct wl_client *client,
|
params_add(struct wl_client *client, struct wl_resource *params_resource,
|
||||||
struct wl_resource *params_resource,
|
int32_t name_fd, uint32_t plane_idx, uint32_t offset,
|
||||||
int32_t name_fd,
|
uint32_t stride, uint32_t modifier_hi, uint32_t modifier_lo)
|
||||||
uint32_t plane_idx,
|
|
||||||
uint32_t offset,
|
|
||||||
uint32_t stride,
|
|
||||||
uint32_t modifier_hi,
|
|
||||||
uint32_t modifier_lo)
|
|
||||||
{
|
{
|
||||||
struct linux_dmabuf_buffer *buffer;
|
struct linux_dmabuf_buffer *buffer;
|
||||||
|
|
||||||
buffer = wl_resource_get_user_data(params_resource);
|
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,
|
wl_resource_post_error(params_resource,
|
||||||
"params was already used to create a wl_buffer");
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED,
|
||||||
close(name_fd);
|
"params was already used to create a wl_buffer");
|
||||||
return;
|
close(name_fd);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
assert(buffer->params_resource == params_resource);
|
assert(buffer->params_resource == params_resource);
|
||||||
assert(!buffer->buffer_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,
|
wl_resource_post_error(params_resource,
|
||||||
"plane index %u is too high", plane_idx);
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX,
|
||||||
close(name_fd);
|
"plane index %u is too high", plane_idx);
|
||||||
return;
|
close(name_fd);
|
||||||
}
|
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,
|
wl_resource_post_error(params_resource,
|
||||||
"a dmabuf has already been added for plane %u",
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET,
|
||||||
plane_idx);
|
"a dmabuf has already been added for plane %u",
|
||||||
close(name_fd);
|
plane_idx);
|
||||||
return;
|
close(name_fd);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
buffer->attributes.fd[plane_idx] = name_fd;
|
buffer->attributes.fd[plane_idx] = name_fd;
|
||||||
buffer->attributes.offset[plane_idx] = offset;
|
buffer->attributes.offset[plane_idx] = offset;
|
||||||
buffer->attributes.stride[plane_idx] = stride;
|
buffer->attributes.stride[plane_idx] = stride;
|
||||||
if (wl_resource_get_version(params_resource) < ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION)
|
if (wl_resource_get_version(params_resource) < ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION)
|
||||||
buffer->attributes.modifier[plane_idx] = DRM_FORMAT_MOD_INVALID;
|
buffer->attributes.modifier[plane_idx] = DRM_FORMAT_MOD_INVALID;
|
||||||
else
|
else
|
||||||
buffer->attributes.modifier[plane_idx] = ((uint64_t)modifier_hi << 32) |
|
{
|
||||||
modifier_lo;
|
buffer->attributes.modifier[plane_idx] =
|
||||||
buffer->attributes.n_planes++;
|
((uint64_t)modifier_hi << 32) | modifier_lo;
|
||||||
}
|
buffer->attributes.n_planes++;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
linux_dmabuf_wl_buffer_destroy(struct wl_client *client,
|
linux_dmabuf_wl_buffer_destroy(struct wl_client *client, struct wl_resource *resource)
|
||||||
struct wl_resource *resource)
|
|
||||||
{
|
{
|
||||||
wl_resource_destroy(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
|
{
|
||||||
|
linux_dmabuf_wl_buffer_destroy
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_linux_dmabuf_wl_buffer(struct wl_resource *resource)
|
destroy_linux_dmabuf_wl_buffer(struct wl_resource *resource)
|
||||||
{
|
{
|
||||||
struct linux_dmabuf_buffer *buffer;
|
struct linux_dmabuf_buffer *buffer;
|
||||||
|
|
||||||
buffer = wl_resource_get_user_data(resource);
|
buffer = wl_resource_get_user_data(resource);
|
||||||
assert(buffer->buffer_resource == resource);
|
assert(buffer->buffer_resource == resource);
|
||||||
assert(!buffer->params_resource);
|
assert(!buffer->params_resource);
|
||||||
|
|
||||||
if (buffer->user_data_destroy_func)
|
if (buffer->user_data_destroy_func)
|
||||||
buffer->user_data_destroy_func(buffer);
|
buffer->user_data_destroy_func(buffer);
|
||||||
|
|
||||||
linux_dmabuf_buffer_destroy(buffer);
|
linux_dmabuf_buffer_destroy(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
params_create_common(struct wl_client *client,
|
params_create_common(struct wl_client *client, struct wl_resource *params_resource,
|
||||||
struct wl_resource *params_resource,
|
uint32_t buffer_id, int32_t width, int32_t height,
|
||||||
uint32_t buffer_id,
|
uint32_t format, uint32_t flags)
|
||||||
int32_t width,
|
|
||||||
int32_t height,
|
|
||||||
uint32_t format,
|
|
||||||
uint32_t flags)
|
|
||||||
{
|
{
|
||||||
struct linux_dmabuf_buffer *buffer;
|
struct linux_dmabuf_buffer *buffer;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
buffer = wl_resource_get_user_data(params_resource);
|
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,
|
wl_resource_post_error(params_resource,
|
||||||
"params was already used to create a wl_buffer");
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED,
|
||||||
return;
|
"params was already used to create a wl_buffer");
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
assert(buffer->params_resource == params_resource);
|
assert(buffer->params_resource == params_resource);
|
||||||
assert(!buffer->buffer_resource);
|
assert(!buffer->buffer_resource);
|
||||||
|
|
||||||
/* Switch the linux_dmabuf_buffer object from params resource to
|
/* Switch the linux_dmabuf_buffer object from params resource to
|
||||||
* eventually wl_buffer resource.
|
* eventually wl_buffer resource.
|
||||||
*/
|
*/
|
||||||
wl_resource_set_user_data(buffer->params_resource, NULL);
|
wl_resource_set_user_data(buffer->params_resource, NULL);
|
||||||
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,
|
wl_resource_post_error(params_resource,
|
||||||
"no dmabuf has been added to the params");
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE,
|
||||||
goto err_out;
|
"no dmabuf has been added to the params");
|
||||||
}
|
goto err_out;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check for holes in the dmabufs set (e.g. [0, 1, 3]) */
|
/* Check for holes in the dmabufs set (e.g. [0, 1, 3]) */
|
||||||
for (i = 0; i < buffer->attributes.n_planes; i++) {
|
for (i = 0; i < buffer->attributes.n_planes; i++)
|
||||||
if (buffer->attributes.fd[i] == -1) {
|
{
|
||||||
wl_resource_post_error(params_resource,
|
if (buffer->attributes.fd[i] == -1)
|
||||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE,
|
{
|
||||||
"no dmabuf has been added for plane %i", i);
|
wl_resource_post_error(params_resource,
|
||||||
goto err_out;
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE,
|
||||||
}
|
"no dmabuf has been added for plane %i", i);
|
||||||
}
|
goto err_out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buffer->attributes.version = 1;
|
buffer->attributes.version = 1;
|
||||||
buffer->attributes.width = width;
|
buffer->attributes.width = width;
|
||||||
buffer->attributes.height = height;
|
buffer->attributes.height = height;
|
||||||
buffer->attributes.format = format;
|
buffer->attributes.format = format;
|
||||||
buffer->attributes.flags = flags;
|
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,
|
wl_resource_post_error(params_resource,
|
||||||
"invalid width %d or height %d", width, height);
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS,
|
||||||
goto err_out;
|
"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;
|
{
|
||||||
|
off_t size;
|
||||||
|
|
||||||
if ((uint64_t) buffer->attributes.offset[i] + buffer->attributes.stride[i] > UINT32_MAX) {
|
if ((uint64_t) buffer->attributes.offset[i] + buffer->attributes.stride[i] > UINT32_MAX) {
|
||||||
wl_resource_post_error(params_resource,
|
wl_resource_post_error(params_resource,
|
||||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
|
||||||
"size overflow for plane %i", i);
|
"size overflow for plane %i", i);
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 0 &&
|
if (i == 0 &&
|
||||||
(uint64_t) buffer->attributes.offset[i] +
|
(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,
|
wl_resource_post_error(params_resource,
|
||||||
"size overflow for plane %i", i);
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
|
||||||
goto err_out;
|
"size overflow for plane %i", i);
|
||||||
}
|
goto err_out;
|
||||||
|
}
|
||||||
|
|
||||||
/* Don't report an error as it might be caused
|
/* Don't report an error as it might be caused
|
||||||
* by the kernel not supporting seeking on dmabuf */
|
* by the kernel not supporting seeking on dmabuf */
|
||||||
size = lseek(buffer->attributes.fd[i], 0, SEEK_END);
|
size = lseek(buffer->attributes.fd[i], 0, SEEK_END);
|
||||||
if (size == -1)
|
if (size == -1) continue;
|
||||||
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,
|
wl_resource_post_error(params_resource,
|
||||||
"invalid offset %i for plane %i",
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
|
||||||
buffer->attributes.offset[i], i);
|
"invalid offset %i for plane %i",
|
||||||
goto err_out;
|
buffer->attributes.offset[i], i);
|
||||||
}
|
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,
|
wl_resource_post_error(params_resource,
|
||||||
"invalid stride %i for plane %i",
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
|
||||||
buffer->attributes.stride[i], i);
|
"invalid stride %i for plane %i",
|
||||||
goto err_out;
|
buffer->attributes.stride[i], i);
|
||||||
}
|
goto err_out;
|
||||||
|
}
|
||||||
|
|
||||||
/* Only valid for first plane as other planes might be
|
/* Only valid for first plane as other planes might be
|
||||||
* sub-sampled according to fourcc format */
|
* sub-sampled according to fourcc format */
|
||||||
if (i == 0 &&
|
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,
|
wl_resource_post_error(params_resource,
|
||||||
"invalid buffer stride or height for plane %i", i);
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
|
||||||
goto err_out;
|
"invalid buffer stride or height for plane %i", i);
|
||||||
}
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* XXX: Some additional sanity checks could be done with respect
|
/* XXX: Some additional sanity checks could be done with respect
|
||||||
* to the fourcc format. A centralized collection (kernel or
|
* to the fourcc format. A centralized collection (kernel or
|
||||||
* libdrm) would be useful to avoid code duplication for these
|
* libdrm) would be useful to avoid code duplication for these
|
||||||
* checks (e.g. drm_format_num_planes).
|
* checks (e.g. drm_format_num_planes).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!e_pixmap_dmabuf_test(buffer))
|
if (!e_pixmap_dmabuf_test(buffer)) goto err_failed;
|
||||||
goto err_failed;
|
|
||||||
|
|
||||||
buffer->buffer_resource = wl_resource_create(client,
|
buffer->buffer_resource =
|
||||||
&wl_buffer_interface,
|
wl_resource_create(client, &wl_buffer_interface, 1, buffer_id);
|
||||||
1, buffer_id);
|
if (!buffer->buffer_resource)
|
||||||
if (!buffer->buffer_resource) {
|
{
|
||||||
wl_resource_post_no_memory(params_resource);
|
wl_resource_post_no_memory(params_resource);
|
||||||
goto err_buffer;
|
goto err_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_resource_set_implementation(buffer->buffer_resource,
|
wl_resource_set_implementation(buffer->buffer_resource,
|
||||||
&linux_dmabuf_buffer_implementation,
|
&linux_dmabuf_buffer_implementation,
|
||||||
buffer, destroy_linux_dmabuf_wl_buffer);
|
buffer, destroy_linux_dmabuf_wl_buffer);
|
||||||
|
|
||||||
/* send 'created' event when the request is not for an immediate
|
/* send 'created' event when the request is not for an immediate
|
||||||
* import, ie buffer_id is zero */
|
* import, ie buffer_id is zero */
|
||||||
if (buffer_id == 0)
|
if (buffer_id == 0)
|
||||||
zwp_linux_buffer_params_v1_send_created(params_resource,
|
zwp_linux_buffer_params_v1_send_created(params_resource,
|
||||||
buffer->buffer_resource);
|
buffer->buffer_resource);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
err_buffer:
|
err_buffer:
|
||||||
if (buffer->user_data_destroy_func)
|
if (buffer->user_data_destroy_func) buffer->user_data_destroy_func(buffer);
|
||||||
buffer->user_data_destroy_func(buffer);
|
|
||||||
|
|
||||||
err_failed:
|
err_failed:
|
||||||
if (buffer_id == 0)
|
if (buffer_id == 0)
|
||||||
zwp_linux_buffer_params_v1_send_failed(params_resource);
|
zwp_linux_buffer_params_v1_send_failed(params_resource);
|
||||||
else
|
else
|
||||||
/* since the behavior is left implementation defined by the
|
/* since the behavior is left implementation defined by the
|
||||||
* protocol in case of create_immed failure due to an unknown cause,
|
* protocol in case of create_immed failure due to an unknown cause,
|
||||||
* we choose to treat it as a fatal error and immediately kill the
|
* we choose to treat it as a fatal error and immediately kill the
|
||||||
* client instead of creating an invalid handle and waiting for it
|
* client instead of creating an invalid handle and waiting for it
|
||||||
* to be used.
|
* to be used.
|
||||||
*/
|
*/
|
||||||
wl_resource_post_error(params_resource,
|
wl_resource_post_error(params_resource,
|
||||||
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_WL_BUFFER,
|
ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_WL_BUFFER,
|
||||||
"importing the supplied dmabufs failed");
|
"importing the supplied dmabufs failed");
|
||||||
|
|
||||||
err_out:
|
err_out:
|
||||||
linux_dmabuf_buffer_destroy(buffer);
|
linux_dmabuf_buffer_destroy(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
params_create(struct wl_client *client,
|
params_create(struct wl_client *client, struct wl_resource *params_resource,
|
||||||
struct wl_resource *params_resource,
|
int32_t width, int32_t height, uint32_t format, uint32_t flags)
|
||||||
int32_t width,
|
|
||||||
int32_t height,
|
|
||||||
uint32_t format,
|
|
||||||
uint32_t flags)
|
|
||||||
{
|
{
|
||||||
params_create_common(client, params_resource, 0, width, height, format,
|
params_create_common(client, params_resource, 0, width, height, format, flags);
|
||||||
flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
params_create_immed(struct wl_client *client,
|
params_create_immed(struct wl_client *client, struct wl_resource *params_resource,
|
||||||
struct wl_resource *params_resource,
|
uint32_t buffer_id, int32_t width, int32_t height,
|
||||||
uint32_t buffer_id,
|
uint32_t format, uint32_t flags)
|
||||||
int32_t width,
|
|
||||||
int32_t height,
|
|
||||||
uint32_t format,
|
|
||||||
uint32_t flags)
|
|
||||||
{
|
{
|
||||||
params_create_common(client, params_resource, buffer_id, width, height,
|
params_create_common(client, params_resource, buffer_id, width, height,
|
||||||
format, flags);
|
format, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct zwp_linux_buffer_params_v1_interface
|
static const struct zwp_linux_buffer_params_v1_interface
|
||||||
zwp_linux_buffer_params_implementation = {
|
zwp_linux_buffer_params_implementation =
|
||||||
params_destroy,
|
{
|
||||||
params_add,
|
params_destroy,
|
||||||
params_create,
|
params_add,
|
||||||
params_create_immed
|
params_create,
|
||||||
|
params_create_immed
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
linux_dmabuf_destroy(struct wl_client *client, struct wl_resource *resource)
|
linux_dmabuf_destroy(struct wl_client *client, struct wl_resource *resource)
|
||||||
{
|
{
|
||||||
wl_resource_destroy(resource);
|
wl_resource_destroy(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -362,40 +356,38 @@ linux_dmabuf_create_params(struct wl_client *client,
|
||||||
struct wl_resource *linux_dmabuf_resource,
|
struct wl_resource *linux_dmabuf_resource,
|
||||||
uint32_t params_id)
|
uint32_t params_id)
|
||||||
{
|
{
|
||||||
void *compositor;
|
void *compositor;
|
||||||
struct linux_dmabuf_buffer *buffer;
|
struct linux_dmabuf_buffer *buffer;
|
||||||
uint32_t version;
|
uint32_t version;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
version = wl_resource_get_version(linux_dmabuf_resource);
|
version = wl_resource_get_version(linux_dmabuf_resource);
|
||||||
compositor = wl_resource_get_user_data(linux_dmabuf_resource);
|
compositor = wl_resource_get_user_data(linux_dmabuf_resource);
|
||||||
|
|
||||||
buffer = calloc(1, sizeof *buffer);
|
buffer = calloc(1, sizeof *buffer);
|
||||||
if (!buffer)
|
if (!buffer) goto err_out;
|
||||||
goto err_out;
|
|
||||||
|
|
||||||
for (i = 0; i < MAX_DMABUF_PLANES; i++)
|
for (i = 0; i < MAX_DMABUF_PLANES; i++)
|
||||||
buffer->attributes.fd[i] = -1;
|
buffer->attributes.fd[i] = -1;
|
||||||
|
|
||||||
buffer->compositor = compositor;
|
buffer->compositor = compositor;
|
||||||
buffer->params_resource =
|
buffer->params_resource =
|
||||||
wl_resource_create(client,
|
wl_resource_create(client, &zwp_linux_buffer_params_v1_interface,
|
||||||
&zwp_linux_buffer_params_v1_interface,
|
version, params_id);
|
||||||
version, params_id);
|
if (!buffer->params_resource)
|
||||||
if (!buffer->params_resource)
|
goto err_dealloc;
|
||||||
goto err_dealloc;
|
|
||||||
|
|
||||||
wl_resource_set_implementation(buffer->params_resource,
|
wl_resource_set_implementation(buffer->params_resource,
|
||||||
&zwp_linux_buffer_params_implementation,
|
&zwp_linux_buffer_params_implementation,
|
||||||
buffer, destroy_params);
|
buffer, destroy_params);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
err_dealloc:
|
err_dealloc:
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
err_out:
|
err_out:
|
||||||
wl_resource_post_no_memory(linux_dmabuf_resource);
|
wl_resource_post_no_memory(linux_dmabuf_resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the linux_dmabuf_buffer from a wl_buffer resource
|
/** Get the linux_dmabuf_buffer from a wl_buffer resource
|
||||||
|
@ -410,21 +402,20 @@ err_out:
|
||||||
EINTERN struct linux_dmabuf_buffer *
|
EINTERN struct linux_dmabuf_buffer *
|
||||||
linux_dmabuf_buffer_get(struct wl_resource *resource)
|
linux_dmabuf_buffer_get(struct wl_resource *resource)
|
||||||
{
|
{
|
||||||
struct linux_dmabuf_buffer *buffer;
|
struct linux_dmabuf_buffer *buffer;
|
||||||
|
|
||||||
if (!resource)
|
if (!resource) return NULL;
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (!wl_resource_instance_of(resource, &wl_buffer_interface,
|
if (!wl_resource_instance_of(resource, &wl_buffer_interface,
|
||||||
&linux_dmabuf_buffer_implementation))
|
&linux_dmabuf_buffer_implementation))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
buffer = wl_resource_get_user_data(resource);
|
buffer = wl_resource_get_user_data(resource);
|
||||||
assert(buffer);
|
assert(buffer);
|
||||||
assert(!buffer->params_resource);
|
assert(!buffer->params_resource);
|
||||||
assert(buffer->buffer_resource == resource);
|
assert(buffer->buffer_resource == resource);
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set renderer-private data
|
/** Set renderer-private data
|
||||||
|
@ -445,14 +436,13 @@ linux_dmabuf_buffer_get(struct wl_resource *resource)
|
||||||
* \sa weston_compositor_import_dmabuf
|
* \sa weston_compositor_import_dmabuf
|
||||||
*/
|
*/
|
||||||
EINTERN void
|
EINTERN void
|
||||||
linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer,
|
linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer, void *data,
|
||||||
void *data,
|
|
||||||
dmabuf_user_data_destroy_func func)
|
dmabuf_user_data_destroy_func func)
|
||||||
{
|
{
|
||||||
assert(data == NULL || buffer->user_data == NULL);
|
assert(data == NULL || buffer->user_data == NULL);
|
||||||
|
|
||||||
buffer->user_data = data;
|
buffer->user_data = data;
|
||||||
buffer->user_data_destroy_func = func;
|
buffer->user_data_destroy_func = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get renderer-private data
|
/** Get renderer-private data
|
||||||
|
@ -467,74 +457,79 @@ linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer,
|
||||||
EINTERN void *
|
EINTERN void *
|
||||||
linux_dmabuf_buffer_get_user_data(struct linux_dmabuf_buffer *buffer)
|
linux_dmabuf_buffer_get_user_data(struct linux_dmabuf_buffer *buffer)
|
||||||
{
|
{
|
||||||
return buffer->user_data;
|
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
|
linux_dmabuf_destroy,
|
||||||
|
linux_dmabuf_create_params
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bind_linux_dmabuf(struct wl_client *client,
|
bind_linux_dmabuf(struct wl_client *client, void *data, uint32_t version, uint32_t id)
|
||||||
void *data, uint32_t version, uint32_t id)
|
|
||||||
{
|
{
|
||||||
void *compositor = data;
|
void *compositor = data;
|
||||||
struct wl_resource *resource;
|
struct wl_resource *resource;
|
||||||
int *formats = NULL;
|
int *formats = NULL;
|
||||||
uint64_t *modifiers = NULL;
|
uint64_t *modifiers = NULL;
|
||||||
int num_formats, num_modifiers;
|
int num_formats, num_modifiers;
|
||||||
uint64_t modifier_invalid = DRM_FORMAT_MOD_INVALID;
|
uint64_t modifier_invalid = DRM_FORMAT_MOD_INVALID;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
resource = wl_resource_create(client, &zwp_linux_dmabuf_v1_interface,
|
resource =
|
||||||
version, id);
|
wl_resource_create(client, &zwp_linux_dmabuf_v1_interface, version, id);
|
||||||
if (resource == NULL) {
|
if (resource == NULL)
|
||||||
wl_client_post_no_memory(client);
|
{
|
||||||
return;
|
wl_client_post_no_memory(client);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wl_resource_set_implementation(resource, &linux_dmabuf_implementation,
|
wl_resource_set_implementation(resource, &linux_dmabuf_implementation,
|
||||||
compositor, NULL);
|
compositor, NULL);
|
||||||
|
|
||||||
if (version < ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION)
|
if (version < ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION)
|
||||||
return;
|
return;
|
||||||
/*
|
|
||||||
* Use EGL_EXT_image_dma_buf_import_modifiers to query and advertise
|
|
||||||
* format/modifier codes.
|
|
||||||
*/
|
|
||||||
e_pixmap_dmabuf_formats_query(&formats,
|
|
||||||
&num_formats);
|
|
||||||
|
|
||||||
for (i = 0; i < num_formats; i++) {
|
/*
|
||||||
e_pixmap_dmabuf_modifiers_query(
|
* Use EGL_EXT_image_dma_buf_import_modifiers to query and advertise
|
||||||
formats[i],
|
* format/modifier codes.
|
||||||
&modifiers,
|
*/
|
||||||
&num_modifiers);
|
e_pixmap_dmabuf_formats_query(&formats, &num_formats);
|
||||||
|
|
||||||
/* send DRM_FORMAT_MOD_INVALID token when no modifiers are supported
|
for (i = 0; i < num_formats; i++)
|
||||||
* for this format */
|
{
|
||||||
if (num_modifiers == 0) {
|
e_pixmap_dmabuf_modifiers_query(formats[i], &modifiers, &num_modifiers);
|
||||||
num_modifiers = 1;
|
|
||||||
modifiers = &modifier_invalid;
|
/* send DRM_FORMAT_MOD_INVALID token when no modifiers are supported
|
||||||
}
|
* for this format */
|
||||||
for (j = 0; j < num_modifiers; j++) {
|
if (num_modifiers == 0)
|
||||||
if (version >= ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION) {
|
{
|
||||||
uint32_t modifier_lo = modifiers[j] & 0xFFFFFFFF;
|
num_modifiers = 1;
|
||||||
uint32_t modifier_hi = modifiers[j] >> 32;
|
modifiers = &modifier_invalid;
|
||||||
zwp_linux_dmabuf_v1_send_modifier(resource, formats[i],
|
}
|
||||||
modifier_hi,
|
|
||||||
modifier_lo);
|
for (j = 0; j < num_modifiers; j++)
|
||||||
} else if (modifiers[j] == DRM_FORMAT_MOD_LINEAR ||
|
{
|
||||||
modifiers == &modifier_invalid) {
|
if (version >= ZWP_LINUX_DMABUF_V1_MODIFIER_SINCE_VERSION)
|
||||||
zwp_linux_dmabuf_v1_send_format(resource,
|
{
|
||||||
formats[i]);
|
uint32_t modifier_lo = modifiers[j] & 0xFFFFFFFF;
|
||||||
}
|
uint32_t modifier_hi = modifiers[j] >> 32;
|
||||||
}
|
|
||||||
if (modifiers != &modifier_invalid)
|
zwp_linux_dmabuf_v1_send_modifier(resource, formats[i],
|
||||||
free(modifiers);
|
modifier_hi,
|
||||||
}
|
modifier_lo);
|
||||||
free(formats);
|
}
|
||||||
|
else if (modifiers[j] == DRM_FORMAT_MOD_LINEAR ||
|
||||||
|
modifiers == &modifier_invalid)
|
||||||
|
{
|
||||||
|
zwp_linux_dmabuf_v1_send_format(resource, formats[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (modifiers != &modifier_invalid)
|
||||||
|
free(modifiers);
|
||||||
|
}
|
||||||
|
free(formats);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Advertise linux_dmabuf support
|
/** Advertise linux_dmabuf support
|
||||||
|
@ -551,12 +546,11 @@ bind_linux_dmabuf(struct wl_client *client,
|
||||||
EINTERN int
|
EINTERN int
|
||||||
linux_dmabuf_setup(struct wl_display *display)
|
linux_dmabuf_setup(struct wl_display *display)
|
||||||
{
|
{
|
||||||
if (!wl_global_create(display,
|
if (!wl_global_create(display, &zwp_linux_dmabuf_v1_interface, 3,
|
||||||
&zwp_linux_dmabuf_v1_interface, 3,
|
NULL, bind_linux_dmabuf))
|
||||||
NULL, bind_linux_dmabuf))
|
return -1;
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resolve an internal compositor error by disconnecting the client.
|
/** Resolve an internal compositor error by disconnecting the client.
|
||||||
|
@ -579,18 +573,17 @@ EINTERN void
|
||||||
linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer,
|
linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer,
|
||||||
const char *msg)
|
const char *msg)
|
||||||
{
|
{
|
||||||
struct wl_client *client;
|
struct wl_client *client;
|
||||||
struct wl_resource *display_resource;
|
struct wl_resource *display_resource;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
|
||||||
assert(buffer->buffer_resource);
|
assert(buffer->buffer_resource);
|
||||||
id = wl_resource_get_id(buffer->buffer_resource);
|
id = wl_resource_get_id(buffer->buffer_resource);
|
||||||
client = wl_resource_get_client(buffer->buffer_resource);
|
client = wl_resource_get_client(buffer->buffer_resource);
|
||||||
display_resource = wl_client_get_object(client, 1);
|
display_resource = wl_client_get_object(client, 1);
|
||||||
|
|
||||||
assert(display_resource);
|
assert(display_resource);
|
||||||
wl_resource_post_error(display_resource,
|
wl_resource_post_error(display_resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
|
||||||
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
"linux_dmabuf server error with "
|
||||||
"linux_dmabuf server error with "
|
"wl_buffer@%u: %s", id, msg);
|
||||||
"wl_buffer@%u: %s", id, msg);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue