derekf pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=2d1802375d1ae08a353cfb32fa151adf94b66b2c

commit 2d1802375d1ae08a353cfb32fa151adf94b66b2c
Author: Derek Foreman <der...@osg.samsung.com>
Date:   Tue May 17 11:40:42 2016 -0500

    Add DMABuf support for wayland
    
    This adds compositor handling of DMABuf buffers.  DMAbuf capabilities
    are advertised for the drm back-ends, and DMAbuf buffers are handled
    as native surfaces.
---
 src/bin/Makefile.mk                                |   4 +
 src/bin/e_comp_wl.c                                |   8 +
 src/bin/e_comp_wl.h                                |   1 +
 src/bin/e_comp_wl_dmabuf.c                         | 503 +++++++++++++++++++++
 src/bin/e_comp_wl_dmabuf.h                         |  92 ++++
 src/bin/e_comp_wl_extensions.c                     |  18 +
 src/bin/e_includes.h                               |   1 +
 src/bin/e_pixmap.c                                 |  60 ++-
 src/bin/e_pixmap.h                                 |   2 +
 .../generated/linux-dmabuf-unstable-v1-protocol.c  |  75 +++
 .../linux-dmabuf-unstable-v1-server-protocol.h     | 448 ++++++++++++++++++
 11 files changed, 1207 insertions(+), 5 deletions(-)

diff --git a/src/bin/Makefile.mk b/src/bin/Makefile.mk
index c6930d3..5fdcb27 100644
--- a/src/bin/Makefile.mk
+++ b/src/bin/Makefile.mk
@@ -222,6 +222,7 @@ src/bin/e_zone.h
 if HAVE_WAYLAND
 ENLIGHTENMENTHEADERS += \
 src/bin/e_comp_wl_data.h \
+src/bin/e_comp_wl_dmabuf.h \
 src/bin/e_comp_wl_input.h \
 src/bin/e_comp_wl.h
 endif
@@ -393,6 +394,8 @@ endif
 
 if HAVE_WAYLAND
 enlightenment_src += \
+src/bin/generated/linux-dmabuf-unstable-v1-server-protocol.h \
+src/bin/generated/linux-dmabuf-unstable-v1-protocol.c \
 src/bin/generated/www-protocol.c \
 src/bin/generated/www-protocol.h \
 src/bin/generated/session-recovery.c \
@@ -401,6 +404,7 @@ src/bin/generated/e_comp_wl_screenshooter_server.c \
 src/bin/generated/e_comp_wl_screenshooter_server.h \
 src/bin/e_comp_wl_data.c \
 src/bin/e_comp_wl_input.c \
+src/bin/e_comp_wl_dmabuf.c \
 src/bin/e_comp_wl.c \
 src/bin/e_comp_wl_extensions.c
 endif
diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index 53a107f..d58e1e2 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -2767,6 +2767,7 @@ e_comp_wl_buffer_get(struct wl_resource *resource)
    E_Comp_Wl_Buffer *buffer;
    struct wl_listener *listener;
    struct wl_shm_buffer *shmbuff;
+   struct linux_dmabuf_buffer *dmabuf;
 
    listener =
      wl_resource_get_destroy_listener(resource, _e_comp_wl_buffer_cb_destroy);
@@ -2775,17 +2776,24 @@ e_comp_wl_buffer_get(struct wl_resource *resource)
 
    if (!(buffer = E_NEW(E_Comp_Wl_Buffer, 1))) return NULL;
    shmbuff = wl_shm_buffer_get(resource);
+   dmabuf = linux_dmabuf_buffer_get(resource);
    if (shmbuff)
      {
         buffer->w = wl_shm_buffer_get_width(shmbuff);
         buffer->h = wl_shm_buffer_get_height(shmbuff);
      }
+   else if (dmabuf)
+     {
+        buffer->w = dmabuf->attributes.width;
+        buffer->h = dmabuf->attributes.height;
+     }
    else if (e_comp->gl)
      {
         e_comp_wl->wl.glapi->evasglQueryWaylandBuffer(e_comp_wl->wl.gl, 
resource, EGL_WIDTH, &buffer->w);
         e_comp_wl->wl.glapi->evasglQueryWaylandBuffer(e_comp_wl->wl.gl, 
resource, EGL_HEIGHT, &buffer->h);
      }
    buffer->shm_buffer = shmbuff;
+   buffer->dmabuf_buffer = dmabuf;
 
    buffer->resource = resource;
    wl_signal_init(&buffer->destroy_signal);
diff --git a/src/bin/e_comp_wl.h b/src/bin/e_comp_wl.h
index 7a7f29a..7bb3f74 100644
--- a/src/bin/e_comp_wl.h
+++ b/src/bin/e_comp_wl.h
@@ -58,6 +58,7 @@ struct _E_Comp_Wl_Buffer
    struct wl_listener deferred_destroy_listener;
    struct wl_shm_buffer *shm_buffer;
    struct wl_shm_pool *pool;
+   struct linux_dmabuf_buffer *dmabuf_buffer;
    E_Pixmap *discarding_pixmap;
    int32_t w, h;
    uint32_t busy;
