neuwld

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

commit 22f8d81948c8f73e0dcbecc28bb7b5ab06d32622
parent ea660218241c7ff45c491420f68dc8495858afa8
Author: Michael Forney <mforney@mforney.org>
Date:   Mon, 13 Jan 2014 14:58:35 -0800

drm: Use exporters

Diffstat:
Mdrm-private.h | 10----------
Mdrm.c | 12------------
Mdrm.h | 19+++----------------
Mdumb.c | 66+++++++++++++++++++++++++++++++++++++-----------------------------
Mintel.c | 40++++++++++++++++++++++++++++------------
Dinterface/drm_drawable.h | 74--------------------------------------------------------------------------
6 files changed, 68 insertions(+), 153 deletions(-)

diff --git a/drm-private.h b/drm-private.h @@ -26,9 +26,6 @@ #include "wld-private.h" -typedef int (* drm_export_func_t)(struct wld_drawable * drawable); -typedef uint32_t (* drm_get_handle_func_t)(struct wld_drawable * drawable); - struct drm_driver { const char * name; @@ -36,13 +33,6 @@ struct drm_driver struct wld_context * (* create_context)(int drm_fd); }; -struct drm_drawable_impl -{ - struct wld_drawable_impl base; - drm_export_func_t export; - drm_get_handle_func_t get_handle; -}; - #if WITH_DRM_INTEL extern const struct drm_driver intel_drm_driver; #endif diff --git a/drm.c b/drm.c @@ -88,15 +88,3 @@ bool wld_drm_is_dumb(struct wld_context * context) return context->impl == dumb_context_impl; } -EXPORT -int wld_drm_export(struct wld_drawable * drawable) -{ - return ((struct drm_drawable_impl *) drawable->impl)->export(drawable); -} - -EXPORT -uint32_t wld_drm_get_handle(struct wld_drawable * drawable) -{ - return ((struct drm_drawable_impl *) drawable->impl)->get_handle(drawable); -} - diff --git a/drm.h b/drm.h @@ -29,8 +29,9 @@ enum wld_drm_object_type { - WLD_DRM_OBJECT_PRIME_FD = 0x00010000, - WLD_DRM_OBJECT_GEM_NAME = 0x00010001 + WLD_DRM_OBJECT_HANDLE = 0x00010000, + WLD_DRM_OBJECT_PRIME_FD = 0x00010001, + WLD_DRM_OBJECT_GEM_NAME = 0x00010002 }; /** @@ -40,19 +41,5 @@ struct wld_context * wld_drm_create_context(int fd); bool wld_drm_is_dumb(struct wld_context * context); -/** - * Export a DRM drawable to a PRIME file descriptor. - * - * @return A PRIME file descriptor for this drawable - */ -int wld_drm_export(struct wld_drawable * drawable); - -/** - * Get the handle of a DRM drawable. - * - * This can be used with various DRM ioctls. - */ -uint32_t wld_drm_get_handle(struct wld_drawable * drawable); - #endif diff --git a/dumb.c b/dumb.c @@ -42,27 +42,19 @@ struct dumb_context struct dumb_drawable { struct pixman_drawable pixman; + struct wld_exporter exporter; struct dumb_context * context; uint32_t handle; }; #define DRM_DRIVER_NAME dumb #include "interface/context.h" +#include "interface/exporter.h" #include "interface/drm.h" IMPL(dumb, context) const struct wld_context_impl * dumb_context_impl = &context_impl; -/* DRM drawable */ -static int drawable_export(struct wld_drawable * drawable); -static uint32_t drawable_get_handle(struct wld_drawable * drawable); - -static struct drm_drawable_impl drawable_impl = { - .export = &drawable_export, - .get_handle = &drawable_get_handle -}; -static bool draw_initialized; - bool driver_device_supported(uint32_t vendor_id, uint32_t device_id) { return true; @@ -81,12 +73,6 @@ struct wld_context * driver_create_context(int drm_fd) context_initialize(&context->base, &context_impl); context->fd = drm_fd; - if (!draw_initialized) - { - drawable_impl.base = *pixman_drawable_impl; - draw_initialized = true; - } - return &context->base; error1: @@ -126,9 +112,10 @@ static struct wld_drawable * new_drawable(struct dumb_context * context, goto error2; } - drawable->pixman.base.impl = &drawable_impl.base; drawable->context = context; drawable->handle = handle; + exporter_initialize(&drawable->exporter, &exporter_impl); + drawable_add_exporter(&drawable->pixman.base, &drawable->exporter); return &drawable->pixman.base; @@ -215,24 +202,45 @@ void context_destroy(struct wld_context * base) free(context); } -static int drawable_export(struct wld_drawable * drawable) +/**** Exporter ****/ + +bool exporter_export(struct wld_exporter * exporter, struct wld_drawable * base, + uint32_t type, union wld_object * object) { - struct dumb_drawable * dumb = (void *) drawable; - int prime_fd, ret; + struct dumb_drawable * drawable = (void *) base; - ret = drmPrimeHandleToFD(dumb->context->fd, dumb->handle, - DRM_CLOEXEC, &prime_fd); + switch (type) + { + case WLD_DRM_OBJECT_HANDLE: + object->u32 = drawable->handle; + return true; + case WLD_DRM_OBJECT_PRIME_FD: + if (drmPrimeHandleToFD(drawable->context->fd, drawable->handle, + DRM_CLOEXEC, &object->i) != 0) + { + return false; + } - if (ret != 0) - return -1; + return true; + case WLD_DRM_OBJECT_GEM_NAME: + { + struct drm_gem_flink flink = { .handle = drawable->handle }; - return prime_fd; + if (drmIoctl(drawable->context->fd, DRM_IOCTL_GEM_FLINK, + &flink) != 0) + { + return false; + } + + object->u32 = flink.name; + return true; + } + default: + return false; + } } -static uint32_t drawable_get_handle(struct wld_drawable * drawable) +void exporter_destroy(struct wld_exporter * exporter) { - struct dumb_drawable * dumb = (void *) drawable; - - return dumb->handle; } diff --git a/intel.c b/intel.c @@ -40,6 +40,7 @@ struct intel_context struct intel_drawable { struct wld_drawable base; + struct wld_exporter exporter; struct intel_context * context; drm_intel_bo * bo; @@ -47,10 +48,12 @@ struct intel_drawable }; #include "interface/context.h" +#include "interface/drawable.h" +#include "interface/exporter.h" #define DRM_DRIVER_NAME intel #include "interface/drm.h" -#include "interface/drm_drawable.h" IMPL(intel, context) +IMPL(intel, drawable) bool driver_device_supported(uint32_t vendor_id, uint32_t device_id) { @@ -96,10 +99,12 @@ static struct intel_drawable * new_drawable(struct intel_context * context, if (!(intel = malloc(sizeof *intel))) return NULL; - drawable_initialize(&intel->base, &drawable_impl.base, + drawable_initialize(&intel->base, &drawable_impl, width, height, format, 0); intel->context = context; intel->virtual = NULL; + exporter_initialize(&intel->exporter, &exporter_impl); + drawable_add_exporter(&intel->base, &intel->exporter); return intel; } @@ -313,20 +318,31 @@ void drawable_destroy(struct wld_drawable * drawable) free(intel); } -int drawable_export(struct wld_drawable * drawable) +/**** Exporter ****/ +bool exporter_export(struct wld_exporter * exporter, struct wld_drawable * base, + uint32_t type, union wld_object * object) { - struct intel_drawable * intel = (void *) drawable; - int prime_fd; - - drm_intel_bo_gem_export_to_prime(intel->bo, &prime_fd); + struct intel_drawable * drawable = intel_drawable(base); - return prime_fd; + switch (type) + { + case WLD_DRM_OBJECT_HANDLE: + object->u32 = drawable->bo->handle; + return true; + case WLD_DRM_OBJECT_PRIME_FD: + if (drm_intel_bo_gem_export_to_prime(drawable->bo, &object->i) != 0) + return false; + return true; + case WLD_DRM_OBJECT_GEM_NAME: + if (drm_intel_bo_flink(drawable->bo, &object->u32) != 0) + return false; + return true; + default: + return false; + } } -uint32_t drawable_get_handle(struct wld_drawable * drawable) +void exporter_destroy(struct wld_exporter * exporter) { - struct intel_drawable * intel = (void *) drawable; - - return intel->bo->handle; } diff --git a/interface/drm_drawable.h b/interface/drm_drawable.h @@ -1,74 +0,0 @@ -/* wld: interface/drm_drawable.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. - */ - -static void drawable_fill_rectangle(struct wld_drawable * drawable, - uint32_t color, int32_t x, int32_t y, - uint32_t width, uint32_t height); -static void drawable_copy_rectangle(struct wld_drawable * src, - struct wld_drawable * dst, - int32_t src_x, int32_t src_y, - int32_t dst_x, int32_t dst_y, - uint32_t width, uint32_t height); -#ifdef DRAWABLE_IMPLEMENTS_REGION -static void drawable_fill_region(struct wld_drawable * drawable, uint32_t color, - pixman_region32_t * region); -static void drawable_copy_region(struct wld_drawable * src, - struct wld_drawable * drawable, - pixman_region32_t * region, - int32_t dst_x, int32_t dst_y); -#endif -static void drawable_draw_text(struct wld_drawable * drawable, - struct font * font, uint32_t color, - int32_t x, int32_t y, - const char * text, int32_t length, - struct wld_extents * extents); -static void drawable_write(struct wld_drawable * drawable, - const void * data, size_t size); -static pixman_image_t * drawable_map(struct wld_drawable * drawable); -static void drawable_flush(struct wld_drawable * drawable); -static void drawable_destroy(struct wld_drawable * drawable); - -static int drawable_export(struct wld_drawable * drawable); -static uint32_t drawable_get_handle(struct wld_drawable * drawable); - -static const struct drm_drawable_impl drawable_impl = { - .base = { - .fill_rectangle = &drawable_fill_rectangle, - .copy_rectangle = &drawable_copy_rectangle, -#ifdef DRAWABLE_IMPLEMENTS_REGION - .fill_region = &drawable_fill_region, - .copy_region = &drawable_copy_region, -#else - .fill_region = &default_fill_region, - .copy_region = &default_copy_region, -#endif - .draw_text = &drawable_draw_text, - .write = &drawable_write, - .map = &drawable_map, - .flush = &drawable_flush, - .destroy = &drawable_destroy - }, - .export = &drawable_export, - .get_handle = &drawable_get_handle -}; -