[Piglit] [v8 10/13] tests/spec: EXT_image_dma_buf_import sample xrgb

Pohjolainen, Topi topi.pohjolainen at intel.com
Mon Aug 5 03:16:04 PDT 2013


On Fri, Aug 02, 2013 at 11:21:33AM -0700, Chad Versace wrote:
> On 08/01/2013 10:45 PM, Pohjolainen, Topi wrote:
> >On Wed, Jul 31, 2013 at 04:10:22PM -0700, Chad Versace wrote:
> >>On 07/10/2013 01:24 AM, Topi Pohjolainen wrote:
> >>>v2:
> >>>    - compile only on platforms that have drm (Eric)
> >>>    - use standard drm definitions for fourcc instead of duplicated
> >>>      local (Daniel, Eric)
> >>>    - use helper variables for width, height and cpp instead
> >>>      of repeating the magic numbers over and over again (Eric)
> >>>    - removed irrelevant quote of the spec (Eric)
> >>>    - used the same refactored common logic as the ARGB test
> >>>
> >>>v3 (Eric):
> >>>    - use properly linked egl-extension calls
> >>>
> >>>v4 (Eric):
> >>>    - add to 'all.tests'
> >>>    - removed inclusion of standard EGL entrypoints as there is the
> >>>      special dispatcher for the test cases to use
> >>>
> >>>v5 (Eric, Chad):
> >>>    - use image external extension for sampling
> >>>    - add into all.tests
> >>>
> >>>Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
> >>>---
> >>>  tests/all.tests                                    |  1 +
> >>>  .../ext_image_dma_buf_import/CMakeLists.gles2.txt  |  1 +
> >>>  .../ext_image_dma_buf_import/sample_xrgb8888.c     | 69 ++++++++++++++++++++++
> >>>  3 files changed, 71 insertions(+)
> >>>  create mode 100644 tests/spec/ext_image_dma_buf_import/sample_xrgb8888.c
> >>>
> >>>diff --git a/tests/all.tests b/tests/all.tests
> >>>index c2e0626..405596b 100644
> >>>--- a/tests/all.tests
> >>>+++ b/tests/all.tests
> >>>@@ -1743,6 +1743,7 @@ add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-invalid_attri
> >>>  add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-missing_attributes')
> >>>  add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-ownership_transfer')
> >>>  add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-sample_argb8888')
> >>>+add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-sample_xrgb8888')
> >>>
> >>>  ext_packed_depth_stencil = Group()
> >>>  spec['EXT_packed_depth_stencil'] = ext_packed_depth_stencil
> >>>diff --git a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
> >>>index 3185bd4..5fc6031 100644
> >>>--- a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
> >>>+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
> >>>@@ -18,6 +18,7 @@ if(LIBDRM_FOUND)
> >>>  	)
> >>>
> >>>  	piglit_add_executable(ext_image_dma_buf_import-sample_argb8888 sample_argb8888.c sample_common.c image_common.c)
> >>>+	piglit_add_executable(ext_image_dma_buf_import-sample_xrgb8888 sample_xrgb8888.c sample_common.c image_common.c)
> >>>  endif(LIBDRM_FOUND)
> >>>
> >>>  # vim: ft=cmake:
> >>>diff --git a/tests/spec/ext_image_dma_buf_import/sample_xrgb8888.c b/tests/spec/ext_image_dma_buf_import/sample_xrgb8888.c
> >>>new file mode 100644
> >>>index 0000000..43415ae
> >>>--- /dev/null
> >>>+++ b/tests/spec/ext_image_dma_buf_import/sample_xrgb8888.c
> >>>@@ -0,0 +1,69 @@
> >>>+/*
> >>>+ * 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"
> >>>+#include <unistd.h>
> >>>+#include <drm_fourcc.h>
> >>>+#include "sample_common.h"
> >>>+#include "image_common.h"
> >>>+
> >>>+/**
> >>>+ * @file sample_xrgb8888.c
> >>>+ *
> >>>+ * Create EGL image out of XRGB8888 formatted dma buffer, set it as external
> >>>+ * texture, set texture filters for avoiding need for other mipmap-levels and
> >>>+ * sample it using a shader program. Additionally check that alpha channel is
> >>>+ * set to one as specified in OES_EGL_image_external:
> >>>+ *
> >>>+ * "If the EGLImage associated with the external texture contains alpha
> >>>+ *  values then the value of the alpha component returned is taken from
> >>>+ *  the image; otherwise the alpha component is 1.0."
> >>>+ */
> >>>+
> >>>+PIGLIT_GL_TEST_CONFIG_BEGIN
> >>>+
> >>>+	config.supports_gl_es_version = 20;
> >>>+
> >>>+PIGLIT_GL_TEST_CONFIG_END
> >>>+
> >>>+enum piglit_result
> >>>+piglit_display(void)
> >>>+{
> >>>+	const unsigned char src[] = {
> >>>+		10, 20, 30, 40, 50, 60, 70, 80,
> >>>+		11, 22, 33, 44, 55, 66, 77, 88 };
> >>>+	enum piglit_result res = dma_buf_create_and_sample_32bpp(
> >>>+					2, 2, 4, DRM_FORMAT_XRGB8888, src);
> >>>+
> >>>+	if (res != PIGLIT_PASS)
> >>>+		return res;
> >>>+
> >>>+	return probe_rect_argb(2, 2, src, true);
> >>>+}
> >>>+
> >>>+void
> >>>+piglit_init(int argc, char **argv)
> >>>+{
> >>>+	piglit_require_egl_extension("EGL_EXT_image_dma_buf_import");
> >>>+	piglit_require_extension("GL_OES_EGL_image_external");
> >>>+}
> >>>
> >>
> >>This test is extremely similar to the test in patch 9. The only differences
> >>are the DRM_FORMAT_XRGB888 and that it checks alpha == 1.
> >>
> >>When tests differ only by formats, then a common convention in Piglit is to
> >>fold all such tests into one excutable that accepts the format as a command
> >>line parameter. The cumulative benefit of doing this throughout Piglit is
> >>that it diminishes Piglit's build time.
> >>
> >>Please fold this test into patch 9. If I recall correctly, the Piglit framework
> >>strips all common command line args such as '-fbo' and '-auto' out of argv before
> >>passing argv to piglit_init().
> >
> >It would in fact require two arguments, one for format and another boolean for
> >telling if alpha channel is expected to be forced to 1.0. Would that be okay?
> 
> The spec says that alpha gets forced to 1.0 if the format has no alpha channel.
> Since that is dictated by the spec, then I think the test only needs one argument,
> the format, because force_alpha can be deduced from the format. At least, I
> think that should work. Am I missing something?
> 

