On 05/28/2013 02:17 AM, Topi Pohjolainen wrote:
v2:
    - upon success close the given file descriptors

v3:
    - use specific entry for dma buffers instead of the basic for
      primes, and enable the extension based on the availability
      of the hook

v4 (Chad):
    - use ARRAY_SIZE
    - improve the comment about the number of file descriptors
    - in case of invalid format report EGL_BAD_ATTRIBUTE instead
      of EGL_BAD_MATCH
    - take into account specific error set by the driver.

Signed-off-by: Topi Pohjolainen <topi.pohjolai...@intel.com>
---
  src/egl/drivers/dri2/egl_dri2.c | 275 ++++++++++++++++++++++++++++++++++++++++
  1 file changed, 275 insertions(+)


+static _EGLImage *
+dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext *ctx,
+                         EGLClientBuffer buffer, const EGLint *attr_list)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   _EGLImage *res;
+   EGLint err;
+   _EGLImageAttribs attrs;
+   __DRIimage *dri_image;
+   unsigned num_fds;
+   unsigned i;
+   int fds[3];
+   int pitches[3];
+   int offsets[3];
+   unsigned error;
+
+   /**
+    * The spec says:
+    *
+    * ""* If <target> is EGL_LINUX_DMA_BUF_EXT and <buffer> is not NULL, the
+    *     error EGL_BAD_PARAMETER is generated."
+    */
+   if (buffer != NULL) {
+      _eglError(EGL_BAD_PARAMETER, "buffer not NULL");
+      return NULL;
+   }
+
+   err = _eglParseImageAttribList(&attrs, disp, attr_list);
+   if (err != EGL_SUCCESS) {
+      _eglError(err, "bad attribute");
+      return NULL;
+   }
+
+   if (!dri2_check_dma_buf_attribs(&attrs))
+      return NULL;
+
+   num_fds = dri2_check_dma_buf_format(&attrs);
+   if (!num_fds)
+      return NULL;
+
+   for (i = 0; i < num_fds; ++i) {
+      fds[i] = attrs.DMABufPlaneFds[i].Value;
+      pitches[i] = attrs.DMABufPlanePitches[i].Value;
+      offsets[i] = attrs.DMABufPlaneOffsets[i].Value;
+   }
+
+   dri_image =
+      dri2_dpy->image->createImageFromDmaBufs(dri2_dpy->dri_screen,
+         attrs.Width, attrs.Height, attrs.DMABufFourCC.Value,
+         fds, num_fds, pitches, offsets,
+         attrs.DMABufYuvColorSpaceHint.Value,
+         attrs.DMABufSampleRangeHint.Value,
+         attrs.DMABufChromaHorizontalSiting.Value,
+         attrs.DMABufChromaVerticalSiting.Value,
+         &error,
+         NULL);
+   dri2_create_image_khr_texture_error(error);

If dri_image is NULL, then the function must return early here.
Otherwise, calling dri2_creat_image(disp, NULL) below will override
the previously EGL error with EGL_BAD_ALLOC.
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to