diff mbox

[2/6] sample_common: allow importing dmabufs with format modifiers

Message ID 1480066519-20283-3-git-send-email-varadgautam@gmail.com
State New
Headers show

Commit Message

Varad Gautam Nov. 25, 2016, 9:35 a.m. UTC
From: Varad Gautam <varad.gautam@collabora.com>

EGL_EXT_image_dma_buf_import_modifiers allows creating EGLImages from
dmabufs with drm_fourcc.h format modifiers. support this in piglit.

Signed-off-by: Varad Gautam <varad.gautam@collabora.com>
---
 tests/spec/ext_image_dma_buf_import/refcount.c     |  6 ++-
 .../spec/ext_image_dma_buf_import/sample_common.c  | 59 +++++++++++++++-------
 .../spec/ext_image_dma_buf_import/sample_common.h  |  8 ++-
 tests/spec/ext_image_dma_buf_import/sample_rgb.c   |  2 +-
 tests/spec/ext_image_dma_buf_import/sample_yuv.c   |  2 +-
 5 files changed, 54 insertions(+), 23 deletions(-)
diff mbox

Patch

diff --git a/tests/spec/ext_image_dma_buf_import/refcount.c b/tests/spec/ext_image_dma_buf_import/refcount.c
index 7ea200e..f125928 100644
--- a/tests/spec/ext_image_dma_buf_import/refcount.c
+++ b/tests/spec/ext_image_dma_buf_import/refcount.c
@@ -70,11 +70,13 @@  piglit_display(void)
 	if (res != PIGLIT_PASS)
 		return res;
 
-	res = egl_image_for_dma_buf_fd(buf, dup(buf->fd), fourcc, &img1);
+	res = egl_image_for_dma_buf_fd(buf, dup(buf->fd), fourcc,
+				       NULL, 0, &img1);
 	if (res != PIGLIT_PASS)
 		return res;
 
-	res = egl_image_for_dma_buf_fd(buf, dup(buf->fd), fourcc, &img2);
+	res = egl_image_for_dma_buf_fd(buf, dup(buf->fd), fourcc,
+				       NULL, 0, &img2);
 	if (res != PIGLIT_PASS)
 		return res;
 
diff --git a/tests/spec/ext_image_dma_buf_import/sample_common.c b/tests/spec/ext_image_dma_buf_import/sample_common.c
index 2f586c7..bff4f6e 100644
--- a/tests/spec/ext_image_dma_buf_import/sample_common.c
+++ b/tests/spec/ext_image_dma_buf_import/sample_common.c
@@ -107,10 +107,13 @@  sample_tex(GLuint tex, unsigned x, unsigned y, unsigned w, unsigned h)
 }
 
 enum piglit_result
