[Piglit] [v5 08/12] tests: spec: EXT_image_dma_buf_import planar with multiple fds

Topi Pohjolainen topi.pohjolainen at intel.com
Fri May 3 04:26:18 PDT 2013


Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 .../ext_image_dma_buf_import/CMakeLists.gles1.txt  |   1 +
 .../spec/ext_image_dma_buf_import/create_yuv420.c  | 154 +++++++++++++++++++++
 .../ext_image_dma_buf_fourcc.h                     |   1 +
 3 files changed, 156 insertions(+)
 create mode 100644 tests/spec/ext_image_dma_buf_import/create_yuv420.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 09ccab9..f6c4ea7 100644
--- a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
@@ -14,5 +14,6 @@ piglit_add_executable(ext_image_dma_buf_import-invalid_hints invalid_hints.c)
 piglit_add_executable(ext_image_dma_buf_import-invalid_attributes invalid_attributes.c)
 piglit_add_executable(ext_image_dma_buf_import-missing_attributes missing_attributes.c)
 piglit_add_executable(ext_image_dma_buf_import-close_buffer close_buffer.c)
+piglit_add_executable(ext_image_dma_buf_import-create_yuv420 create_yuv420.c)
 
 # vim: ft=cmake:
diff --git a/tests/spec/ext_image_dma_buf_import/create_yuv420.c b/tests/spec/ext_image_dma_buf_import/create_yuv420.c
new file mode 100644
index 0000000..aee94d2
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/create_yuv420.c
@@ -0,0 +1,154 @@
+/*
+ * 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 "ext_image_dma_buf_fourcc.h"
+
+/**
+ * @file create_yuv420.c
+ *
+ * Allocates three dma buffers from via drm and creates an YUV420 formatted EGL
+ * image each buffer representing one plane.
+ */
+
+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 *buf0, void *buf1, void *buf2,
+			int fd0, int fd1, int fd2,
+			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, fd0,
+		EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset0,
+		EGL_DMA_BUF_PLANE0_PITCH_EXT, stride0,
+		EGL_DMA_BUF_PLANE1_FD_EXT, fd1,
+		EGL_DMA_BUF_PLANE1_OFFSET_EXT, offset1,
+		EGL_DMA_BUF_PLANE1_PITCH_EXT, stride1,
+		EGL_DMA_BUF_PLANE2_FD_EXT, fd2,
+		EGL_DMA_BUF_PLANE2_OFFSET_EXT, offset2,
+		EGL_DMA_BUF_PLANE2_PITCH_EXT, stride2,
+		EGL_NONE
+	};
+
+	/**
+	 * The spec says:
+	 *
+	 *     "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid
+	 *      display, <ctx> must be EGL_NO_CONTEXT, and <buffer> must be
+	 *      NULL, cast into the type EGLClientBuffer."
+	 */
+	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(buf0);
+	piglit_destroy_dma_buf(buf1);
+	piglit_destroy_dma_buf(buf2);
+
+	/**
+	 * Upon failure EGL does _not_ take the ownership, and needs to close
+	 * the file descriptors here.
+	 */
+	if (!piglit_check_egl_error(EGL_SUCCESS)) {
+		close(fd0);
+		close(fd1);
+		close(fd2);
+		return false;
+	}
+
+	if (!img) {
+		fprintf(stderr, "image creation succeed but returned NULL\n");
+		return false;
+	}
+
+	eglDestroyImageKHR(eglGetCurrentDisplay(), img);
+
+	return true;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	const unsigned char pixels0[4 * 4 * 1];
+	const unsigned char pixels1[2 * 2 * 1];
+	const unsigned char pixels2[2 * 2 * 1];
+	struct piglit_dma_buf *buf0, *buf1, *buf2;
+	unsigned stride0, stride1, stride2;
+	unsigned offset0, offset1, offset2;
+	int fd0, fd1, fd2;
+	enum piglit_result res;
+
+	res = piglit_create_dma_buf(4, 4, 1, pixels0, 4 * 1, &buf0, &fd0,
+				&stride0, &offset0);
+	if (res != PIGLIT_PASS) {
+		fprintf(stderr, "buffer creation for Y-plane failed\n");
+		return res;
+	}
+
+	res = piglit_create_dma_buf(2, 2, 1, pixels1, 2 * 1, &buf1, &fd1,
+				&stride1, &offset1);
+	if (res != PIGLIT_PASS) {
+		fprintf(stderr, "buffer creation for U-plane failed\n");
+		piglit_destroy_dma_buf(buf0);
+		close(fd0);
+		return res;
+	}
+
+	res = piglit_create_dma_buf(2, 2, 1, pixels2, 2 * 1, &buf2, &fd2,
+				&stride2, &offset2);
+	if (res != PIGLIT_PASS) {
+		fprintf(stderr, "buffer creation for V-plane failed\n");
+		piglit_destroy_dma_buf(buf0);
+		piglit_destroy_dma_buf(buf1);
+		close(fd0);
+		close(fd1);
+		return res;
+	}
+
+	return test_create_and_destroy(4, 4, buf0, buf1, buf2, fd0, fd1, fd2,
+			stride0, stride1, stride2, offset0, offset1, offset2) ?
+			PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_egl_extension("EGL_EXT_image_dma_buf_import");
+}
diff --git a/tests/spec/ext_image_dma_buf_import/ext_image_dma_buf_fourcc.h b/tests/spec/ext_image_dma_buf_import/ext_image_dma_buf_fourcc.h
index 5432ff0..7d39d5c 100644
--- a/tests/spec/ext_image_dma_buf_import/ext_image_dma_buf_fourcc.h
+++ b/tests/spec/ext_image_dma_buf_import/ext_image_dma_buf_fourcc.h
@@ -27,5 +27,6 @@
 				((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
 #define DRM_FORMAT_ARGB8888 fourcc_code('A', 'R', '2', '4')
 #define DRM_FORMAT_INVALID fourcc_code('F', 'O', 'O', '0')
+#define DRM_FORMAT_YUV420 fourcc_code('Y', 'U', '1', '2')
 
 #endif /* EXT_IMAGE_DMA_BUF_FOURCC_H */
-- 
1.8.1.2



More information about the Piglit mailing list