neuwld

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

commit d8a80f70d6f54059d1e2e302dc00ec60a14b9d52
parent 2cf1a72198a0c3591df691cc6a005220a81cdb3e
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 14 Jan 2014 01:42:35 -0800

Style

Diffstat:
Mdumb.c | 15++++++---------
Mintel.c | 1+
Mwayland-drm.c | 50+++++++++++++++++++++++---------------------------
Mwayland-shm.c | 18++++++++----------
4 files changed, 38 insertions(+), 46 deletions(-)

diff --git a/dumb.c b/dumb.c @@ -105,19 +105,16 @@ struct wld_buffer * context_create_buffer(struct wld_context * base, { struct dumb_context * context = dumb_context(base); struct wld_buffer * buffer; - struct drm_mode_create_dumb create_dumb_arg = { + struct drm_mode_create_dumb create_dumb = { .height = height, .width = width, .bpp = format_bytes_per_pixel(format) * 8, }; - int ret; - ret = drmIoctl(context->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb_arg); - - if (ret != 0) + if (drmIoctl(context->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb) != 0) goto error0; buffer = new_buffer(context, width, height, format, - create_dumb_arg.handle, create_dumb_arg.pitch); + create_dumb.handle, create_dumb.pitch); if (!buffer) goto error1; @@ -126,11 +123,11 @@ struct wld_buffer * context_create_buffer(struct wld_context * base, error1: { - struct drm_mode_destroy_dumb destroy_dumb_arg = { - .handle = create_dumb_arg.handle + struct drm_mode_destroy_dumb destroy_dumb = { + .handle = create_dumb.handle }; - drmIoctl(context->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb_arg); + drmIoctl(context->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb); } error0: return NULL; diff --git a/intel.c b/intel.c @@ -60,6 +60,7 @@ IMPL(intel, context) IMPL(intel, renderer) IMPL(intel, buffer) +/**** DRM driver ****/ bool driver_device_supported(uint32_t vendor_id, uint32_t device_id) { return vendor_id == 0x8086; diff --git a/wayland-drm.c b/wayland-drm.c @@ -22,9 +22,9 @@ */ #include "wayland-drm.h" -#include "protocol/wayland-drm-client-protocol.h" #include "wayland.h" #include "drm.h" +#include "protocol/wayland-drm-client-protocol.h" #include "wayland-private.h" #include "wld-private.h" #include "drm-private.h" @@ -84,48 +84,44 @@ EXPORT struct wld_context * wld_wayland_drm_create_context(struct wl_display * display, struct wl_event_queue * queue) { - struct drm_context * drm; - - drm = malloc(sizeof *drm); + struct drm_context * context; - if (!drm) + if (!(context = malloc(sizeof *context))) goto error0; - context_initialize(&drm->base, &context_impl); - drm->wl = NULL; - drm->fd = -1; - drm->capabilities = 0; - wl_array_init(&drm->formats); + context_initialize(&context->base, &context_impl); + context->wl = NULL; + context->fd = -1; + context->capabilities = 0; + wl_array_init(&context->formats); - drm->registry = wl_display_get_registry(display); - - if (!drm->registry) + if (!(context->registry = wl_display_get_registry(display))) goto error1; - wl_registry_add_listener(drm->registry, &registry_listener, drm); - wl_proxy_set_queue((struct wl_proxy *) drm->registry, queue); + wl_registry_add_listener(context->registry, &registry_listener, context); + wl_proxy_set_queue((struct wl_proxy *) context->registry, queue); /* Wait for wl_drm global. */ wayland_roundtrip(display, queue); - if (!drm->wl) + if (!context->wl) { DEBUG("No wl_drm global\n"); goto error2; } - wl_drm_add_listener(drm->wl, &drm_listener, drm); + wl_drm_add_listener(context->wl, &drm_listener, context); /* Wait for DRM capabilities and device. */ wayland_roundtrip(display, queue); - if (!(drm->capabilities & WL_DRM_CAPABILITY_PRIME)) + if (!(context->capabilities & WL_DRM_CAPABILITY_PRIME)) { DEBUG("No PRIME support\n"); goto error3; } - if (drm->fd == -1) + if (context->fd == -1) { DEBUG("No DRM device\n"); goto error3; @@ -134,29 +130,29 @@ struct wld_context * wld_wayland_drm_create_context(struct wl_display * display, /* Wait for DRM authentication. */ wayland_roundtrip(display, queue); - if (!drm->authenticated) + if (!context->authenticated) { DEBUG("DRM authentication failed\n"); goto error4; } - if (!(drm->driver_context = wld_drm_create_context(drm->fd))) + if (!(context->driver_context = wld_drm_create_context(context->fd))) { DEBUG("Couldn't initialize context for DRM device\n"); goto error4; } - return &drm->base; + return &context->base; error4: - close(drm->fd); + close(context->fd); error3: - wl_drm_destroy(drm->wl); + wl_drm_destroy(context->wl); error2: - wl_registry_destroy(drm->registry); + wl_registry_destroy(context->registry); error1: - wl_array_release(&drm->formats); - free(drm); + wl_array_release(&context->formats); + free(context); error0: return NULL; } diff --git a/wayland-shm.c b/wayland-shm.c @@ -29,11 +29,11 @@ #include "wld-private.h" #include "pixman.h" +#include <fcntl.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> -#include <fcntl.h> #include <sys/mman.h> +#include <unistd.h> #include <wayland-client.h> struct shm_context @@ -69,7 +69,7 @@ const static struct wl_shm_listener shm_listener = { .format = &shm_format, }; -static inline uint32_t wayland_format(uint32_t format) +static inline uint32_t format_wld_to_shm(uint32_t format) { switch (format) { @@ -158,10 +158,8 @@ struct wld_buffer * context_create_buffer(struct wld_context * base, struct wld_exporter * exporter; char name[] = "/tmp/wld-XXXXXX"; uint32_t pitch = width * format_bytes_per_pixel(format); - uint32_t size = height * pitch; + size_t size = pitch * height; int fd; - void * data; - uint32_t shm_format = wayland_format(format); union wld_object object; struct wl_shm_pool * pool; struct wl_buffer * wl; @@ -176,12 +174,11 @@ struct wld_buffer * context_create_buffer(struct wld_context * base, if (ftruncate(fd, size) < 0) goto error1; - data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + object.ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (data == MAP_FAILED) + if (object.ptr == MAP_FAILED) goto error1; - object.ptr = data; buffer = wld_import_buffer(wld_pixman_context, WLD_OBJECT_DATA, object, width, height, format, pitch); @@ -191,7 +188,8 @@ struct wld_buffer * context_create_buffer(struct wld_context * base, if (!(pool = wl_shm_create_pool(context->wl, fd, size))) goto error3; - wl = wl_shm_pool_create_buffer(pool, 0, width, height, pitch, shm_format); + wl = wl_shm_pool_create_buffer(pool, 0, width, height, pitch, + format_wld_to_shm(format)); wl_shm_pool_destroy(pool); if (!wl)