neuwld

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

commit e9462f03b18072aad3ded11ee08de5b38d6d61f0
parent e2b75f7a994eafbe9c28af48f40f8bee61d77749
Author: Michael Forney <mforney@mforney.org>
Date:   Mon, 13 Jan 2014 18:24:33 -0800

dumb: Use map mechanism instead of pixman drawable

Diffstat:
Mdumb.c | 93++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Dpixman-private.h | 46----------------------------------------------
Mpixman.c | 23++++++-----------------
3 files changed, 63 insertions(+), 99 deletions(-)

diff --git a/dumb.c b/dumb.c @@ -21,10 +21,9 @@ * SOFTWARE. */ -#include "pixman.h" -#include "pixman-private.h" #include "drm-private.h" #include "drm.h" +#include "pixman.h" #include <fcntl.h> #include <unistd.h> @@ -41,17 +40,19 @@ struct dumb_context struct dumb_drawable { - struct pixman_drawable pixman; + struct wld_drawable base; struct wld_exporter exporter; struct dumb_context * context; uint32_t handle; }; -#define DRM_DRIVER_NAME dumb #include "interface/context.h" +#include "interface/drawable.h" #include "interface/exporter.h" +#define DRM_DRIVER_NAME dumb #include "interface/drm.h" IMPL(dumb, context) +IMPL(dumb, drawable) const struct wld_context_impl * dumb_context_impl = &context_impl; @@ -84,44 +85,18 @@ static struct wld_drawable * new_drawable(struct dumb_context * context, unsigned long pitch) { struct dumb_drawable * drawable; - struct drm_mode_map_dumb map_dumb_arg = { .handle = handle }; - void * data; - size_t size = pitch * height; - int ret; if (!(drawable = malloc(sizeof *drawable))) - goto error0; - - ret = drmIoctl(context->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_dumb_arg); - - if (ret != 0) - goto error1; - - data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, context->fd, - map_dumb_arg.offset); - - if (data == MAP_FAILED) - goto error1; - - if (!pixman_initialize_drawable(wld_pixman_context, &drawable->pixman, - width, height, data, pitch, format)) - { - goto error2; - } + return NULL; + drawable_initialize(&drawable->base, &drawable_impl, + width, height, format, pitch); drawable->context = context; drawable->handle = handle; exporter_initialize(&drawable->exporter, &exporter_impl); - drawable_add_exporter(&drawable->pixman.base, &drawable->exporter); + drawable_add_exporter(&drawable->base, &drawable->exporter); - return &drawable->pixman.base; - - error2: - munmap(data, size); - error1: - free(drawable); - error0: - return NULL; + return &drawable->base; } struct wld_drawable * context_create_drawable(struct wld_context * base, @@ -199,12 +174,58 @@ void context_destroy(struct wld_context * base) free(context); } +/**** Drawable ****/ + +bool drawable_map(struct wld_drawable * drawable) +{ + struct dumb_drawable * dumb = dumb_drawable(drawable); + struct drm_mode_map_dumb map_dumb = { .handle = dumb->handle }; + void * data; + + if (drmIoctl(dumb->context->fd, DRM_IOCTL_MODE_MAP_DUMB, + &map_dumb) != 0) + { + return false; + } + + data = mmap(NULL, drawable->pitch * drawable->height, PROT_READ | PROT_WRITE, + MAP_SHARED, dumb->context->fd, map_dumb.offset); + + if (data == MAP_FAILED) + return false; + + drawable->map.data = data; + + return true; +} + +bool drawable_unmap(struct wld_drawable * drawable) +{ + if (munmap(drawable->map.data, drawable->pitch * drawable->height) == -1) + return false; + + drawable->map.data = NULL; + + return true; +} + +void drawable_destroy(struct wld_drawable * drawable_base) +{ + struct dumb_drawable * drawable = dumb_drawable(drawable_base); + struct drm_mode_destroy_dumb destroy_dumb = { + .handle = drawable->handle + }; + + drmIoctl(drawable->context->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb); + free(drawable); +} + /**** Exporter ****/ bool exporter_export(struct wld_exporter * exporter, struct wld_drawable * base, uint32_t type, union wld_object * object) { - struct dumb_drawable * drawable = (void *) base; + struct dumb_drawable * drawable = dumb_drawable(base); switch (type) { diff --git a/pixman-private.h b/pixman-private.h @@ -1,46 +0,0 @@ -/* wld: pixman-private.h - * - * Copyright (c) 2013 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_PIXMAN_PRIVATE_H -#define WLD_PIXMAN_PRIVATE_H - -#include "wld.h" - -struct wld_context; - -struct pixman_drawable -{ - struct wld_drawable base; - pixman_image_t * image; - struct pixman_context * context; -}; - -extern const struct wld_drawable_impl * const pixman_drawable_impl; - -bool pixman_initialize_drawable - (struct wld_context * context, struct pixman_drawable * drawable, - uint32_t width, uint32_t height, - void * data, uint32_t pitch, uint32_t format); - -#endif - diff --git a/pixman.c b/pixman.c @@ -22,7 +22,6 @@ */ #include "pixman.h" -#include "pixman-private.h" #include "wld-private.h" #define PIXMAN_COLOR(c) { \ @@ -39,6 +38,12 @@ struct pixman_renderer pixman_glyph_cache_t * glyph_cache; }; +struct pixman_drawable +{ + struct wld_drawable base; + pixman_image_t * image; +}; + struct pixman_exporter { struct wld_exporter base; @@ -55,7 +60,6 @@ IMPL(pixman, drawable) IMPL(pixman, exporter) static struct wld_context context = { .impl = &context_impl }; -const struct wld_drawable_impl * const pixman_drawable_impl = &drawable_impl; EXPORT struct wld_context * wld_pixman_context = &context; @@ -81,21 +85,6 @@ struct wld_renderer * context_create_renderer(struct wld_context * context) return NULL; } -bool pixman_initialize_drawable - (struct wld_context * context, struct pixman_drawable * drawable, - uint32_t width, uint32_t height, - void * data, uint32_t pitch, uint32_t format) -{ - drawable_initialize(&drawable->base, &drawable_impl, - width, height, format, pitch); - drawable->context = (void *) context; - drawable->image = pixman_image_create_bits(format_wld_to_pixman(format), - width, height, - (uint32_t *) data, pitch); - - return drawable->image != NULL; -} - struct wld_drawable * new_drawable(pixman_image_t * image) { struct pixman_drawable * drawable;