[Piglit] [PATCH 3/8] sample_common: Factor out image creation for a dmabuf fd.

Eric Anholt eric at anholt.net
Tue Jul 26 00:43:39 UTC 2016


I need to reuse this part, without the destruction, for refcounting
tests.
---
 .../spec/ext_image_dma_buf_import/sample_common.c  | 40 ++++++++++++++++------
 .../spec/ext_image_dma_buf_import/sample_common.h  |  4 +++
 2 files changed, 34 insertions(+), 10 deletions(-)

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 7373cd4c5176..370baa426693 100644
--- a/tests/spec/ext_image_dma_buf_import/sample_common.c
+++ b/tests/spec/ext_image_dma_buf_import/sample_common.c
@@ -110,9 +110,9 @@ sample_and_destroy_img(unsigned w, unsigned h, EGLImageKHR img)
 	return PIGLIT_PASS;
 }
 
-static enum piglit_result
-sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h,
-	unsigned stride, unsigned offset)
+enum piglit_result
+egl_image_for_dma_buf_fd(int fd, int fourcc, int w, int h,
+			 unsigned stride, unsigned offset, EGLImageKHR *out_img)
 {
 	EGLint error;
 	EGLImageKHR img;
@@ -170,10 +170,9 @@ sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h,
 	}
 
 	img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
-				EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);
-
-	/* Release the creator side of the buffer. */
-	piglit_destroy_dma_buf(buf);
+				 EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0,
+				 attr);
+	*out_img = img;
 
 	error = eglGetError();
 
@@ -185,9 +184,6 @@ sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h,
 		printf("eglCreateImageKHR() failed: %s 0x%x\n",
 			piglit_get_egl_error_name(error), error);
 
-		/* Close the descriptor also, EGL does not have ownership */
-		close(fd);
-
 		return PIGLIT_FAIL;
 	}
 
@@ -196,6 +192,30 @@ sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h,
 		return PIGLIT_FAIL;
 	}
 
+	*out_img = img;
+	return PIGLIT_PASS;
+}
+
+static enum piglit_result
+sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h,
+	      unsigned stride, unsigned offset)
+{
+	enum piglit_result res;
+	EGLImageKHR img;
+
+	res = egl_image_for_dma_buf_fd(fd, fourcc, w, h, stride, offset, &img);
+
+	/* Release the creator side of the buffer. */
+	piglit_destroy_dma_buf(buf);
+
+	if (!img) {
+		/* Close the descriptor also, EGL does not have ownership */
+		close(fd);
+	}
+
+	if (res != PIGLIT_PASS)
+		return res;
+
 	return sample_and_destroy_img(w, h, img);
 }
 
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 8559e9fe5896..7160b816ca03 100644
--- a/tests/spec/ext_image_dma_buf_import/sample_common.h
+++ b/tests/spec/ext_image_dma_buf_import/sample_common.h
@@ -35,4 +35,8 @@ enum piglit_result
 dma_buf_create_and_sample_32bpp(unsigned w, unsigned h, unsigned cpp,
 			        int fourcc, const unsigned char *src);
 
+enum piglit_result
+egl_image_for_dma_buf_fd(int fd, int fourcc, int w, int h,
+			 unsigned stride, unsigned offset, EGLImageKHR *out_img);
+
 #endif /* SAMPLE_COMMON_H */
-- 
2.8.1



More information about the Piglit mailing list