Simple test checking that EGL can close the export file handle
and the creator can in turn can its reference.

Signed-off-by: Topi Pohjolainen <[email protected]>
---
 .../ext_image_dma_buf_import/CMakeLists.gles1.txt  |   1 +
 tests/spec/ext_image_dma_buf_import/close_buffer.c | 117 +++++++++++++++++++++
 2 files changed, 118 insertions(+)
 create mode 100644 tests/spec/ext_image_dma_buf_import/close_buffer.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 e34f4b7..09ccab9 100644
--- a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles1.txt
@@ -13,5 +13,6 @@ link_libraries(
 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)
 
 # vim: ft=cmake:
diff --git a/tests/spec/ext_image_dma_buf_import/close_buffer.c 
b/tests/spec/ext_image_dma_buf_import/close_buffer.c
new file mode 100644
index 0000000..fb03d1b
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/close_buffer.c
@@ -0,0 +1,117 @@
+/*
+ * 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 "ext_image_dma_buf_fourcc.h"
+
+/**
+ * @file close_buffer.c
+ *
+ * From the EXT_image_dma_buf_import spec:
+ *
+ * "3. Does ownership of the file descriptor pass to the EGL library?
+ *
+ *   ANSWER: If eglCreateImageKHR is successful, EGL assumes ownership of the
+ *   file descriptors and is responsible for closing them."
+ *
+ *
+ * Here on checks that the creator of the buffer can drop its reference once
+ * it has given the buffer to EGL, i.e., after calling 'eglCreateImageKHR()'.
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+       config.supports_gl_es_version = 10;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static bool
+test_create_and_destroy(void *buf, int fd, unsigned w, unsigned h,
+                       unsigned stride, unsigned offset)
+{
+       EGLImageKHR img;
+       EGLint attr[] = {
+               EGL_WIDTH, w,
+               EGL_HEIGHT, h,
+               EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
+               EGL_DMA_BUF_PLANE0_FD_EXT, fd,
+               EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
+               EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
+               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 buffer, EGL should have the
+        * ownership now.
+        */
+       piglit_destroy_dma_buf(buf);
+
+       if (!piglit_check_egl_error(EGL_SUCCESS))
+               return false;
+
+       if (!img) {
+               fprintf(stderr, "image creation succeed but returned NULL\n");
+               return false;
+       }
+
+       eglDestroyImageKHR(eglGetCurrentDisplay(), img);
+
+       return piglit_check_egl_error(EGL_SUCCESS);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+       const unsigned char pixels[2 * 2 * 4];
+       struct piglit_dma_buf *buf;
+       unsigned stride;
+       unsigned offset;
+       int fd;
+       enum piglit_result res;
+
+       res = piglit_create_dma_buf(2, 2, 4, pixels, 2 * 4, &buf, &fd, &stride,
+                               &offset);
+       if (res != PIGLIT_PASS)
+               return res;
+
+       return test_create_and_destroy(buf, fd, 2, 2, stride, offset) ?
+                       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

Reply via email to