st/dri: implement DRIimage creation from dmabufs with modifiers
authorVarad Gautam <varad.gautam@collabora.com>
Tue, 30 May 2017 11:53:44 +0000 (17:23 +0530)
committerEmil Velikov <emil.l.velikov@gmail.com>
Fri, 9 Jun 2017 13:12:37 +0000 (14:12 +0100)
support importing dmabufs into DRIimage while taking format modifiers
in account, as per DRIimage extension version 15.

v2: initialize winsys modifier to DRM_FORMAT_MOD_INVALID (Daniel Stone)
v3: do not bump DRIimageExtension version. split out winsys changes.

Signed-off-by: Varad Gautam <varad.gautam@collabora.com>
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
src/gallium/state_trackers/dri/dri2.c

index 5f1cd0429e3c13214e4b9f0ad0126ccdc962a6a2..228686c2e1b8c059f3537c7d4b50f7147abc8893 100644 (file)
@@ -888,8 +888,8 @@ dri2_create_image_from_name(__DRIscreen *_screen,
 static __DRIimage *
 dri2_create_image_from_fd(__DRIscreen *_screen,
                           int width, int height, int fourcc,
-                          int *fds, int num_fds, int *strides,
-                          int *offsets, unsigned *error,
+                          uint64_t modifier, int *fds, int num_fds,
+                          int *strides, int *offsets, unsigned *error,
                           int *dri_components, void *loaderPrivate)
 {
    struct winsys_handle whandles[3];
@@ -934,7 +934,7 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
       whandles[i].handle = (unsigned)fds[i];
       whandles[i].stride = (unsigned)strides[i];
       whandles[i].offset = (unsigned)offsets[i];
-      whandles[i].modifier = DRM_FORMAT_MOD_INVALID;
+      whandles[i].modifier = modifier;
    }
 
    if (fourcc == __DRI_IMAGE_FOURCC_YVU420) {
@@ -1311,7 +1311,8 @@ dri2_from_fds(__DRIscreen *screen, int width, int height, int fourcc,
    int dri_components;
 
    img = dri2_create_image_from_fd(screen, width, height, fourcc,
-                                   fds, num_fds, strides, offsets, NULL,
+                                   DRM_FORMAT_MOD_INVALID, fds, num_fds,
+                                   strides, offsets, NULL,
                                    &dri_components, loaderPrivate);
    if (img == NULL)
       return NULL;
@@ -1336,7 +1337,8 @@ dri2_from_dma_bufs(__DRIscreen *screen,
    int dri_components;
 
    img = dri2_create_image_from_fd(screen, width, height, fourcc,
-                                   fds, num_fds, strides, offsets, error,
+                                   DRM_FORMAT_MOD_INVALID, fds, num_fds,
+                                   strides, offsets, error,
                                    &dri_components, loaderPrivate);
    if (img == NULL)
       return NULL;
@@ -1351,6 +1353,37 @@ dri2_from_dma_bufs(__DRIscreen *screen,
    return img;
 }
 
+static __DRIimage *
+dri2_from_dma_bufs2(__DRIscreen *screen,
+                    int width, int height, int fourcc,
+                    uint64_t modifier, 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 dri_components;
+
+   img = dri2_create_image_from_fd(screen, width, height, fourcc,
+                                   modifier, fds, num_fds, strides, offsets,
+                                   error, &dri_components, loaderPrivate);
+   if (img == NULL)
+      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_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
                 int dstx0, int dsty0, int dstwidth, int dstheight,
@@ -1882,6 +1915,7 @@ dri2_init_screen(__DRIscreen * sPriv)
           (cap & DRM_PRIME_CAP_IMPORT)) {
          dri2ImageExtension.createImageFromFds = dri2_from_fds;
          dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
+         dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
       }
    }
 
@@ -1958,6 +1992,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
           (cap & DRM_PRIME_CAP_IMPORT)) {
       dri2ImageExtension.createImageFromFds = dri2_from_fds;
       dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
+      dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
    }
 
    sPriv->extensions = dri_screen_extensions;