neuwld

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

commit a291d87fa7a34edd1206481e70bd227a0d96a1ca
parent b1a964a62d4dae378acc87045f1447092198c16f
Author: Michael Forney <mforney@mforney.org>
Date:   Fri, 19 Jul 2013 00:52:02 -0700

Only create single buffers in wayland-{drm,shm}

Diffstat:
Mwayland-drm.c | 36+++++++++++++++---------------------
Mwayland-drm.h | 6+++---
Mwayland-private.h | 5+++--
Mwayland-shm.c | 29+++++++++++------------------
Mwayland-shm.h | 6+++---
Mwayland.c | 39+++++++++++++++++++++++++++------------
Mwayland.h | 5+++--
7 files changed, 65 insertions(+), 61 deletions(-)

diff --git a/wayland-drm.c b/wayland-drm.c @@ -239,32 +239,26 @@ int wld_drm_get_fd(struct wld_drm_context * drm) } struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * drm, - struct wl_surface * surface, uint32_t width, uint32_t height, - uint32_t format) + enum wld_format format, + struct wl_buffer ** buffer) { - struct drm_drawable * drawable0, * drawable1; - uint32_t name0, name1, pitch0, pitch1; - struct wl_buffer * buffer0, * buffer1; + struct drm_drawable * drawable; - if (!wld_drm_has_format(drm, format)) + if (buffer && !wld_drm_has_format(drm, format)) return NULL; - drawable0 = (void *) drm->interface->create_drawable(drm->context, - width, height, format); - drawable1 = (void *) drm->interface->create_drawable(drm->context, - width, height, format); - - buffer0 = wl_drm_create_prime_buffer(drm->wl, drawable0->fd, width, height, - format, 0, drawable0->pitch, - 0, 0, 0, 0); - buffer1 = wl_drm_create_prime_buffer(drm->wl, drawable1->fd, width, height, - format, 0, drawable1->pitch, - 0, 0, 0, 0); - - return wld_wayland_create_drawable_from_buffers(surface, - buffer0, &drawable0->base, - buffer1, &drawable1->base); + drawable = (void *) drm->interface->create_drawable(drm->context, + width, height, format); + + if (buffer) + { + *buffer = wl_drm_create_prime_buffer(drm->wl, drawable->fd, + width, height, format, + 0, drawable->pitch, 0, 0, 0, 0); + } + + return &drawable->base; } void registry_global(void * data, struct wl_registry * registry, uint32_t name, diff --git a/wayland-drm.h b/wayland-drm.h @@ -33,7 +33,7 @@ enum wld_format; struct wl_display; struct wl_event_queue; -struct wl_surface; +struct wl_buffer; /** * Create a new drawable context which creates Wayland buffers through the @@ -64,9 +64,9 @@ int wld_drm_get_fd(struct wld_drm_context * context); * Create a new DRM drawable with the specified dimensions. */ struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * context, - struct wl_surface * surface, uint32_t width, uint32_t height, - enum wld_format format); + enum wld_format format, + struct wl_buffer ** buffer); #endif diff --git a/wayland-private.h b/wayland-private.h @@ -31,13 +31,14 @@ enum wld_format format; struct wl_display; struct wl_event_queue; +struct wl_buffer; typedef void * (* wayland_create_context_func_t)(struct wl_display * display, struct wl_event_queue * queue); typedef void (* wayland_destroy_context_func_t)(void * context); typedef struct wld_drawable * (* wayland_create_drawable_func_t) - (void * context, struct wl_surface * surface, - uint32_t width, uint32_t height, enum wld_format format); + (void * context, uint32_t width, uint32_t height, enum wld_format format, + struct wl_buffer ** buffer); struct wld_wayland_interface { diff --git a/wayland-shm.c b/wayland-shm.c @@ -152,9 +152,9 @@ bool wld_shm_has_format(struct wld_shm_context * shm, uint32_t format) } struct wld_drawable * wld_shm_create_drawable(struct wld_shm_context * shm, - struct wl_surface * surface, uint32_t width, uint32_t height, - uint32_t format) + enum wld_format format, + struct wl_buffer ** buffer) { char name[] = "/tmp/wld-XXXXXX"; uint32_t pitch = width * format_bytes_per_pixel(format); @@ -162,8 +162,7 @@ struct wld_drawable * wld_shm_create_drawable(struct wld_shm_context * shm, int fd; void * data; struct wl_shm_pool * pool; - struct wl_buffer * buffer0, * buffer1; - struct wld_drawable * drawable0, * drawable1; + struct wld_drawable * drawable; uint32_t shm_format = wayland_format(format); fd = mkostemp(name, O_CLOEXEC); @@ -173,30 +172,24 @@ struct wld_drawable * wld_shm_create_drawable(struct wld_shm_context * shm, unlink(name); - if (ftruncate(fd, size * 2) < 0) + if (ftruncate(fd, size) < 0) goto error1; - data = mmap(NULL, size * 2, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (data == MAP_FAILED) goto error1; - pool = wl_shm_create_pool(shm->wl, fd, size * 2); - buffer0 = wl_shm_pool_create_buffer(pool, 0, width, height, pitch, - shm_format); - buffer1 = wl_shm_pool_create_buffer(pool, size, width, height, pitch, + drawable = wld_pixman_create_drawable(shm->pixman_context, width, height, + data, pitch, format); + + pool = wl_shm_create_pool(shm->wl, fd, size); + *buffer = wl_shm_pool_create_buffer(pool, 0, width, height, pitch, shm_format); wl_shm_pool_destroy(pool); close(fd); - drawable0 = wld_pixman_create_drawable(shm->pixman_context, width, height, - data, pitch, format); - drawable1 = wld_pixman_create_drawable(shm->pixman_context, width, height, - data + size, pitch, format); - - return wld_wayland_create_drawable_from_buffers(surface, - buffer0, drawable0, - buffer1, drawable1); + return drawable; error1: close(fd); diff --git a/wayland-shm.h b/wayland-shm.h @@ -33,7 +33,7 @@ enum wld_format; struct wl_display; struct wl_event_queue; -struct wl_surface; +struct wl_buffer; /** * Create a new drawable context which creates Wayland buffers through the @@ -59,9 +59,9 @@ bool wld_shm_has_format(struct wld_shm_context * context, * Create a new SHM drawable with the specified dimensions. */ struct wld_drawable * wld_shm_create_drawable(struct wld_shm_context * context, - struct wl_surface * surface, uint32_t width, uint32_t height, - enum wld_format format); + enum wld_format format, + struct wl_buffer ** buffer); #endif diff --git a/wayland.c b/wayland.c @@ -41,6 +41,8 @@ struct wld_wayland_context struct wayland_drawable { struct wld_drawable base; + + struct wld_wayland_context * context; struct wl_surface * surface; struct { @@ -175,20 +177,32 @@ struct wld_drawable * wld_wayland_create_drawable (struct wld_wayland_context * context, struct wl_surface * surface, uint32_t width, uint32_t height, enum wld_format format) { - return context->interface->create_drawable(context->context, surface, - width, height, format); + struct wayland_drawable * wayland; + struct wld_drawable * drawables[2]; + struct wl_buffer * buffers[2]; + + drawables[0] = context->interface->create_drawable + (context->context, width, height, format, &buffers[0]); + drawables[1] = context->interface->create_drawable + (context->context, width, height, format, &buffers[1]); + + wayland = (void *) wld_wayland_create_drawable_from_buffers + (surface, buffers, drawables); + + wayland->context = context; + + return &wayland->base; } struct wld_drawable * wld_wayland_create_drawable_from_buffers (struct wl_surface * surface, - struct wl_buffer * buffer0, struct wld_drawable * drawable0, - struct wl_buffer * buffer1, struct wld_drawable * drawable1) + struct wl_buffer * buffers[], struct wld_drawable * drawables[]) { struct wayland_drawable * wayland; uint32_t * data; - if (drawable0->width != drawable1->width - || drawable0->height != drawable1->height) + if (drawables[0]->width != drawables[1]->width + || drawables[0]->height != drawables[1]->height) { DEBUG("Drawables aren't the same dimensions\n"); return NULL; @@ -199,16 +213,17 @@ struct wld_drawable * wld_wayland_create_drawable_from_buffers if (!wayland) return NULL; - wayland->buffers[0].buffer = buffer0; - wayland->buffers[1].buffer = buffer1; - wayland->buffers[0].drawable = drawable0; - wayland->buffers[1].drawable = drawable1; + wayland->context = NULL; + wayland->buffers[0].buffer = buffers[0]; + wayland->buffers[1].buffer = buffers[1]; + wayland->buffers[0].drawable = drawables[0]; + wayland->buffers[1].drawable = drawables[1]; wayland->front_buffer = 0; wayland->surface = surface; wayland->base.interface = &wayland_draw; - wayland->base.width = drawable0->width; - wayland->base.height = drawable0->height; + wayland->base.width = drawables[0]->width; + wayland->base.height = drawables[0]->height; return &wayland->base; } diff --git a/wayland.h b/wayland.h @@ -81,13 +81,14 @@ struct wld_drawable * wld_wayland_create_drawable * Create a new Wayland drawable for the given surface, using the given buffers * and drawables as backing for the surface. * + * You must pass exactly two buffers and drawables + * * This method does not require a Wayland context to be created because buffers * and drawables are passed to it explicitly. */ struct wld_drawable * wld_wayland_create_drawable_from_buffers (struct wl_surface * surface, - struct wl_buffer * buffer0, struct wld_drawable * drawable0, - struct wl_buffer * buffer1, struct wld_drawable * drawable1); + struct wl_buffer * buffers[], struct wld_drawable * drawables[]); #endif