neuwld

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

commit 17319a10de5214484243a04b957fb0cdc51f61dc
parent 50e7d711ba84881a2751175d66ba677f6035c4c7
Author: Michael Forney <mforney@mforney.org>
Date:   Thu,  5 Sep 2013 01:59:00 -0700

drm: Add buffer import support

Diffstat:
Mdrm-private.h | 8++++++++
Mdrm.c | 26++++++++++++++++++++++++++
Mdrm.h | 19+++++++++++++++++++
Mintel.c | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
4 files changed, 115 insertions(+), 10 deletions(-)

diff --git a/drm-private.h b/drm-private.h @@ -32,6 +32,12 @@ 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 struct drm_drawable * (* drm_import_func_t) + (void * context, uint32_t width, uint32_t height, uint32_t format, + int prime_fd, unsigned long pitch); +typedef struct drm_drawable * (* drm_import_gem_func_t) + (void * context, uint32_t width, uint32_t height, uint32_t format, + uint32_t gem_name, unsigned long pitch); typedef int (* drm_export_func_t)(struct drm_drawable * drawable); struct wld_drm_interface @@ -40,6 +46,8 @@ 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_import_func_t import; + drm_import_gem_func_t import_gem; drm_export_func_t export; }; diff --git a/drm.c b/drm.c @@ -130,6 +130,32 @@ struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * drm, return finish_drawable(drm, drawable); } +struct wld_drawable * wld_drm_import(struct wld_drm_context * drm, + uint32_t width, uint32_t height, + uint32_t format, + int prime_fd, unsigned long pitch) +{ + struct drm_drawable * drawable; + + drawable = drm->interface->import(drm->context, width, height, format, + prime_fd, pitch); + + return finish_drawable(drm, drawable); +} + +struct wld_drawable * wld_drm_import_gem(struct wld_drm_context * drm, + uint32_t width, uint32_t height, + uint32_t format, + uint32_t gem_name, unsigned long pitch) +{ + struct drm_drawable * drawable; + + drawable = drm->interface->import_gem(drm->context, width, height, format, + gem_name, pitch); + + return finish_drawable(drm, drawable); +} + int wld_drm_export(struct wld_drawable * drawable) { struct drm_drawable * drm_drawable = (void *) drawable; diff --git a/drm.h b/drm.h @@ -47,6 +47,25 @@ struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * drm, uint32_t format); /** + * Create a new DRM drawable by importing a PRIME file descriptor. + */ +struct wld_drawable * wld_drm_import(struct wld_drm_context * context, + uint32_t width, uint32_t height, + uint32_t format, + int prime_fd, unsigned long pitch); + +/** + * Create a new DRM drawable by importing a GEM name. + * + * This is provided for compatibility with clients that don't support PRIME. + * You should use wld_drm_import_drawable and PRIME if possible. + */ +struct wld_drawable * wld_drm_import_gem(struct wld_drm_context * context, + uint32_t width, uint32_t height, + uint32_t format, uint32_t gem_name, + unsigned long pitch); + +/** * Export a DRM drawable to a PRIME file descriptor. * * @return A PRIME file descriptor for this drawable diff --git a/intel.c b/intel.c @@ -72,6 +72,12 @@ 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 struct drm_drawable * intel_import + (struct wld_intel_context * context, uint32_t width, uint32_t height, + uint32_t format, int prime_fd, unsigned long pitch); +static struct drm_drawable * intel_import_gem + (struct wld_intel_context * context, uint32_t width, uint32_t height, + uint32_t format, uint32_t gem_name, unsigned long pitch); static int intel_export(struct drm_drawable * drawable); const static struct wld_draw_interface intel_draw = { @@ -89,6 +95,8 @@ 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, + .import = (drm_import_func_t) &intel_import, + .import_gem = (drm_import_gem_func_t) &intel_import_gem, .export = (drm_export_func_t) &intel_export, }; @@ -118,26 +126,70 @@ void intel_destroy_context(struct wld_intel_context * context) free(context); } -struct drm_drawable * intel_create_drawable - (struct wld_intel_context * context, uint32_t width, uint32_t height, - uint32_t format) +static struct intel_drawable * new_drawable(struct wld_intel_context * context, + uint32_t width, uint32_t height) { struct intel_drawable * intel; - uint32_t tiling_mode = I915_TILING_X, pitch; - intel = malloc(sizeof *intel); - - if (!intel) + if (!(intel = malloc(sizeof *intel))) return NULL; intel->drm.base.interface = &intel_draw; intel->drm.base.width = width; intel->drm.base.height = height; - intel->context = context; + + return intel; +} + +struct drm_drawable * intel_create_drawable + (struct wld_intel_context * context, uint32_t width, uint32_t height, + uint32_t format) +{ + struct intel_drawable * intel; + uint32_t tiling_mode = I915_TILING_X; + + if (!(intel = new_drawable(context, width, height))) + return NULL; + intel->bo = drm_intel_bo_alloc_tiled(context->bufmgr, "drawable", - width, height, 4, - &tiling_mode, &intel->drm.base.pitch, 0); + width, height, 4, &tiling_mode, + &intel->drm.base.pitch, 0); + + return &intel->drm; +} + +struct drm_drawable * intel_import(struct wld_intel_context * context, + uint32_t width, uint32_t height, + uint32_t format, + int prime_fd, unsigned long pitch) +{ + struct intel_drawable * intel; + uint32_t size = width * height * 4; + + if (!(intel = new_drawable(context, width, height))) + return NULL; + + intel->drm.base.pitch = pitch; + intel->bo = drm_intel_bo_gem_create_from_prime(context->bufmgr, + prime_fd, size); + + return &intel->drm; +} + +struct drm_drawable * intel_import_gem(struct wld_intel_context * context, + uint32_t width, uint32_t height, + uint32_t format, + uint32_t gem_name, unsigned long pitch) +{ + struct intel_drawable * intel; + + if (!(intel = new_drawable(context, width, height))) + return NULL; + + intel->drm.base.pitch = pitch; + intel->bo = drm_intel_bo_gem_create_from_name(context->bufmgr, "drawable", + gem_name); return &intel->drm; }