diff --git a/src/bin/e_comp_wl_dmabuf.c b/src/bin/e_comp_wl_dmabuf.c
new file mode 100644
index 0000000..ae0581a
--- /dev/null
+++ b/src/bin/e_comp_wl_dmabuf.c
@@ -0,0 +1,503 @@
+/* Shamelessly stolen from weston and modified, original license boiler plate
+ * follows.
+ */
+
+/*
+ * Copyright © 2014, 2015 Collabora, Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#define E_COMP_WL
+#include "e.h"
+
+#include <sys/mman.h>
+
+#include <assert.h>
+
+#include "linux-dmabuf-unstable-v1-server-protocol.h"
+
+static void
+linux_dmabuf_buffer_destroy(struct linux_dmabuf_buffer *buffer)
+{
+       int i;
+
+       for (i = 0; i < buffer->attributes.n_planes; i++) {
+               close(buffer->attributes.fd[i]);
+               buffer->attributes.fd[i] = -1;
+       }
+
+       buffer->attributes.n_planes = 0;
+
+       free(buffer);
+}
+
+static void
+destroy_params(struct wl_resource *params_resource)
+{
+       struct linux_dmabuf_buffer *buffer;
+
+       buffer = wl_resource_get_user_data(params_resource);
+
+       if (!buffer)
+               return;
+
+       linux_dmabuf_buffer_destroy(buffer);
+}
+
+static void
+params_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+       wl_resource_destroy(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)
+{
+       struct linux_dmabuf_buffer *buffer;
+
+       buffer = wl_resource_get_user_data(params_resource);
+       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");
+               close(name_fd);
+               return;
+       }
+
+       assert(buffer->params_resource == params_resource);
+       assert(!buffer->buffer_resource);
+
+       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);
+               close(name_fd);
+               return;
+       }
+
+       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",
+                       plane_idx);
+               close(name_fd);
+               return;
+       }
+
+       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
+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 = {
+       linux_dmabuf_wl_buffer_destroy
+};
+
+static void
+destroy_linux_dmabuf_wl_buffer(struct wl_resource *resource)
+{
+       struct linux_dmabuf_buffer *buffer;
+
+       buffer = wl_resource_get_user_data(resource);
+       assert(buffer->buffer_resource == resource);
+       assert(!buffer->params_resource);
+
+       if (buffer->user_data_destroy_func)
+               buffer->user_data_destroy_func(buffer);
+
+       linux_dmabuf_buffer_destroy(buffer);
+}
+
+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)
+{
+       struct linux_dmabuf_buffer *buffer;
+       int i;
+       void *lala;
+
+       buffer = wl_resource_get_user_data(params_resource);
+
+       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");
+               return;
+       }
+
+       assert(buffer->params_resource == params_resource);
+       assert(!buffer->buffer_resource);
+
+       /* Switch the linux_dmabuf_buffer object from params resource to
+        * eventually wl_buffer resource.
+        */
+       wl_resource_set_user_data(buffer->params_resource, NULL);
+       buffer->params_resource = NULL;
+
+       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");
+               goto err_out;
+       }
+
+       /* 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) {
+                       wl_resource_post_error(params_resource,
+                               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.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,
+                       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++) {
+               off_t size;
+
+               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);
+                       goto err_out;
+               }
+
+               if (i == 0 &&
+                  (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);
+                       goto err_out;
+               }
+
+               /* 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 (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->attributes.offset[i], i);
+                       goto err_out;
+               }
+
+               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->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->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);
+                       goto err_out;
+               }
+       }
+
+       /* XXX: Some additional sanity checks could be done with respect
+        * to the fourcc format. A centralized collection (kernel or
+        * libdrm) would be useful to avoid code duplication for these
+        * checks (e.g. drm_format_num_planes).
+        */
+
+       if (!e_pixmap_dmabuf_test(buffer))
+               goto err_failed;
+
+       buffer->buffer_resource = wl_resource_create(client,
+                                                    &wl_buffer_interface,
+                                                    1, 0);
+       if (!buffer->buffer_resource) {
+               wl_resource_post_no_memory(params_resource);
+               goto err_buffer;
+       }
+
+       wl_resource_set_implementation(buffer->buffer_resource,
+                                      &linux_dmabuf_buffer_implementation,
+                                      buffer, destroy_linux_dmabuf_wl_buffer);
+
+       zwp_linux_buffer_params_v1_send_created(params_resource,
+                                               buffer->buffer_resource);
+
+       return;
+
+err_buffer:
+       if (buffer->user_data_destroy_func)
+               buffer->user_data_destroy_func(buffer);
+
+err_failed:
+       zwp_linux_buffer_params_v1_send_failed(params_resource);
+
+err_out:
+       linux_dmabuf_buffer_destroy(buffer);
+}
+
+static const struct zwp_linux_buffer_params_v1_interface
+zwp_linux_buffer_params_implementation = {
+       params_destroy,
+       params_add,
+       params_create
+};
+
+static void
+linux_dmabuf_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+       wl_resource_destroy(resource);
+}
+
+static void
+linux_dmabuf_create_params(struct wl_client *client,
+                          struct wl_resource *linux_dmabuf_resource,
+                          uint32_t params_id)
+{
+       struct weston_compositor *compositor;
+       struct linux_dmabuf_buffer *buffer;
+       uint32_t version;
+       int i;
+
+       version = wl_resource_get_version(linux_dmabuf_resource);
+       compositor = wl_resource_get_user_data(linux_dmabuf_resource);
+
+       buffer = calloc(1, sizeof *buffer);
+       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,
+                                  version, params_id);
+       if (!buffer->params_resource)
+               goto err_dealloc;
+
+       wl_resource_set_implementation(buffer->params_resource,
+                                      &zwp_linux_buffer_params_implementation,
+                                      buffer, destroy_params);
+
+       return;
+
+err_dealloc:
+       free(buffer);
+
+err_out:
+       wl_resource_post_no_memory(linux_dmabuf_resource);
+}
+
+/** Get the linux_dmabuf_buffer from a wl_buffer resource
+ *
+ * If the given wl_buffer resource was created through the linux_dmabuf
+ * protocol interface, returns the linux_dmabuf_buffer object. This can
+ * be used as a type check for a wl_buffer.
+ *
+ * \param resource A wl_buffer resource.
+ * \return The linux_dmabuf_buffer if it exists, or NULL otherwise.
+ */
+EINTERN struct linux_dmabuf_buffer *
+linux_dmabuf_buffer_get(struct wl_resource *resource)
+{
+       struct linux_dmabuf_buffer *buffer;
+
+       if (!resource)
+               return NULL;
+
+       if (!wl_resource_instance_of(resource, &wl_buffer_interface,
+                                    &linux_dmabuf_buffer_implementation))
+               return NULL;
+
+       buffer = wl_resource_get_user_data(resource);
+       assert(buffer);
+       assert(!buffer->params_resource);
+       assert(buffer->buffer_resource == resource);
+
+       return buffer;
+}
+
+/** Set renderer-private data
+ *
+ * Set the user data for the linux_dmabuf_buffer. It is invalid to overwrite
+ * a non-NULL user data with a new non-NULL pointer. This is meant to
+ * protect against renderers fighting over linux_dmabuf_buffer user data
+ * ownership.
+ *
+ * The renderer-private data is usually set from the
+ * weston_renderer::import_dmabuf hook.
+ *
+ * \param buffer The linux_dmabuf_buffer object to set for.
+ * \param data The new renderer-private data pointer.
+ * \param func Destructor function to be called for the renderer-private
+ *             data when the linux_dmabuf_buffer gets destroyed.
+ *
+ * \sa weston_compositor_import_dmabuf
+ */
+EINTERN void
+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);
+
+       buffer->user_data = data;
+       buffer->user_data_destroy_func = func;
+}
+
+/** Get renderer-private data
+ *
+ * Get the user data from the linux_dmabuf_buffer.
+ *
+ * \param buffer The linux_dmabuf_buffer to query.
+ * \return Renderer-private data pointer.
+ *
+ * \sa linux_dmabuf_buffer_set_user_data
+ */
+EINTERN void *
+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 
= {
+       linux_dmabuf_destroy,
+       linux_dmabuf_create_params
+};
+
+static void
+bind_linux_dmabuf(struct wl_client *client,
+                 void *data, uint32_t version, uint32_t id)
+{
+       struct weston_compositor *compositor = data;
+       struct wl_resource *resource;
+
+       resource = wl_resource_create(client, &zwp_linux_dmabuf_v1_interface,
+                                     version, id);
+       if (resource == NULL) {
+               wl_client_post_no_memory(client);
+               return;
+       }
+
+       wl_resource_set_implementation(resource, &linux_dmabuf_implementation,
+                                      compositor, NULL);
+
+       /* EGL_EXT_image_dma_buf_import does not provide a way to query the
+        * supported pixel formats. */
+       /* XXX: send formats */
+}
+
+/** Advertise linux_dmabuf support
+ *
+ * Calling this initializes the zwp_linux_dmabuf protocol support, so that
+ * the interface will be advertised to clients. Essentially it creates a
+ * global. Do not call this function multiple times in the compositor's
+ * lifetime. There is no way to deinit explicitly, globals will be reaped
+ * when the wl_display gets destroyed.
+ *
+ * \param compositor The compositor to init for.
+ * \return Zero on success, -1 on failure.
+ */
+EINTERN int
+linux_dmabuf_setup(struct wl_display *display)
+{
+       if (!wl_global_create(display,
+                             &zwp_linux_dmabuf_v1_interface, 1,
+                             NULL, bind_linux_dmabuf))
+               return -1;
+
+       return 0;
+}
+
+/** Resolve an internal compositor error by disconnecting the client.
+ *
+ * This function is used in cases when the dmabuf-based wl_buffer
+ * turns out unusable and there is no fallback path. This is used by
+ * renderers which are the fallback path in the first place.
+ *
+ * It is possible the fault is caused by a compositor bug, the underlying
+ * graphics stack bug or normal behaviour, or perhaps a client mistake.
+ * In any case, the options are to either composite garbage or nothing,
+ * or disconnect the client. This is a helper function for the latter.
+ *
+ * The error is sent as a INVALID_OBJECT error on the client's wl_display.
+ *
+ * \param buffer The linux_dmabuf_buffer that is unusable.
+ * \param msg A custom error message attached to the protocol error.
+ */
+EINTERN void
+linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer,
+                                     const char *msg)
+{
+       struct wl_client *client;
+       struct wl_resource *display_resource;
+       uint32_t id;
+
+       assert(buffer->buffer_resource);
+       id = wl_resource_get_id(buffer->buffer_resource);
+       client = wl_resource_get_client(buffer->buffer_resource);
+       display_resource = wl_client_get_object(client, 1);
+
+       assert(display_resource);
+       wl_resource_post_error(display_resource,
+                              WL_DISPLAY_ERROR_INVALID_OBJECT,
+                              "linux_dmabuf server error with "
+                              "wl_buffer@%u: %s", id, msg);
+}
diff --git a/src/bin/e_comp_wl_dmabuf.h b/src/bin/e_comp_wl_dmabuf.h
new file mode 100644
index 0000000..1299724
--- /dev/null
+++ b/src/bin/e_comp_wl_dmabuf.h
@@ -0,0 +1,92 @@
+/* Shamelessly stolen from weston and modified, original license boiler plate
+ * follows.
+ */
+/*
+ * Copyright © 2014, 2015 Collabora, Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef WESTON_LINUX_DMABUF_H
+#define WESTON_LINUX_DMABUF_H
+
+#include <stdint.h>
+
+#define MAX_DMABUF_PLANES 4
+
+struct linux_dmabuf_buffer;
+typedef void (*dmabuf_user_data_destroy_func)(
+                       struct linux_dmabuf_buffer *buffer);
+
+struct dmabuf_attributes {
+        int version;
+       int32_t width;
+       int32_t height;
+       uint32_t format;
+       uint32_t flags; /* enum zlinux_buffer_params_flags */
+       int n_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;
+
+       /* XXX:
+        *
+        * Add backend private data. This would be for the backend
+        * to do all additional imports it might ever use in advance.
+        * The basic principle, even if not implemented in drivers today,
+        * is that dmabufs are first attached, but the actual allocation
+        * is deferred to first use. This would allow the exporter and all
+        * attachers to agree on how to allocate.
+        *
+        * The DRM backend would use this to create drmFBs for each
+        * dmabuf_buffer, just in case at some point it would become
+        * feasible to scan it out directly. This would improve the
+        * possibilities to successfully scan out, avoiding compositing.
+        */
+};
+
+int
+linux_dmabuf_setup(struct wl_display *display);
+
+struct linux_dmabuf_buffer *
+linux_dmabuf_buffer_get(struct wl_resource *resource);
+
+void
+linux_dmabuf_buffer_set_user_data(struct linux_dmabuf_buffer *buffer,
+                                 void *data,
+                                 dmabuf_user_data_destroy_func func);
+void *
+linux_dmabuf_buffer_get_user_data(struct linux_dmabuf_buffer *buffer);
+
+void
+linux_dmabuf_buffer_send_server_error(struct linux_dmabuf_buffer *buffer,
+                                     const char *msg);
+
+#endif /* WESTON_LINUX_DMABUF_H */
diff --git a/src/bin/e_comp_wl_extensions.c b/src/bin/e_comp_wl_extensions.c
index 4849682..3e1292c 100644
--- a/src/bin/e_comp_wl_extensions.c
+++ b/src/bin/e_comp_wl_extensions.c
@@ -253,6 +253,22 @@ GLOBAL_BIND_CB(www, www_interface)
         } \
    } while (0)
 
