neuwld

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

commit 6b8e13e49537d0a56312058647f03b4a680c332a
parent 06017f56346b52237d9d04d862eca6d9930dc668
Author: Michael Forney <mforney@mforney.org>
Date:   Thu,  5 Sep 2013 01:36:30 -0700

Don't automatically export DRM drawable to PRIME

Diffstat:
Mdrm-private.h | 3++-
Mdrm.c | 7+++++++
Mdrm.h | 7+++++++
Mintel.c | 14++++++++++++--
Mwayland-drm.c | 19+++++++++----------
Mwayland-drm.h | 7-------
6 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/drm-private.h b/drm-private.h @@ -32,6 +32,7 @@ typedef void * (* drm_create_context_func_t)(int drm_fd); typedef void (* drm_destroy_context_func_t)(void * context); typedef struct drm_drawable * (* drm_create_drawable_func_t) (void * context, uint32_t width, uint32_t height, uint32_t format); +typedef int (* drm_export_func_t)(struct drm_drawable * drawable); struct wld_drm_interface { @@ -39,6 +40,7 @@ struct wld_drm_interface drm_create_context_func_t create_context; drm_destroy_context_func_t destroy_context; drm_create_drawable_func_t create_drawable; + drm_export_func_t export; }; struct wld_drm_context @@ -51,7 +53,6 @@ struct drm_drawable { struct wld_drawable base; struct wld_drm_context * drm; - int fd; }; _Static_assert(offsetof(struct drm_drawable, base) == 0, diff --git a/drm.c b/drm.c @@ -130,3 +130,10 @@ struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * drm, return finish_drawable(drm, drawable); } +int wld_drm_export(struct wld_drawable * drawable) +{ + struct drm_drawable * drm_drawable = (void *) drawable; + + return drm_drawable->drm->interface->export(drm_drawable); +} + diff --git a/drm.h b/drm.h @@ -46,5 +46,12 @@ struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * drm, uint32_t width, uint32_t height, uint32_t format); +/** + * 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); + #endif diff --git a/intel.c b/intel.c @@ -72,6 +72,7 @@ static bool intel_device_supported(uint32_t vendor_id, uint32_t device_id); static struct drm_drawable * intel_create_drawable (struct wld_intel_context * context, uint32_t width, uint32_t height, uint32_t format); +static int intel_export(struct drm_drawable * drawable); const static struct wld_draw_interface intel_draw = { .fill_rectangle = &intel_fill_rectangle, @@ -88,6 +89,7 @@ const struct wld_drm_interface intel_drm = { .create_context = (drm_create_context_func_t) &intel_create_context, .destroy_context = (drm_destroy_context_func_t) &intel_destroy_context, .create_drawable = (drm_create_drawable_func_t) &intel_create_drawable, + .export = (drm_export_func_t) &intel_export, }; bool intel_device_supported(uint32_t vendor_id, uint32_t device_id) @@ -136,11 +138,20 @@ struct drm_drawable * intel_create_drawable intel->bo = drm_intel_bo_alloc_tiled(context->bufmgr, "drawable", width, height, 4, &tiling_mode, &intel->drm.base.pitch, 0); - drm_intel_bo_gem_export_to_prime(intel->bo, &intel->drm.fd); return &intel->drm; } +int intel_export(struct drm_drawable * drawable) +{ + struct intel_drawable * intel = (void *) drawable; + int prime_fd; + + drm_intel_bo_gem_export_to_prime(intel->bo, &prime_fd); + + return prime_fd; +} + static void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color, int32_t x, int32_t y, uint32_t width, uint32_t height) @@ -245,7 +256,6 @@ static void intel_destroy(struct wld_drawable * drawable) { struct intel_drawable * intel = (void *) drawable; drm_intel_bo_unreference(intel->bo); - close(intel->drm.fd); free(intel); } diff --git a/wayland-drm.c b/wayland-drm.c @@ -192,29 +192,28 @@ struct wld_drawable * wld_wayland_drm_create_drawable (struct wld_wayland_drm_context * drm, uint32_t width, uint32_t height, enum wld_format format, struct wl_buffer ** buffer) { - struct drm_drawable * drawable; + struct wld_drawable * drawable; if (buffer && !wld_wayland_drm_has_format(drm, format)) return NULL; - drawable = (void *) wld_drm_create_drawable(&drm->context, width, height, format); + drawable = wld_drm_create_drawable(&drm->context, width, height, format); if (!drawable) return NULL; if (buffer) { - *buffer = wl_drm_create_prime_buffer(drm->wl, drawable->fd, + int prime_fd; + + prime_fd = wld_drm_export(drawable); + *buffer = wl_drm_create_prime_buffer(drm->wl, prime_fd, width, height, format, - 0, drawable->base.pitch, 0, 0, 0, 0); + 0, drawable->pitch, 0, 0, 0, 0); + close(prime_fd); } - return &drawable->base; -} - -int wld_wayland_drm_get_prime_fd(struct wld_drawable * drawable) -{ - return ((struct drm_drawable *)(void *) drawable)->fd; + return drawable; } void registry_global(void * data, struct wl_registry * registry, uint32_t name, diff --git a/wayland-drm.h b/wayland-drm.h @@ -67,12 +67,5 @@ struct wld_drawable * wld_wayland_drm_create_drawable (struct wld_wayland_drm_context * context, uint32_t width, uint32_t height, enum wld_format format, struct wl_buffer ** buffer); -/** - * Get a PRIME file descriptor for this DRM drawable. - * - * @note The drawable must have been created with wld_drm_create_drawable - */ -int wld_wayland_drm_get_prime_fd(struct wld_drawable * drawable); - #endif