@@ -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
new file mode 100644
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="dmabuf">
+
+ <copyright>
+ 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.
+ </copyright>
+
+ <!-- dmabuf support. This object is created by the server and published
+ using the display's global event. -->
+ <interface name="wl_dmabuf" version="1">
+ <enum name="error">
+ <entry name="invalid_format" value="1"/>
+ <entry name="invalid_file_descriptor" value="2"/>
+ </enum>
+
+ <enum name="format">
+ <!-- The dmabuf format codes match the #defines in drm_fourcc.h.
+ The formats actually supported by the compositor will be
+ reported by the format event. -->
+ <entry name="c8" value="0x20203843"/>
+ <entry name="rgb332" value="0x38424752"/>
+ <entry name="bgr233" value="0x38524742"/>
+ <entry name="xrgb4444" value="0x32315258"/>
+ <entry name="xbgr4444" value="0x32314258"/>
+ <entry name="rgbx4444" value="0x32315852"/>
+ <entry name="bgrx4444" value="0x32315842"/>
+ <entry name="argb4444" value="0x32315241"/>
+ <entry name="abgr4444" value="0x32314241"/>
+ <entry name="rgba4444" value="0x32314152"/>
+ <entry name="bgra4444" value="0x32314142"/>
+ <entry name="xrgb1555" value="0x35315258"/>
+ <entry name="xbgr1555" value="0x35314258"/>
+ <entry name="rgbx5551" value="0x35315852"/>
+ <entry name="bgrx5551" value="0x35315842"/>
+ <entry name="argb1555" value="0x35315241"/>
+ <entry name="abgr1555" value="0x35314241"/>
+ <entry name="rgba5551" value="0x35314152"/>
+ <entry name="bgra5551" value="0x35314142"/>
+ <entry name="rgb565" value="0x36314752"/>
+ <entry name="bgr565" value="0x36314742"/>
+ <entry name="rgb888" value="0x34324752"/>
+ <entry name="bgr888" value="0x34324742"/>
+ <entry name="xrgb8888" value="0x34325258"/>
+ <entry name="xbgr8888" value="0x34324258"/>
+ <entry name="rgbx8888" value="0x34325852"/>
+ <entry name="bgrx8888" value="0x34325842"/>
+ <entry name="argb8888" value="0x34325241"/>
+ <entry name="abgr8888" value="0x34324241"/>
+ <entry name="rgba8888" value="0x34324152"/>
+ <entry name="bgra8888" value="0x34324142"/>
+ <entry name="xrgb2101010" value="0x30335258"/>
+ <entry name="xbgr2101010" value="0x30334258"/>
+ <entry name="rgbx1010102" value="0x30335852"/>
+ <entry name="bgrx1010102" value="0x30335842"/>
+ <entry name="argb2101010" value="0x30335241"/>
+ <entry name="abgr2101010" value="0x30334241"/>
+ <entry name="rgba1010102" value="0x30334152"/>
+ <entry name="bgra1010102" value="0x30334142"/>
+ <entry name="yuyv" value="0x56595559"/>
+ <entry name="yvyu" value="0x55595659"/>
+ <entry name="uyvy" value="0x59565955"/>
+ <entry name="vyuy" value="0x59555956"/>
+ <entry name="ayuv" value="0x56555941"/>
+ <entry name="nv12" value="0x3231564e"/>
+ <entry name="nv21" value="0x3132564e"/>
+ <entry name="nv16" value="0x3631564e"/>
+ <entry name="nv61" value="0x3136564e"/>
+ <entry name="yuv410" value="0x39565559"/>
+ <entry name="yvu410" value="0x39555659"/>
+ <entry name="yuv411" value="0x31315559"/>
+ <entry name="yvu411" value="0x31315659"/>
+ <entry name="yuv420" value="0x32315559"/>
+ <entry name="yvu420" value="0x32315659"/>
+ <entry name="yuv422" value="0x36315559"/>
+ <entry name="yvu422" value="0x36315659"/>
+ <entry name="yuv444" value="0x34325559"/>
+ <entry name="yvu444" value="0x34325659"/>
+ </enum>
+
+ <!-- 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">
+ <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="stride" type="int"/>
+ </request>
+
+ <event name="format">
+ <arg name="format" type="uint"/>
+ </event>
+
+ <!-- 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
+ be be passed to the server using this drm object's
+ create_buffer request. -->
+ <event name="device">
+ <arg name="name" type="string"/>
+ </event>
+
+ </interface>
+
+</protocol>
@@ -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
new file mode 100644
@@ -0,0 +1,231 @@
+/*
+ * 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 <krh@bitplanet.net>
+ * Benjamin Franzke <benjaminfranzke@googlemail.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <sys/mman.h>
+
+#include "wayland-server.h"
+#include "wayland-dmabuf.h"
+#include "wayland-dmabuf-server-protocol.h"
+
+struct wl_dmabuf {
+ struct wl_global *wl_dmabuf_global;
+ void *user_data;
+ struct wl_dmabuf_callbacks *callbacks;
+};
+
+static void
+destroy_buffer(struct wl_resource *resource)
+{
+ struct wl_dmabuf_buffer *buffer = wl_resource_get_user_data(resource);
+
+ buffer->refcount--;
+
+ if (buffer->refcount)
+ return;
+
+ close(buffer->fd);
+ 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
+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 stride)
+{
+ struct wl_dmabuf *dmabuf = wl_resource_get_user_data(resource);
+ struct wl_dmabuf_buffer *buffer;
+
+ buffer = calloc(1, sizeof *buffer);
+ if (buffer == NULL) {
+ wl_resource_post_no_memory(resource);
+ return;
+ }
+
+ buffer->resource =
+ wl_resource_create(client, &wl_buffer_interface, 1, id);
+ if (!buffer->resource) {
+ wl_resource_post_no_memory(resource);
+ free(buffer);
+ return;
+ }
+
+ buffer->dmabuf = dmabuf;
+ buffer->width = width;
+ buffer->height = height;
+ buffer->format = format;
+ buffer->data = NULL;
+ buffer->mmapcount = 0;
+ buffer->refcount = 1;
+ /* make sure we have your own file descriptor */
+ buffer->fd = dup(fd);
+ close(fd);
+ buffer->stride = stride;
+
+ wl_resource_set_implementation(buffer->resource,
+ &dmabuf_buffer_interface,
+ buffer, destroy_buffer);
+}
+
+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;
+ }
+
+ wl_resource_set_implementation(resource, &dmabuf_interface, data, NULL);
+
+ if (dmabuf->callbacks->send_server_info)
+ dmabuf->callbacks->send_server_info(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->callbacks = callbacks;
+ dmabuf->user_data = user_data;
+
+ 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 struct wl_dmabuf_buffer *
+wl_dmabuf_buffer_get(struct wl_resource *resource)
+{
+ if (resource == NULL)
+ return NULL;
+
+ if (wl_resource_instance_of(resource, &wl_buffer_interface,
+ &dmabuf_buffer_interface))
+ return wl_resource_get_user_data(resource);
+
+ return NULL;
+}
+
+WL_EXPORT uint32_t
+wl_dmabuf_buffer_get_format(struct wl_dmabuf_buffer *buffer)
+{
+ return buffer->format;
+}
+
+WL_EXPORT int32_t
+wl_dmabuf_buffer_get_stride(struct wl_dmabuf_buffer *buffer)
+{
+ return buffer->stride;
+}
+
+WL_EXPORT void *
+wl_dmabuf_buffer_get_data(struct wl_dmabuf_buffer *buffer)
+{
+ uint32_t size;
+
+ buffer->refcount++;
+
+ if (buffer->mmapcount++)
+ return buffer->data;
+
+ size = buffer->width * buffer->height * 4;
+ buffer->data = mmap (0, size, PROT_READ | PROT_WRITE, MAP_SHARED, buffer->fd, 0);
+
+ return buffer->data;
+}
+
+WL_EXPORT void
+wl_dmabuf_buffer_put_data(struct wl_dmabuf_buffer *buffer)
+{
+ uint32_t size;
+
+ buffer->mmapcount--;
+ buffer->refcount--;
+
+ if (buffer->mmapcount)
+ return;
+
+ size = buffer->width * buffer->height * 4;
+ munmap (buffer->data, size);
+ buffer->data = NULL;
+
+ if (buffer->refcount)
+ return;
+
+ close(buffer->fd);
+ free(buffer);
+}
+
+WL_EXPORT int32_t
+wl_dmabuf_buffer_get_width(struct wl_dmabuf_buffer *buffer)
+{
+ return buffer->width;
+}
+
+WL_EXPORT int32_t
+wl_dmabuf_buffer_get_height(struct wl_dmabuf_buffer *buffer)
+{
+ return buffer->height;
+}
new file mode 100644
@@ -0,0 +1,123 @@
+#ifndef WAYLAND_DMABUF_H
+#define WAYLAND_DMABUF_H
+
+#include <wayland-server.h>
+
+#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;
+ int32_t stride;
+ uint32_t format;
+ uint8_t *data;
+ int mmapcount;
+ int refcount;
+ int fd;
+};
+
+/* struct wl_dmabuf_callbacks
+ *
+ * @send_server_info: ask to the server to send all
+ * supported pixel formats and device name
+ */
+struct wl_dmabuf_callbacks {
+ void (*send_server_info)(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);
+
+struct wl_dmabuf_buffer *
+wl_dmabuf_buffer_get(struct wl_resource *resource);
+
+uint32_t
+wl_dmabuf_buffer_get_format(struct wl_dmabuf_buffer *buffer);
+
+int32_t
+wl_dmabuf_buffer_get_stride(struct wl_dmabuf_buffer *buffer);
+
+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