-egl_image_for_dma_buf_fd(struct piglit_dma_buf *buf, int fd, int fourcc, EGLImageKHR *out_img)
+egl_image_for_dma_buf_fd(struct piglit_dma_buf *buf, int fd, int fourcc,
+			 uint64_t *modifiers, int num_modifiers,
+			 EGLImageKHR *out_img)
 {
 	EGLint error;
 	EGLImageKHR img;
+	int i = 0;
 	EGLint attr_packed[] = {
 		EGL_WIDTH, buf->w,
 		EGL_HEIGHT, buf->h,
@@ -121,18 +124,36 @@  egl_image_for_dma_buf_fd(struct piglit_dma_buf *buf, int fd, int fourcc, EGLImag
 		EGL_NONE
 	};
 
-	EGLint attr_nv12[] = {
-		EGL_WIDTH, buf->w,
-		EGL_HEIGHT, buf->h,
-		EGL_LINUX_DRM_FOURCC_EXT, fourcc,
-		EGL_DMA_BUF_PLANE0_FD_EXT, fd,
-		EGL_DMA_BUF_PLANE0_OFFSET_EXT, buf->offset[0],
-		EGL_DMA_BUF_PLANE0_PITCH_EXT, buf->stride[0],
-		EGL_DMA_BUF_PLANE1_FD_EXT, fd,
-		EGL_DMA_BUF_PLANE1_OFFSET_EXT, buf->offset[1],
-		EGL_DMA_BUF_PLANE1_PITCH_EXT, buf->stride[1],
-		EGL_NONE
-	};
+	EGLint attr_nv12[30];
+	attr_nv12[i++] = EGL_WIDTH;
+	attr_nv12[i++] = buf->w;
+	attr_nv12[i++] = EGL_HEIGHT;
+	attr_nv12[i++] = buf->h;
+	attr_nv12[i++] = EGL_LINUX_DRM_FOURCC_EXT;
+	attr_nv12[i++] = fourcc;
+	attr_nv12[i++] = EGL_DMA_BUF_PLANE0_FD_EXT;
+	attr_nv12[i++] = fd;
+	attr_nv12[i++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT;
+	attr_nv12[i++] = buf->offset[0];
+	attr_nv12[i++] = EGL_DMA_BUF_PLANE0_PITCH_EXT;
+	attr_nv12[i++] = buf->stride[0];
+	attr_nv12[i++] = EGL_DMA_BUF_PLANE1_FD_EXT;
+	attr_nv12[i++] = fd;
+	attr_nv12[i++] = EGL_DMA_BUF_PLANE1_OFFSET_EXT;
+	attr_nv12[i++] = buf->offset[1];
+	attr_nv12[i++] = EGL_DMA_BUF_PLANE1_PITCH_EXT;
+	attr_nv12[i++] = buf->stride[1];
+	if (modifiers && num_modifiers == 2) {
+		attr_nv12[i++] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT;
+		attr_nv12[i++] = (EGLint) modifiers[0];
+		attr_nv12[i++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
+		attr_nv12[i++] = modifiers[0] >> 32;
+		attr_nv12[i++] = EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT;
+		attr_nv12[i++] = (EGLint) modifiers[1];
+		attr_nv12[i++] = EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT;
+		attr_nv12[i++] = modifiers[1] >> 32;
+	}
+	attr_nv12[i] = EGL_NONE;
 
 	EGLint attr_yuv420[] = {
 		EGL_WIDTH, buf->w,
@@ -192,7 +213,8 @@  egl_image_for_dma_buf_fd(struct piglit_dma_buf *buf, int fd, int fourcc, EGLImag
 }
 
 static enum piglit_result
-sample_buffer(struct piglit_dma_buf *buf, int fourcc)
+sample_buffer(struct piglit_dma_buf *buf, int fourcc,
+	      uint64_t *modifiers, int num_modifiers)
 {
 	enum piglit_result res;
 	EGLImageKHR img;
@@ -200,7 +222,8 @@  sample_buffer(struct piglit_dma_buf *buf, int fourcc)
 	int w = buf->w;
 	int h = buf->h;
 
-	res = egl_image_for_dma_buf_fd(buf, buf->fd, fourcc, &img);
+	res = egl_image_for_dma_buf_fd(buf, buf->fd, fourcc, modifiers,
+				       num_modifiers, &img);
 
 	/* Release the creator side of the buffer. */
 	piglit_destroy_dma_buf(buf);
@@ -228,7 +251,9 @@  destroy:
 
 enum piglit_result
 dma_buf_create_and_sample_32bpp(unsigned w, unsigned h,
-				int fourcc, const unsigned char *src)
+				int fourcc, uint64_t *modifiers,
+				int num_modifiers,
+				const unsigned char *src)
 {
 	struct piglit_dma_buf *buf;
 	enum piglit_result res;
@@ -237,5 +262,5 @@  dma_buf_create_and_sample_32bpp(unsigned w, unsigned h,
 	if (res != PIGLIT_PASS)
 		return res;
 
-	return sample_buffer(buf, fourcc);
+	return sample_buffer(buf, fourcc, modifiers, num_modifiers);
 }
diff --git a/tests/spec/ext_image_dma_buf_import/sample_common.h b/tests/spec/ext_image_dma_buf_import/sample_common.h
index 36a5bb5..15e0fff 100644
--- a/tests/spec/ext_image_dma_buf_import/sample_common.h
+++ b/tests/spec/ext_image_dma_buf_import/sample_common.h
@@ -33,10 +33,14 @@ 
  */
 enum piglit_result
 dma_buf_create_and_sample_32bpp(unsigned w, unsigned h,
-			        int fourcc, const unsigned char *src);
+			        int fourcc, uint64_t *modifiers,
+				int num_modifiers,
+			        const unsigned char *src);
 
 enum piglit_result
-egl_image_for_dma_buf_fd(struct piglit_dma_buf *buf, int fd, int fourcc, EGLImageKHR *out_img);
+egl_image_for_dma_buf_fd(struct piglit_dma_buf *buf, int fd, int fourcc,
+			 uint64_t *modifiers, int num_modifiers,
+			 EGLImageKHR *out_img);
 
 enum piglit_result
 texture_for_egl_image(EGLImageKHR img, GLuint *out_tex);
diff --git a/tests/spec/ext_image_dma_buf_import/sample_rgb.c b/tests/spec/ext_image_dma_buf_import/sample_rgb.c
index b659717..10f4ed1 100644
--- a/tests/spec/ext_image_dma_buf_import/sample_rgb.c
+++ b/tests/spec/ext_image_dma_buf_import/sample_rgb.c
@@ -59,7 +59,7 @@  piglit_display(void)
 
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-	res = dma_buf_create_and_sample_32bpp(2, 2, fourcc, src);
+	res = dma_buf_create_and_sample_32bpp(2, 2, fourcc, NULL, 0, src);
 	if (res != PIGLIT_PASS)
 		return res;
 
diff --git a/tests/spec/ext_image_dma_buf_import/sample_yuv.c b/tests/spec/ext_image_dma_buf_import/sample_yuv.c
index a314bc5..856cf04 100644
--- a/tests/spec/ext_image_dma_buf_import/sample_yuv.c
+++ b/tests/spec/ext_image_dma_buf_import/sample_yuv.c
@@ -120,7 +120,7 @@  piglit_display(void)
 
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-	res = dma_buf_create_and_sample_32bpp(4, 4, fourcc, t);
+	res = dma_buf_create_and_sample_32bpp(4, 4, fourcc, NULL, 0, t);
 	if (res != PIGLIT_PASS)
 		return res;