From patchwork Thu Dec 5 17:36:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 22082 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f198.google.com (mail-vc0-f198.google.com [209.85.220.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7479D202E0 for ; Thu, 5 Dec 2013 17:37:09 +0000 (UTC) Received: by mail-vc0-f198.google.com with SMTP id ld13sf37492330vcb.9 for ; Thu, 05 Dec 2013 09:37:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=9bhRRg+k420Vx/qCpXQ0tMSzlM1ZPr0EGsgeRiQ4coc=; b=WaBDATsQr/r5p7e6a8Z6x+buCgW+JEpGlvxXAv2BvrXVQ9EhMKMqpgJWBTmHr94Dx3 nZJWQh2qrNrXK1lAXLwhg0O90h325mJj1oBa2rDBBy+PL+dLg9yIrqa5jGztC3t1dQqE k1TSdra4orx4huxUzsYgha6mMVRlGPcqgMU4xWE0UO8tkeZamjbtVGIJkio6ueN+vF3d b3JnYiappEXi4eOYFe8gNDJbp0PhlqfMSJXJpnc1ox+4M5lE+TgDLitAY4PjS2Siwtoj AsjVUQdorWlJF8nmqIg0UdeRCdi+Pm3FIO675hZHeA+UM2kwOJwt2rZZnRCpbfOQ0raf idDg== X-Gm-Message-State: ALoCoQnZUGr7NudhMMniRe2WekIrsoq6w6511xivKCyxTYqIFmuzrRgEyTesKAYQ5TWBNLk59CI6 X-Received: by 10.58.188.113 with SMTP id fz17mr28203315vec.26.1386265028614; Thu, 05 Dec 2013 09:37:08 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.128.200 with SMTP id nq8ls914382qeb.95.gmail; Thu, 05 Dec 2013 09:37:08 -0800 (PST) X-Received: by 10.52.111.200 with SMTP id ik8mr20447155vdb.2.1386265028487; Thu, 05 Dec 2013 09:37:08 -0800 (PST) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id f10si35130661vck.95.2013.12.05.09.37.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 05 Dec 2013 09:37:08 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id c14so14496145vea.9 for ; Thu, 05 Dec 2013 09:37:08 -0800 (PST) X-Received: by 10.52.72.100 with SMTP id c4mr1762902vdv.86.1386265028076; Thu, 05 Dec 2013 09:37:08 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp33525vcz; Thu, 5 Dec 2013 09:37:07 -0800 (PST) X-Received: by 10.15.91.3 with SMTP id r3mr82095073eez.18.1386265026753; Thu, 05 Dec 2013 09:37:06 -0800 (PST) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id l44si11713026eem.82.2013.12.05.09.37.05 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 05 Dec 2013 09:37:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1VocoG-0000DR-Ov; Thu, 05 Dec 2013 17:33:56 +0000 Received: from mail-we0-f178.google.com ([74.125.82.178]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1VocoB-0000DM-IG for linaro-mm-sig@lists.linaro.org; Thu, 05 Dec 2013 17:33:51 +0000 Received: by mail-we0-f178.google.com with SMTP id u57so11157014wes.37 for ; Thu, 05 Dec 2013 09:36:52 -0800 (PST) X-Received: by 10.194.104.66 with SMTP id gc2mr605961wjb.75.1386265012452; Thu, 05 Dec 2013 09:36:52 -0800 (PST) Received: from lmenx321.lme.st.com (lya72-2-88-175-155-153.fbx.proxad.net. [88.175.155.153]) by mx.google.com with ESMTPSA id je17sm8246740wic.4.2013.12.05.09.36.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 05 Dec 2013 09:36:52 -0800 (PST) From: benjamin.gaignard@linaro.org To: wayland-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Date: Thu, 5 Dec 2013 18:36:38 +0100 Message-Id: <1386264998-3827-1-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 Subject: [Linaro-mm-sig] =?utf-8?q?=5BPATCH=5D_Add_wl=5Fdmabuf_protocol?= X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: linaro-mm-sig-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: benjamin.gaignard@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Benjamin Gaignard It allow to use a dmabuf file descriptor in a wayland protocol. To make as generic as possible it is up to the server to call wl_dmabuf_send_format() and/or wl_dmabuf_send_capabilities() to signal it capabilities. Signed-off-by: Benjamin Gaignard --- protocol/Makefile.am | 6 +- protocol/wayland-dmabuf.xml | 134 +++++++++++++++++++++ src/Makefile.am | 12 +- src/wayland-dmabuf.c | 275 +++++++++++++++++++++++++++++++++++++++++++ src/wayland-dmabuf.h | 134 +++++++++++++++++++++ 5 files changed, 557 insertions(+), 4 deletions(-) create mode 100644 protocol/wayland-dmabuf.xml create mode 100644 src/wayland-dmabuf.c create mode 100644 src/wayland-dmabuf.h diff --git a/protocol/Makefile.am b/protocol/Makefile.am index e8b6290..8c9499f 100644 --- a/protocol/Makefile.am +++ b/protocol/Makefile.am @@ -1,4 +1,4 @@ -dist_pkgdata_DATA = wayland.xml wayland.dtd +dist_pkgdata_DATA = wayland.xml wayland-dmabuf.xml wayland.dtd if HAVE_XMLLINT .PHONY: validate @@ -6,9 +6,9 @@ if HAVE_XMLLINT .%.xml.valid: %.xml $(AM_V_GEN)$(XMLLINT) --noout --dtdvalid $(srcdir)/wayland.dtd $^ > $@ -validate: .wayland.xml.valid +validate: .wayland.xml.valid .wayland-dmabuf.xml.valid all-local: validate -CLEANFILES = .wayland.xml.valid +CLEANFILES = .wayland.xml.valid .wayland-dmabuf.xml.valid endif diff --git a/protocol/wayland-dmabuf.xml b/protocol/wayland-dmabuf.xml new file mode 100644 index 0000000..b3b7ded --- /dev/null +++ b/protocol/wayland-dmabuf.xml @@ -0,0 +1,134 @@ + + + + + Copyright © 2008-2011 Kristian Høgsberg + Copyright © 2010-2011 Intel Corporation + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that\n 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. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bitmask of capabilities. + + + + + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am index 15f44a5..b3c414c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,8 +4,11 @@ noinst_LTLIBRARIES = libwayland-util.la include_HEADERS = \ wayland-util.h \ wayland-server-protocol.h \ + wayland-dmabuf-server-protocol.h \ wayland-server.h \ + wayland-dmabuf.h \ wayland-client-protocol.h \ + wayland-dmabuf-client-protocol.h \ wayland-client.h \ wayland-egl.h \ wayland-version.h @@ -22,14 +25,17 @@ libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-util.la -lrt -lm libwayland_server_la_LDFLAGS = -version-info 1:0:1 libwayland_server_la_SOURCES = \ wayland-protocol.c \ + wayland-dmabuf-protocol.c \ wayland-server.c \ wayland-shm.c \ + wayland-dmabuf.c \ event-loop.c libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-util.la -lrt -lm libwayland_client_la_LDFLAGS = -version-info 2:0:2 libwayland_client_la_SOURCES = \ wayland-protocol.c \ + wayland-dmabuf-protocol.c \ wayland-client.c pkgconfigdir = $(libdir)/pkgconfig @@ -65,7 +71,11 @@ endif BUILT_SOURCES = \ wayland-server-protocol.h \ wayland-client-protocol.h \ - wayland-protocol.c + wayland-protocol.c \ + wayland-dmabuf-server-protocol.h \ + wayland-dmabuf-client-protocol.h \ + wayland-dmabuf-protocol.c + CLEANFILES = $(BUILT_SOURCES) DISTCLEANFILES = wayland-version.h diff --git a/src/wayland-dmabuf.c b/src/wayland-dmabuf.c new file mode 100644 index 0000000..857d743 --- /dev/null +++ b/src/wayland-dmabuf.c @@ -0,0 +1,275 @@ +/* + * Copyright © 2011 Kristian Høgsberg + * Copyright © 2011 Benjamin Franzke + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Kristian Høgsberg + * Benjamin Franzke + */ + +#include +#include +#include +#include +#include + +#include "wayland-server.h" +#include "wayland-dmabuf.h" +#include "wayland-dmabuf-server-protocol.h" + +struct wl_dmabuf { + struct wl_display *display; + struct wl_global *wl_dmabuf_global; + + void *user_data; + uint32_t flags; + + struct wl_dmabuf_callbacks *callbacks; + + struct wl_buffer_interface buffer_interface; +}; + +static void +destroy_buffer(struct wl_resource *resource) +{ + struct wl_dmabuf_buffer *buffer = resource->data; + struct wl_dmabuf *dmabuf = buffer->dmabuf; + + dmabuf->callbacks->release_buffer(dmabuf->user_data, buffer); + free(buffer); +} + +static void +buffer_destroy(struct wl_client *client, struct wl_resource *resource) +{ + wl_resource_destroy(resource); +} + +static const struct wl_buffer_interface dmabuf_buffer_interface = { + buffer_destroy +}; + +static void +create_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) +{ + struct wl_dmabuf *dmabuf = resource->data; + struct wl_dmabuf_buffer *buffer; + + buffer = calloc(1, sizeof *buffer); + if (buffer == NULL) { + wl_resource_post_no_memory(resource); + return; + } + + buffer->dmabuf = dmabuf; + buffer->width = width; + buffer->height = height; + buffer->format = format; + buffer->offset[0] = offset0; + buffer->stride[0] = stride0; + buffer->offset[1] = offset1; + buffer->stride[1] = stride1; + buffer->offset[2] = offset2; + buffer->stride[2] = stride2; + + dmabuf->callbacks->reference_buffer(dmabuf->user_data, fd, buffer); + if (buffer->driver_buffer == NULL) { + wl_resource_post_error(resource, + WL_DMABUF_ERROR_INVALID_FILE_DESCRIPTOR, + "invalid file descriptor"); + return; + } + + buffer->resource = + wl_resource_create(client, &wl_buffer_interface, 1, id); + if (!buffer->resource) { + wl_resource_post_no_memory(resource); + free(buffer); + return; + } + + wl_resource_set_implementation(buffer->resource, + (void (**)(void)) &dmabuf->buffer_interface, + buffer, destroy_buffer); +} + +static void +dmabuf_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, fd, width, height, format, + offset0, stride0, offset1, stride1, offset2, stride2); + close(fd); +} + +static const struct wl_dmabuf_interface dmabuf_interface = { + dmabuf_create_prime_buffer +}; + +static void +bind_dmabuf(struct wl_client *client, void *data, uint32_t version, uint32_t id) +{ + struct wl_dmabuf *dmabuf = data; + struct wl_resource *resource; + + resource = wl_resource_create(client, &wl_dmabuf_interface, 1, id); + if (!resource) { + wl_client_post_no_memory(client); + return; + } + + dmabuf = resource->data; + + if (dmabuf->callbacks->send_supported_formats) + dmabuf->callbacks->send_supported_formats(dmabuf->user_data, resource); + + if (dmabuf->callbacks->send_capabilities) + dmabuf->callbacks->send_capabilities(dmabuf->user_data, resource); +} + +WL_EXPORT struct wl_dmabuf * +wl_dmabuf_init(struct wl_display *display, struct wl_dmabuf_callbacks *callbacks, + void *user_data, uint32_t flags) +{ + struct wl_dmabuf *dmabuf; + + dmabuf = malloc(sizeof *dmabuf); + + dmabuf->display = display; + dmabuf->callbacks = callbacks; + dmabuf->user_data = user_data; + dmabuf->flags = flags; + + dmabuf->buffer_interface.destroy = buffer_destroy; + + dmabuf->wl_dmabuf_global = + wl_global_create(display, &wl_dmabuf_interface, 1, dmabuf, bind_dmabuf); + + return dmabuf; +} + +WL_EXPORT void +wl_dmabuf_uninit(struct wl_dmabuf *dmabuf) +{ + wl_global_destroy(dmabuf->wl_dmabuf_global); + + free(dmabuf); +} + +WL_EXPORT int +wl_buffer_is_dmabuf(struct wl_dmabuf_buffer *buffer) +{ + struct wl_dmabuf *dmabuf = buffer->dmabuf; + + return wl_resource_instance_of(buffer->resource, + &wl_buffer_interface, &dmabuf->buffer_interface); +} + +WL_EXPORT uint32_t +wl_dmabuf_buffer_get_format(struct wl_dmabuf_buffer *buffer) +{ + if (!wl_buffer_is_dmabuf(buffer)) + return 0; + + return buffer->format; +} + +WL_EXPORT void * +wl_dmabuf_buffer_get_buffer(struct wl_dmabuf_buffer *buffer) +{ + if (!wl_buffer_is_dmabuf(buffer)) + return NULL; + + return buffer->driver_buffer; +} + +WL_EXPORT int32_t +wl_dmabuf_buffer_get_stride(struct wl_dmabuf_buffer *buffer, int idx) +{ + if (!wl_buffer_is_dmabuf(buffer)) + return 0; + + return buffer->stride[idx]; +} + +WL_EXPORT void * +wl_dmabuf_buffer_get_data(struct wl_dmabuf_buffer *buffer) +{ + struct wl_dmabuf *dmabuf; + + if (!wl_buffer_is_dmabuf(buffer)) + return NULL; + + dmabuf = buffer->dmabuf; + + if (dmabuf->callbacks->get_data) + return dmabuf->callbacks->get_data(dmabuf->user_data, buffer); + + return NULL; +} + +WL_EXPORT void +wl_dmabuf_buffer_put_data(struct wl_dmabuf_buffer *buffer) +{ + struct wl_dmabuf *dmabuf; + + if (!wl_buffer_is_dmabuf(buffer)) + return; + + dmabuf = buffer->dmabuf; + + if (dmabuf->callbacks->put_data) + dmabuf->callbacks->put_data(dmabuf->user_data, buffer); + + return; +} + + +WL_EXPORT int32_t +wl_dmabuf_buffer_get_width(struct wl_dmabuf_buffer *buffer) +{ + if (!wl_buffer_is_dmabuf(buffer)) + return 0; + + return buffer->width; +} + +WL_EXPORT int32_t +wl_dmabuf_buffer_get_height(struct wl_dmabuf_buffer *buffer) +{ + if (!wl_buffer_is_dmabuf(buffer)) + return 0; + + return buffer->height; +} diff --git a/src/wayland-dmabuf.h b/src/wayland-dmabuf.h new file mode 100644 index 0000000..5e3bb5c --- /dev/null +++ b/src/wayland-dmabuf.h @@ -0,0 +1,134 @@ +#ifndef WAYLAND_DMABUF_H +#define WAYLAND_DMABUF_H + +#include + +#ifndef WL_DMABUF_FORMAT_ENUM +#define WL_DMABUF_FORMAT_ENUM + +enum wl_dmabuf_format { + WL_DMABUF_FORMAT_C8 = 0x20203843, + WL_DMABUF_FORMAT_RGB332 = 0x38424752, + WL_DMABUF_FORMAT_BGR233 = 0x38524742, + WL_DMABUF_FORMAT_XRGB4444 = 0x32315258, + WL_DMABUF_FORMAT_XBGR4444 = 0x32314258, + WL_DMABUF_FORMAT_RGBX4444 = 0x32315852, + WL_DMABUF_FORMAT_BGRX4444 = 0x32315842, + WL_DMABUF_FORMAT_ARGB4444 = 0x32315241, + WL_DMABUF_FORMAT_ABGR4444 = 0x32314241, + WL_DMABUF_FORMAT_RGBA4444 = 0x32314152, + WL_DMABUF_FORMAT_BGRA4444 = 0x32314142, + WL_DMABUF_FORMAT_XRGB1555 = 0x35315258, + WL_DMABUF_FORMAT_XBGR1555 = 0x35314258, + WL_DMABUF_FORMAT_RGBX5551 = 0x35315852, + WL_DMABUF_FORMAT_BGRX5551 = 0x35315842, + WL_DMABUF_FORMAT_ARGB1555 = 0x35315241, + WL_DMABUF_FORMAT_ABGR1555 = 0x35314241, + WL_DMABUF_FORMAT_RGBA5551 = 0x35314152, + WL_DMABUF_FORMAT_BGRA5551 = 0x35314142, + WL_DMABUF_FORMAT_RGB565 = 0x36314752, + WL_DMABUF_FORMAT_BGR565 = 0x36314742, + WL_DMABUF_FORMAT_RGB888 = 0x34324752, + WL_DMABUF_FORMAT_BGR888 = 0x34324742, + WL_DMABUF_FORMAT_XRGB8888 = 0x34325258, + WL_DMABUF_FORMAT_XBGR8888 = 0x34324258, + WL_DMABUF_FORMAT_RGBX8888 = 0x34325852, + WL_DMABUF_FORMAT_BGRX8888 = 0x34325842, + WL_DMABUF_FORMAT_ARGB8888 = 0x34325241, + WL_DMABUF_FORMAT_ABGR8888 = 0x34324241, + WL_DMABUF_FORMAT_RGBA8888 = 0x34324152, + WL_DMABUF_FORMAT_BGRA8888 = 0x34324142, + WL_DMABUF_FORMAT_XRGB2101010 = 0x30335258, + WL_DMABUF_FORMAT_XBGR2101010 = 0x30334258, + WL_DMABUF_FORMAT_RGBX1010102 = 0x30335852, + WL_DMABUF_FORMAT_BGRX1010102 = 0x30335842, + WL_DMABUF_FORMAT_ARGB2101010 = 0x30335241, + WL_DMABUF_FORMAT_ABGR2101010 = 0x30334241, + WL_DMABUF_FORMAT_RGBA1010102 = 0x30334152, + WL_DMABUF_FORMAT_BGRA1010102 = 0x30334142, + WL_DMABUF_FORMAT_YUYV = 0x56595559, + WL_DMABUF_FORMAT_YVYU = 0x55595659, + WL_DMABUF_FORMAT_UYVY = 0x59565955, + WL_DMABUF_FORMAT_VYUY = 0x59555956, + WL_DMABUF_FORMAT_AYUV = 0x56555941, + WL_DMABUF_FORMAT_NV12 = 0x3231564e, + WL_DMABUF_FORMAT_NV21 = 0x3132564e, + WL_DMABUF_FORMAT_NV16 = 0x3631564e, + WL_DMABUF_FORMAT_NV61 = 0x3136564e, + WL_DMABUF_FORMAT_YUV410 = 0x39565559, + WL_DMABUF_FORMAT_YVU410 = 0x39555659, + WL_DMABUF_FORMAT_YUV411 = 0x31315559, + WL_DMABUF_FORMAT_YVU411 = 0x31315659, + WL_DMABUF_FORMAT_YUV420 = 0x32315559, + WL_DMABUF_FORMAT_YVU420 = 0x32315659, + WL_DMABUF_FORMAT_YUV422 = 0x36315559, + WL_DMABUF_FORMAT_YVU422 = 0x36315659, + WL_DMABUF_FORMAT_YUV444 = 0x34325559, + WL_DMABUF_FORMAT_YVU444 = 0x34325659, +}; +#endif /* WL_DMABUF_FORMAT_ENUM */ + +struct wl_dmabuf; + +struct wl_dmabuf_buffer { + struct wl_resource *resource; + struct wl_dmabuf *dmabuf; + int32_t width, height; + uint32_t format; + int32_t offset[3]; + int32_t stride[3]; + void *driver_buffer; +}; + +/* struct wl_dmabuf_callbacks + * + * @reference_buffer: take a reference on buffer + * @release_buffer: release a reference on buffer + * @get_data: get access to buffer memory to use it + * @put_data: indicated that buffer memory is no more used + * @send_supported_formats: post the pixel format supported by the server + * @send_capabilities: post the dmabuf capabilities of the server + */ +struct wl_dmabuf_callbacks { + void (*reference_buffer)(void *user_data, int fd, + struct wl_dmabuf_buffer *buffer); + void (*release_buffer)(void *user_data, struct wl_dmabuf_buffer *buffer); + void* (*get_data)(void *user_data, struct wl_dmabuf_buffer *buffer); + void (*put_data)(void *user_data, struct wl_dmabuf_buffer *buffer); + void (*send_supported_formats)(void *user_data, struct wl_resource *resource); + void (*send_capabilities)(void *user_data, struct wl_resource *resource); +}; + +struct wl_dmabuf * +wl_dmabuf_init(struct wl_display *display, + struct wl_dmabuf_callbacks *callbacks, + void *user_data, uint32_t flags); + +void +wl_dmabuf_uninit(struct wl_dmabuf *dmabuf); + +int +wl_buffer_is_dmabuf(struct wl_dmabuf_buffer *buffer); + +uint32_t +wl_dmabuf_buffer_get_format(struct wl_dmabuf_buffer *buffer); + +void * +wl_dmabuf_buffer_get_buffer(struct wl_dmabuf_buffer *buffer); + +int32_t +wl_dmabuf_buffer_get_stride(struct wl_dmabuf_buffer *buffer, int idx); + +void * +wl_dmabuf_buffer_get_data(struct wl_dmabuf_buffer *buffer); + +void +wl_dmabuf_buffer_put_data(struct wl_dmabuf_buffer *buffer); + +int32_t +wl_dmabuf_buffer_get_width(struct wl_dmabuf_buffer *buffer); + +int32_t +wl_dmabuf_buffer_get_height(struct wl_dmabuf_buffer *buffer); + +#endif