[Mesa-dev] [PATCH 09/11] dri, i965: Add entry point for creating image from native handle

Ander Conselvan de Oliveira conselvan2 at gmail.com
Tue Apr 8 13:28:46 PDT 2014


From: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>

The native handle is a pointer to drm_intel_bo for the i965 driver.
---
 include/GL/internal/dri_interface.h       | 13 +++++++-
 src/mesa/drivers/dri/i965/intel_regions.c | 50 ++++++++++++++++++-------------
 src/mesa/drivers/dri/i965/intel_regions.h |  6 ++++
 src/mesa/drivers/dri/i965/intel_screen.c  | 37 +++++++++++++++++++++--
 4 files changed, 82 insertions(+), 24 deletions(-)

diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index 6c2312a..552dd2a 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1005,7 +1005,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 8
+#define __DRI_IMAGE_VERSION 9
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -1239,6 +1239,17 @@ struct __DRIimageExtensionRec {
                                          enum __DRIChromaSiting vert_siting,
                                          unsigned *error,
                                          void *loaderPrivate);
+   /**
+    * Create image from a driver-dependent handle. Depends on the shared
+    * bufmgr extension.
+    *
+    * \since 9 ?
+    */
+   __DRIimage *(*createImageFromHandle)(__DRIscreen *screen,
+				      int width, int height, int format,
+				      void *handle, int pitch,
+				      void *loaderPrivate);
+
 };
 
 
diff --git a/src/mesa/drivers/dri/i965/intel_regions.c b/src/mesa/drivers/dri/i965/intel_regions.c
index d891e09..745bfe6 100644
--- a/src/mesa/drivers/dri/i965/intel_regions.c
+++ b/src/mesa/drivers/dri/i965/intel_regions.c
@@ -172,30 +172,47 @@ intel_region_flink(struct intel_region *region, uint32_t *name)
 }
 
 struct intel_region *
