intel: Support EGL_MESA_image_drm
authorKristian Høgsberg <krh@bitplanet.net>
Mon, 7 Jun 2010 00:39:19 +0000 (20:39 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 25 Aug 2010 13:17:48 +0000 (09:17 -0400)
src/mesa/drivers/dri/intel/intel_regions.c
src/mesa/drivers/dri/intel/intel_regions.h
src/mesa/drivers/dri/intel/intel_screen.c

index 57ffe611d1b91e84dd83ca4880dd465916ddc0a3..e87e29462c38934794bad322af12160ceb4b5d60 100644 (file)
@@ -192,6 +192,22 @@ intel_region_alloc(struct intel_screen *screen,
                                      aligned_pitch / cpp, tiling, buffer);
 }
 
+GLboolean
+intel_region_flink(struct intel_region *region, uint32_t *name)
+{
+   if (region->name == 0) {
+      if (drm_intel_bo_flink(region->buffer, &region->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_screen *screen,
                              GLuint cpp,
index c88395be18087c6277162e74e2e510e363e51d43..8464a5e937d205fdf6c077e0cadfee4e90bd9d68 100644 (file)
@@ -88,6 +88,9 @@ intel_region_alloc_for_handle(struct intel_screen *screen,
                              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);
 
index 643e7762b0553433f2388a08f68a9df15f6772d1..0a542a7303d71fcf988b877cdbba4cf8bfbdc17a 100644 (file)
@@ -207,11 +207,79 @@ intel_destroy_image(__DRIimage *image)
     FREE(image);
 }
 
+static __DRIimage *
+intel_create_image(__DRIscreen *screen,
+                  int width, int height, int format,
+                  unsigned int use,
+                  void *loaderPrivate)
+{
+   __DRIimage *image;
+   struct intel_screen *intelScreen = screen->private;
+   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(intelScreen, 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, (uint32_t *) 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[] = {