diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-04-18 15:45:25 +0200 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2011-04-18 16:28:52 +0200 |
commit | 2a71baba83672fcb800be7648da34b37abd5c02a (patch) | |
tree | ddacb10855609d17362b6b933bf7eb6f6d8c1ef5 |
-rw-r--r-- | .gitignore | 28 | ||||
-rw-r--r-- | Makefile.am | 1 | ||||
-rwxr-xr-x | autogen.sh | 9 | ||||
-rw-r--r-- | configure.ac | 37 | ||||
-rw-r--r-- | m4/.gitignore | 5 | ||||
-rw-r--r-- | protocol/wayland-drm.xml | 38 | ||||
-rw-r--r-- | wayland-drm/.gitignore | 3 | ||||
-rw-r--r-- | wayland-drm/Makefile.am | 30 | ||||
-rw-r--r-- | wayland-drm/wayland-drm-client.pc.in | 10 | ||||
-rw-r--r-- | wayland-drm/wayland-drm-server.c | 210 | ||||
-rw-r--r-- | wayland-drm/wayland-drm-server.h | 34 | ||||
-rw-r--r-- | wayland-drm/wayland-drm-server.pc.in | 10 |
12 files changed, 415 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7c5bfe5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +*.deps +*.jpg +*.la +*.lo +*.o +*.pc +*.so +*.swp +*~ +.libs +/aclocal.m4 +/autom4te.cache +/config.guess +/config.h +/config.h.in +/config.log +/config.mk +/config.status +/config.sub +/configure +/depcomp +/install-sh +/libtool +/ltmain.sh +/missing +/stamp-h1 +Makefile +Makefile.in diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..eb17dc6 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = wayland-drm diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..916169a --- /dev/null +++ b/autogen.sh @@ -0,0 +1,9 @@ +#! /bin/sh + +test -n "$srcdir" || srcdir=`dirname "$0"` +test -n "$srcdir" || srcdir=. +( + cd "$srcdir" && + autoreconf --force -v --install +) || exit +test -n "$NOCONFIGURE" || "$srcdir/configure" "$@" diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..686133a --- /dev/null +++ b/configure.ac @@ -0,0 +1,37 @@ +AC_PREREQ([2.64]) +AC_INIT([wayland-drm], + [0.1], + [https://bugs.freedesktop.org/enter_bug.cgi?product=wayland], + [wayland-drm], + [http://wayland.freedesktop.org/]) + +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_MACRO_DIR([m4]) + +AM_INIT_AUTOMAKE([1.11 foreign dist-bzip2]) + +AM_SILENT_RULES([yes]) + +# Check for programs +AC_PROG_CC + +# Initialize libtool +LT_PREREQ([2.2]) +LT_INIT + +PKG_PROG_PKG_CONFIG() +PKG_CHECK_MODULES(WAYLAND_SERVER, [wayland-server]) +PKG_CHECK_MODULES(WAYLAND_CLIENT, [wayland-client]) + +if test "x$GCC" = "xyes"; then + GCC_CFLAGS="-Wall -g -Wstrict-prototypes -Wmissing-prototypes -fvisibility=hidden" +fi +AC_SUBST(GCC_CFLAGS) + +WAYLAND_SCANNER_RULES(['$(top_srcdir)/protocol']) + +AC_CONFIG_FILES([Makefile + wayland-drm/Makefile + wayland-drm/wayland-drm-server.pc + wayland-drm/wayland-drm-client.pc]) +AC_OUTPUT diff --git a/m4/.gitignore b/m4/.gitignore new file mode 100644 index 0000000..464ba5c --- /dev/null +++ b/m4/.gitignore @@ -0,0 +1,5 @@ +libtool.m4 +lt~obsolete.m4 +ltoptions.m4 +ltsugar.m4 +ltversion.m4 diff --git a/protocol/wayland-drm.xml b/protocol/wayland-drm.xml new file mode 100644 index 0000000..90a6daa --- /dev/null +++ b/protocol/wayland-drm.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="wayland_drm"> + <!-- drm support. This object is created by the server and published + using the display's global event. --> + <interface name="drm" version="1"> + <!-- Call this request with the magic received from drmGetMagic(). + It will be passed on to the drmAuthMagic() or + DRIAuthConnection() call. This authentication must be + completed before create_buffer could be used. --> + <request name="authenticate"> + <arg name="id" type="uint"/> + </request> + + <!-- Create a wayland buffer for the named DRM buffer. The DRM + surface must have a name using the flink ioctl --> + <request name="create_buffer"> + <arg name="id" type="new_id" interface="buffer"/> + <arg name="name" type="uint"/> + <arg name="width" type="int"/> + <arg name="height" type="int"/> + <arg name="stride" type="uint"/> + <arg name="visual" type="object" interface="visual"/> + </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 + be be passed to the server using this drm object's + create_buffer request. --> + <event name="device"> + <arg name="name" type="string"/> + </event> + + <!-- Raised if the authenticate request succeeded --> + <event name="authenticated"/> + </interface> + +</protocol> diff --git a/wayland-drm/.gitignore b/wayland-drm/.gitignore new file mode 100644 index 0000000..1741a58 --- /dev/null +++ b/wayland-drm/.gitignore @@ -0,0 +1,3 @@ +wayland-drm-client-protocol.h +wayland-drm-protocol.c +wayland-drm-server-protocol.h diff --git a/wayland-drm/Makefile.am b/wayland-drm/Makefile.am new file mode 100644 index 0000000..c955ea2 --- /dev/null +++ b/wayland-drm/Makefile.am @@ -0,0 +1,30 @@ +lib_LTLIBRARIES = libwayland-drm-server.la libwayland-drm-client.la + +include_HEADERS = \ + wayland-drm-server.h \ + wayland-drm-server-protocol.h \ + wayland-drm-client-protocol.h + +libwayland_drm_server_la_LIBADD = $(WAYLAND_SERVER_LIBS) +libwayland_drm_server_la_SOURCES = \ + wayland-drm-protocol.c \ + wayland-drm-server.c + +libwayland_drm_client_la_LIBADD = $(WAYLAND_CLIENT_LIBS) +libwayland_drm_client_la_SOURCES = \ + wayland-drm-protocol.c + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = wayland-drm-server.pc wayland-drm-client.pc + +AM_CPPFLAGS = $(WAYLAND_SERVER_CFLAGS) $(WAYLAND_CLIENT_CFLAGS) +AM_CFLAGS = $(GCC_CFLAGS) + +BUILT_SOURCES = \ + wayland-drm-server-protocol.h \ + wayland-drm-client-protocol.h \ + wayland-drm-protocol.c + +CLEANFILES = $(BUILT_SOURCES) + +@wayland_scanner_rules@ diff --git a/wayland-drm/wayland-drm-client.pc.in b/wayland-drm/wayland-drm-client.pc.in new file mode 100644 index 0000000..8200b2f --- /dev/null +++ b/wayland-drm/wayland-drm-client.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: Wayland DRM Client +Description: Wayland DRM client side library +Version: 0.1 +Cflags: -I${includedir} +Libs: -L${libdir} -lwayland-drm-client diff --git a/wayland-drm/wayland-drm-server.c b/wayland-drm/wayland-drm-server.c new file mode 100644 index 0000000..5142431 --- /dev/null +++ b/wayland-drm/wayland-drm-server.c @@ -0,0 +1,210 @@ +/* + * 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 <wayland-server.h> +#include "wayland-drm-server.h" +#include "wayland-drm-server-protocol.h" + +struct wl_drm { + struct wl_object object; + struct wl_display *display; + + void *user_data; + char *device_name; + + struct wl_drm_callbacks *callbacks; +}; + +struct wl_drm_buffer { + struct wl_buffer buffer; + struct wl_drm *drm; + + void *driver_buffer; +}; + +static void +drm_buffer_damage(struct wl_buffer *buffer_base, + struct wl_surface *surface, + int32_t x, int32_t y, int32_t width, int32_t height) +{ +} + +static void +destroy_buffer(struct wl_resource *resource, struct wl_client *client) +{ + struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) resource; + struct wl_drm *drm = buffer->drm; + + drm->callbacks->release_buffer(drm->user_data, + buffer->driver_buffer); + free(buffer); +} + +static void +buffer_destroy(struct wl_client *client, struct wl_buffer *buffer) +{ + wl_resource_destroy(&buffer->resource, client); +} + +const static struct wl_buffer_interface drm_buffer_interface = { + buffer_destroy +}; + +static void +drm_create_buffer(struct wl_client *client, struct wl_drm *drm, + uint32_t id, uint32_t name, int32_t width, int32_t height, + uint32_t stride, struct wl_visual *visual) +{ + struct wl_drm_buffer *buffer; + + buffer = malloc(sizeof *buffer); + if (buffer == NULL) { + wl_client_post_no_memory(client); + return; + } + + buffer->drm = drm; + buffer->buffer.compositor = NULL; + buffer->buffer.width = width; + buffer->buffer.height = height; + buffer->buffer.visual = visual; + buffer->buffer.attach = NULL; + buffer->buffer.damage = drm_buffer_damage; + + if (visual->object.interface != &wl_visual_interface) { + /* FIXME: Define a real exception event instead of + * abusing this one */ + wl_client_post_event(client, + (struct wl_object *) drm->display, + WL_DISPLAY_INVALID_OBJECT, 0); + fprintf(stderr, "invalid visual in create_buffer\n"); + return; + } + + buffer->driver_buffer = + drm->callbacks->reference_buffer(drm->user_data, name, + width, height, + stride, visual); + + if (buffer->driver_buffer == NULL) { + /* FIXME: Define a real exception event instead of + * abusing this one */ + wl_client_post_event(client, + (struct wl_object *) drm->display, + WL_DISPLAY_INVALID_OBJECT, 0); + fprintf(stderr, "failed to create image for name %d\n", name); + return; + } + + buffer->buffer.resource.object.id = id; + buffer->buffer.resource.object.interface = &wl_buffer_interface; + buffer->buffer.resource.object.implementation = (void (**)(void)) + &drm_buffer_interface; + + buffer->buffer.resource.destroy = destroy_buffer; + + wl_client_add_resource(client, &buffer->buffer.resource); +} + +static void +drm_authenticate(struct wl_client *client, + struct wl_drm *drm, uint32_t id) +{ + if (drm->callbacks->authenticate(drm->user_data, id) < 0) + wl_client_post_event(client, + (struct wl_object *) drm->display, + WL_DISPLAY_INVALID_OBJECT, 0); + else + wl_client_post_event(client, &drm->object, + WL_DRM_AUTHENTICATED); +} + +const static struct wl_drm_interface drm_interface = { + drm_authenticate, + drm_create_buffer +}; + +static void +post_drm_device(struct wl_client *client, struct wl_object *global) +{ + struct wl_drm *drm = (struct wl_drm *) global; + + wl_client_post_event(client, global, WL_DRM_DEVICE, drm->device_name); +} + +WL_EXPORT struct wl_drm * +wl_drm_init(struct wl_display *display, char *device_name, + struct wl_drm_callbacks *callbacks, void *user_data) +{ + struct wl_drm *drm; + + drm = malloc(sizeof *drm); + + drm->display = display; + drm->device_name = strdup(device_name); + drm->callbacks = callbacks; + drm->user_data = user_data; + + drm->object.interface = &wl_drm_interface; + drm->object.implementation = (void (**)(void)) &drm_interface; + wl_display_add_object(display, &drm->object); + wl_display_add_global(display, &drm->object, post_drm_device); + + return drm; +} + +WL_EXPORT void +wl_drm_finish(struct wl_drm *drm) +{ + free(drm->device_name); + + /* FIXME: need wl_display_del_{object,global} */ + + free(drm); +} + +WL_EXPORT int +wl_buffer_is_drm(struct wl_buffer *buffer) +{ + return buffer->resource.object.implementation == + (void (**)(void)) &drm_buffer_interface; +} + +WL_EXPORT void * +wl_drm_buffer_get_buffer(struct wl_buffer *buffer_base) +{ + struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) buffer_base; + + return buffer->driver_buffer; +} diff --git a/wayland-drm/wayland-drm-server.h b/wayland-drm/wayland-drm-server.h new file mode 100644 index 0000000..dbab7d7 --- /dev/null +++ b/wayland-drm/wayland-drm-server.h @@ -0,0 +1,34 @@ +#ifndef _WAYLAND_DRM_SERVER_H_ +#define _WAYLAND_DRM_SERVER_H_ + +#include <stdint.h> + +struct wl_display; +struct wl_drm; +struct wl_buffer; +struct wl_visual; + +struct wl_drm_callbacks { + int (*authenticate)(void *user_data, uint32_t id); + + void *(*reference_buffer)(void *user_data, uint32_t name, + int32_t width, int32_t height, + uint32_t stride, struct wl_visual *visual); + + void (*release_buffer)(void *user_data, void *buffer); +}; + +struct wl_drm * +wl_drm_init(struct wl_display *display, char *device_name, + struct wl_drm_callbacks *callbacks, void *user_data); + +void +wl_drm_finish(struct wl_drm *drm); + +int +wl_buffer_is_drm(struct wl_buffer *buffer); + +void * +wl_drm_buffer_get_buffer(struct wl_buffer *buffer); + +#endif /* _WAYLAND_DRM_SERVER_H_ */ diff --git a/wayland-drm/wayland-drm-server.pc.in b/wayland-drm/wayland-drm-server.pc.in new file mode 100644 index 0000000..bd5e989 --- /dev/null +++ b/wayland-drm/wayland-drm-server.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: Wayland DRM Server +Description: Wayland DRM server side library +Version: 0.1 +Cflags: -I${includedir} +Libs: -L${libdir} -lwayland-drm-server |