egl: implement eglQueryDmaBufModifiersEXT
authorVarad Gautam <varad.gautam@collabora.com>
Tue, 30 May 2017 11:53:39 +0000 (17:23 +0530)
committerEric Engestrom <eric.engestrom@imgtec.com>
Tue, 30 May 2017 12:56:20 +0000 (13:56 +0100)
query and return supported dmabuf format modifiers for
EGL_EXT_image_dma_buf_import_modifiers.

v2: move format check to the driver instead of making format queries
   here and then checking.
v3: Check DRIimageExtension version before query (Daniel Stone)
v4:
- move to DRIimageExtension version 15, check queryDmaBufModifiers before
  calling (Jason Ekstrand)
- pass external_only to the driver instead of setting as EGL_TRUE here
  (Emil Velikov, Daniel Stone)

Signed-off-by: Varad Gautam <varad.gautam@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
src/egl/drivers/dri2/egl_dri2.c
src/egl/main/eglapi.c
src/egl/main/eglapi.h
src/egl/main/eglentrypoint.h

index c2715528d88b852eb07c76b94be0ba259417f372..bcafdf9f4c5a8989696698881ceadcb4f1ebcfb9 100644 (file)
@@ -2178,6 +2178,38 @@ 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);
+
+   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;
+   }
+
+   if (dri2_dpy->image->base.version < 15 ||
+       dri2_dpy->image->queryDmaBufModifiers == NULL)
+      return EGL_FALSE;
+
+   if (dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen, format,
+                                             max, modifiers,
+                                             (unsigned int *) external_only,
+                                             count) == false) {
+      _eglError(EGL_BAD_PARAMETER, "invalid format");
+      return EGL_FALSE;
+   }
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -3116,6 +3148,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;
index d613920b012f2d0257dd9db2587f1805e00a0fcb..a4d5f896e6dccefad90f98b29982ea802f3e460a 100644 (file)
@@ -2404,6 +2404,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)
 {
index c9f98963dbac249eca456b555b7968d9f22d0333..cab3e9605a0082b25ddababdfba8fe0f5d43e871 100644 (file)
@@ -202,6 +202,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);
 };
 
 #ifdef __cplusplus
index 91536239e9fe1657e2254e7a6975fd87b4a7d7e0..b9dca7ceda282fdb305a9526978cff78f17c1e66 100644 (file)
@@ -57,6 +57,7 @@ EGL_ENTRYPOINT(eglQueryAPI)
 EGL_ENTRYPOINT(eglQueryContext)
 EGL_ENTRYPOINT(eglQueryDebugKHR)
 EGL_ENTRYPOINT(eglQueryDmaBufFormatsEXT)
+EGL_ENTRYPOINT(eglQueryDmaBufModifiersEXT)
 EGL_ENTRYPOINT(eglQueryString)
 EGL_ENTRYPOINT(eglQuerySurface)
 EGL_ENTRYPOINT(eglQueryWaylandBufferWL)