[Mesa-dev] [PATCH v2 13/14] egl: implement eglQueryDmaBufModifiersEXT

Varad Gautam varadgautam at gmail.com
Thu Nov 24 15:20:50 UTC 2016


From: Varad Gautam <varad.gautam at collabora.com>

query and return supported dmabuf format modifiers for
EGL_EXT_image_dma_buf_import_modifiers.

Signed-off-by: Varad Gautam <varad.gautam at collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 47 +++++++++++++++++++++++++++++++++++++++++
 src/egl/main/eglapi.c           | 21 ++++++++++++++++++
 src/egl/main/eglapi.h           |  5 +++++
 3 files changed, 73 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index bae7da8..d387e28 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2097,6 +2097,52 @@ dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay *disp,
    return EGL_TRUE;
 }
 
+static EGLBoolean
+dri2_query_dma_buf_modifiers(_EGLDriver *drv, _EGLDisplay *disp, EGLint format,
+                             EGLint max, EGLuint64KHR *modifiers,
+                             EGLBoolean *external_only, EGLint *count)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   EGLint* formats;
+   EGLint num_formats;
+   EGLint i;
+
+   if (max < 0) {
+      _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+      return EGL_FALSE;
+   }
+
+   if (max > 0 && modifiers == NULL) {
+      _eglError(EGL_BAD_PARAMETER, "invalid modifiers array");
+      return EGL_FALSE;
+   }
+
+   /* query and check if the received format is supported */
+   dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, 0, NULL,
+                                       &num_formats);
+   formats = calloc(num_formats, sizeof(EGLint));
+   dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, num_formats,
+                                       formats, &num_formats);
+   for (i = 0; i < num_formats; i++) {
+      if (format == formats[i])
+         break;
+   }
+   if (i == num_formats) {
+      _eglError(EGL_BAD_PARAMETER, "invalid format");
+      return EGL_FALSE;
+   }
+
+   dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen, format, max,
+                                         modifiers, count);
+
+   if (external_only != NULL) {
+      for (i = 0; i < *count && i < max; i++)
+         external_only[i] = EGL_TRUE;
+   }
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -2981,6 +3027,7 @@ _eglBuiltInDriverDRI2(const char *args)
    dri2_drv->base.API.ExportDMABUFImageQueryMESA = dri2_export_dma_buf_image_query_mesa;
    dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
    dri2_drv->base.API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
+   dri2_drv->base.API.QueryDmaBufModifiersEXT = dri2_query_dma_buf_modifiers;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
    dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 53d34d8..cd65115 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2275,6 +2275,26 @@ eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats,
    RETURN_EGL_EVAL(disp, ret);
 }
 
+static EGLBoolean EGLAPIENTRY
+eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers,
+                           EGLuint64KHR *modifiers, EGLBoolean *external_only,
+                           EGLint *num_modifiers)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   ret = drv->API.QueryDmaBufModifiersEXT(drv, disp, format, max_modifiers,
+                                          modifiers, external_only,
+                                          num_modifiers);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
 eglGetProcAddress(const char *procname)
 {
@@ -2359,6 +2379,7 @@ eglGetProcAddress(const char *procname)
       { "eglDebugMessageControlKHR", (_EGLProc) eglDebugMessageControlKHR },
       { "eglQueryDebugKHR", (_EGLProc) eglQueryDebugKHR },
       { "eglQueryDmaBufFormatsEXT", (_EGLProc) eglQueryDmaBufFormatsEXT },
+      { "eglQueryDmaBufModifiersEXT", (_EGLProc) eglQueryDmaBufModifiersEXT },
       { NULL, NULL }
    };
    EGLint i;
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index 13388b1..3428195 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -200,6 +200,11 @@ struct _egl_api
    EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDriver *drv, _EGLDisplay *dpy,
                                        EGLint max_formats, EGLint *formats,
                                        EGLint *num_formats);
+   EGLBoolean (*QueryDmaBufModifiersEXT) (_EGLDriver *drv, _EGLDisplay *dpy,
+                                          EGLint format, EGLint max_modifiers,
+                                          EGLuint64KHR *modifiers,
+                                          EGLBoolean *external_only,
+                                          EGLint *num_modifiers);
 };
 
 EGLint _eglConvertIntsToAttribs(const EGLint *int_list,
-- 
2.6.2



More information about the mesa-dev mailing list