commit 8d413279181bb54c798ed3cd772a05a74d0398da
parent 182f6d36893ce7c35efe98959cba241af240759f
Author: Michael Forney <mforney@mforney.org>
Date: Wed, 15 Jan 2014 14:36:37 -0800
wayland: Add surfaces
Diffstat:
6 files changed, 113 insertions(+), 4 deletions(-)
diff --git a/wayland-drm.c b/wayland-drm.c
@@ -90,6 +90,7 @@ struct wld_context * wld_wayland_drm_create_context(struct wl_display * display,
goto error0;
context_initialize(&context->base.base, &context_impl);
+ context->base.display = display;
context->base.queue = queue;
context->wl = NULL;
context->fd = -1;
diff --git a/wayland-private.h b/wayland-private.h
@@ -39,6 +39,7 @@ struct wld_wayland_interface
struct wayland_context
{
struct wld_context base;
+ struct wl_display * display;
struct wl_event_queue * queue;
};
diff --git a/wayland-shm.c b/wayland-shm.c
@@ -99,6 +99,7 @@ struct wld_context * wld_wayland_shm_create_context
goto error0;
context_initialize(&context->base.base, &context_impl);
+ context->base.display = display;
context->base.queue = queue;
context->wl = NULL;
wl_array_init(&context->formats);
diff --git a/wayland.c b/wayland.c
@@ -34,9 +34,32 @@ struct wayland_exporter
struct wl_buffer * buffer;
};
+struct wayland_buffer_socket
+{
+ struct wld_buffer_socket base;
+ struct wl_buffer_listener listener;
+ struct wld_surface * surface;
+ struct wl_surface * wl;
+ struct wl_display * display;
+ struct wl_event_queue * queue;
+};
+
#include "interface/exporter.h"
IMPL(wayland, exporter)
+static bool buffer_socket_attach(struct wld_buffer_socket * socket,
+ struct wld_buffer * buffer);
+static void buffer_socket_process(struct wld_buffer_socket * socket);
+static void buffer_socket_destroy(struct wld_buffer_socket * socket);
+
+static const struct wld_buffer_socket_impl buffer_socket_impl = {
+ .attach = &buffer_socket_attach,
+ .process = &buffer_socket_process,
+ .destroy = &buffer_socket_destroy
+};
+
+IMPL(wayland, buffer_socket)
+
static void sync_done(void * data, struct wl_callback * callback,
uint32_t msecs);
@@ -44,6 +67,8 @@ static const struct wl_callback_listener sync_listener = {
.done = &sync_done
};
+static void buffer_release(void * data, struct wl_buffer * buffer);
+
const static struct wld_wayland_interface * interfaces[] = {
#if WITH_WAYLAND_DRM
[WLD_DRM] = &wayland_drm_interface,
@@ -130,6 +155,36 @@ struct wld_context * wld_wayland_create_context
return context;
}
+EXPORT
+struct wld_surface * wld_wayland_create_surface(struct wld_context * context,
+ uint32_t width, uint32_t height,
+ uint32_t format,
+ struct wl_surface * wl)
+{
+ struct wayland_buffer_socket * socket;
+
+ if (!(socket = malloc(sizeof *socket)))
+ goto error0;
+
+ socket->base.impl = &buffer_socket_impl;
+ socket->listener.release = &buffer_release;
+ socket->wl = wl;
+ socket->queue = ((struct wayland_context *) context)->queue;
+ socket->display = ((struct wayland_context *) context)->display;
+ socket->surface = buffered_surface_create(context, width, height, format,
+ &socket->base);
+
+ if (!socket->surface)
+ goto error1;
+
+ return socket->surface;
+
+ error1:
+ free(socket);
+ error0:
+ return NULL;
+}
+
int wayland_roundtrip(struct wl_display * display,
struct wl_event_queue * queue)
{
@@ -185,6 +240,42 @@ void exporter_destroy(struct wld_exporter * base)
free(exporter);
}
+bool buffer_socket_attach(struct wld_buffer_socket * base,
+ struct wld_buffer * buffer)
+{
+ struct wayland_buffer_socket * socket = wayland_buffer_socket(base);
+ struct wl_buffer * wl;
+ union wld_object object;
+
+ if (!wld_export(buffer, WLD_WAYLAND_OBJECT_BUFFER, &object))
+ return false;
+
+ wl = object.ptr;
+
+ if (!wl_proxy_get_listener((struct wl_proxy *) wl))
+ wl_buffer_add_listener(wl, &socket->listener, buffer);
+
+ wl_surface_attach(socket->wl, wl, 0, 0);
+ wl_surface_commit(socket->wl);
+
+ return true;
+}
+
+void buffer_socket_process(struct wld_buffer_socket * base)
+{
+ struct wayland_buffer_socket * socket = wayland_buffer_socket(base);
+
+ /* Since events for our wl_buffers lie in a special queue used by WLD, we
+ * must dispatch these events here so that we see any release events before
+ * the next back buffer is chosen. */
+ wl_display_dispatch_queue_pending(socket->display, socket->queue);
+}
+
+void buffer_socket_destroy(struct wld_buffer_socket * socket)
+{
+ free(socket);
+}
+
void sync_done(void * data, struct wl_callback * callback, uint32_t msecs)
{
bool * done = data;
@@ -193,3 +284,14 @@ void sync_done(void * data, struct wl_callback * callback, uint32_t msecs)
wl_callback_destroy(callback);
}
+void buffer_release(void * data, struct wl_buffer * wl)
+{
+ struct wld_buffer * buffer = data;
+ const struct wl_buffer_listener * listener
+ = wl_proxy_get_listener((struct wl_proxy *) wl);
+ struct wayland_buffer_socket * socket
+ = CONTAINER_OF(listener, struct wayland_buffer_socket, listener);
+
+ wld_surface_release(socket->surface, buffer);
+}
+
diff --git a/wayland.h b/wayland.h
@@ -27,6 +27,7 @@
#include <stdint.h>
struct wl_display;
+struct wl_surface;
enum wld_wayland_interface_id
{
@@ -64,5 +65,10 @@ enum wld_wayland_object_type
struct wld_context * wld_wayland_create_context
(struct wl_display * display, enum wld_wayland_interface_id id, ...);
+struct wld_surface * wld_wayland_create_surface(struct wld_context * context,
+ uint32_t width, uint32_t height,
+ uint32_t format,
+ struct wl_surface * surface);
+
#endif
diff --git a/wld-private.h b/wld-private.h
@@ -33,10 +33,6 @@
#include FT_FREETYPE_H
#include FT_BITMAP_H
-#ifndef offsetof
-# define offsetof __builtin_offsetof
-#endif
-
#define ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0])
#if ENABLE_DEBUG
# define DEBUG(format, ...) \
@@ -46,6 +42,8 @@
#endif
#define EXPORT __attribute__((visibility("default")))
+#define CONTAINER_OF(ptr, type, member) \
+ ((type *)((uintptr_t) ptr - offsetof(type, member)))
#define IMPL(name, type) \
static inline struct name ## _ ## type * name ## _ ## type \
(struct wld_ ## type * type) \