Debian Codegraph @

src/egl/main/eglimage.c

raw
1 /**************************************************************************
2 *
3 * Copyright 2009-2010 Chia-I Wu <[email protected]>
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 #include <assert.h>
30 #include <string.h>
31
32 #include "eglcurrent.h"
33 #include "eglimage.h"
34 #include "egllog.h"
35
36 static EGLint
37 _eglParseKHRImageAttribs(_EGLImageAttribs *attrs, _EGLDisplay *disp,
38 EGLint attr, EGLint val)
39 {
40 switch (attr) {
41 case EGL_IMAGE_PRESERVED_KHR:
42 if (!disp->Extensions.KHR_image_base)
43 return EGL_BAD_PARAMETER;
44
45 attrs->ImagePreserved = val;
46 break;
47
48 case EGL_GL_TEXTURE_LEVEL_KHR:
49 if (!disp->Extensions.KHR_gl_texture_2D_image)
50 return EGL_BAD_PARAMETER;
51
52 attrs->GLTextureLevel = val;
53 break;
54 case EGL_GL_TEXTURE_ZOFFSET_KHR:
55 if (!disp->Extensions.KHR_gl_texture_3D_image)
56 return EGL_BAD_PARAMETER;
57
58 attrs->GLTextureZOffset = val;
59 break;
60 case EGL_PROTECTED_CONTENT_EXT:
61 if (!disp->Extensions.EXT_protected_content &&
62 !disp->Extensions.EXT_protected_surface)
63 return EGL_BAD_PARAMETER;
64
65 attrs->ProtectedContent = val;
66 break;
67 default:
68 return EGL_BAD_PARAMETER;
69 }
70
71 return EGL_SUCCESS;
72 }
73
74 #ifdef HAVE_BIND_WL_DISPLAY
75 static EGLint
76 _eglParseWLBindWaylandDisplayAttribs(_EGLImageAttribs *attrs, _EGLDisplay *disp,
77 EGLint attr, EGLint val)
78 {
79 if (!disp->Extensions.WL_bind_wayland_display)
80 return EGL_BAD_PARAMETER;
81
82 switch (attr) {
83 case EGL_WAYLAND_PLANE_WL:
84 attrs->PlaneWL = val;
85 break;
86 default:
87 return EGL_BAD_PARAMETER;
88 }
89
90 return EGL_SUCCESS;
91 }
92 #endif
93
94 static EGLint
95 _eglParseEXTImageDmaBufImportAttribs(_EGLImageAttribs *attrs, _EGLDisplay *disp,
96 EGLint attr, EGLint val)
97 {
98 if (!disp->Extensions.EXT_image_dma_buf_import)
99 return EGL_BAD_PARAMETER;
100
101 switch (attr) {
102 case EGL_WIDTH:
103 attrs->Width = val;
104 break;
105 case EGL_HEIGHT:
106 attrs->Height = val;
107 break;
108 case EGL_LINUX_DRM_FOURCC_EXT:
109 attrs->DMABufFourCC.Value = val;
110 attrs->DMABufFourCC.IsPresent = EGL_TRUE;
111 break;
112 case EGL_DMA_BUF_PLANE0_FD_EXT:
113 attrs->DMABufPlaneFds[0].Value = val;
114 attrs->DMABufPlaneFds[0].IsPresent = EGL_TRUE;
115 break;
116 case EGL_DMA_BUF_PLANE0_OFFSET_EXT:
117 attrs->DMABufPlaneOffsets[0].Value = val;
118 attrs->DMABufPlaneOffsets[0].IsPresent = EGL_TRUE;
119 break;
120 case EGL_DMA_BUF_PLANE0_PITCH_EXT:
121 attrs->DMABufPlanePitches[0].Value = val;
122 attrs->DMABufPlanePitches[0].IsPresent = EGL_TRUE;
123 break;
124 case EGL_DMA_BUF_PLANE1_FD_EXT:
125 attrs->DMABufPlaneFds[1].Value = val;
126 attrs->DMABufPlaneFds[1].IsPresent = EGL_TRUE;
127 break;
128 case EGL_DMA_BUF_PLANE1_OFFSET_EXT:
129 attrs->DMABufPlaneOffsets[1].Value = val;
130 attrs->DMABufPlaneOffsets[1].IsPresent = EGL_TRUE;
131 break;
132 case EGL_DMA_BUF_PLANE1_PITCH_EXT:
133 attrs->DMABufPlanePitches[1].Value = val;
134 attrs->DMABufPlanePitches[1].IsPresent = EGL_TRUE;
135 break;
136 case EGL_DMA_BUF_PLANE2_FD_EXT:
137 attrs->DMABufPlaneFds[2].Value = val;
138 attrs->DMABufPlaneFds[2].IsPresent = EGL_TRUE;
139 break;
140 case EGL_DMA_BUF_PLANE2_OFFSET_EXT:
141 attrs->DMABufPlaneOffsets[2].Value = val;
142 attrs->DMABufPlaneOffsets[2].IsPresent = EGL_TRUE;
143 break;
144 case EGL_DMA_BUF_PLANE2_PITCH_EXT:
145 attrs->DMABufPlanePitches[2].Value = val;
146 attrs->DMABufPlanePitches[2].IsPresent = EGL_TRUE;
147 break;
148 case EGL_YUV_COLOR_SPACE_HINT_EXT:
149 if (val != EGL_ITU_REC601_EXT && val != EGL_ITU_REC709_EXT &&
150 val != EGL_ITU_REC2020_EXT)
151 return EGL_BAD_ATTRIBUTE;
152
153 attrs->DMABufYuvColorSpaceHint.Value = val;
154 attrs->DMABufYuvColorSpaceHint.IsPresent = EGL_TRUE;
155 break;
156 case EGL_SAMPLE_RANGE_HINT_EXT:
157 if (val != EGL_YUV_FULL_RANGE_EXT && val != EGL_YUV_NARROW_RANGE_EXT)
158 return EGL_BAD_ATTRIBUTE;
159
160 attrs->DMABufSampleRangeHint.Value = val;
161 attrs->DMABufSampleRangeHint.IsPresent = EGL_TRUE;
162 break;
163 case EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT:
164 if (val != EGL_YUV_CHROMA_SITING_0_EXT &&
165 val != EGL_YUV_CHROMA_SITING_0_5_EXT)
166 return EGL_BAD_ATTRIBUTE;
167
168 attrs->DMABufChromaHorizontalSiting.Value = val;
169 attrs->DMABufChromaHorizontalSiting.IsPresent = EGL_TRUE;
170 break;
171 case EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT:
172 if (val != EGL_YUV_CHROMA_SITING_0_EXT &&
173 val != EGL_YUV_CHROMA_SITING_0_5_EXT)
174 return EGL_BAD_ATTRIBUTE;
175
176 attrs->DMABufChromaVerticalSiting.Value = val;
177 attrs->DMABufChromaVerticalSiting.IsPresent = EGL_TRUE;
178 break;
179 default:
180 return EGL_BAD_PARAMETER;
181 }
182
183 return EGL_SUCCESS;
184 }
185
186 static EGLint
187 _eglParseEXTImageDmaBufImportModifiersAttribs(_EGLImageAttribs *attrs,
188 _EGLDisplay *disp, EGLint attr,
189 EGLint val)
190 {
191 if (!disp->Extensions.EXT_image_dma_buf_import_modifiers)
192 return EGL_BAD_PARAMETER;
193
194 switch (attr) {
195 case EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT:
196 attrs->DMABufPlaneModifiersLo[0].Value = val;
197 attrs->DMABufPlaneModifiersLo[0].IsPresent = EGL_TRUE;
198 break;
199 case EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT:
200 attrs->DMABufPlaneModifiersHi[0].Value = val;
201 attrs->DMABufPlaneModifiersHi[0].IsPresent = EGL_TRUE;
202 break;
203 case EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT:
204 attrs->DMABufPlaneModifiersLo[1].Value = val;
205 attrs->DMABufPlaneModifiersLo[1].IsPresent = EGL_TRUE;
206 break;
207 case EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT:
208 attrs->DMABufPlaneModifiersHi[1].Value = val;
209 attrs->DMABufPlaneModifiersHi[1].IsPresent = EGL_TRUE;
210 break;
211 case EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT:
212 attrs->DMABufPlaneModifiersLo[2].Value = val;
213 attrs->DMABufPlaneModifiersLo[2].IsPresent = EGL_TRUE;
214 break;
215 case EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT:
216 attrs->DMABufPlaneModifiersHi[2].Value = val;
217 attrs->DMABufPlaneModifiersHi[2].IsPresent = EGL_TRUE;
218 break;
219 case EGL_DMA_BUF_PLANE3_FD_EXT:
220 attrs->DMABufPlaneFds[3].Value = val;
221 attrs->DMABufPlaneFds[3].IsPresent = EGL_TRUE;
222 break;
223 case EGL_DMA_BUF_PLANE3_OFFSET_EXT:
224 attrs->DMABufPlaneOffsets[3].Value = val;
225 attrs->DMABufPlaneOffsets[3].IsPresent = EGL_TRUE;
226 break;
227 case EGL_DMA_BUF_PLANE3_PITCH_EXT:
228 attrs->DMABufPlanePitches[3].Value = val;
229 attrs->DMABufPlanePitches[3].IsPresent = EGL_TRUE;
230 break;
231 case EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT:
232 attrs->DMABufPlaneModifiersLo[3].Value = val;
233 attrs->DMABufPlaneModifiersLo[3].IsPresent = EGL_TRUE;
234 break;
235 case EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT:
236 attrs->DMABufPlaneModifiersHi[3].Value = val;
237 attrs->DMABufPlaneModifiersHi[3].IsPresent = EGL_TRUE;
238 break;
239 default:
240 return EGL_BAD_PARAMETER;
241 }
242
243 return EGL_SUCCESS;
244 }
245
246 /**
247 * Parse the list of image attributes.
248 *
249 * Returns EGL_TRUE on success and EGL_FALSE otherwise.
250 * Function calls _eglError to set the correct error code.
251 */
252 EGLBoolean
253 _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *disp,
254 const EGLint *attrib_list)
255 {
256 EGLint i, err;
257
258 memset(attrs, 0, sizeof(*attrs));
259
260 if (!attrib_list)
261 return EGL_TRUE;
262
263 for (i = 0; attrib_list[i] != EGL_NONE; i++) {
264 EGLint attr = attrib_list[i++];
265 EGLint val = attrib_list[i];
266
267 err = _eglParseKHRImageAttribs(attrs, disp, attr, val);
268 if (err == EGL_SUCCESS)
269 continue;
270
271 #ifdef HAVE_BIND_WL_DISPLAY
272 err = _eglParseWLBindWaylandDisplayAttribs(attrs, disp, attr, val);
273 if (err == EGL_SUCCESS)
274 continue;
275 #endif
276
277 err = _eglParseEXTImageDmaBufImportAttribs(attrs, disp, attr, val);
278 if (err == EGL_SUCCESS)
279 continue;
280
281 /* EXT_image_dma_buf_import states that if invalid value is provided for
282 * its attributes, we should return EGL_BAD_ATTRIBUTE.
283 * Bail out ASAP, since follow-up calls can return another EGL_BAD error.
284 */
285 if (err == EGL_BAD_ATTRIBUTE)
286 return _eglError(err, __func__);
287
288 err =
289 _eglParseEXTImageDmaBufImportModifiersAttribs(attrs, disp, attr, val);
290 if (err == EGL_SUCCESS)
291 continue;
292
293 return _eglError(err, __func__);
294 }
295
296 return EGL_TRUE;
297 }