gbm: Add import from fd
authorKristian Høgsberg <krh@bitplanet.net>
Fri, 28 Mar 2014 17:17:11 +0000 (10:17 -0700)
committerKristian Høgsberg <krh@bitplanet.net>
Tue, 1 Apr 2014 19:27:26 +0000 (12:27 -0700)
Add a new import type that lets us create a gbm bo from a
DMA-BUF file descriptor.

Signed-off-by: Kristian Høgsberg <krh@bitplanet.net>
src/gbm/backends/dri/gbm_dri.c
src/gbm/main/gbm.c
src/gbm/main/gbm.h

index a674036bf6f7a6c65bf5e16b2a5a7c88dca007ad..50fa588ff39374c04b80f34e9673ef0e536ccca5 100644 (file)
@@ -448,7 +448,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
       if (!wb)
          return NULL;
 
-      image = wb->driver_buffer;
+      image = dri->image->dupImage(wb->driver_buffer, NULL);
 
       switch (wb->format) {
       case WL_DRM_FORMAT_XRGB8888:
@@ -477,6 +477,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
          return NULL;
 
       image = dri->lookup_image(dri->screen, buffer, dri->lookup_user_data);
+      image = dri->image->dupImage(image, NULL);
       dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &dri_format);
       gbm_format = gbm_dri_to_gbm_format(dri_format);
       if (gbm_format == 0)
@@ -484,6 +485,22 @@ gbm_dri_bo_import(struct gbm_device *gbm,
       break;
    }
 
+   case GBM_BO_IMPORT_FD:
+   {
+      struct gbm_import_fd_data *fd_data = buffer;
+      int stride = fd_data->stride, offset = 0;
+
+      image = dri->image->createImageFromFds(dri->screen,
+                                             fd_data->width,
+                                             fd_data->height,
+                                             fd_data->format,
+                                             &fd_data->fd, 1,
+                                             &stride, &offset,
+                                             NULL);
+      gbm_format = fd_data->format;
+      break;
+   }
+
    default:
       return NULL;
    }
@@ -493,7 +510,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
    if (bo == NULL)
       return NULL;
 
-   bo->image = dri->image->dupImage(image, NULL);
+   bo->image = image;
 
    if (usage & GBM_BO_USE_SCANOUT)
       dri_use |= __DRI_IMAGE_USE_SCANOUT;
index ad5208ca13607aa48dd1771eea7dbd339a830bb6..6179e5b830d4a42818492820577de4d5ac36b9bc 100644 (file)
@@ -362,6 +362,7 @@ gbm_bo_create(struct gbm_device *gbm,
  *
  *   GBM_BO_IMPORT_WL_BUFFER
  *   GBM_BO_IMPORT_EGL_IMAGE
+ *   GBM_BO_IMPORT_FD
  *
  * The the gbm bo shares the underlying pixels but its life-time is
  * independent of the foreign object.
index 9e0c7705ea8c9a9a7bd9b021ba76e87b365a7164..92d472a07620a98104de5506b6441fec4527ade3 100644 (file)
@@ -232,6 +232,15 @@ gbm_bo_create(struct gbm_device *gbm,
 
 #define GBM_BO_IMPORT_WL_BUFFER         0x5501
 #define GBM_BO_IMPORT_EGL_IMAGE         0x5502
+#define GBM_BO_IMPORT_FD                0x5503
+
+struct gbm_import_fd_data {
+   int fd;
+   uint32_t width;
+   uint32_t height;
+   uint32_t stride;
+   uint32_t format;
+};
 
 struct gbm_bo *
 gbm_bo_import(struct gbm_device *gbm, uint32_t type,