-intel_region_alloc_for_handle(struct intel_screen *screen,
+intel_region_alloc_for_buffer(struct intel_screen *screen,
 			      GLuint cpp,
 			      GLuint width, GLuint height, GLuint pitch,
-			      GLuint handle, const char *name)
+			      drm_intel_bo *buffer, const char *name)
 {
    struct intel_region *region;
-   drm_intel_bo *buffer;
    int ret;
    uint32_t bit_6_swizzle, tiling;
 
-   buffer = intel_bo_gem_create_from_name(screen->bufmgr, name, handle);
-   if (buffer == NULL)
-      return NULL;
    ret = drm_intel_bo_get_tiling(buffer, &tiling, &bit_6_swizzle);
    if (ret != 0) {
-      fprintf(stderr, "Couldn't get tiling of buffer %d (%s): %s\n",
-	      handle, name, strerror(-ret));
-      drm_intel_bo_unreference(buffer);
+      fprintf(stderr, "Couldn't get tiling of buffer (%s): %s\n",
+	      name, strerror(-ret));
       return NULL;
    }
 
    region = intel_region_alloc_internal(screen, cpp,
 					width, height, pitch, tiling, buffer);
-   if (region == NULL) {
+   if (region == NULL)
+      return NULL;
+
+   return region;
+}
+
+struct intel_region *
+intel_region_alloc_for_handle(struct intel_screen *screen,
+			      GLuint cpp,
+			      GLuint width, GLuint height, GLuint pitch,
+			      GLuint handle, const char *name)
+{
+   struct intel_region *region;
+   drm_intel_bo *buffer;
+
+   buffer = intel_bo_gem_create_from_name(screen->bufmgr, name, handle);
+   if (buffer == NULL)
+      return NULL;
+
+   region = intel_region_alloc_for_buffer(screen, cpp, width, height, pitch,
+					  buffer, name);
+
+   if (!region) {
       drm_intel_bo_unreference(buffer);
       return NULL;
    }
@@ -214,22 +231,13 @@ intel_region_alloc_for_fd(struct intel_screen *screen,
 {
    struct intel_region *region;
    drm_intel_bo *buffer;
-   int ret;
-   uint32_t bit_6_swizzle, tiling;
 
    buffer = drm_intel_bo_gem_create_from_prime(screen->bufmgr, fd, size);
    if (buffer == NULL)
       return NULL;
-   ret = drm_intel_bo_get_tiling(buffer, &tiling, &bit_6_swizzle);
-   if (ret != 0) {
-      fprintf(stderr, "Couldn't get tiling of buffer (%s): %s\n",
-	      name, strerror(-ret));
-      drm_intel_bo_unreference(buffer);
-      return NULL;
-   }
 
-   region = intel_region_alloc_internal(screen, cpp,
-					width, height, pitch, tiling, buffer);
+   region = intel_region_alloc_for_buffer(screen, cpp, width, height, pitch,
+					  buffer, name);
    if (region == NULL) {
       drm_intel_bo_unreference(buffer);
       return NULL;
diff --git a/src/mesa/drivers/dri/i965/intel_regions.h b/src/mesa/drivers/dri/i965/intel_regions.h
index eb2123e..a35eae8 100644
--- a/src/mesa/drivers/dri/i965/intel_regions.h
+++ b/src/mesa/drivers/dri/i965/intel_regions.h
@@ -83,6 +83,12 @@ struct intel_region *intel_region_alloc(struct intel_screen *screen,
 					bool expect_accelerated_upload);
 
 struct intel_region *
+intel_region_alloc_for_buffer(struct intel_screen *screen,
+			      GLuint cpp,
+			      GLuint width, GLuint height, GLuint pitch,
+			      drm_intel_bo *buffer, const char *name);
+
+struct intel_region *
 intel_region_alloc_for_handle(struct intel_screen *screen,
 			      GLuint cpp,
 			      GLuint width, GLuint height, GLuint pitch,
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index 8ffbf17..86bc5ab 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -796,8 +796,40 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
     return image;
 }
 
+static __DRIimage *
+intel_create_image_from_handle(__DRIscreen *screen,
+			       int width, int height, int format,
+			       void *handle, int pitch, void *loaderPrivate)
+{
+    struct intel_screen *intelScreen = screen->driverPrivate;
+    __DRIimage *image;
+    int cpp;
+
+    image = intel_allocate_image(format, loaderPrivate);
+    if (image == NULL)
+       return NULL;
+
+    if (image->format == MESA_FORMAT_NONE)
+       cpp = 1;
+    else
+       cpp = _mesa_get_format_bytes(image->format);
+    image->region = intel_region_alloc_for_buffer(intelScreen,
+						  cpp, width, height,
+						  pitch * cpp, handle, "image");
+    if (image->region == NULL) {
+       free(image);
+       return NULL;
+    }
+
+    drm_intel_bo_reference(handle);
+
+    intel_setup_image_from_dimensions(image);
+
+    return image;
+}
+
 static struct __DRIimageExtensionRec intelImageExtension = {
-    .base = { __DRI_IMAGE, 8 },
+    .base = { __DRI_IMAGE, 9 },
 
     .createImageFromName                = intel_create_image_from_name,
     .createImageFromRenderbuffer        = intel_create_image_from_renderbuffer,
@@ -810,7 +842,8 @@ static struct __DRIimageExtensionRec intelImageExtension = {
     .fromPlanar                         = intel_from_planar,
     .createImageFromTexture             = intel_create_image_from_texture,
     .createImageFromFds                 = intel_create_image_from_fds,
-    .createImageFromDmaBufs             = intel_create_image_from_dma_bufs
+    .createImageFromDmaBufs             = intel_create_image_from_dma_bufs,
+    .createImageFromHandle              = intel_create_image_from_handle
 };
 
 static int
-- 
1.8.3.2



More information about the mesa-dev mailing list