ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_image_dma_buf_import / invalid_hints.c
blobc2b43a23a4bf3d4f6318b3790258f5f3ecd98b89
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
24 #include "piglit-framework-gl/piglit_drm_dma_buf.h"
26 #include "image_common.h"
28 /**
29 * @file invalid_hints.c
31 * From the EXT_image_dma_buf_import spec:
33 * "Accepted as the value for the EGL_YUV_COLOR_SPACE_HINT_EXT attribute:
35 * EGL_ITU_REC601_EXT 0x327F
36 * EGL_ITU_REC709_EXT 0x3280
37 * EGL_ITU_REC2020_EXT 0x3281
39 * Accepted as the value for the EGL_SAMPLE_RANGE_HINT_EXT attribute:
41 * EGL_YUV_FULL_RANGE_EXT 0x3282
42 * EGL_YUV_NARROW_RANGE_EXT 0x3283
44 * Accepted as the value for the EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT &
45 * EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT attributes:
47 * EGL_YUV_CHROMA_SITING_0_EXT 0x3284
48 * EGL_YUV_CHROMA_SITING_0_5_EXT 0x3285"
51 * In order to test these, one needs to have the following in place:
52 * EGL_WIDTH, EGL_HEIGHT, EGL_LINUX_DRM_FOURCC_EXT, EGL_DMA_BUF_PLANE0_FD_EXT,
53 * EGL_DMA_BUF_PLANE0_OFFSET_EXT and EGL_DMA_BUF_PLANE0_PITCH_EXT.
55 * \see invalid_attributes.c and missing_attributes.c
58 PIGLIT_GL_TEST_CONFIG_BEGIN
60 config.supports_gl_es_version = 10;
62 PIGLIT_GL_TEST_CONFIG_END
64 static bool
65 test_invalid_hint(unsigned w, unsigned h, int fd, unsigned stride,
66 unsigned offset, int hint, int val)
68 EGLImageKHR img;
69 EGLint attr[] = {
70 EGL_WIDTH, w,
71 EGL_HEIGHT, h,
72 EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ARGB8888,
73 EGL_DMA_BUF_PLANE0_FD_EXT, fd,
74 EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset,
75 EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
76 hint, val,
77 EGL_NONE
80 img = eglCreateImageKHR(eglGetCurrentDisplay(), EGL_NO_CONTEXT,
81 EGL_LINUX_DMA_BUF_EXT, (EGLClientBuffer)NULL, attr);
83 if (!piglit_check_egl_error(EGL_BAD_ATTRIBUTE)) {
84 if (img)
85 eglDestroyImageKHR(eglGetCurrentDisplay(), img);
86 return false;
89 return true;
92 /**
93 * One and same buffer is used for all the tests. Each test is expected to fail
94 * meaning that the ownership is not transferred to the EGL in any point.
96 enum piglit_result
97 piglit_display(void)
99 const unsigned w = 2;
100 const unsigned h = 2;
101 const unsigned cpp = 4;
102 const unsigned fourcc = DRM_FORMAT_ARGB8888;
103 const unsigned char *pixels = alloca(w * h * cpp);
104 struct piglit_dma_buf *buf;
105 enum piglit_result res;
106 bool pass = true;
108 res = piglit_create_dma_buf(w, h, fourcc, pixels, &buf);
109 if (res != PIGLIT_PASS)
110 return res;
112 pass = test_invalid_hint(w, h, buf->fd, buf->stride[0], buf->offset[0],
113 EGL_YUV_COLOR_SPACE_HINT_EXT, 0) && pass;
114 pass = test_invalid_hint(w, h, buf->fd, buf->stride[0], buf->offset[0],
115 EGL_SAMPLE_RANGE_HINT_EXT, 0) && pass;
116 pass = test_invalid_hint(w, h, buf->fd, buf->stride[0], buf->offset[0],
117 EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT, 0) && pass;
118 pass = test_invalid_hint(w, h, buf->fd, buf->stride[0], buf->offset[0],
119 EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT, 0) && pass;
122 * EGL stack can claim the ownership of the file descriptor only when it
123 * succeeds. Close the descriptor and check that it really wasn't closed
124 * by EGL.
126 pass = (close(buf->fd) == 0) && pass;
128 piglit_destroy_dma_buf(buf);
130 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
133 void
134 piglit_init(int argc, char **argv)
136 EGLDisplay egl_dpy = eglGetCurrentDisplay();
137 piglit_require_egl_extension(egl_dpy, "EGL_EXT_image_dma_buf_import");