gl-renderer: allow importing fourth dmabuf plane

EGL_EXT_image_dma_buf_import_modifiers supports importing upto four dmabuf
planes into an EGLImage.

v2: correct PLANE3_PITCH token (Daniel Stone)

Signed-off-by: Varad Gautam <varad.gautam@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
diff --git a/libweston/gl-renderer.c b/libweston/gl-renderer.c
index f5e5371..a1301ff 100644
--- a/libweston/gl-renderer.c
+++ b/libweston/gl-renderer.c
@@ -1577,7 +1577,7 @@
                      struct dmabuf_attributes *attributes)
 {
 	struct egl_image *image;
-	EGLint attribs[40];
+	EGLint attribs[50];
 	int atti = 0;
 
 	/* This requires the Mesa commit in
@@ -1640,6 +1640,21 @@
 		}
 	}
 
+	if (gr->has_dmabuf_import_modifiers) {
+		if (attributes->n_planes > 3) {
+			attribs[atti++] = EGL_DMA_BUF_PLANE3_FD_EXT;
+			attribs[atti++] = attributes->fd[3];
+			attribs[atti++] = EGL_DMA_BUF_PLANE3_OFFSET_EXT;
+			attribs[atti++] = attributes->offset[3];
+			attribs[atti++] = EGL_DMA_BUF_PLANE3_PITCH_EXT;
+			attribs[atti++] = attributes->stride[3];
+			attribs[atti++] = EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT;
+			attribs[atti++] = attributes->modifier[3] & 0xFFFFFFFF;
+			attribs[atti++] = EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT;
+			attribs[atti++] = attributes->modifier[3] >> 32;
+		}
+	}
+
 	attribs[atti++] = EGL_NONE;
 
 	image = egl_image_create(gr, EGL_LINUX_DMA_BUF_EXT, NULL,