egl: handle EGL_IMAGE_EXTERNAL_FLUSH_EXT
authorMarek Olšák <marek.olsak@amd.com>
Thu, 17 Oct 2019 22:59:23 +0000 (18:59 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 25 Oct 2019 23:59:04 +0000 (19:59 -0400)
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Reviewed-By: Tapani Pälli <tapani.palli@intel.com>
src/egl/drivers/dri2/egl_dri2.c
src/egl/main/eglimage.c
src/egl/main/eglimage.h

index 23d0e469427db25301ea3f0d45be00ede0de14b0..e9468dcf9911df0c631fd034478826bec1d3e681 100644 (file)
@@ -2297,14 +2297,27 @@ dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx,
       return NULL;
    }
 
-   dri_image =
-      dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen,
-                                           attrs.Width,
-                                           attrs.Height,
-                                           format,
-                                           name,
-                                           pitch,
-                                           NULL);
+   if (dri2_dpy->image->base.version >= 18) {
+      unsigned use = 0;
+
+      if (attrs.ImageFlushExternal)
+         use |= __DRI_IMAGE_USE_FLUSH_EXTERNAL;
+
+      dri_image =
+         dri2_dpy->image->createImageFromName2(dri2_dpy->dri_screen,
+                                               attrs.Width, attrs.Height,
+                                               format, name, pitch, use,
+                                               NULL);
+   } else {
+      dri_image =
+         dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen,
+                                              attrs.Width,
+                                              attrs.Height,
+                                              format,
+                                              name,
+                                              pitch,
+                                              NULL);
+   }
 
    return dri2_create_image_from_dri(disp, dri_image);
 }
@@ -2646,7 +2659,26 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext *ctx,
       has_modifier = true;
    }
 
-   if (has_modifier) {
+   if (dri2_dpy->image->base.version >= 18) {
+      unsigned use = 0;
+
+      if (attrs.ImageFlushExternal)
+         use |= __DRI_IMAGE_USE_FLUSH_EXTERNAL;
+
+      if (!has_modifier)
+         modifier = DRM_FORMAT_MOD_INVALID;
+
+      dri_image =
+         dri2_dpy->image->createImageFromDmaBufs3(dri2_dpy->dri_screen,
+            attrs.Width, attrs.Height, attrs.DMABufFourCC.Value,
+            modifier, use, fds, num_fds, pitches, offsets,
+            attrs.DMABufYuvColorSpaceHint.Value,
+            attrs.DMABufSampleRangeHint.Value,
+            attrs.DMABufChromaHorizontalSiting.Value,
+            attrs.DMABufChromaVerticalSiting.Value,
+            &error,
+            NULL);
+   } else if (has_modifier) {
       if (dri2_dpy->image->base.version < 15 ||
           dri2_dpy->image->createImageFromDmaBufs2 == NULL) {
          _eglError(EGL_BAD_MATCH, "unsupported dma_buf format modifier");
@@ -2662,8 +2694,7 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext *ctx,
             attrs.DMABufChromaVerticalSiting.Value,
             &error,
             NULL);
-   }
-   else {
+   } else {
       dri_image =
          dri2_dpy->image->createImageFromDmaBufs(dri2_dpy->dri_screen,
             attrs.Width, attrs.Height, attrs.DMABufFourCC.Value,
@@ -2734,6 +2765,8 @@ dri2_create_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp,
       dri_use |= __DRI_IMAGE_USE_SCANOUT;
    if (attrs.DRMBufferUseMESA & EGL_DRM_BUFFER_USE_CURSOR_MESA)
       dri_use |= __DRI_IMAGE_USE_CURSOR;
+   if (attrs.ImageFlushExternal)
+      dri_use |= __DRI_IMAGE_USE_FLUSH_EXTERNAL;
 
    dri2_img = malloc(sizeof *dri2_img);
    if (!dri2_img) {
index 9df6b6511d57755ef4705809b4d665eea5e47d97..ef4a68f236739fe779affb6dcc4ec511996129a8 100644 (file)
@@ -265,6 +265,25 @@ _eglParseEXTImageDmaBufImportModifiersAttribs(_EGLImageAttribs *attrs,
    return EGL_SUCCESS;
 }
 
+static EGLint
+_eglParseEXTImageFlushExternalAttribs(_EGLImageAttribs *attrs,
+                                      _EGLDisplay *disp,
+                                      EGLint attr, EGLint val)
+{
+   if (!disp->Extensions.EXT_image_flush_external)
+      return EGL_BAD_PARAMETER;
+
+   switch (attr) {
+   case EGL_IMAGE_EXTERNAL_FLUSH_EXT:
+      attrs->ImageFlushExternal = val;
+      break;
+   default:
+      return EGL_BAD_PARAMETER;
+   }
+
+   return EGL_SUCCESS;
+}
+
 /**
  * Parse the list of image attributes.
  *
@@ -286,6 +305,10 @@ _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *disp,
       EGLint attr = attrib_list[i++];
       EGLint val = attrib_list[i];
 
+      err = _eglParseEXTImageFlushExternalAttribs(attrs, disp, attr, val);
+      if (err == EGL_SUCCESS)
+         continue;
+
       err = _eglParseKHRImageAttribs(attrs, disp, attr, val);
       if (err == EGL_SUCCESS)
          continue;
index 6d2e7ba8a2d3b0c812f573b62bcf95e3a4c81d07..84ad0f01b0c9cc81e484da982db203da779125e8 100644 (file)
@@ -50,6 +50,9 @@ struct _egl_image_attrib_int
 
 struct _egl_image_attribs
 {
+   /* EGL_EXT_image_flush_external */
+   EGLBoolean ImageFlushExternal;
+
    /* EGL_KHR_image_base */
    EGLBoolean ImagePreserved;