Mesa (master): st/dri: add support for dma-buf importer (DRIimage v8)

Dave Airlie airlied at kemper.freedesktop.org
Mon Mar 3 01:21:06 UTC 2014


Module: Mesa
Branch: master
Commit: 15b4ff3f4e9460320dd629026743e17fa7109156
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=15b4ff3f4e9460320dd629026743e17fa7109156

Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Dec 18 10:01:27 2013 +1000

st/dri: add support for dma-buf importer (DRIimage v8)

This is just a simple implementation that stores the extra values into the DRIimage
struct and just uses the fd importer. I haven't looked into what is required
to import YUV or deal with the extra parameters.

Signed-off-by: Dave Airlie <airlied at redhat.com>

---

 src/gallium/state_trackers/dri/common/dri_screen.h |    9 ++++
 src/gallium/state_trackers/dri/drm/dri2.c          |   49 +++++++++++++++++++-
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/dri/common/dri_screen.h b/src/gallium/state_trackers/dri/common/dri_screen.h
index f263a90..7c8e582 100644
--- a/src/gallium/state_trackers/dri/common/dri_screen.h
+++ b/src/gallium/state_trackers/dri/common/dri_screen.h
@@ -95,6 +95,15 @@ struct __DRIimageRec {
    uint32_t dri_components;
 
    void *loader_private;
+
+   /**
+    * Provided by EGL_EXT_image_dma_buf_import.
+    */
+   enum __DRIYUVColorSpace yuv_color_space;
+   enum __DRISampleRange sample_range;
+   enum __DRIChromaSiting horizontal_siting;
+   enum __DRIChromaSiting vertical_siting;
+
 };
 
 #ifndef __NOT_HAVE_DRM_H
diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c
index 5004839..3d8d569 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -974,6 +974,52 @@ dri2_from_fds(__DRIscreen *screen, int width, int height, int fourcc,
    return img;
 }
 
+static __DRIimage *
+dri2_from_dma_bufs(__DRIscreen *screen,
+                   int width, int height, int fourcc,
+                   int *fds, int num_fds,
+                   int *strides, int *offsets,
+                   enum __DRIYUVColorSpace yuv_color_space,
+                   enum __DRISampleRange sample_range,
+                   enum __DRIChromaSiting horizontal_siting,
+                   enum __DRIChromaSiting vertical_siting,
+                   unsigned *error,
+                   void *loaderPrivate)
+{
+   __DRIimage *img;
+   int format, stride, dri_components;
+
+   if (num_fds != 1 || offsets[0] != 0) {
+      *error = __DRI_IMAGE_ERROR_BAD_MATCH;
+      return NULL;
+   }
+
+   format = convert_fourcc(fourcc, &dri_components);
+   if (format == -1) {
+      *error = __DRI_IMAGE_ERROR_BAD_MATCH;
+      return NULL;
+   }
+
+   /* Strides are in bytes not pixels. */
+   stride = strides[0] /4;
+
+   img = dri2_create_image_from_fd(screen, width, height, format,
+                                   fds[0], stride, loaderPrivate);
+   if (img == NULL) {
+      *error = __DRI_IMAGE_ERROR_BAD_ALLOC;
+      return NULL;
+   }
+
+   img->yuv_color_space = yuv_color_space;
+   img->sample_range = sample_range;
+   img->horizontal_siting = horizontal_siting;
+   img->vertical_siting = vertical_siting;
+   img->dri_components = dri_components;
+
+   *error = __DRI_IMAGE_ERROR_SUCCESS;
+   return img;
+}
+
 static void
 dri2_destroy_image(__DRIimage *img)
 {
@@ -1048,8 +1094,9 @@ dri2_init_screen(__DRIscreen * sPriv)
       if (drmGetCap(sPriv->fd, DRM_CAP_PRIME, &cap) == 0 &&
           (cap & DRM_PRIME_CAP_IMPORT)) {
 
-         dri2ImageExtension.base.version = 7;
+         dri2ImageExtension.base.version = 8;
          dri2ImageExtension.createImageFromFds = dri2_from_fds;
+         dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
       }
    }
 




More information about the mesa-commit mailing list