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 "piglit-framework-gl/piglit_drm_dma_buf.h"
26 #include "image_common.h"
29 * @file invalid_attributes.c
31 * From the EXT_image_dma_buf_import spec:
33 * "* If <target> is EGL_LINUX_DMA_BUF_EXT and <buffer> is not NULL, the
34 * error EGL_BAD_PARAMETER is generated."
38 * "* If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
39 * attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is
40 * generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
41 * attributes are specified.
43 * * If <target> is EGL_LINUX_DMA_BUF_EXT and one or more of the values
44 * specified for a plane's pitch or offset isn't supported by EGL,
45 * EGL_BAD_ACCESS is generated."
48 PIGLIT_GL_TEST_CONFIG_BEGIN
50 config
.supports_gl_es_version
= 10;
52 PIGLIT_GL_TEST_CONFIG_END
54 #define DRM_FORMAT_NONEXISTENT fourcc_code('F', 'O', 'O', '0')
57 test_excess_attributes(unsigned w
, unsigned h
, int fd
, unsigned stride
,
58 unsigned offset
, EGLint attr_id
, EGLint attr_val
)
60 const EGLint excess_attr
[2 * 7 + 1] = {
63 EGL_LINUX_DRM_FOURCC_EXT
, DRM_FORMAT_ARGB8888
,
64 EGL_DMA_BUF_PLANE0_FD_EXT
, fd
,
65 EGL_DMA_BUF_PLANE0_OFFSET_EXT
, offset
,
66 EGL_DMA_BUF_PLANE0_PITCH_EXT
, stride
,
69 EGLImageKHR img
= eglCreateImageKHR(eglGetCurrentDisplay(),
70 EGL_NO_CONTEXT
, EGL_LINUX_DMA_BUF_EXT
,
71 (EGLClientBuffer
)NULL
, excess_attr
);
73 if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE
)) {
75 eglDestroyImageKHR(eglGetCurrentDisplay(), img
);
83 test_buffer_not_null(unsigned w
, unsigned h
, int fd
, unsigned stride
,
90 EGL_LINUX_DRM_FOURCC_EXT
, DRM_FORMAT_ARGB8888
,
91 EGL_DMA_BUF_PLANE0_FD_EXT
, fd
,
92 EGL_DMA_BUF_PLANE0_OFFSET_EXT
, offset
,
93 EGL_DMA_BUF_PLANE0_PITCH_EXT
, stride
,
100 * "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid
101 * display, <ctx> must be EGL_NO_CONTEXT, and <buffer> must be
102 * NULL, cast into the type EGLClientBuffer."
104 img
= eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT
,
105 EGL_LINUX_DMA_BUF_EXT
, (EGLClientBuffer
)1, attr
);
107 if (!piglit_check_egl_error(EGL_BAD_PARAMETER
)) {
109 eglDestroyImageKHR(eglGetCurrentDisplay(), img
);
117 test_invalid_context(unsigned w
, unsigned h
, int fd
, unsigned stride
,
124 EGL_LINUX_DRM_FOURCC_EXT
, DRM_FORMAT_ARGB8888
,
125 EGL_DMA_BUF_PLANE0_FD_EXT
, fd
,
126 EGL_DMA_BUF_PLANE0_OFFSET_EXT
, offset
,
127 EGL_DMA_BUF_PLANE0_PITCH_EXT
, stride
,
134 * "If <target> is EGL_LINUX_DMA_BUF_EXT, <dpy> must be a valid
135 * display, <ctx> must be EGL_NO_CONTEXT, and <buffer> must be
136 * NULL, cast into the type EGLClientBuffer."
138 img
= eglCreateImageKHR(eglGetCurrentDisplay(), eglGetCurrentContext(),
139 EGL_LINUX_DMA_BUF_EXT
, (EGLClientBuffer
)NULL
, attr
);
141 if (!piglit_check_egl_error(EGL_BAD_PARAMETER
)) {
143 eglDestroyImageKHR(eglGetCurrentDisplay(), img
);
151 test_invalid_format(unsigned w
, unsigned h
, int fd
, unsigned stride
,
158 EGL_LINUX_DRM_FOURCC_EXT
, DRM_FORMAT_NONEXISTENT
,
159 EGL_DMA_BUF_PLANE0_FD_EXT
, fd
,
160 EGL_DMA_BUF_PLANE0_OFFSET_EXT
, offset
,
161 EGL_DMA_BUF_PLANE0_PITCH_EXT
, stride
,
168 * "If <target> is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
169 * attribute is set to a format not supported by the EGL, EGL_BAD_MATCH
172 img
= eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT
,
173 EGL_LINUX_DMA_BUF_EXT
, (EGLClientBuffer
)0, attr
);
175 if (!piglit_check_egl_error(EGL_BAD_MATCH
)) {
177 eglDestroyImageKHR(eglGetCurrentDisplay(), img
);
185 test_pitch_zero(unsigned w
, unsigned h
, int fd
, unsigned stride
,
192 EGL_LINUX_DRM_FOURCC_EXT
, DRM_FORMAT_ARGB8888
,
193 EGL_DMA_BUF_PLANE0_FD_EXT
, fd
,
194 EGL_DMA_BUF_PLANE0_OFFSET_EXT
, offset
,
195 EGL_DMA_BUF_PLANE0_PITCH_EXT
, 0,
199 img
= eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT
,
200 EGL_LINUX_DMA_BUF_EXT
, (EGLClientBuffer
)0, attr
);
202 if (!piglit_check_egl_error(EGL_BAD_ACCESS
)) {
204 eglDestroyImageKHR(eglGetCurrentDisplay(), img
);
212 * One and same buffer is used for all the tests. Each test is expected to fail
213 * meaning that the ownership is not transferred to the EGL in any point.
218 const unsigned w
= 2;
219 const unsigned h
= 2;
220 const unsigned cpp
= 4;
221 const unsigned fourcc
= DRM_FORMAT_ARGB8888
;
222 const unsigned char *pixels
= alloca(w
* h
* cpp
);
223 struct piglit_dma_buf
*buf
;
224 enum piglit_result res
;
227 res
= piglit_create_dma_buf(w
, h
, fourcc
, pixels
, &buf
);
228 if (res
!= PIGLIT_PASS
)
231 pass
= test_excess_attributes(w
, h
, buf
->fd
, buf
->stride
[0], buf
->offset
[0],
232 EGL_DMA_BUF_PLANE1_FD_EXT
, buf
->fd
) && pass
;
233 pass
= test_excess_attributes(w
, h
, buf
->fd
, buf
->stride
[0], buf
->offset
[0],
234 EGL_DMA_BUF_PLANE1_OFFSET_EXT
, 0) && pass
;
235 pass
= test_excess_attributes(w
, h
, buf
->fd
, buf
->stride
[0], buf
->offset
[0],
236 EGL_DMA_BUF_PLANE1_PITCH_EXT
, buf
->stride
[0]) && pass
;
237 pass
= test_excess_attributes(w
, h
, buf
->fd
, buf
->stride
[0], buf
->offset
[0],
238 EGL_DMA_BUF_PLANE2_FD_EXT
, buf
->fd
) && pass
;
239 pass
= test_excess_attributes(w
, h
, buf
->fd
, buf
->stride
[0], buf
->offset
[0],
240 EGL_DMA_BUF_PLANE2_OFFSET_EXT
, 0) && pass
;
241 pass
= test_excess_attributes(w
, h
, buf
->fd
, buf
->stride
[0], buf
->offset
[0],
242 EGL_DMA_BUF_PLANE2_PITCH_EXT
, buf
->stride
[0]) && pass
;
243 pass
= test_buffer_not_null(w
, h
, buf
->fd
, buf
->stride
[0], buf
->offset
[0]) && pass
;
244 pass
= test_invalid_context(w
, h
, buf
->fd
, buf
->stride
[0], buf
->offset
[0]) && pass
;
245 pass
= test_invalid_format(w
, h
, buf
->fd
, buf
->stride
[0], buf
->offset
[0]) && pass
;
246 pass
= test_pitch_zero(w
, h
, buf
->fd
, buf
->stride
[0], buf
->offset
[0]) && pass
;
249 * EGL stack can claim the ownership of the file descriptor only when it
250 * succeeds. Close the file descriptor here and check that it really
251 * wasn't closed by EGL.
253 pass
= (close(buf
->fd
) == 0) && pass
;
255 piglit_destroy_dma_buf(buf
);
257 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
261 piglit_init(int argc
, char **argv
)
263 EGLDisplay egl_dpy
= eglGetCurrentDisplay();
264 piglit_require_egl_extension(egl_dpy
, "EGL_EXT_image_dma_buf_import");