From 4fddb2ba21add1c1968330e5224ecead59da3995 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Wed, 2 May 2012 15:30:13 -0400 Subject: gbm: Add gbm_bo_write entry point This new gbm entry point allows writing data into a gbm bo. The bo has to be created with the GBM_BO_USE_WRITE flag, and it's only required to work for GBM_BO_USE_CURSOR_64X64 bos. The gbm API is designed to be the glue layer between EGL and KMS, but there was never a mechanism initialize a buffer suitable for use with KMS hw cursors. The hw cursor bo is typically not compatible with anything EGL can render to, and thus there's no way to get data into such a bo. gbm_bo_write() fills that gap while staying out of the efficient cpu->gpu pixel transfer business. Reviewed-by: Ander Conselvan de Oliveira --- src/mesa/drivers/dri/intel/intel_regions.h | 1 + src/mesa/drivers/dri/intel/intel_screen.c | 32 ++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) (limited to 'src/mesa/drivers') diff --git a/src/mesa/drivers/dri/intel/intel_regions.h b/src/mesa/drivers/dri/intel/intel_regions.h index 4ea970ad6d1..af3a059560a 100644 --- a/src/mesa/drivers/dri/intel/intel_regions.h +++ b/src/mesa/drivers/dri/intel/intel_regions.h @@ -132,6 +132,7 @@ void _mesa_copy_rect(GLubyte * dst, struct __DRIimageRec { struct intel_region *region; GLenum internal_format; + uint32_t usage; uint32_t dri_format; GLuint format; GLenum data_type; diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c index 9db56064bea..458178fe927 100644 --- a/src/mesa/drivers/dri/intel/intel_screen.c +++ b/src/mesa/drivers/dri/intel/intel_screen.c @@ -305,10 +305,16 @@ intel_create_image(__DRIscreen *screen, tiling = I915_TILING_NONE; } + /* We only support write for cursor drm images */ + if ((use & __DRI_IMAGE_USE_WRITE) && + use != (__DRI_IMAGE_USE_WRITE | __DRI_IMAGE_USE_CURSOR)) + return NULL; + image = CALLOC(sizeof *image); if (image == NULL) return NULL; + image->usage = use; image->dri_format = format; switch (format) { @@ -392,6 +398,7 @@ intel_dup_image(__DRIimage *orig_image, void *loaderPrivate) } image->internal_format = orig_image->internal_format; + image->usage = orig_image->usage; image->dri_format = orig_image->dri_format; image->format = orig_image->format; image->data_type = orig_image->data_type; @@ -408,18 +415,39 @@ intel_validate_usage(__DRIimage *image, unsigned int use) return GL_FALSE; } + /* We only support write for cursor drm images */ + if ((use & __DRI_IMAGE_USE_WRITE) && + use != (__DRI_IMAGE_USE_WRITE | __DRI_IMAGE_USE_CURSOR)) + return GL_FALSE; + return GL_TRUE; } +static int +intel_image_write(__DRIimage *image, const void *buf, size_t count) +{ + if (image->region->map_refcount) + return -1; + if (!(image->usage & __DRI_IMAGE_USE_WRITE)) + return -1; + + drm_intel_bo_map(image->region->bo, true); + memcpy(image->region->bo->virtual, buf, count); + drm_intel_bo_unmap(image->region->bo); + + return 0; +} + static struct __DRIimageExtensionRec intelImageExtension = { - { __DRI_IMAGE, 3 }, + { __DRI_IMAGE, 4 }, intel_create_image_from_name, intel_create_image_from_renderbuffer, intel_destroy_image, intel_create_image, intel_query_image, intel_dup_image, - intel_validate_usage + intel_validate_usage, + intel_image_write }; static const __DRIextension *intelScreenExtensions[] = { -- cgit v1.2.3