neuwld

patched neuwld library (tracked)
git clone https://git.daat.foo/neuwld.git
Log | Files | Refs | README | LICENSE

commit c71dc185142ca14233050341533262efaf8d5c7f
parent 7fe3933898d156324e2836726617355649e53ed9
Author: Michael Forney <mforney@mforney.org>
Date:   Sat, 18 Oct 2014 19:03:32 -0700

wayland: Remove wayland-drm and wayland-shm headers

Add a wayland_impl struct.

Diffstat:
MMakefile | 2--
Ainterface/wayland.h | 41+++++++++++++++++++++++++++++++++++++++++
Mwayland-drm.c | 23+++++++----------------
Dwayland-drm.h | 53-----------------------------------------------------
Mwayland-private.h | 18++++++++++--------
Mwayland-shm.c | 25+++++++++++--------------
Dwayland-shm.h | 48------------------------------------------------
Mwayland.c | 55++++++++++++++++++++++++++++++++++---------------------
Mwayland.h | 8++++++++
9 files changed, 111 insertions(+), 162 deletions(-)

diff --git a/Makefile b/Makefile @@ -63,13 +63,11 @@ ifeq ($(ENABLE_WAYLAND),1) ifneq ($(findstring shm,$(WAYLAND_INTERFACES)),) WLD_SOURCES += wayland-shm.c - WLD_HEADERS += wayland-shm.h WLD_CPPFLAGS += -DWITH_WAYLAND_SHM=1 endif ifneq ($(findstring drm,$(WAYLAND_INTERFACES)),) WLD_SOURCES += wayland-drm.c protocol/wayland-drm-protocol.c - WLD_HEADERS += wayland-drm.h WLD_CPPFLAGS += -DWITH_WAYLAND_DRM=1 endif endif diff --git a/interface/wayland.h b/interface/wayland.h @@ -0,0 +1,41 @@ +/* wld: interface/wayland.h + * + * Copyright (c) 2014 Michael Forney + * + * 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 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. + */ + +#ifndef WAYLAND_IMPL_NAME +# error you must define WAYLAND_IMPL_NAME before including interface/wayland.h +#endif + +static struct wayland_context * wayland_create_context + (struct wl_display * display, struct wl_event_queue * queue); +static bool wayland_has_format(struct wld_context * context, uint32_t format); + +#define EXPAND(f, x) f(x) +#define VAR(name) name ## _wayland_impl +const struct wayland_impl EXPAND(VAR, WAYLAND_IMPL_NAME) = { + .create_context = &wayland_create_context, + .has_format = &wayland_has_format, + //.create_surface = &wayland_create_surface, +}; +#undef VAR +#undef EXPAND + diff --git a/wayland-drm.c b/wayland-drm.c @@ -21,7 +21,6 @@ * SOFTWARE. */ -#include "wayland-drm.h" #include "wayland.h" #include "drm.h" #include "protocol/wayland-drm-client-protocol.h" @@ -35,8 +34,6 @@ #include <fcntl.h> #include <xf86drm.h> -#include <stdio.h> - struct drm_context { struct wayland_context base; @@ -49,7 +46,9 @@ struct drm_context bool authenticated; }; +#define WAYLAND_IMPL_NAME drm #include "interface/context.h" +#include "interface/wayland.h" IMPL(drm_context, wld_context) static void registry_global(void * data, struct wl_registry * registry, @@ -64,10 +63,6 @@ static void drm_authenticated(void * data, struct wl_drm * wl); static void drm_capabilities(void * data, struct wl_drm * wl, uint32_t capabilities); -const struct wld_wayland_interface wayland_drm_interface = { - .create_context = &wld_wayland_drm_create_context, -}; - const static struct wl_registry_listener registry_listener = { .global = &registry_global, .global_remove = &registry_global_remove @@ -80,9 +75,8 @@ const static struct wl_drm_listener drm_listener = { .capabilities = &drm_capabilities }; -EXPORT -struct wld_context * wld_wayland_drm_create_context(struct wl_display * display, - struct wl_event_queue * queue) +struct wayland_context * wayland_create_context(struct wl_display * display, + struct wl_event_queue * queue) { struct drm_context * context; @@ -90,8 +84,6 @@ struct wld_context * wld_wayland_drm_create_context(struct wl_display * display, goto error0; context_initialize(&context->base.base, &wld_context_impl); - context->base.display = display; - context->base.queue = queue; context->wl = NULL; context->fd = -1; context->capabilities = 0; @@ -144,7 +136,7 @@ struct wld_context * wld_wayland_drm_create_context(struct wl_display * display, goto error4; } - return &context->base.base; + return &context->base; error4: close(context->fd); @@ -159,8 +151,7 @@ struct wld_context * wld_wayland_drm_create_context(struct wl_display * display, return NULL; } -EXPORT -bool wld_wayland_drm_has_format(struct wld_context * base, uint32_t format) +bool wayland_has_format(struct wld_context * base, uint32_t format) { struct drm_context * context = drm_context(base); uint32_t * supported_format; @@ -198,7 +189,7 @@ struct buffer * context_create_buffer(struct wld_context * base, union wld_object object; struct wl_buffer * wl; - if (!wld_wayland_drm_has_format(base, format)) + if (!wayland_has_format(base, format)) goto error0; buffer = context->driver_context->impl->create_buffer diff --git a/wayland-drm.h b/wayland-drm.h @@ -1,53 +0,0 @@ -/* wld: wayland-drm.h - * - * Copyright (c) 2013, 2014 Michael Forney - * - * 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 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. - */ - -#ifndef WLD_WAYLAND_DRM_H -#define WLD_WAYLAND_DRM_H - -#include <stdbool.h> -#include <stdint.h> - -struct wl_display; -struct wl_event_queue; - -/** - * Create a new WLD context which creates Wayland buffers through the wl_drm - * interface, backed by hardware specific buffer implementations. - */ -struct wld_context * wld_wayland_drm_create_context - (struct wl_display * display, struct wl_event_queue * queue); - -/** - * Check if the wl_drm global has the specified pixel format. - * - * @see enum wld_format - */ -bool wld_wayland_drm_has_format(struct wld_context * context, uint32_t format); - -/** - * Get the opened file descriptor for the DRM device. - */ -int wld_wayland_drm_get_fd(struct wld_context * context); - -#endif - diff --git a/wayland-private.h b/wayland-private.h @@ -31,25 +31,27 @@ struct wl_display; struct wl_event_queue; struct wl_buffer; -struct wld_wayland_interface -{ - struct wld_context * (* create_context)(struct wl_display * display, - struct wl_event_queue * queue); -}; - struct wayland_context { struct wld_context base; + const struct wayland_impl * impl; struct wl_display * display; struct wl_event_queue * queue; }; +struct wayland_impl +{ + struct wayland_context * (* create_context)(struct wl_display * display, + struct wl_event_queue * queue); + bool (* has_format)(struct wld_context * context, uint32_t format); +}; + #if WITH_WAYLAND_DRM -extern const struct wld_wayland_interface wayland_drm_interface; +extern const struct wayland_impl drm_wayland_impl; #endif #if WITH_WAYLAND_SHM -extern const struct wld_wayland_interface wayland_shm_interface; +extern const struct wayland_impl shm_wayland_impl; #endif bool wayland_buffer_add_exporter(struct buffer * buffer, struct wl_buffer * wl); diff --git a/wayland-shm.c b/wayland-shm.c @@ -23,7 +23,6 @@ #define _GNU_SOURCE /* Required for mkostemp */ -#include "wayland-shm.h" #include "wayland.h" #include "wayland-private.h" #include "wld-private.h" @@ -50,8 +49,10 @@ struct shm_buffer int fd; }; +#define WAYLAND_IMPL_NAME shm #include "interface/context.h" #include "interface/buffer.h" +#include "interface/wayland.h" IMPL(shm_context, wld_context) IMPL(shm_buffer, wld_buffer) @@ -63,10 +64,6 @@ static void registry_global_remove(void * data, struct wl_registry * registry, static void shm_format(void * data, struct wl_shm * wl, uint32_t format); -const struct wld_wayland_interface wayland_shm_interface = { - .create_context = &wld_wayland_shm_create_context, -}; - const static struct wl_registry_listener registry_listener = { .global = &registry_global, .global_remove = &registry_global_remove @@ -89,9 +86,8 @@ static inline uint32_t format_wld_to_shm(uint32_t format) } } -EXPORT -struct wld_context * wld_wayland_shm_create_context - (struct wl_display * display, struct wl_event_queue * queue) +struct wayland_context * wayland_create_context(struct wl_display * display, + struct wl_event_queue * queue) { struct shm_context * context; @@ -99,8 +95,6 @@ struct wld_context * wld_wayland_shm_create_context goto error0; context_initialize(&context->base.base, &wld_context_impl); - context->base.display = display; - context->base.queue = queue; context->wl = NULL; wl_array_init(&context->formats); @@ -127,7 +121,7 @@ struct wld_context * wld_wayland_shm_create_context /* Wait for SHM formats. */ wl_display_roundtrip_queue(display, queue); - return &context->base.base; + return &context->base; error2: wl_registry_destroy(context->registry); @@ -138,15 +132,15 @@ struct wld_context * wld_wayland_shm_create_context return NULL; } -EXPORT -bool wld_shm_has_format(struct wld_context * base, uint32_t format) +bool wayland_has_format(struct wld_context * base, uint32_t format) { struct shm_context * context = shm_context(base); uint32_t * supported_format; + uint32_t shm_format = format_wld_to_shm(format); wl_array_for_each(supported_format, &context->formats) { - if (*supported_format == format) + if (*supported_format == shm_format) return true; } @@ -171,6 +165,9 @@ struct buffer * context_create_buffer(struct wld_context * base, struct wl_shm_pool * pool; struct wl_buffer * wl; + if (!wayland_has_format(base, format)) + goto error0; + if (!(buffer = malloc(sizeof *buffer))) goto error0; diff --git a/wayland-shm.h b/wayland-shm.h @@ -1,48 +0,0 @@ -/* wld: wayland-shm.h - * - * Copyright (c) 2013, 2014 Michael Forney - * - * 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 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. - */ - -#ifndef WLD_WAYLAND_SHM_H -#define WLD_WAYLAND_SHM_H - -#include <stdbool.h> -#include <stdint.h> - -struct wl_display; -struct wl_event_queue; - -/** - * Create a new WLD context which creates Wayland buffers through the wl_shm - * interface, backed by Pixman images. - */ -struct wld_context * wld_wayland_shm_create_context - (struct wl_display * display, struct wl_event_queue * queue); - -/** - * Check if the wl_shm global has the specified pixel format. - * - * @see enum wld_format - */ -bool wld_wayland_shm_has_format(struct wld_context * context, uint32_t format); - -#endif - diff --git a/wayland.c b/wayland.c @@ -67,13 +67,13 @@ static const struct wl_callback_listener sync_listener = { static void buffer_release(void * data, struct wl_buffer * buffer); -const static struct wld_wayland_interface * interfaces[] = { +const static struct wayland_impl * impls[] = { #if WITH_WAYLAND_DRM - [WLD_DRM] = &wayland_drm_interface, + [WLD_DRM] = &drm_wayland_impl, #endif #if WITH_WAYLAND_SHM - [WLD_SHM] = &wayland_shm_interface + [WLD_SHM] = &shm_wayland_impl, #endif }; @@ -93,10 +93,10 @@ EXPORT struct wld_context * wld_wayland_create_context (struct wl_display * display, enum wld_wayland_interface_id id, ...) { - struct wld_context * context = NULL; + struct wayland_context * context = NULL; struct wl_event_queue * queue; - va_list requested_interfaces; - bool interfaces_tried[ARRAY_LENGTH(interfaces)] = {0}; + va_list requested_impls; + bool impls_tried[ARRAY_LENGTH(impls)] = {0}; const char * interface_string; if (!(queue = wl_display_create_queue(display))) @@ -106,8 +106,8 @@ struct wld_context * wld_wayland_create_context { id = interface_id(interface_string); - if ((context = interfaces[id]->create_context(display, queue))) - return context; + if ((context = impls[id]->create_context(display, queue))) + return &context->base; fprintf(stderr, "Could not create context for Wayland interface '%s'\n", interface_string); @@ -115,42 +115,47 @@ struct wld_context * wld_wayland_create_context return NULL; } - va_start(requested_interfaces, id); + va_start(requested_impls, id); while (id >= 0) { - if (interfaces_tried[id] || !interfaces[id]) + if (impls_tried[id] || !impls[id]) continue; - if ((context = interfaces[id]->create_context(display, queue))) - break; + if ((context = impls[id]->create_context(display, queue))) + goto done; - interfaces_tried[id] = true; - id = va_arg(requested_interfaces, enum wld_wayland_interface_id); + impls_tried[id] = true; + id = va_arg(requested_impls, enum wld_wayland_interface_id); } - va_end(requested_interfaces); + va_end(requested_impls); - /* If the user specified WLD_ANY, try any remaining interfaces. */ + /* If the user specified WLD_ANY, try any remaining implementations. */ if (!context && id == WLD_ANY) { - for (id = 0; id < ARRAY_LENGTH(interfaces); ++id) + for (id = 0; id < ARRAY_LENGTH(impls); ++id) { - if (interfaces_tried[id] || !interfaces[id]) + if (impls_tried[id] || !impls[id]) continue; - if ((context = interfaces[id]->create_context(display, queue))) + if ((context = impls[id]->create_context(display, queue))) break; } } if (!context) { - DEBUG("Could not initialize any of the specified interfaces\n"); + DEBUG("Could not initialize any of the specified implementations\n"); return NULL; } - return context; + done: + context->impl = impls[id]; + context->display = display; + context->queue = queue; + + return &context->base; } EXPORT @@ -183,6 +188,14 @@ struct wld_surface * wld_wayland_create_surface(struct wld_context * context, return NULL; } +EXPORT +bool wld_wayland_has_format(struct wld_context * base, uint32_t format) +{ + struct wayland_context * context = (void *) base; + + return context->impl->has_format(base, format); +} + static bool buffer_export(struct wld_exporter * exporter, struct wld_buffer * buffer, uint32_t type, union wld_object * object) diff --git a/wayland.h b/wayland.h @@ -24,6 +24,7 @@ #ifndef WLD_WAYLAND_H #define WLD_WAYLAND_H +#include <stdbool.h> #include <stdint.h> struct wl_display; @@ -72,5 +73,12 @@ struct wld_surface * wld_wayland_create_surface(struct wld_context * context, uint32_t format, uint32_t flags, struct wl_surface * surface); +/** + * Check if the wayland implementation supports a particular pixel format. + * + * @see enum wld_format + */ +bool wld_wayland_has_format(struct wld_context * context, uint32_t format); + #endif