+static Eina_Bool
+_dmabuf_add(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
+{
+   Ecore_Wl2_Event_Sync_Done *ev;
+   int w = 0, h = 0;
+
+   ev = event;
+   if (ev->display != e_comp_wl->wl.client_disp)
+     return ECORE_CALLBACK_PASS_ON;
+
+   /* Proxy not supported yet */
+   if (!(e_comp_wl->dmabuf_disable || e_comp_wl->dmabuf_proxy))
+     linux_dmabuf_setup(e_comp_wl->wl.disp);
+
+   return ECORE_CALLBACK_PASS_ON;
+}
 
 EINTERN Eina_Bool
 e_comp_wl_extensions_init(void)
@@ -262,6 +278,8 @@ e_comp_wl_extensions_init(void)
    GLOBAL_CREATE_OR_RETURN(screenshooter, screenshooter_interface);
    GLOBAL_CREATE_OR_RETURN(www, www_interface);
 
+   ecore_event_handler_add(ECORE_WL2_EVENT_SYNC_DONE, _dmabuf_add, NULL);
+
    e_client_hook_add(E_CLIENT_HOOK_MOVE_BEGIN, 
_e_comp_wl_extensions_client_move_begin, NULL);
    e_client_hook_add(E_CLIENT_HOOK_MOVE_END, 
_e_comp_wl_extensions_client_move_end, NULL);
 
diff --git a/src/bin/e_includes.h b/src/bin/e_includes.h
index cfc6f53..5e4caca 100644
--- a/src/bin/e_includes.h
+++ b/src/bin/e_includes.h
@@ -156,5 +156,6 @@
 #ifdef HAVE_WAYLAND
 # include "e_comp_wl.h"
 # include "e_comp_wl_data.h"
+# include "e_comp_wl_dmabuf.h"
 # include "e_comp_wl_input.h"
 #endif
diff --git a/src/bin/e_pixmap.c b/src/bin/e_pixmap.c
index 0a77df0..126c016 100644
--- a/src/bin/e_pixmap.c
+++ b/src/bin/e_pixmap.c
@@ -8,11 +8,16 @@
 # ifndef EGL_TEXTURE_RGBA
 #  define EGL_TEXTURE_RGBA             0x305E
 # endif
+# ifndef DRM_FORMAT_ARGB8888
+#  define DRM_FORMAT_ARGB8888           0x34325241
+#  define DRM_FORMAT_XRGB8888           0x34325258
+# endif
 #endif
 #ifndef HAVE_WAYLAND_ONLY
 # include "e_comp_x.h"
 #endif
 
+#include <sys/mman.h>
 #include <uuid.h>
 
 static Eina_Hash *pixmaps[2] = {NULL};
@@ -42,6 +47,7 @@ struct _E_Pixmap
 
 #ifdef HAVE_WAYLAND
    E_Comp_Wl_Buffer *buffer;
+   E_Comp_Wl_Buffer *native_buffer;
    E_Comp_Wl_Buffer *held_buffer;
    struct wl_listener buffer_destroy_listener;
    struct wl_listener held_buffer_destroy_listener;
@@ -500,6 +506,7 @@ e_pixmap_refresh(E_Pixmap *cp)
         {
            E_Comp_Wl_Buffer *buffer = cp->buffer;
            struct wl_shm_buffer *shm_buffer;
+           struct linux_dmabuf_buffer *dmabuf_buffer;
            int format;
 
            cp->w = cp->h = 0;
@@ -513,10 +520,14 @@ e_pixmap_refresh(E_Pixmap *cp)
 
            if (shm_buffer)
              format = wl_shm_buffer_get_format(shm_buffer);
+           else if (buffer->dmabuf_buffer)
+             format = buffer->dmabuf_buffer->attributes.format;
            else
              e_comp_wl->wl.glapi->evasglQueryWaylandBuffer(e_comp_wl->wl.gl, 
buffer->resource, EGL_TEXTURE_FORMAT, &format);
+
            switch (format)
              {
+              case DRM_FORMAT_ARGB8888:
               case WL_SHM_FORMAT_ARGB8888:
               case EGL_TEXTURE_RGBA:
                 cp->image_argb = EINA_TRUE;
@@ -705,10 +716,27 @@ e_pixmap_native_surface_init(E_Pixmap *cp, 
Evas_Native_Surface *ns)
       case E_PIXMAP_TYPE_WL:
 #ifdef HAVE_WAYLAND
         if (!cp->buffer) return EINA_FALSE;
-        ns->type = EVAS_NATIVE_SURFACE_WL;
-        ns->version = EVAS_NATIVE_SURFACE_VERSION;
-        ns->data.wl.legacy_buffer = cp->buffer->resource;
-        ret = !cp->buffer->shm_buffer;
+        if (cp->buffer->dmabuf_buffer)
+          {
+             struct dmabuf_attributes *a;
+
+             a = &cp->buffer->dmabuf_buffer->attributes;
+             ns->type = EVAS_NATIVE_SURFACE_WL_DMABUF;
+             ns->version = EVAS_NATIVE_SURFACE_VERSION;
+
+             ns->data.wl_dmabuf.attr = &cp->buffer->dmabuf_buffer->attributes;
+             ns->data.wl_dmabuf.resource = cp->buffer->resource;
+             cp->native_buffer = cp->buffer;
+             ret = EINA_TRUE;
+          }
+        else if (!cp->buffer->shm_buffer)
+          {
+             ns->type = EVAS_NATIVE_SURFACE_WL;
+             ns->version = EVAS_NATIVE_SURFACE_VERSION;
+             ns->data.wl.legacy_buffer = cp->buffer->resource;
+             ret = EINA_TRUE;
+          }
+        else ret = EINA_FALSE;
 #endif
         break;
       default:
@@ -852,7 +880,7 @@ e_pixmap_image_exists(const E_Pixmap *cp)
      return !!cp->image;
 #endif
 #ifdef HAVE_WAYLAND
-   return (!!cp->data) || (e_comp->gl && (!cp->buffer->shm_buffer));
+   return (!!cp->data) || (e_comp->gl && (!cp->buffer->shm_buffer)) || 
cp->buffer->dmabuf_buffer;
 #endif
 
    return EINA_FALSE;
@@ -1018,3 +1046,25 @@ e_pixmap_alias(E_Pixmap *cp, E_Pixmap_Type type, ...)
      }
    va_end(l);
 }
+
+E_API Eina_Bool
+e_pixmap_dmabuf_test(struct linux_dmabuf_buffer *dmabuf)
+{
+   int size;
+   void *data;
+
+   if (e_comp->gl) return EINA_TRUE;
+
+   /* TODO: Software rendering for multi-plane formats */
+   if (dmabuf->attributes.n_planes != 1) return EINA_FALSE;
+   if (dmabuf->attributes.format != DRM_FORMAT_ARGB8888 &&
+       dmabuf->attributes.format != DRM_FORMAT_XRGB8888) return EINA_FALSE;
+
+   /* This is only legit for ARGB8888 */
+   size = dmabuf->attributes.height * dmabuf->attributes.stride[0];
+   data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, 
dmabuf->attributes.fd[0], 0);
+   if (data == MAP_FAILED) return EINA_FALSE;
+   munmap(data, size);
+
+   return EINA_TRUE;
+}
diff --git a/src/bin/e_pixmap.h b/src/bin/e_pixmap.h
index cdd1f18..1a6fb02 100644
--- a/src/bin/e_pixmap.h
+++ b/src/bin/e_pixmap.h
@@ -53,6 +53,8 @@ E_API void e_pixmap_image_opaque_get(E_Pixmap *cp, int *x, 
int *y, int *w, int *
 
 E_API void e_pixmap_alias(E_Pixmap *cp, E_Pixmap_Type type, ...);
 
+E_API Eina_Bool e_pixmap_dmabuf_test(struct linux_dmabuf_buffer *);
+
 static inline Eina_Bool
 e_pixmap_is_x(const E_Pixmap *cp)
 {
diff --git a/src/bin/generated/linux-dmabuf-unstable-v1-protocol.c 
b/src/bin/generated/linux-dmabuf-unstable-v1-protocol.c
new file mode 100644
index 0000000..a4c929a
--- /dev/null
+++ b/src/bin/generated/linux-dmabuf-unstable-v1-protocol.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright © 2014, 2015 Collabora, Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this
+ * software and its documentation for any purpose is hereby granted
+ * without fee, provided that the above copyright notice appear in
+ * all copies and that both that copyright notice and this permission
+ * notice appear in supporting documentation, and that the name of
+ * the copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+#include "wayland-util.h"
+
+extern const struct wl_interface wl_buffer_interface;
+extern const struct wl_interface zwp_linux_buffer_params_v1_interface;
+
+static const struct wl_interface *types[] = {
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       &zwp_linux_buffer_params_v1_interface,
+       &wl_buffer_interface,
+};
+
+static const struct wl_message zwp_linux_dmabuf_v1_requests[] = {
+       { "destroy", "", types + 0 },
+       { "create_params", "n", types + 6 },
+};
+
+static const struct wl_message zwp_linux_dmabuf_v1_events[] = {
+       { "format", "u", types + 0 },
+};
+
+WL_EXPORT const struct wl_interface zwp_linux_dmabuf_v1_interface = {
+       "zwp_linux_dmabuf_v1", 1,
+       2, zwp_linux_dmabuf_v1_requests,
+       1, zwp_linux_dmabuf_v1_events,
+};
+
+static const struct wl_message zwp_linux_buffer_params_v1_requests[] = {
+       { "destroy", "", types + 0 },
+       { "add", "huuuuu", types + 0 },
+       { "create", "iiuu", types + 0 },
+};
+
+static const struct wl_message zwp_linux_buffer_params_v1_events[] = {
+       { "created", "n", types + 7 },
+       { "failed", "", types + 0 },
+};
+
+WL_EXPORT const struct wl_interface zwp_linux_buffer_params_v1_interface = {
+       "zwp_linux_buffer_params_v1", 1,
+       3, zwp_linux_buffer_params_v1_requests,
+       2, zwp_linux_buffer_params_v1_events,
+};
+
diff --git a/src/bin/generated/linux-dmabuf-unstable-v1-server-protocol.h 
b/src/bin/generated/linux-dmabuf-unstable-v1-server-protocol.h
new file mode 100644
index 0000000..ce1b93d
--- /dev/null
+++ b/src/bin/generated/linux-dmabuf-unstable-v1-server-protocol.h
@@ -0,0 +1,448 @@
+#ifndef LINUX_DMABUF_UNSTABLE_V1_SERVER_PROTOCOL_H
+#define LINUX_DMABUF_UNSTABLE_V1_SERVER_PROTOCOL_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <stddef.h>
+#include "wayland-server.h"
+
+struct wl_client;
+struct wl_resource;
+
+/**
+ * @page page_linux_dmabuf_unstable_v1 The linux_dmabuf_unstable_v1 protocol
+ * @section page_ifaces_linux_dmabuf_unstable_v1 Interfaces
+ * - @subpage page_iface_zwp_linux_dmabuf_v1 - factory for creating 
dmabuf-based wl_buffers
+ * - @subpage page_iface_zwp_linux_buffer_params_v1 - parameters for creating 
a dmabuf-based wl_buffer
+ * @section page_copyright_linux_dmabuf_unstable_v1 Copyright
+ * <pre>
+ *
+ * Copyright © 2014, 2015 Collabora, Ltd.
+ *
+ * Permission to use, copy, modify, distribute, and sell this
+ * software and its documentation for any purpose is hereby granted
+ * without fee, provided that the above copyright notice appear in
+ * all copies and that both that copyright notice and this permission
+ * notice appear in supporting documentation, and that the name of
+ * the copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ * </pre>
+ */
+struct wl_buffer;
+struct zwp_linux_buffer_params_v1;
+struct zwp_linux_dmabuf_v1;
+
+/**
+ * @page page_iface_zwp_linux_dmabuf_v1 zwp_linux_dmabuf_v1
+ * @section page_iface_zwp_linux_dmabuf_v1_desc Description
+ *
+ * Following the interfaces from:
+ * 
https://www.khronos.org/registry/egl/extensions/EXT/EGL_EXT_image_dma_buf_import.txt
+ * and the Linux DRM sub-system's AddFb2 ioctl.
+ *
+ * This interface offers a way to create generic dmabuf-based
+ * wl_buffers. Immediately after a client binds to this interface,
+ * the set of supported formats is sent with 'format' events.
+ *
+ * The following are required from clients:
+ *
+ * - Clients must ensure that either all data in the dma-buf is
+ * coherent for all subsequent read access or that coherency is
+ * correctly handled by the underlying kernel-side dma-buf
+ * implementation.
+ *
+ * - Don't make any more attachments after sending the buffer to the
+ * compositor. Making more attachments later increases the risk of
+ * the compositor not being able to use (re-import) an existing
+ * dmabuf-based wl_buffer.
+ *
+ * The underlying graphics stack must ensure the following:
+ *
+ * - The dmabuf file descriptors relayed to the server will stay valid
+ * for the whole lifetime of the wl_buffer. This means the server may
+ * at any time use those fds to import the dmabuf into any kernel
+ * sub-system that might accept it.
+ *
+ * To create a wl_buffer from one or more dmabufs, a client creates a
+ * zwp_linux_dmabuf_params_v1 object with zwp_linux_dmabuf_v1.create_params
+ * request. All planes required by the intended format are added with
+ * the 'add' request. Finally, 'create' request is issued. The server
+ * will reply with either 'created' event which provides the final
+ * wl_buffer or 'failed' event saying that it cannot use the dmabufs
+ * provided.
+ *
+ * Warning! The protocol described in this file is experimental and
+ * backward incompatible changes may be made. Backward compatible changes
+ * may be added together with the corresponding interface version bump.
+ * Backward incompatible changes are done by bumping the version number in
+ * the protocol and interface names and resetting the interface version.
+ * Once the protocol is to be declared stable, the 'z' prefix and the
+ * version number in the protocol and interface names are removed and the
+ * interface version number is reset.
+ * @section page_iface_zwp_linux_dmabuf_v1_api API
+ * See @ref iface_zwp_linux_dmabuf_v1.
+ */
+/**
+ * @defgroup iface_zwp_linux_dmabuf_v1 The zwp_linux_dmabuf_v1 interface
+ *
+ * Following the interfaces from:
+ * 
https://www.khronos.org/registry/egl/extensions/EXT/EGL_EXT_image_dma_buf_import.txt
+ * and the Linux DRM sub-system's AddFb2 ioctl.
+ *
+ * This interface offers a way to create generic dmabuf-based
+ * wl_buffers. Immediately after a client binds to this interface,
+ * the set of supported formats is sent with 'format' events.
+ *
+ * The following are required from clients:
+ *
+ * - Clients must ensure that either all data in the dma-buf is
+ * coherent for all subsequent read access or that coherency is
+ * correctly handled by the underlying kernel-side dma-buf
+ * implementation.
+ *
+ * - Don't make any more attachments after sending the buffer to the
+ * compositor. Making more attachments later increases the risk of
+ * the compositor not being able to use (re-import) an existing
+ * dmabuf-based wl_buffer.
+ *
+ * The underlying graphics stack must ensure the following:
+ *
+ * - The dmabuf file descriptors relayed to the server will stay valid
+ * for the whole lifetime of the wl_buffer. This means the server may
+ * at any time use those fds to import the dmabuf into any kernel
+ * sub-system that might accept it.
+ *
+ * To create a wl_buffer from one or more dmabufs, a client creates a
+ * zwp_linux_dmabuf_params_v1 object with zwp_linux_dmabuf_v1.create_params
+ * request. All planes required by the intended format are added with
+ * the 'add' request. Finally, 'create' request is issued. The server
+ * will reply with either 'created' event which provides the final
+ * wl_buffer or 'failed' event saying that it cannot use the dmabufs
+ * provided.
+ *
+ * Warning! The protocol described in this file is experimental and
+ * backward incompatible changes may be made. Backward compatible changes
+ * may be added together with the corresponding interface version bump.
+ * Backward incompatible changes are done by bumping the version number in
+ * the protocol and interface names and resetting the interface version.
+ * Once the protocol is to be declared stable, the 'z' prefix and the
+ * version number in the protocol and interface names are removed and the
+ * interface version number is reset.
+ */
+extern const struct wl_interface zwp_linux_dmabuf_v1_interface;
+/**
+ * @page page_iface_zwp_linux_buffer_params_v1 zwp_linux_buffer_params_v1
+ * @section page_iface_zwp_linux_buffer_params_v1_desc Description
+ *
+ * This temporary object is a collection of dmabufs and other
+ * parameters that together form a single logical buffer. The temporary
+ * object may eventually create one wl_buffer unless cancelled by
+ * destroying it before requesting 'create'.
+ *
+ * Single-planar formats only require one dmabuf, however
+ * multi-planar formats may require more than one dmabuf. For all
+ * formats, 'add' request must be called once per plane (even if the
+ * underlying dmabuf fd is identical).
+ *
+ * You must use consecutive plane indices ('plane_idx' argument for 'add')
+ * from zero to the number of planes used by the drm_fourcc format code.
+ * All planes required by the format must be given exactly once, but can
+ * be given in any order. Each plane index can be set only once.
+ * @section page_iface_zwp_linux_buffer_params_v1_api API
+ * See @ref iface_zwp_linux_buffer_params_v1.
+ */
+/**
+ * @defgroup iface_zwp_linux_buffer_params_v1 The zwp_linux_buffer_params_v1 
interface
+ *
+ * This temporary object is a collection of dmabufs and other
+ * parameters that together form a single logical buffer. The temporary
+ * object may eventually create one wl_buffer unless cancelled by
+ * destroying it before requesting 'create'.
+ *
+ * Single-planar formats only require one dmabuf, however
+ * multi-planar formats may require more than one dmabuf. For all
+ * formats, 'add' request must be called once per plane (even if the
+ * underlying dmabuf fd is identical).
+ *
+ * You must use consecutive plane indices ('plane_idx' argument for 'add')
+ * from zero to the number of planes used by the drm_fourcc format code.
+ * All planes required by the format must be given exactly once, but can
+ * be given in any order. Each plane index can be set only once.
+ */
+extern const struct wl_interface zwp_linux_buffer_params_v1_interface;
+
+/**
+ * @ingroup iface_zwp_linux_dmabuf_v1
+ * @struct zwp_linux_dmabuf_v1_interface
+ */
+struct zwp_linux_dmabuf_v1_interface {
+       /**
+        * unbind the factory
+        *
+        * Objects created through this interface, especially wl_buffers,
+        * will remain valid.
+        */
+       void (*destroy)(struct wl_client *client,
+                       struct wl_resource *resource);
+       /**
+        * create a temporary object for buffer parameters
+        *
+        * This temporary object is used to collect multiple dmabuf
+        * handles into a single batch to create a wl_buffer. It can only
+        * be used once and should be destroyed after an 'created' or
+        * 'failed' event has been received.
+        * @param params_id the new temporary
+        */
+       void (*create_params)(struct wl_client *client,
+                             struct wl_resource *resource,
+                             uint32_t params_id);
+};
+
+#define ZWP_LINUX_DMABUF_V1_FORMAT     0
+
+/**
+ * @ingroup iface_zwp_linux_dmabuf_v1
+ */
+#define ZWP_LINUX_DMABUF_V1_FORMAT_SINCE_VERSION       1
+
+/**
+ * @ingroup iface_zwp_linux_dmabuf_v1
+ * Sends an format event to the client owning the resource.
+* @param resource_ The client's resource
+ * @param format DRM_FORMAT code
+ */
+static inline void
+zwp_linux_dmabuf_v1_send_format(struct wl_resource *resource_, uint32_t format)
+{
+       wl_resource_post_event(resource_, ZWP_LINUX_DMABUF_V1_FORMAT, format);
+}
+
+#ifndef ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ENUM
+#define ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ENUM
+enum zwp_linux_buffer_params_v1_error {
+       /**
+        * the dmabuf_batch object has already been used to create a wl_buffer
+        */
+       ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED = 0,
+       /**
+        * plane index out of bounds
+        */
+       ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX = 1,
+       /**
+        * the plane index was already set
+        */
+       ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_SET = 2,
+       /**
+        * missing or too many planes to create a buffer
+        */
+       ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE = 3,
+       /**
+        * format not supported
+        */
+       ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT = 4,
+       /**
+        * invalid width or height
+        */
+       ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS = 5,
+       /**
+        * offset + stride * height goes out of dmabuf bounds
+        */
+       ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS = 6,
+};
+#endif /* ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ENUM */
+
+#ifndef ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_ENUM
+#define ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_ENUM
+enum zwp_linux_buffer_params_v1_flags {
+       /**
+        * contents are y-inverted
+        */
+       ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT = 1,
+       /**
+        * content is interlaced
+        */
+       ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_INTERLACED = 2,
+       /**
+        * bottom field first
+        */
+       ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_BOTTOM_FIRST = 4,
+};
+#endif /* ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_ENUM */
+
+/**
+ * @ingroup iface_zwp_linux_buffer_params_v1
+ * @struct zwp_linux_buffer_params_v1_interface
+ */
+struct zwp_linux_buffer_params_v1_interface {
+       /**
+        * delete this object, used or not
+        *
+        * Cleans up the temporary data sent to the server for
+        * dmabuf-based wl_buffer creation.
+        */
+       void (*destroy)(struct wl_client *client,
+                       struct wl_resource *resource);
+       /**
+        * add a dmabuf to the temporary set
+        *
+        * This request adds one dmabuf to the set in this
+        * zwp_linux_buffer_params_v1.
+        *
+        * The 64-bit unsigned value combined from modifier_hi and
+        * modifier_lo is the dmabuf layout modifier. DRM AddFB2 ioctl
+        * calls this the fb modifier, which is defined in drm_mode.h of
+        * Linux UAPI. This is an opaque token. Drivers use this token to
+        * express tiling, compression, etc. driver-specific modifications
+        * to the base format defined by the DRM fourcc code.
+        *
+        * This request raises the PLANE_IDX error if plane_idx is too
+        * large. The error PLANE_SET is raised if attempting to set a
+        * plane that was already set.
+        * @param fd dmabuf fd
+        * @param plane_idx plane index
+        * @param offset offset in bytes
+        * @param stride stride in bytes
+        * @param modifier_hi high 32 bits of layout modifier
+        * @param modifier_lo low 32 bits of layout modifier
+        */
+       void (*add)(struct wl_client *client,
+                   struct wl_resource *resource,
+                   int32_t fd,
+                   uint32_t plane_idx,
+                   uint32_t offset,
+                   uint32_t stride,
+                   uint32_t modifier_hi,
+                   uint32_t modifier_lo);
+       /**
+        * create a wl_buffer from the given dmabufs
+        *
+        * This asks for creation of a wl_buffer from the added dmabuf
+        * buffers. The wl_buffer is not created immediately but returned
+        * via the 'created' event if the dmabuf sharing succeeds. The
+        * sharing may fail at runtime for reasons a client cannot predict,
+        * in which case the 'failed' event is triggered.
+        *
+        * The 'format' argument is a DRM_FORMAT code, as defined by the
+        * libdrm's drm_fourcc.h. The Linux kernel's DRM sub-system is the
+        * authoritative source on how the format codes should work.
+        *
+        * The 'flags' is a bitfield of the flags defined in enum "flags".
+        * 'y_invert' means the that the image needs to be y-flipped.
+        *
+        * Flag 'interlaced' means that the frame in the buffer is not
+        * progressive as usual, but interlaced. An interlaced buffer as
+        * supported here must always contain both top and bottom fields.
+        * The top field always begins on the first pixel row. The temporal
+        * ordering between the two fields is top field first, unless
+        * 'bottom_first' is specified. It is undefined whether
+        * 'bottom_first' is ignored if 'interlaced' is not set.
+        *
+        * This protocol does not convey any information about field rate,
+        * duration, or timing, other than the relative ordering between
+        * the two fields in one buffer. A compositor may have to estimate
+        * the intended field rate from the incoming buffer rate. It is
+        * undefined whether the time of receiving wl_surface.commit with a
+        * new buffer attached, applying the wl_surface state,
+        * wl_surface.frame callback trigger, presentation, or any other
+        * point in the compositor cycle is used to measure the frame or
+        * field times. There is no support for detecting missed or late
+        * frames/fields/buffers either, and there is no support whatsoever
+        * for cooperating with interlaced compositor output.
+        *
+        * The composited image quality resulting from the use of
+        * interlaced buffers is explicitly undefined. A compositor may use
+        * elaborate hardware features or software to deinterlace and
+        * create progressive output frames from a sequence of interlaced
+        * input buffers, or it may produce substandard image quality.
+        * However, compositors that cannot guarantee reasonable image
+        * quality in all cases are recommended to just reject all
+        * interlaced buffers.
+        *
+        * Any argument errors, including non-positive width or height,
+        * mismatch between the number of planes and the format, bad
+        * format, bad offset or stride, may be indicated by fatal protocol
+        * errors: INCOMPLETE, INVALID_FORMAT, INVALID_DIMENSIONS,
+        * OUT_OF_BOUNDS.
+        *
+        * Dmabuf import errors in the server that are not obvious client
+        * bugs are returned via the 'failed' event as non-fatal. This
+        * allows attempting dmabuf sharing and falling back in the client
+        * if it fails.
+        *
+        * This request can be sent only once in the object's lifetime,
+        * after which the only legal request is destroy. This object
+        * should be destroyed after issuing 'create' request. Attempting
+        * to use this object after issuing 'create' raises ALREADY_USED
+        * protocol error.
+        *
+        * It is not mandatory to issue 'create'. If a client wants to
+        * cancel the buffer creation, it can just destroy this object.
+        * @param width base plane width in pixels
+        * @param height base plane height in pixels
+        * @param format DRM_FORMAT code
+        * @param flags see enum flags
+        */
+       void (*create)(struct wl_client *client,
+                      struct wl_resource *resource,
+                      int32_t width,
+                      int32_t height,
+                      uint32_t format,
+                      uint32_t flags);
+};
+
+#define ZWP_LINUX_BUFFER_PARAMS_V1_CREATED     0
+#define ZWP_LINUX_BUFFER_PARAMS_V1_FAILED      1
+
+/**
+ * @ingroup iface_zwp_linux_buffer_params_v1
+ */
+#define ZWP_LINUX_BUFFER_PARAMS_V1_CREATED_SINCE_VERSION       1
+/**
+ * @ingroup iface_zwp_linux_buffer_params_v1
+ */
+#define ZWP_LINUX_BUFFER_PARAMS_V1_FAILED_SINCE_VERSION        1
+
+/**
+ * @ingroup iface_zwp_linux_buffer_params_v1
+ * Sends an created event to the client owning the resource.
+* @param resource_ The client's resource
+ * @param buffer the newly created wl_buffer
+ */
+static inline void
+zwp_linux_buffer_params_v1_send_created(struct wl_resource *resource_, struct 
wl_resource *buffer)
+{
+       wl_resource_post_event(resource_, ZWP_LINUX_BUFFER_PARAMS_V1_CREATED, 
buffer);
+}
+
+/**
+ * @ingroup iface_zwp_linux_buffer_params_v1
+ * Sends an failed event to the client owning the resource.
+* @param resource_ The client's resource
+ */
+static inline void
+zwp_linux_buffer_params_v1_send_failed(struct wl_resource *resource_)
+{
+       wl_resource_post_event(resource_, ZWP_LINUX_BUFFER_PARAMS_V1_FAILED);
+}
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif

-- 


Reply via email to