2 * Copyright © 2016 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 various YUV formatted dma buffers, set
31 * them as external textures, set texture filters for avoiding need
32 * for other mipmap-levels and sample the textures using a shader
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_es_version
= 20;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
;
41 PIGLIT_GL_TEST_CONFIG_END
43 static int fourcc
= -1;
46 format_has_alpha(int fourcc
)
61 12850, 17990, 23130, 28270,
62 12850, 17990, 23130, 28270,
63 12850, 17990, 23130, 28270,
64 12850, 17990, 23130, 28270,
66 30840, 33410, 35980, 33410,
67 30840, 41120, 35980, 41120,
70 static const unsigned char nv12
[] = {
104 /* Increasing alpha ramp. */
146 static unsigned char expected
[4 * 4 * 4] = {
168 const unsigned char *t
;
170 enum piglit_result res
;
172 case DRM_FORMAT_P010
:
173 for (uint32_t i
= 0; i
< ARRAY_SIZE(p0xx
); i
++)
174 p0xx
[i
] &= (1023 << 6);
175 t
= (unsigned char *) p0xx
;
177 case DRM_FORMAT_P012
:
178 for (uint32_t i
= 0; i
< ARRAY_SIZE(p0xx
); i
++)
179 p0xx
[i
] &= (4095 << 4);
180 t
= (unsigned char *) p0xx
;
182 case DRM_FORMAT_P016
:
183 t
= (unsigned char *) p0xx
;
185 case DRM_FORMAT_NV12
:
188 case DRM_FORMAT_YUV420
:
191 case DRM_FORMAT_YVU420
:
194 case DRM_FORMAT_AYUV
:
195 case DRM_FORMAT_XYUV8888
:
198 case DRM_FORMAT_YUYV
:
201 case DRM_FORMAT_UYVY
:
208 /* Modify alpha values of the expected result. */
209 if (format_has_alpha(fourcc
)) {
210 unsigned char *p
= expected
;
211 for (uint32_t i
= 0; i
< 4 * 4; i
++, p
+= 4)
212 p
[3] = i
* (256 / 4);
215 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
217 res
= dma_buf_create_and_sample_32bpp(4, 4, fourcc
, t
);
218 if (res
!= PIGLIT_PASS
)
221 /* Lower tolerance in case we're running against a 565 render
224 piglit_set_tolerance_for_bits(5, 6, 5, 8);
226 if (!piglit_probe_image_ubyte(0, 0, 4, 4, GL_RGBA
, expected
))
229 piglit_present_results();
235 parse_format(const char *s
)
240 return (int)fourcc_code(s
[0], s
[1], s
[2], s
[3]);
244 piglit_init(int argc
, char **argv
)
247 EGLDisplay egl_dpy
= eglGetCurrentDisplay();
249 piglit_require_egl_extension(egl_dpy
, "EGL_EXT_image_dma_buf_import");
250 piglit_require_extension("GL_OES_EGL_image_external");
252 for (i
= 1; i
< argc
; i
++) {
253 static const char fmt
[] = "-fmt=";
255 if (strncmp(argv
[i
], fmt
, sizeof(fmt
) - 1)) {
256 fprintf(stderr
, "unknown argument %s\n", argv
[i
]);
260 fourcc
= parse_format(argv
[i
] + sizeof(fmt
) - 1);
262 fprintf(stderr
, "invalid format: %s\n", argv
[i
]);
263 piglit_report_result(PIGLIT_SKIP
);
268 fprintf(stderr
, "format not specified\n");
269 piglit_report_result(PIGLIT_SKIP
);