2 * Copyright © 2013 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "sample_common.h"
25 #include "image_common.h"
30 * Create EGL images out of ARGB8888 and XRGB8888 formatted dma buffers, set
31 * them as external textures, set texture filters for avoiding need for other
32 * mipmap-levels and sample the textures using a shader program.
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config
.supports_gl_es_version
= 20;
38 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
;
40 PIGLIT_GL_TEST_CONFIG_END
42 static bool force_alpha_to_one
= false;
43 static int fourcc
= -1;
48 const unsigned char src
[] = {
53 const unsigned char expected
[] = {
54 src
[ 2], src
[ 1], src
[ 0], force_alpha_to_one
? 255 : src
[ 3],
55 src
[ 6], src
[ 5], src
[ 4], force_alpha_to_one
? 255 : src
[ 7],
56 src
[10], src
[ 9], src
[ 8], force_alpha_to_one
? 255 : src
[11],
57 src
[14], src
[13], src
[12], force_alpha_to_one
? 255 : src
[15] };
58 enum piglit_result res
;
60 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
62 res
= dma_buf_create_and_sample_32bpp(2, 2, fourcc
, src
);
63 if (res
!= PIGLIT_PASS
)
66 if (!piglit_probe_image_ubyte(0, 0, 2, 2, GL_RGBA
, expected
))
69 piglit_present_results();
75 parse_format(const char *s
)
80 return (int)fourcc_code(s
[0], s
[1], s
[2], s
[3]);
84 piglit_init(int argc
, char **argv
)
87 EGLDisplay egl_dpy
= eglGetCurrentDisplay();
89 piglit_require_egl_extension(egl_dpy
, "EGL_EXT_image_dma_buf_import");
90 piglit_require_extension("GL_OES_EGL_image_external");
92 for (i
= 1; i
< argc
; i
++) {
93 static const char fmt
[] = "-fmt=";
95 if (!strcmp(argv
[i
], "-alpha-one")) {
96 force_alpha_to_one
= true;
100 if (strncmp(argv
[i
], fmt
, sizeof(fmt
) - 1)) {
101 fprintf(stderr
, "unknown argument %s\n", argv
[i
]);
105 fourcc
= parse_format(argv
[i
] + sizeof(fmt
) - 1);
107 fprintf(stderr
, "invalid format: %s\n", argv
[i
]);
108 piglit_report_result(PIGLIT_SKIP
);
113 fprintf(stderr
, "format not specified\n");
114 piglit_report_result(PIGLIT_SKIP
);