egl: refine dma buf export to support multi plane

Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Acked-by: Daniel Stone <daniels@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31658>
This commit is contained in:
Qiang Yu 2024-09-18 14:57:59 +08:00 committed by Marge Bot
parent 41cde01b0b
commit f416a52960

View file

@ -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_display *dri2_dpy = dri2_egl_display_lock(disp);
struct dri2_egl_image *dri2_img = dri2_egl_image(img); struct dri2_egl_image *dri2_img = dri2_egl_image(img);
EGLint nplanes;
if (!dri2_can_export_dma_buf_image(disp, img)) { if (!dri2_can_export_dma_buf_image(disp, img)) {
mtx_unlock(&dri2_dpy->lock); mtx_unlock(&dri2_dpy->lock);
return EGL_FALSE; return EGL_FALSE;
} }
/* EGL_MESA_image_dma_buf_export spec says: int nplanes;
* "If the number of fds is less than the number of planes, then /* Query nplanes so that we know how big the given array is. */
* subsequent fd slots should contain -1." 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) { int is_disjoint = false;
/* Query nplanes so that we know how big the given array is. */ if (nplanes > 1) {
dri2_query_image(dri2_img->dri_image, dri2_query_image(dri2_img->dri_image, __DRI_IMAGE_ATTRIB_DISJOINT_PLANES,
__DRI_IMAGE_ATTRIB_NUM_PLANES, &nplanes); &is_disjoint);
memset(fds, -1, nplanes * sizeof(int));
} }
/* rework later to provide multiple fds/strides/offsets */ for (int i = 0; i < nplanes; i++) {
if (fds) struct dri_image *image = dri2_img->dri_image;
dri2_query_image(dri2_img->dri_image, __DRI_IMAGE_ATTRIB_FD, if (i)
fds); image = dri2_from_planar(image, i, NULL);
if (strides) if (fds) {
dri2_query_image(dri2_img->dri_image, /* EGL_MESA_image_dma_buf_export spec says:
__DRI_IMAGE_ATTRIB_STRIDE, strides); * "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) { if (strides && !dri2_query_image(image, __DRI_IMAGE_ATTRIB_STRIDE, &strides[i]))
int img_offset; strides[i] = 0;
bool ret = dri2_query_image(
dri2_img->dri_image, __DRI_IMAGE_ATTRIB_OFFSET, &img_offset); if (offsets && !dri2_query_image(image, __DRI_IMAGE_ATTRIB_OFFSET, &offsets[i]))
if (ret) offsets[i] = 0;
offsets[0] = img_offset;
else if (i)
offsets[0] = 0; dri2_destroy_image(image);
} }
mtx_unlock(&dri2_dpy->lock); mtx_unlock(&dri2_dpy->lock);