[Mesa-dev] [PATCH 6/6] intel: Add support for MESA_drm_image
Kristian Høgsberg
krh at bitplanet.net
Fri Jun 4 06:46:28 PDT 2010
---
src/mesa/drivers/dri/intel/intel_regions.c | 17 +++++++
src/mesa/drivers/dri/intel/intel_regions.h | 3 +
src/mesa/drivers/dri/intel/intel_screen.c | 68 ++++++++++++++++++++++++++++
3 files changed, 88 insertions(+), 0 deletions(-)
diff --git a/src/mesa/drivers/dri/intel/intel_regions.c b/src/mesa/drivers/dri/intel/intel_regions.c
index 8cdeaf6..f2ea14b 100644
--- a/src/mesa/drivers/dri/intel/intel_regions.c
+++ b/src/mesa/drivers/dri/intel/intel_regions.c
@@ -190,10 +190,27 @@ intel_region_alloc(struct intel_context *intel,
region = intel_region_alloc_internal(intel, cpp, width, height,
aligned_pitch / cpp, buffer);
region->tiling = tiling;
+ region->screen = intel->intelScreen;
return region;
}
+GLboolean
+intel_region_flink(struct intel_region *region, uint32_t *name)
+{
+ if (region->name == 0) {
+ if (drm_intel_bo_flink(region->buffer, ®ion->name))
+ return GL_FALSE;
+
+ _mesa_HashInsert(region->screen->named_regions,
+ region->name, region);
+ }
+
+ *name = region->name;
+
+ return GL_TRUE;
+}
+
struct intel_region *
intel_region_alloc_for_handle(struct intel_context *intel,
GLuint cpp,
diff --git a/src/mesa/drivers/dri/intel/intel_regions.h b/src/mesa/drivers/dri/intel/intel_regions.h
index 2459c9a..ef86e73 100644
--- a/src/mesa/drivers/dri/intel/intel_regions.h
+++ b/src/mesa/drivers/dri/intel/intel_regions.h
@@ -87,6 +87,9 @@ intel_region_alloc_for_handle(struct intel_context *intel,
GLuint width, GLuint height, GLuint pitch,
unsigned int handle, const char *name);
+GLboolean
+intel_region_flink(struct intel_region *region, uint32_t *name);
+
void intel_region_reference(struct intel_region **dst,
struct intel_region *src);
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index 15a465c..0089832 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -206,11 +206,79 @@ intel_destroy_image(__DRIimage *image)
FREE(image);
}
+static __DRIimage *
+intel_create_image(__DRIcontext *context,
+ int width, int height, int format,
+ unsigned int use,
+ void *loaderPrivate)
+{
+ __DRIimage *image;
+ struct intel_context *intel = context->driverPrivate;
+ int cpp;
+
+ image = CALLOC(sizeof *image);
+ if (image == NULL)
+ return NULL;
+
+ switch (format) {
+ case __DRI_IMAGE_FORMAT_RGB565:
+ image->format = MESA_FORMAT_RGB565;
+ image->internal_format = GL_RGB;
+ image->data_type = GL_UNSIGNED_BYTE;
+ break;
+ case __DRI_IMAGE_FORMAT_XRGB8888:
+ image->format = MESA_FORMAT_XRGB8888;
+ image->internal_format = GL_RGB;
+ image->data_type = GL_UNSIGNED_BYTE;
+ break;
+ case __DRI_IMAGE_FORMAT_ARGB8888:
+ image->format = MESA_FORMAT_ARGB8888;
+ image->internal_format = GL_RGBA;
+ image->data_type = GL_UNSIGNED_BYTE;
+ break;
+ default:
+ free(image);
+ return NULL;
+ }
+
+ image->data = loaderPrivate;
+ cpp = _mesa_get_format_bytes(image->format);
+
+ image->region =
+ intel_region_alloc(intel, I915_TILING_NONE,
+ cpp, width, height, GL_TRUE);
+ if (image->region == NULL) {
+ FREE(image);
+ return NULL;
+ }
+
+ return image;
+}
+
+static GLboolean
+intel_query_image(__DRIimage *image, int attrib, int *value)
+{
+ switch (attrib) {
+ case __DRI_IMAGE_ATTRIB_STRIDE:
+ *value = image->region->pitch * image->region->cpp;
+ return GL_TRUE;
+ case __DRI_IMAGE_ATTRIB_HANDLE:
+ *value = image->region->buffer->handle;
+ return GL_TRUE;
+ case __DRI_IMAGE_ATTRIB_NAME:
+ return intel_region_flink(image->region, (int *) value);
+ default:
+ return GL_FALSE;
+ }
+}
+
static struct __DRIimageExtensionRec intelImageExtension = {
{ __DRI_IMAGE, __DRI_IMAGE_VERSION },
intel_create_image_from_name,
intel_create_image_from_renderbuffer,
intel_destroy_image,
+ intel_create_image,
+ intel_query_image
};
static const __DRIextension *intelScreenExtensions[] = {
--
1.7.1
More information about the mesa-dev
mailing list