[Mesa-dev,1/2] dri: add support for EXT_dma_buf_import revision #7.

Submitted by Gwenole Beauchesne on March 19, 2014, 6:31 p.m.

Details

Message ID 1395253869-29517-1-git-send-email-gwenole.beauchesne@intel.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Gwenole Beauchesne March 19, 2014, 6:31 p.m.
Allow an application to specify the layout of dma_buf immported images
with standard GL|GLES texture internal formats, instead of DRM fourcc
values.

This allows for the application to map each individual plane of a YUV
planar surface separately for additional processing or customized
composition kernels, but also for non-presentable memory buffers to be
shared with EGL or OpenCL.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
---
 include/EGL/eglext.h                   |    1 +
 include/GL/internal/dri_interface.h    |   16 ++++++++++++++++
 src/egl/drivers/dri2/egl_dri2.c        |   12 +++++++++++-
 src/egl/main/eglimage.c                |    5 +++++
 src/egl/main/eglimage.h                |    1 +
 src/mesa/drivers/dri/common/dri_util.c |    6 ++++--
 6 files changed, 38 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index 243da4a..194e38c 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -447,6 +447,7 @@  EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurfacePointerANGLE (EGLDisplay dpy, EGLSu
 #define EGL_YUV_NARROW_RANGE_EXT          0x3283
 #define EGL_YUV_CHROMA_SITING_0_EXT       0x3284
 #define EGL_YUV_CHROMA_SITING_0_5_EXT     0x3285
+#define EGL_IMAGE_INTERNAL_FORMAT_EXT     0x1003
 #endif /* EGL_EXT_image_dma_buf_import */
 
 #ifndef EGL_EXT_multiview_window
diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index d028d05..c2eec8f 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1021,6 +1021,7 @@  struct __DRIdri2ExtensionRec {
  * createImage, and are returned by query from sub images created with
  * createImageFromNames (NONE, see above) and fromPlane (R8 & GR88).
  */
+#define __DRI_IMAGE_FORMAT_MASK         0xffff
 #define __DRI_IMAGE_FORMAT_RGB565       0x1001
 #define __DRI_IMAGE_FORMAT_XRGB8888     0x1002
 #define __DRI_IMAGE_FORMAT_ARGB8888     0x1003
@@ -1033,6 +1034,13 @@  struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FORMAT_ARGB2101010  0x100a
 #define __DRI_IMAGE_FORMAT_SARGB8       0x100b
 
+/** Special base value for mesa_format derived formats */
+#define __DRI_IMAGE_FORMAT_MESA_BASE    0x100c
+
+/** Generates a DRI image format that packs a mesa_format */
+#define __DRI_IMAGE_FORMAT_MESA(mesa_format) \
+   (__DRI_IMAGE_FORMAT_MESA_BASE | ((mesa_format) << 16))
+
 #define __DRI_IMAGE_USE_SHARE		0x0001
 #define __DRI_IMAGE_USE_SCANOUT		0x0002
 #define __DRI_IMAGE_USE_CURSOR		0x0004 /* Depricated */
@@ -1061,6 +1069,10 @@  struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FOURCC_NV16		0x3631564e
 #define __DRI_IMAGE_FOURCC_YUYV		0x56595559
 
+/** Generates a DRI image FOURCC value for a standard GL texture format */
+#define __DRI_IMAGE_FOURCC_GL_FORMAT(gl_format) \
+   ((uint32_t)('G') | ((uint32_t)('L') << 8) | ((gl_format) << 16))
+
 
 /**
  * Queryable on images created by createImageFromNames.
@@ -1080,6 +1092,10 @@  struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_COMPONENTS_Y_U_V	0x3003
 #define __DRI_IMAGE_COMPONENTS_Y_UV	0x3004
 #define __DRI_IMAGE_COMPONENTS_Y_XUXV	0x3005
+#define __DRI_IMAGE_COMPONENTS_X	0x3006
+#define __DRI_IMAGE_COMPONENTS_XY	0x3007
+#define __DRI_IMAGE_COMPONENTS_XYZ	0x3008
+#define __DRI_IMAGE_COMPONENTS_XYZW	0x3009
 
 
 /**
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 8abe8ac..5716fd3 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1528,7 +1528,7 @@  dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs)
      *    incomplete, EGL_BAD_PARAMETER is generated."
      */
    if (attrs->Width <= 0 || attrs->Height <= 0 ||
-       !attrs->DMABufFourCC.IsPresent) {
+       (!attrs->DMABufFourCC.IsPresent && !attrs->InternalFormat.IsPresent)) {
       _eglError(EGL_BAD_PARAMETER, "attribute(s) missing");
       return EGL_FALSE;
    }
@@ -1621,6 +1621,10 @@  dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
       plane_n = 3;
       break;
    default:
+      if (attrs->InternalFormat.IsPresent) {
+         plane_n = 1;
+         break;
+      }
       _eglError(EGL_BAD_ATTRIBUTE, "invalid format");
       return 0;
    }
@@ -1729,6 +1733,12 @@  dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext *ctx,
    if (!dri2_check_dma_buf_attribs(&attrs))
       return NULL;
 
+   if (!attrs.DMABufFourCC.IsPresent || attrs.DMABufFourCC.Value == 0) {
+      attrs.DMABufFourCC.Value =
+         __DRI_IMAGE_FOURCC_GL_FORMAT(attrs.InternalFormat.Value);
+      attrs.DMABufFourCC.IsPresent = EGL_TRUE;
+   }
+
    num_fds = dri2_check_dma_buf_format(&attrs);
    if (!num_fds)
       return NULL;
diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c
index 818b597..75d06af 100644
--- a/src/egl/main/eglimage.c
+++ b/src/egl/main/eglimage.c
@@ -93,6 +93,11 @@  _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
          attrs->PlaneWL = val;
          break;
 
+      /* EXT_image_dma_buf_import */
+      case EGL_IMAGE_INTERNAL_FORMAT_EXT:
+         attrs->InternalFormat.Value = val;
+         attrs->InternalFormat.IsPresent = EGL_TRUE;
+         break;
       case EGL_LINUX_DRM_FOURCC_EXT:
          attrs->DMABufFourCC.Value = val;
          attrs->DMABufFourCC.IsPresent = EGL_TRUE;
diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h
index 1b4d6cd..30b2cc3 100644
--- a/src/egl/main/eglimage.h
+++ b/src/egl/main/eglimage.h
@@ -60,6 +60,7 @@  struct _egl_image_attribs
    EGLint PlaneWL;
 
    /* EGL_EXT_image_dma_buf_import */
+   struct _egl_image_attrib_int InternalFormat;
    struct _egl_image_attrib_int DMABufFourCC;
    struct _egl_image_attrib_int DMABufPlaneFds[3];
    struct _egl_image_attrib_int DMABufPlaneOffsets[3];
diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c
index aed73c7..150a8a0 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -837,14 +837,14 @@  driGLFormatToImageFormat(mesa_format format)
    case MESA_FORMAT_B8G8R8A8_SRGB:
       return __DRI_IMAGE_FORMAT_SARGB8;
    default:
-      return 0;
+      return __DRI_IMAGE_FORMAT_MESA(format);
    }
 }
 
 mesa_format
 driImageFormatToGLFormat(uint32_t image_format)
 {
-   switch (image_format) {
+   switch (image_format & __DRI_IMAGE_FORMAT_MASK) {
    case __DRI_IMAGE_FORMAT_RGB565:
       return MESA_FORMAT_B5G6R5_UNORM;
    case __DRI_IMAGE_FORMAT_XRGB8888:
@@ -867,6 +867,8 @@  driImageFormatToGLFormat(uint32_t image_format)
       return MESA_FORMAT_B8G8R8A8_SRGB;
    case __DRI_IMAGE_FORMAT_NONE:
       return MESA_FORMAT_NONE;
+   case __DRI_IMAGE_FORMAT_MESA_BASE:
+      return (mesa_format)(image_format >> 16);
    default:
       return MESA_FORMAT_NONE;
    }