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_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;
}
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.
*/
int is_disjoint = false;
if (nplanes > 1) {
dri2_query_image(dri2_img->dri_image, __DRI_IMAGE_ATTRIB_DISJOINT_PLANES,
&is_disjoint);
}
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 (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 (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));
if (i == 0 || is_disjoint)
dri2_query_image(image, __DRI_IMAGE_ATTRIB_FD, &fds[i]);
else
fds[i] = -1;
}
/* rework later to provide multiple fds/strides/offsets */
if (fds)
dri2_query_image(dri2_img->dri_image, __DRI_IMAGE_ATTRIB_FD,
fds);
if (strides && !dri2_query_image(image, __DRI_IMAGE_ATTRIB_STRIDE, &strides[i]))
strides[i] = 0;
if (strides)
dri2_query_image(dri2_img->dri_image,
__DRI_IMAGE_ATTRIB_STRIDE, strides);
if (offsets && !dri2_query_image(image, __DRI_IMAGE_ATTRIB_OFFSET, &offsets[i]))
offsets[i] = 0;
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 (i)
dri2_destroy_image(image);
}
mtx_unlock(&dri2_dpy->lock);