From f416a52960b978f939fdebe062167949fa93f997 Mon Sep 17 00:00:00 2001 From: Qiang Yu Date: Wed, 18 Sep 2024 14:57:59 +0800 Subject: [PATCH] egl: refine dma buf export to support multi plane MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Acked-by: Pierre-Eric Pelloux-Prayer Reviewed-by: Marek Olšák Acked-by: Daniel Stone Part-of: --- src/egl/drivers/dri2/egl_dri2.c | 56 +++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 469e4ddeabf..5bac0a2edca 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -2541,41 +2541,49 @@ dri2_export_dma_buf_image_mesa(_EGLDisplay *disp, _EGLImage *img, int *fds, { struct dri2_egl_display *dri2_dpy = dri2_egl_display_lock(disp); struct dri2_egl_image *dri2_img = dri2_egl_image(img); - EGLint nplanes; if (!dri2_can_export_dma_buf_image(disp, img)) { mtx_unlock(&dri2_dpy->lock); return EGL_FALSE; } - /* EGL_MESA_image_dma_buf_export spec says: - * "If the number of fds is less than the number of planes, then - * subsequent fd slots should contain -1." + int nplanes; + /* Query nplanes so that we know how big the given array is. */ + dri2_query_image(dri2_img->dri_image, __DRI_IMAGE_ATTRIB_NUM_PLANES, &nplanes); + + /* For driver which does not implement disjoint query, still uses + * single fd to match previous behavior. */ - if (fds) { - /* Query nplanes so that we know how big the given array is. */ - dri2_query_image(dri2_img->dri_image, - __DRI_IMAGE_ATTRIB_NUM_PLANES, &nplanes); - memset(fds, -1, nplanes * sizeof(int)); + int is_disjoint = false; + if (nplanes > 1) { + dri2_query_image(dri2_img->dri_image, __DRI_IMAGE_ATTRIB_DISJOINT_PLANES, + &is_disjoint); } - /* rework later to provide multiple fds/strides/offsets */ - if (fds) - dri2_query_image(dri2_img->dri_image, __DRI_IMAGE_ATTRIB_FD, - fds); + for (int i = 0; i < nplanes; i++) { + struct dri_image *image = dri2_img->dri_image; + if (i) + image = dri2_from_planar(image, i, NULL); - if (strides) - dri2_query_image(dri2_img->dri_image, - __DRI_IMAGE_ATTRIB_STRIDE, strides); + if (fds) { + /* EGL_MESA_image_dma_buf_export spec says: + * "If the number of fds is less than the number of planes, then + * subsequent fd slots should contain -1." + */ + if (i == 0 || is_disjoint) + dri2_query_image(image, __DRI_IMAGE_ATTRIB_FD, &fds[i]); + else + fds[i] = -1; + } - if (offsets) { - int img_offset; - bool ret = dri2_query_image( - dri2_img->dri_image, __DRI_IMAGE_ATTRIB_OFFSET, &img_offset); - if (ret) - offsets[0] = img_offset; - else - offsets[0] = 0; + if (strides && !dri2_query_image(image, __DRI_IMAGE_ATTRIB_STRIDE, &strides[i])) + strides[i] = 0; + + if (offsets && !dri2_query_image(image, __DRI_IMAGE_ATTRIB_OFFSET, &offsets[i])) + offsets[i] = 0; + + if (i) + dri2_destroy_image(image); } mtx_unlock(&dri2_dpy->lock);