Well I was just trying to keep the test case simple without any logic knowing
about drm-fourcc formats and if the alpha is to be treated specially for one
and not for the other. Something on these lines:


------

Tests that one can sample the given buffer without other mipmap
levels by setting texture filtering accordingly.

v2:
   - compile only on platforms that have drm (Eric)
   - use standard drm definitions for fourcc instead of duplicated
     local (Daniel, Eric)
   - removed irrelevant quote of the spec (Eric)
   - use helper variables for width, height and cpp instead
     of repeating the magic numbers over and over again (Eric)
   - used the same refactored common logic as the mipmap ARGB test

v3 (Eric):
   - use properly linked egl-extension calls

v4 (Eric):
   - add to 'all.tests'
   - removed inclusion of standard EGL entrypoints as there is the
     special dispatcher for the test cases to use

v5 (Eric, Chad):
   - sample using image-external extension
   - fix inclusion in all.tests

v6 (Chad):
   - check for GL error instead of EGL when invoking
     glEGLImageTargetTexture2DOES()
   - allow the test to be skipped if external textures or the
     chosen format are not supported
   - fix the scope of the comment describing the need for closing
     file descriptors in case image creation fails
   - introduce format as command line argument and merge the XRGB
     test here

Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 tests/all.tests                                    |   2 +
 .../ext_image_dma_buf_import/CMakeLists.gles2.txt  |  23 +++
 .../spec/ext_image_dma_buf_import/sample_common.c  | 191 +++++++++++++++++++++
 .../spec/ext_image_dma_buf_import/sample_common.h  |  47 +++++
 tests/spec/ext_image_dma_buf_import/sample_rgb.c   | 103 +++++++++++
 5 files changed, 366 insertions(+)
 create mode 100644 tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
 create mode 100644 tests/spec/ext_image_dma_buf_import/sample_common.c
 create mode 100644 tests/spec/ext_image_dma_buf_import/sample_common.h
 create mode 100644 tests/spec/ext_image_dma_buf_import/sample_rgb.c

