gbm: Axe buffer import format conversion table
authorDaniel Stone <daniels@collabora.com>
Fri, 16 Jun 2017 09:28:03 +0000 (10:28 +0100)
committerDaniel Stone <daniels@collabora.com>
Tue, 18 Jul 2017 21:16:20 +0000 (22:16 +0100)
Wayland buffers coming from wl_drm use the WL_DRM_FORMAT_* enums, which
are identical to GBM_FORMAT_*. Similarly, FD imports do not need to
convert between GBM and DRI FourCC, since they are (almost) completely
compatible.

This widens the formats accepted by gbm_bo_import() when importing
wl_buffers; previously, only XRGB8888, ARGB8888, RGB565 and YUYV were
supported.

Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/egl/wayland/wayland-drm/wayland-drm.xml
src/gbm/backends/dri/gbm_dri.c
src/gbm/main/gbm.h

index 5e64622df67b06e9575ad30369019c5e1f195c52..83aa5615539bcb2680219407c49b1cea0e5e723a 100644 (file)
@@ -39,7 +39,8 @@
     <enum name="format">
       <!-- The drm format codes match the #defines in drm_fourcc.h.
            The formats actually supported by the compositor will be
-           reported by the format event. -->
+           reported by the format event. New codes must not be added,
+           unless directly taken from drm_fourcc.h. -->
       <entry name="c8" value="0x20203843"/>
       <entry name="rgb332" value="0x38424752"/>
       <entry name="bgr233" value="0x38524742"/>
index ecb360773c3188b4b202c8a591d3c06f694c766f..d4bf243034132d4c68ab1620d4ceb7c01e5d711d 100644 (file)
@@ -850,23 +850,9 @@ gbm_dri_bo_import(struct gbm_device *gbm,
 
       image = dri->image->dupImage(wb->driver_buffer, NULL);
 
-      switch (wb->format) {
-      case WL_DRM_FORMAT_XRGB8888:
-         gbm_format = GBM_FORMAT_XRGB8888;
-         break;
-      case WL_DRM_FORMAT_ARGB8888:
-         gbm_format = GBM_FORMAT_ARGB8888;
-         break;
-      case WL_DRM_FORMAT_RGB565:
-         gbm_format = GBM_FORMAT_RGB565;
-         break;
-      case WL_DRM_FORMAT_YUYV:
-         gbm_format = GBM_FORMAT_YUYV;
-         break;
-      default:
-         dri->image->destroyImage(image);
-         return NULL;
-      }
+      /* GBM_FORMAT_* is identical to WL_DRM_FORMAT_*, so no conversion
+       * required. */
+      gbm_format = wb->format;
       break;
    }
 #endif
@@ -895,23 +881,27 @@ gbm_dri_bo_import(struct gbm_device *gbm,
    {
       struct gbm_import_fd_data *fd_data = buffer;
       int stride = fd_data->stride, offset = 0;
-      int dri_format;
+      int fourcc;
 
+      /* GBM's GBM_FORMAT_* tokens are a strict superset of the DRI FourCC
+       * tokens accepted by createImageFromFds, except for not supporting
+       * the sARGB format. Also, GBM_BO_FORMAT_* are defined differently to
+       * their GBM_FORMAT_* equivalents, so remap them here. */
       switch (fd_data->format) {
       case GBM_BO_FORMAT_XRGB8888:
-         dri_format = GBM_FORMAT_XRGB8888;
+         fourcc = GBM_FORMAT_XRGB8888;
          break;
       case GBM_BO_FORMAT_ARGB8888:
-         dri_format = GBM_FORMAT_ARGB8888;
+         fourcc = GBM_FORMAT_ARGB8888;
          break;
       default:
-         dri_format = fd_data->format;
+         fourcc = fd_data->format;
       }
 
       image = dri->image->createImageFromFds(dri->screen,
                                              fd_data->width,
                                              fd_data->height,
-                                             dri_format,
+                                             fourcc,
                                              &fd_data->fd, 1,
                                              &stride, &offset,
                                              NULL);
@@ -936,27 +926,19 @@ gbm_dri_bo_import(struct gbm_device *gbm,
          return NULL;
       }
 
-      switch(fd_data->format) {
-      case GBM_FORMAT_RGB565:
-         fourcc = __DRI_IMAGE_FOURCC_RGB565;
-         break;
-      case GBM_FORMAT_ARGB8888:
-      case GBM_BO_FORMAT_ARGB8888:
-         fourcc = __DRI_IMAGE_FOURCC_ARGB8888;
-         break;
-      case GBM_FORMAT_XRGB8888:
+      /* GBM's GBM_FORMAT_* tokens are a strict superset of the DRI FourCC
+       * tokens accepted by createImageFromDmaBufs2, except for not supporting
+       * the sARGB format. Also, GBM_BO_FORMAT_* are defined differently to
+       * their GBM_FORMAT_* equivalents, so remap them here. */
+      switch (fd_data->format) {
       case GBM_BO_FORMAT_XRGB8888:
-         fourcc = __DRI_IMAGE_FOURCC_XRGB8888;
-         break;
-      case GBM_FORMAT_ABGR8888:
-         fourcc = __DRI_IMAGE_FOURCC_ABGR8888;
+         fourcc = GBM_FORMAT_XRGB8888;
          break;
-      case GBM_FORMAT_XBGR8888:
-         fourcc = __DRI_IMAGE_FOURCC_XBGR8888;
+      case GBM_BO_FORMAT_ARGB8888:
+         fourcc = GBM_FORMAT_ARGB8888;
          break;
       default:
-         errno = EINVAL;
-         return NULL;
+         fourcc = fd_data->format;
       }
 
       image = dri->image->createImageFromDmaBufs2(dri->screen, fd_data->width,
@@ -973,7 +955,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
          return NULL;
       }
 
-      gbm_format = fd_data->format;
+      gbm_format = fourcc;
       break;
    }
 
index 6a9bf1fc2a802746c1e9d3e18b39871a28794aab..879f003f1b403a0ef552329c3cae4488ee6beb42 100644 (file)
@@ -77,6 +77,12 @@ enum gbm_bo_format {
    GBM_BO_FORMAT_ARGB8888
 };
 
+
+/**
+ * The FourCC format codes are taken from the drm_fourcc.h definition, and
+ * re-namespaced. New GBM formats must not be added, unless they are
+ * identical ports from drm_fourcc.
+ */
 #define __gbm_fourcc_code(a,b,c,d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \
                              ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))