egl: call _eglError within _eglParseImageAttribList
[mesa.git] / src / egl / main / eglimage.c
1 /**************************************************************************
2 *
3 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
4 * Copyright 2010-2011 LunarG, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29
30 #include <assert.h>
31 #include <string.h>
32
33 #include "eglcurrent.h"
34 #include "eglimage.h"
35 #include "egllog.h"
36
37
38 /**
39 * Parse the list of image attributes.
40 *
41 * Returns EGL_TRUE on success and EGL_FALSE otherwise.
42 * Function calls _eglError to set the correct error code.
43 */
44 EGLBoolean
45 _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
46 const EGLint *attrib_list)
47 {
48 EGLint i, err = EGL_SUCCESS;
49
50 (void) dpy;
51
52 memset(attrs, 0, sizeof(*attrs));
53
54 if (!attrib_list)
55 return EGL_TRUE;
56
57 for (i = 0; attrib_list[i] != EGL_NONE; i++) {
58 EGLint attr = attrib_list[i++];
59 EGLint val = attrib_list[i];
60
61 switch (attr) {
62 /* EGL_KHR_image_base */
63 case EGL_IMAGE_PRESERVED_KHR:
64 attrs->ImagePreserved = val;
65 break;
66
67 /* EGL_KHR_gl_image */
68 case EGL_GL_TEXTURE_LEVEL_KHR:
69 attrs->GLTextureLevel = val;
70 break;
71 case EGL_GL_TEXTURE_ZOFFSET_KHR:
72 attrs->GLTextureZOffset = val;
73 break;
74
75 /* EGL_MESA_drm_image */
76 case EGL_WIDTH:
77 attrs->Width = val;
78 break;
79 case EGL_HEIGHT:
80 attrs->Height = val;
81 break;
82 case EGL_DRM_BUFFER_FORMAT_MESA:
83 attrs->DRMBufferFormatMESA = val;
84 break;
85 case EGL_DRM_BUFFER_USE_MESA:
86 attrs->DRMBufferUseMESA = val;
87 break;
88 case EGL_DRM_BUFFER_STRIDE_MESA:
89 attrs->DRMBufferStrideMESA = val;
90 break;
91
92 /* EGL_WL_bind_wayland_display */
93 case EGL_WAYLAND_PLANE_WL:
94 attrs->PlaneWL = val;
95 break;
96
97 case EGL_LINUX_DRM_FOURCC_EXT:
98 attrs->DMABufFourCC.Value = val;
99 attrs->DMABufFourCC.IsPresent = EGL_TRUE;
100 break;
101 case EGL_DMA_BUF_PLANE0_FD_EXT:
102 attrs->DMABufPlaneFds[0].Value = val;
103 attrs->DMABufPlaneFds[0].IsPresent = EGL_TRUE;
104 break;
105 case EGL_DMA_BUF_PLANE0_OFFSET_EXT:
106 attrs->DMABufPlaneOffsets[0].Value = val;
107 attrs->DMABufPlaneOffsets[0].IsPresent = EGL_TRUE;
108 break;
109 case EGL_DMA_BUF_PLANE0_PITCH_EXT:
110 attrs->DMABufPlanePitches[0].Value = val;
111 attrs->DMABufPlanePitches[0].IsPresent = EGL_TRUE;
112 break;
113 case EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT:
114 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
115 err = EGL_BAD_PARAMETER;
116 attrs->DMABufPlaneModifiersLo[0].Value = val;
117 attrs->DMABufPlaneModifiersLo[0].IsPresent = EGL_TRUE;
118 break;
119 case EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT:
120 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
121 err = EGL_BAD_PARAMETER;
122 attrs->DMABufPlaneModifiersHi[0].Value = val;
123 attrs->DMABufPlaneModifiersHi[0].IsPresent = EGL_TRUE;
124 break;
125 case EGL_DMA_BUF_PLANE1_FD_EXT:
126 attrs->DMABufPlaneFds[1].Value = val;
127 attrs->DMABufPlaneFds[1].IsPresent = EGL_TRUE;
128 break;
129 case EGL_DMA_BUF_PLANE1_OFFSET_EXT:
130 attrs->DMABufPlaneOffsets[1].Value = val;
131 attrs->DMABufPlaneOffsets[1].IsPresent = EGL_TRUE;
132 break;
133 case EGL_DMA_BUF_PLANE1_PITCH_EXT:
134 attrs->DMABufPlanePitches[1].Value = val;
135 attrs->DMABufPlanePitches[1].IsPresent = EGL_TRUE;
136 break;
137 case EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT:
138 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
139 err = EGL_BAD_PARAMETER;
140 attrs->DMABufPlaneModifiersLo[1].Value = val;
141 attrs->DMABufPlaneModifiersLo[1].IsPresent = EGL_TRUE;
142 break;
143 case EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT:
144 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
145 err = EGL_BAD_PARAMETER;
146 attrs->DMABufPlaneModifiersHi[1].Value = val;
147 attrs->DMABufPlaneModifiersHi[1].IsPresent = EGL_TRUE;
148 break;
149 case EGL_DMA_BUF_PLANE2_FD_EXT:
150 attrs->DMABufPlaneFds[2].Value = val;
151 attrs->DMABufPlaneFds[2].IsPresent = EGL_TRUE;
152 break;
153 case EGL_DMA_BUF_PLANE2_OFFSET_EXT:
154 attrs->DMABufPlaneOffsets[2].Value = val;
155 attrs->DMABufPlaneOffsets[2].IsPresent = EGL_TRUE;
156 break;
157 case EGL_DMA_BUF_PLANE2_PITCH_EXT:
158 attrs->DMABufPlanePitches[2].Value = val;
159 attrs->DMABufPlanePitches[2].IsPresent = EGL_TRUE;
160 break;
161 case EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT:
162 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
163 err = EGL_BAD_PARAMETER;
164 attrs->DMABufPlaneModifiersLo[2].Value = val;
165 attrs->DMABufPlaneModifiersLo[2].IsPresent = EGL_TRUE;
166 break;
167 case EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT:
168 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
169 err = EGL_BAD_PARAMETER;
170 attrs->DMABufPlaneModifiersHi[2].Value = val;
171 attrs->DMABufPlaneModifiersHi[2].IsPresent = EGL_TRUE;
172 break;
173 case EGL_DMA_BUF_PLANE3_FD_EXT:
174 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
175 err = EGL_BAD_PARAMETER;
176 attrs->DMABufPlaneFds[3].Value = val;
177 attrs->DMABufPlaneFds[3].IsPresent = EGL_TRUE;
178 break;
179 case EGL_DMA_BUF_PLANE3_OFFSET_EXT:
180 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
181 err = EGL_BAD_PARAMETER;
182 attrs->DMABufPlaneOffsets[3].Value = val;
183 attrs->DMABufPlaneOffsets[3].IsPresent = EGL_TRUE;
184 break;
185 case EGL_DMA_BUF_PLANE3_PITCH_EXT:
186 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
187 err = EGL_BAD_PARAMETER;
188 attrs->DMABufPlanePitches[3].Value = val;
189 attrs->DMABufPlanePitches[3].IsPresent = EGL_TRUE;
190 break;
191 case EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT:
192 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
193 err = EGL_BAD_PARAMETER;
194 attrs->DMABufPlaneModifiersLo[3].Value = val;
195 attrs->DMABufPlaneModifiersLo[3].IsPresent = EGL_TRUE;
196 break;
197 case EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT:
198 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
199 err = EGL_BAD_PARAMETER;
200 attrs->DMABufPlaneModifiersHi[3].Value = val;
201 attrs->DMABufPlaneModifiersHi[3].IsPresent = EGL_TRUE;
202 break;
203 case EGL_YUV_COLOR_SPACE_HINT_EXT:
204 if (val != EGL_ITU_REC601_EXT && val != EGL_ITU_REC709_EXT &&
205 val != EGL_ITU_REC2020_EXT) {
206 err = EGL_BAD_ATTRIBUTE;
207 } else {
208 attrs->DMABufYuvColorSpaceHint.Value = val;
209 attrs->DMABufYuvColorSpaceHint.IsPresent = EGL_TRUE;
210 }
211 break;
212 case EGL_SAMPLE_RANGE_HINT_EXT:
213 if (val != EGL_YUV_FULL_RANGE_EXT && val != EGL_YUV_NARROW_RANGE_EXT) {
214 err = EGL_BAD_ATTRIBUTE;
215 } else {
216 attrs->DMABufSampleRangeHint.Value = val;
217 attrs->DMABufSampleRangeHint.IsPresent = EGL_TRUE;
218 }
219 break;
220 case EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT:
221 if (val != EGL_YUV_CHROMA_SITING_0_EXT &&
222 val != EGL_YUV_CHROMA_SITING_0_5_EXT) {
223 err = EGL_BAD_ATTRIBUTE;
224 } else {
225 attrs->DMABufChromaHorizontalSiting.Value = val;
226 attrs->DMABufChromaHorizontalSiting.IsPresent = EGL_TRUE;
227 }
228 break;
229 case EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT:
230 if (val != EGL_YUV_CHROMA_SITING_0_EXT &&
231 val != EGL_YUV_CHROMA_SITING_0_5_EXT) {
232 err = EGL_BAD_ATTRIBUTE;
233 } else {
234 attrs->DMABufChromaVerticalSiting.Value = val;
235 attrs->DMABufChromaVerticalSiting.IsPresent = EGL_TRUE;
236 }
237 break;
238
239 default:
240 return _eglError(EGL_BAD_ATTRIBUTE, __func__);
241 }
242
243 if (err != EGL_SUCCESS)
244 return _eglError(err, __func__);
245 }
246
247 return EGL_TRUE;
248 }