Create a planar image where all the planes are located in the same dma buffer, just in different offsets.
Signed-off-by: Topi Pohjolainen <[email protected]> --- .../ext_image_dma_buf_import/CMakeLists.gles1.txt | 1 + .../create_yuv420_same_fd.c | 135 +++++++++++++++++++++ 2 files changed, 136 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 f6c4ea7..8cfc90a 100644 --- a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt +++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt @@ -15,5 +15,6 @@ piglit_add_executable(ext_image_dma_buf_import-invalid_attributes invalid_attrib 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) +piglit_add_executable(ext_image_dma_buf_import-create_yuv420_same_fd create_yuv420_same_fd.c) # 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..e8fa8da --- /dev/null +++ b/tests/spec/ext_image_dma_buf_import/create_yuv420_same_fd.c @@ -0,0 +1,135 @@ +/* + * 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_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 + }; + + /** + * 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(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); + + return true; +} + +enum piglit_result +piglit_display(void) +{ + /** + * 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[4 * 4 * 1 + 2 * 2 * 1 + 2 * 2 * 1]; + struct piglit_dma_buf *buf; + unsigned stride; + unsigned offset; + int fd; + enum piglit_result res; + + res = piglit_create_dma_buf(4, 6, 1, pixels, 4 * 1, &buf, &fd, + &stride, &offset); + if (res != PIGLIT_PASS) { + fprintf(stderr, "buffer creation failed\n"); + return res; + } + + return test_create_and_destroy(4, 4, buf, fd, 4, 2, 2, + offset, + offset + 4 * 4 * 1, + offset + 4 * 4 * 1 + 2 * 2 * 1) ? + 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 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