diff --git a/tests/all.tests b/tests/all.tests
index 1b5d442..91d57af 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1757,6 +1757,8 @@ add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-invalid_hints
 add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-invalid_attributes')
 add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-missing_attributes')
 add_plain_test(ext_image_dma_buf_import, 'ext_image_dma_buf_import-ownership_transfer')
+ext_image_dma_buf_import['ext_image_dma_buf_import-sample_argb8888'] = PlainExecTest(['ext_image_dma_buf_import-sample_rgb', '-fmt=AR24', '-auto'])
+ext_image_dma_buf_import['ext_image_dma_buf_import-sample_xrgb8888'] = PlainExecTest(['ext_image_dma_buf_import-sample_rgb', '-auto', '-fmt=XR24', '-alpha-one'])
 
 ext_packed_depth_stencil = Group()
 spec['EXT_packed_depth_stencil'] = ext_packed_depth_stencil
diff --git a/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
new file mode 100644
index 0000000..b36e96b
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/CMakeLists.gles2.txt
@@ -0,0 +1,23 @@
+#add_definitions(-DSOURCE_DIR="${piglit_SOURCE_DIR}/")
+
+include_directories(
+	${OPENGL_INCLUDE_PATH}
+	)
+
+link_libraries(
+	${OPENGL_egl_LIBRARY}
+	piglitutil_gles2
+	)
+
+# These tests rely on drm and are hence compiled only on linux/drm platforms
+if(LIBDRM_FOUND)
+	add_definitions(-DHAVE_LIBDRM)
+
+	include_directories(
+		${LIBDRM_INCLUDE_DIRS}
+	)
+
+	piglit_add_executable(ext_image_dma_buf_import-sample_rgb sample_rgb.c sample_common.c image_common.c)
+endif(LIBDRM_FOUND)
+
+# vim: ft=cmake:
diff --git a/tests/spec/ext_image_dma_buf_import/sample_common.c b/tests/spec/ext_image_dma_buf_import/sample_common.c
new file mode 100644
index 0000000..8963045
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/sample_common.c
@@ -0,0 +1,191 @@
+/*
+ * 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 "sample_common.h"
+#include "piglit-util-egl.h"
+#define EGL_EGLEXT_PROTOTYPES 1
+#include <EGL/eglext.h>
+#include <unistd.h>
+
+static const char fs_src[] =
+	"#extension GL_OES_EGL_image_external : require\n"
+	"uniform samplerExternalOES sampler;\n"
+	"varying vec2 texcoords;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"gl_FragColor = texture2D(sampler, texcoords);\n"
+	"}\n";
+static const char vs_src[] =
+	"attribute vec4 position;\n"
+	"varying vec2 texcoords;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"texcoords = 0.5 * (position.xy + vec2(1.0, 1.0));\n"
+	"gl_Position = position;\n"
+	"}\n";
+
+static void
+set_vertices(GLuint prog)
+{
+	static const GLfloat v[] = { -1.0f,  1.0f, -1.0f, -1.0f,
+				      1.0f, -1.0f,  1.0f,  1.0f };
+
+	GLint i = glGetAttribLocation(prog, "position");
+	glVertexAttribPointer(i, 2, GL_FLOAT, GL_FALSE, 0, v);
+	glEnableVertexAttribArray(i);
+}
+
+static enum piglit_result
+sample_and_destroy_img(unsigned w, unsigned h, EGLImageKHR img)
+{
+	GLuint prog, tex;
+	GLenum error;
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
+
+	/* Set the image as level zero */
+	glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES,
+			(GLeglImageOES)img);
+	error = glGetError();
+
+	/**
+	 * EGL may not support binding of external textures, this is not an
+	 * error.
+	 */
+	if (error == GL_INVALID_OPERATION)
+		return PIGLIT_SKIP;
+
+	if (!piglit_check_gl_error(GL_NO_ERROR))
+		return PIGLIT_FAIL;
+
+	glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER,
+			GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER,
+			GL_NEAREST);
+
+	prog = piglit_build_simple_program(vs_src, fs_src);
+	
+	glUseProgram(prog);
+
+	glUniform1i(glGetUniformLocation(prog, "sampler"), 0);
+	set_vertices(prog);
+
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+	glViewport(0, 0, w, h);
+	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+	glDeleteProgram(prog);
+	glUseProgram(0);
+
+	glDeleteTextures(1, &tex);
+	eglDestroyImageKHR(eglGetCurrentDisplay(), img);
+
+	return PIGLIT_PASS;
+}
+
+static enum piglit_result
+sample_buffer(void *buf, int fd, int fourcc, unsigned w, unsigned h,
+	unsigned stride, unsigned offset)
+{
+	EGLImageKHR img;
+	EGLint attr[] = {
+		EGL_WIDTH, w,
+		EGL_HEIGHT, h,
+		EGL_LINUX_DRM_FOURCC_EXT, fourcc,
+		EGL_DMA_BUF_PLANE0_FD_EXT, fd,
+		EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
+		EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
+		EGL_NONE
+	};
+
+	img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
+			EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)0, attr);
+
+	/* Release the creator side of the buffer. */
+	piglit_destroy_dma_buf(buf);
+
+	/* EGL may not support the format, this is not an error. */
+	if (!img && piglit_check_egl_error(EGL_BAD_MATCH))
+		return PIGLIT_SKIP;
+
+	if (!piglit_check_egl_error(EGL_SUCCESS)) {
+		/* Close the descriptor also, EGL does not have ownership */
+		close(fd);
+		return PIGLIT_FAIL;
+	}
+
+	if (!img) {
+		fprintf(stderr, "image creation succeeded but returned NULL\n");
+		return PIGLIT_FAIL;
+	}
+
+	return sample_and_destroy_img(w, h, img);
+}
+
+enum piglit_result
+dma_buf_create_and_sample_32bpp(unsigned w, unsigned h, unsigned cpp,
+			int fourcc, const unsigned char *src)
+{
+	struct piglit_dma_buf *buf;
+	unsigned stride, offset;
+	int fd;
+	enum piglit_result res;
+
+	res = piglit_create_dma_buf(w, h, cpp, src, w * cpp, &buf, &fd, &stride,
+				&offset);
+	if (res != PIGLIT_PASS)
+		return res;
+
+	return sample_buffer(buf, fd, fourcc, w, h, stride, offset);
+}
+
+enum piglit_result
+probe_rect_argb(unsigned w, unsigned h, const unsigned char *argb,
+		bool force_alpha_to_one)
+{
+	const unsigned cpp = 4;
+	unsigned i, j;
+
+	for (i = 0; i < h; ++i) {
+		for (j = 0; j < w; ++j) {
+			float expected[] = {
+				argb[i * w * cpp + j * cpp + 2] / 255.0f,
+				argb[i * w * cpp + j * cpp + 1] / 255.0f,
+				argb[i * w * cpp + j * cpp + 0] / 255.0f,
+				argb[i * w * cpp + j * cpp + 3] / 255.0f};
+
+			if (force_alpha_to_one)
+				expected[3] = 1.0f;
+
+			if (!piglit_probe_pixel_rgba(j, i, expected))
+				return PIGLIT_FAIL;
+		}
+	}
+
+	return PIGLIT_PASS;
+}
+
diff --git a/tests/spec/ext_image_dma_buf_import/sample_common.h b/tests/spec/ext_image_dma_buf_import/sample_common.h
new file mode 100644
index 0000000..abbb93b
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/sample_common.h
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+#ifndef SAMPLE_COMMON_H
+#define SAMPLE_COMMON_H
+
+#include <stdbool.h>
+
+/**
+ * Create a dma buffer with format 'fourcc' setting the given pixels as its
+ * content, create an EGL image against the buffer, bind it as texture and
+ * sample it using a shader program.
+ */
+enum piglit_result
+dma_buf_create_and_sample_32bpp(unsigned w, unsigned h, unsigned cpp,
+			        int fourcc, const unsigned char *src);
+
+/**
+ * A flavour of rectangle probing where each pixel is defined explicitly
+ * instead of assumed to have one and same color. Note that pixels are also
+ * defined in ARGB-order. Setting 'force_alpha_to_one' to true allows one to
+ * ignore the alpha values in the given vector but expect it to have value 1.0.
+ */
+enum piglit_result
+probe_rect_argb(unsigned w, unsigned h, const unsigned char *argb,
+		bool force_alpha_to_one);
+
+#endif /* SAMPLE_COMMON_H */
diff --git a/tests/spec/ext_image_dma_buf_import/sample_rgb.c b/tests/spec/ext_image_dma_buf_import/sample_rgb.c
new file mode 100644
index 0000000..57bc027
--- /dev/null
+++ b/tests/spec/ext_image_dma_buf_import/sample_rgb.c
@@ -0,0 +1,103 @@
+/*
+ * 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"
+#include <unistd.h>
+#include <drm_fourcc.h>
+#include "sample_common.h"
+#include "image_common.h"
+
+/**
+ * @file sample_rgb.c
+ *
+ * Create EGL images out of ARGB8888 and XRGB8888 formatted dma buffers, set
+ * them as external textures, set texture filters for avoiding need for other
+ * mipmap-levels and sample the textures using a shader program.
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es_version = 20;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static bool force_alpha_to_one = false;
+static int fourcc = -1;
+
+enum piglit_result
+piglit_display(void)
+{
+	const unsigned char src[] = {
+		10, 20, 30, 40, 50, 60, 70, 80,
+		11, 22, 33, 44, 55, 66, 77, 88 };
+	enum piglit_result res = dma_buf_create_and_sample_32bpp(
+					2, 2, 4, fourcc, src);
+
+	if (res != PIGLIT_PASS)
+		return res;
+
+	return probe_rect_argb(2, 2, src, force_alpha_to_one);
+}
+
+static int
+parse_format(const char *s)
+{
+	if (strlen(s) != 4)
+		return -1;
+
+	return (int)fourcc_code(s[0], s[1], s[2], s[3]);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	unsigned i;
+
+	piglit_require_egl_extension("EGL_EXT_image_dma_buf_import");
+	piglit_require_extension("GL_OES_EGL_image_external");
+
+	for (i = 1; i < argc; i++) {
+                static const char fmt[] = "-fmt=";
+
+                if (!strcmp(argv[i], "-alpha-one")) {
+			force_alpha_to_one = true;
+                        continue;
+                }
+
+                if (strncmp(argv[i], fmt, sizeof(fmt) - 1)) {
+			fprintf(stderr, "unknown argument %s\n", argv[i]);
+                        continue;
+		}
+
+		fourcc = parse_format(argv[i] + sizeof(fmt) - 1);
+		if (fourcc == -1) {
+			fprintf(stderr, "invalid format: %s\n", argv[i]);
+			piglit_report_result(PIGLIT_SKIP);
+		}
+        }
+
+	if (fourcc == -1) {
+		fprintf(stderr, "format not specified\n");
+		piglit_report_result(PIGLIT_SKIP);
+	}
+}
-- 
1.8.1.2


More information about the Piglit mailing list