[Piglit] [v7 09/12] tests: spec: EXT_image_dma_buf_import planar with single fd

Topi Pohjolainen topi.pohjolainen at intel.com
Tue May 28 02:51:45 PDT 2013


Create a planar image where all the planes are located in the
same dma buffer, just in different offsets.

v2:
   - compile only on platforms that have drm (Eric)
   - use standard drm definitions for fourcc instead of duplicated
     local (Daniel, Eric)
   - try to close the export file descriptor and check that it is
     already closed by the EGL stack (Eric, Chad)
   - use helper variables for width and height (Eric)
   - use helper variable for reporting the result (Chad)

v3:
   - use properly linked egl-extension calls (Eric)
   - check for EBADF and not just for close()-failure (Daniel)

Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 .../ext_image_dma_buf_import/CMakeLists.gles1.txt  |   1 +
 .../create_yuv420_same_fd.c                        | 138 +++++++++++++++++++++
 2 files changed, 139 insertions(+)
 create mode 100644 tests/spec/ext_image_dma_buf_import/create_yuv420_same_fd.c

diff --git a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
index 66707fc..f918703 100644
--- a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
@@ -23,6 +23,7 @@ if(LIBDRM_FOUND)
 	piglit_add_executable(ext_image_dma_buf_import-missing_attributes missing_attributes.c image_common.c)
 	piglit_add_executable(ext_image_dma_buf_import-ownership_transfer ownership_transfer.c image_common.c)
 	piglit_add_executable(ext_image_dma_buf_import-create_yuv420 create_yuv420.c image_common.c)
+	piglit_add_executable(ext_image_dma_buf_import-create_yuv420_same_fd create_yuv420_same_fd.c image_common.c)
 endif(LIBDRM_FOUND)
 
 # vim: ft=cmake:
diff --git a/tests/spec/ext_image_dma_buf_import/create_yuv420_same_fd.c b/tests/spec/ext_image_dma_buf_import/create_yuv420_same_fd.c
new file mode 100644
index 0000000..32f89f0
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/create_yuv420_same_fd.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright © 2013 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "piglit-util-egl.h"
+#define EGL_EGLEXT_PROTOTYPES 1
+#include <EGL/eglext.h>
+#include <unistd.h>
+#include <errno.h>
+#include <drm_fourcc.h>
+#include "image_common.h"
+
+/**
+ * @file create_yuv420_same_fd.c
+ *
+ * Allocates one dma buffer via drm holding all the three planes and creates an
+ * YUV420 formatted EGL image out of it. The intention is to test that EGL can
+ * cope with the same file descriptor being referenced multiple times.
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es_version = 10;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static bool
+test_create_and_destroy(unsigned w, unsigned h,
+			void *buf, int fd,
+			unsigned stride0, unsigned stride1, unsigned stride2,
+			unsigned offset0, unsigned offset1, unsigned offset2)
+{
+	EGLImageKHR img;
+	EGLint attr[] = {
+		EGL_WIDTH, w,
+		EGL_HEIGHT, h,
+		EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_YUV420,
+		EGL_DMA_BUF_PLANE0_FD_EXT, fd,
+		EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset0,
+		EGL_DMA_BUF_PLANE0_PITCH_EXT, stride0,
+		EGL_DMA_BUF_PLANE1_FD_EXT, fd,
+		EGL_DMA_BUF_PLANE1_OFFSET_EXT, offset1,
+		EGL_DMA_BUF_PLANE1_PITCH_EXT, stride1,
+		EGL_DMA_BUF_PLANE2_FD_EXT, fd,
+		EGL_DMA_BUF_PLANE2_OFFSET_EXT, offset2,
+		EGL_DMA_BUF_PLANE2_PITCH_EXT, stride2,
+		EGL_NONE
+	};
+
+	img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
+			EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);
+
+	/**
+	 * Release the creator side of the buffers, EGL should have the
+	 * ownership now.
+	 */
+	piglit_destroy_dma_buf(buf);
+
+	/**
+	 * Upon failure EGL does not take the ownership and the file descriptor
+	 * needs to be closed here.
+	 */
+	if (!piglit_check_egl_error(EGL_SUCCESS)) {
+		close(fd);
+		return false;
+	}
+
+	if (!img) {
+		fprintf(stderr, "image creation succeed but returned NULL\n");
+		return false;
+	}
+
+	eglDestroyImageKHR(eglGetCurrentDisplay(), img);
+
+	if (!piglit_check_egl_error(EGL_SUCCESS))
+		return false;
+
+	/* EGL stack should have closed the importing file descriptor */
+	return close(fd) && errno == EBADF;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	const unsigned w = 4;
+	const unsigned h = 4;
+	/**
+	 * All three planes for 4x4 can be represented using six four-byte rows,
+	 * first four representing 4x4 and the two following 2x2 subsampled
+	 * chroma planes each.
+	 */
+	const unsigned char pixels[w * h + 2 * (w / 2) * (h / 2)];
+	struct piglit_dma_buf *buf;
+	unsigned stride;
+	unsigned offset;
+	int fd;
+	enum piglit_result res;
+	bool pass;
+
+	res = piglit_create_dma_buf(w, h + 2 * (h / 2), 1, pixels, w,
+				&buf, &fd, &stride, &offset);
+	if (res != PIGLIT_PASS) {
+		fprintf(stderr, "buffer creation failed\n");
+		return res;
+	}
+
+	pass = test_create_and_destroy(w, h, buf, fd, stride, (w / 2), (w / 2),
+			offset,
+			offset + w * h,
+			offset + w * h + (w / 2) * (h / 2));
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_egl_extension("EGL_EXT_image_dma_buf_import");
+}
-- 
1.8.1.2



More information about the Piglit mailing list