diff options
author | Kristian Høgsberg <[email protected]> | 2013-02-02 12:26:12 -0500 |
---|---|---|
committer | Kristian Høgsberg <[email protected]> | 2013-03-18 21:15:41 -0400 |
commit | de315f76a266ce51ca0638b9ea2ec3ccfd31f03b (patch) | |
tree | 2b467ec888d24b2645bbdb0e6c0cad7204d520aa /src/egl/wayland/wayland-drm | |
parent | 2356e28452454ed3b584af9b4d28c553c2a80769 (diff) |
wayland: Add prime fd passing as a buffer sharing mechanism
Reviewed-by: Ander Conselvan de Oliveira <[email protected]>
Diffstat (limited to 'src/egl/wayland/wayland-drm')
-rw-r--r-- | src/egl/wayland/wayland-drm/wayland-drm.c | 40 | ||||
-rw-r--r-- | src/egl/wayland/wayland-drm/wayland-drm.h | 7 | ||||
-rw-r--r-- | src/egl/wayland/wayland-drm/wayland-drm.xml | 29 |
3 files changed, 67 insertions, 9 deletions
diff --git a/src/egl/wayland/wayland-drm/wayland-drm.c b/src/egl/wayland/wayland-drm/wayland-drm.c index d02aab66324..7e2073a73f3 100644 --- a/src/egl/wayland/wayland-drm/wayland-drm.c +++ b/src/egl/wayland/wayland-drm/wayland-drm.c @@ -31,6 +31,7 @@ #include <stdlib.h> #include <string.h> #include <stddef.h> +#include <unistd.h> #include <wayland-server.h> #include "wayland-drm.h" @@ -41,6 +42,7 @@ struct wl_drm { void *user_data; char *device_name; + uint32_t flags; struct wayland_drm_callbacks *callbacks; }; @@ -67,7 +69,8 @@ const static struct wl_buffer_interface drm_buffer_interface = { static void create_buffer(struct wl_client *client, struct wl_resource *resource, - uint32_t id, uint32_t name, int32_t width, int32_t height, + uint32_t id, uint32_t name, int fd, + int32_t width, int32_t height, uint32_t format, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, @@ -93,7 +96,7 @@ create_buffer(struct wl_client *client, struct wl_resource *resource, buffer->offset[2] = offset2; buffer->stride[2] = stride2; - drm->callbacks->reference_buffer(drm->user_data, name, buffer); + drm->callbacks->reference_buffer(drm->user_data, name, fd, buffer); if (buffer->driver_buffer == NULL) { wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_NAME, @@ -131,7 +134,7 @@ drm_create_buffer(struct wl_client *client, struct wl_resource *resource, } create_buffer(client, resource, id, - name, width, height, format, 0, stride, 0, 0, 0, 0); + name, -1, width, height, format, 0, stride, 0, 0, 0, 0); } static void @@ -159,11 +162,25 @@ drm_create_planar_buffer(struct wl_client *client, return; } - create_buffer(client, resource, id, name, width, height, format, + create_buffer(client, resource, id, name, -1, width, height, format, offset0, stride0, offset1, stride1, offset2, stride2); } static void +drm_create_prime_buffer(struct wl_client *client, + struct wl_resource *resource, + uint32_t id, int fd, + int32_t width, int32_t height, uint32_t format, + int32_t offset0, int32_t stride0, + int32_t offset1, int32_t stride1, + int32_t offset2, int32_t stride2) +{ + create_buffer(client, resource, id, 0, fd, width, height, format, + offset0, stride0, offset1, stride1, offset2, stride2); + close(fd); +} + +static void drm_authenticate(struct wl_client *client, struct wl_resource *resource, uint32_t id) { @@ -180,7 +197,8 @@ drm_authenticate(struct wl_client *client, const static struct wl_drm_interface drm_interface = { drm_authenticate, drm_create_buffer, - drm_create_planar_buffer + drm_create_planar_buffer, + drm_create_prime_buffer }; static void @@ -188,6 +206,7 @@ bind_drm(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wl_drm *drm = data; struct wl_resource *resource; + uint32_t capabilities; resource = wl_client_add_object(client, &wl_drm_interface, &drm_interface, id, data); @@ -204,11 +223,19 @@ bind_drm(struct wl_client *client, void *data, uint32_t version, uint32_t id) wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV12); wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV16); wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUYV); + + capabilities = 0; + if (drm->flags & WAYLAND_DRM_PRIME) + capabilities |= WL_DRM_CAPABILITY_PRIME; + + if (version >= 2) + wl_resource_post_event(resource, WL_DRM_CAPABILITIES, capabilities); } struct wl_drm * wayland_drm_init(struct wl_display *display, char *device_name, - struct wayland_drm_callbacks *callbacks, void *user_data) + struct wayland_drm_callbacks *callbacks, void *user_data, + uint32_t flags) { struct wl_drm *drm; @@ -218,6 +245,7 @@ wayland_drm_init(struct wl_display *display, char *device_name, drm->device_name = strdup(device_name); drm->callbacks = callbacks; drm->user_data = user_data; + drm->flags = flags; wl_display_add_global(display, &wl_drm_interface, drm, bind_drm); diff --git a/src/egl/wayland/wayland-drm/wayland-drm.h b/src/egl/wayland/wayland-drm/wayland-drm.h index 3e8f95173ac..335073a879c 100644 --- a/src/egl/wayland/wayland-drm/wayland-drm.h +++ b/src/egl/wayland/wayland-drm/wayland-drm.h @@ -82,15 +82,18 @@ struct wl_drm_buffer { struct wayland_drm_callbacks { int (*authenticate)(void *user_data, uint32_t id); - void (*reference_buffer)(void *user_data, uint32_t name, + void (*reference_buffer)(void *user_data, uint32_t name, int fd, struct wl_drm_buffer *buffer); void (*release_buffer)(void *user_data, struct wl_drm_buffer *buffer); }; +enum { WAYLAND_DRM_PRIME = 0x01 }; + struct wl_drm * wayland_drm_init(struct wl_display *display, char *device_name, - struct wayland_drm_callbacks *callbacks, void *user_data); + struct wayland_drm_callbacks *callbacks, void *user_data, + uint32_t flags); void wayland_drm_uninit(struct wl_drm *drm); diff --git a/src/egl/wayland/wayland-drm/wayland-drm.xml b/src/egl/wayland/wayland-drm/wayland-drm.xml index 265d4f892af..8a3ad69b21d 100644 --- a/src/egl/wayland/wayland-drm/wayland-drm.xml +++ b/src/egl/wayland/wayland-drm/wayland-drm.xml @@ -29,7 +29,7 @@ <!-- drm support. This object is created by the server and published using the display's global event. --> - <interface name="wl_drm" version="1"> + <interface name="wl_drm" version="2"> <enum name="error"> <entry name="authenticate_fail" value="0"/> <entry name="invalid_format" value="1"/> @@ -135,6 +135,22 @@ <arg name="stride2" type="int"/> </request> + <!-- Create a wayland buffer for the prime fd. Use for regular and planar + buffers. Pass 0 for offset and stride for unused planes. --> + <request name="create_prime_buffer" since="2"> + <arg name="id" type="new_id" interface="wl_buffer"/> + <arg name="name" type="fd"/> + <arg name="width" type="int"/> + <arg name="height" type="int"/> + <arg name="format" type="uint"/> + <arg name="offset0" type="int"/> + <arg name="stride0" type="int"/> + <arg name="offset1" type="int"/> + <arg name="stride1" type="int"/> + <arg name="offset2" type="int"/> + <arg name="stride2" type="int"/> + </request> + <!-- Notification of the path of the drm device which is used by the server. The client should use this device for creating local buffers. Only buffers created from this device should @@ -150,6 +166,17 @@ <!-- Raised if the authenticate request succeeded --> <event name="authenticated"/> + + <enum name="capability" since="2"> + <description summary="wl_drm capability bitmask"> + Bitmask of capabilities. + </description> + <entry name="prime" value="1" summary="wl_drm prime available"/> + </enum> + + <event name="capabilities"> + <arg name="value" type="uint"/> + </event> </interface> </protocol> |