[Piglit] [v6 08/12] tests: spec: EXT_image_dma_buf_import planar with multiple fds
Topi Pohjolainen
topi.pohjolainen at intel.com
Thu May 16 02:51:21 PDT 2013
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, height and cpp instead of
repeating the magic numbers over and over again (Eric)
- removed irrelevant quotes of the spec (Eric)
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 +++++++++++++++++++++
2 files changed, 155 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 e54b4d4..edc508a 100644
--- a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
@@ -22,6 +22,7 @@ if(LIBDRM_FOUND)
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-ownership_transfer ownership_transfer.c)
+ piglit_add_executable(ext_image_dma_buf_import-create_yuv420 create_yuv420.c)
endif(LIBDRM_FOUND)
# 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..4729a3d
--- /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 <drm_fourcc.h>
+#include <unistd.h>
+#include <errno.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
+ };
+
+ 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);
+
+ if (!piglit_check_egl_error(EGL_SUCCESS))
+ return false;
+
+ /* EGL stack should have closed the importing file descriptors */
+ return close(fd0) && close(fd1) && close(fd2);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ const unsigned w = 4;
+ const unsigned h = 4;
+ const unsigned char y[w * h];
+ const unsigned char u[(w / 2) * (h / 2)];
+ const unsigned char v[(w / 2) * (h / 2)];
+ 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(w, h, 1, y, w,
+ &buf0, &fd0, &stride0, &offset0);
+ if (res != PIGLIT_PASS) {
+ fprintf(stderr, "buffer creation for Y-plane failed\n");
+ return res;
+ }
+
+ res = piglit_create_dma_buf(w / 2, h / 2, 1, u, w / 2,
+ &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(w / 2, h / 2, 1, v, w / 2,
+ &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(w, h, 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");
+}
--
1.8.1.2
More information about the Piglit
mailing list