egl: drop _eglInitImage() return type
[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 "eglimage.h"
34 #include "egllog.h"
35
36
37 /**
38 * Parse the list of image attributes and return the proper error code.
39 */
40 EGLint
41 _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
42 const EGLint *attrib_list)
43 {
44 EGLint i, err = EGL_SUCCESS;
45
46 (void) dpy;
47
48 memset(attrs, 0, sizeof(*attrs));
49
50 if (!attrib_list)
51 return err;
52
53 for (i = 0; attrib_list[i] != EGL_NONE; i++) {
54 EGLint attr = attrib_list[i++];
55 EGLint val = attrib_list[i];
56
57 switch (attr) {
58 /* EGL_KHR_image_base */
59 case EGL_IMAGE_PRESERVED_KHR:
60 attrs->ImagePreserved = val;
61 break;
62
63 /* EGL_KHR_gl_image */
64 case EGL_GL_TEXTURE_LEVEL_KHR:
65 attrs->GLTextureLevel = val;
66 break;
67 case EGL_GL_TEXTURE_ZOFFSET_KHR:
68 attrs->GLTextureZOffset = val;
69 break;
70
71 /* EGL_MESA_drm_image */
72 case EGL_WIDTH:
73 attrs->Width = val;
74 break;
75 case EGL_HEIGHT:
76 attrs->Height = val;
77 break;
78 case EGL_DRM_BUFFER_FORMAT_MESA:
79 attrs->DRMBufferFormatMESA = val;
80 break;
81 case EGL_DRM_BUFFER_USE_MESA:
82 attrs->DRMBufferUseMESA = val;
83 break;
84 case EGL_DRM_BUFFER_STRIDE_MESA:
85 attrs->DRMBufferStrideMESA = val;
86 break;
87
88 /* EGL_WL_bind_wayland_display */
89 case EGL_WAYLAND_PLANE_WL:
90 attrs->PlaneWL = val;
91 break;
92
93 case EGL_LINUX_DRM_FOURCC_EXT:
94 attrs->DMABufFourCC.Value = val;
95 attrs->DMABufFourCC.IsPresent = EGL_TRUE;
96 break;
97 case EGL_DMA_BUF_PLANE0_FD_EXT:
98 attrs->DMABufPlaneFds[0].Value = val;
99 attrs->DMABufPlaneFds[0].IsPresent = EGL_TRUE;
100 break;
101 case EGL_DMA_BUF_PLANE0_OFFSET_EXT:
102 attrs->DMABufPlaneOffsets[0].Value = val;
103 attrs->DMABufPlaneOffsets[0].IsPresent = EGL_TRUE;
104 break;
105 case EGL_DMA_BUF_PLANE0_PITCH_EXT:
106 attrs->DMABufPlanePitches[0].Value = val;
107 attrs->DMABufPlanePitches[0].IsPresent = EGL_TRUE;
108 break;
109 case EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT:
110 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
111 err = EGL_BAD_PARAMETER;
112 attrs->DMABufPlaneModifiersLo[0].Value = val;
113 attrs->DMABufPlaneModifiersLo[0].IsPresent = EGL_TRUE;
114 break;
115 case EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT:
116 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
117 err = EGL_BAD_PARAMETER;
118 attrs->DMABufPlaneModifiersHi[0].Value = val;
119 attrs->DMABufPlaneModifiersHi[0].IsPresent = EGL_TRUE;
120 break;
121 case EGL_DMA_BUF_PLANE1_FD_EXT:
122 attrs->DMABufPlaneFds[1].Value = val;
123 attrs->DMABufPlaneFds[1].IsPresent = EGL_TRUE;
124 break;
125 case EGL_DMA_BUF_PLANE1_OFFSET_EXT:
126 attrs->DMABufPlaneOffsets[1].Value = val;
127 attrs->DMABufPlaneOffsets[1].IsPresent = EGL_TRUE;
128 break;
129 case EGL_DMA_BUF_PLANE1_PITCH_EXT:
130 attrs->DMABufPlanePitches[1].Value = val;
131 attrs->DMABufPlanePitches[1].IsPresent = EGL_TRUE;
132 break;
133 case EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT:
134 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
135 err = EGL_BAD_PARAMETER;
136 attrs->DMABufPlaneModifiersLo[1].Value = val;
137 attrs->DMABufPlaneModifiersLo[1].IsPresent = EGL_TRUE;
138 break;
139 case EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT:
140 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
141 err = EGL_BAD_PARAMETER;
142 attrs->DMABufPlaneModifiersHi[1].Value = val;
143 attrs->DMABufPlaneModifiersHi[1].IsPresent = EGL_TRUE;
144 break;
145 case EGL_DMA_BUF_PLANE2_FD_EXT:
146 attrs->DMABufPlaneFds[2].Value = val;
147 attrs->DMABufPlaneFds[2].IsPresent = EGL_TRUE;
148 break;
149 case EGL_DMA_BUF_PLANE2_OFFSET_EXT:
150 attrs->DMABufPlaneOffsets[2].Value = val;
151 attrs->DMABufPlaneOffsets[2].IsPresent = EGL_TRUE;
152 break;
153 case EGL_DMA_BUF_PLANE2_PITCH_EXT:
154 attrs->DMABufPlanePitches[2].Value = val;
155 attrs->DMABufPlanePitches[2].IsPresent = EGL_TRUE;
156 break;
157 case EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT:
158 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
159 err = EGL_BAD_PARAMETER;
160 attrs->DMABufPlaneModifiersLo[2].Value = val;
161 attrs->DMABufPlaneModifiersLo[2].IsPresent = EGL_TRUE;
162 break;
163 case EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT:
164 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
165 err = EGL_BAD_PARAMETER;
166 attrs->DMABufPlaneModifiersHi[2].Value = val;
167 attrs->DMABufPlaneModifiersHi[2].IsPresent = EGL_TRUE;
168 break;
169 case EGL_DMA_BUF_PLANE3_FD_EXT:
170 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
171 err = EGL_BAD_PARAMETER;
172 attrs->DMABufPlaneFds[3].Value = val;
173 attrs->DMABufPlaneFds[3].IsPresent = EGL_TRUE;
174 break;
175 case EGL_DMA_BUF_PLANE3_OFFSET_EXT:
176 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
177 err = EGL_BAD_PARAMETER;
178 attrs->DMABufPlaneOffsets[3].Value = val;
179 attrs->DMABufPlaneOffsets[3].IsPresent = EGL_TRUE;
180 break;
181 case EGL_DMA_BUF_PLANE3_PITCH_EXT:
182 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
183 err = EGL_BAD_PARAMETER;
184 attrs->DMABufPlanePitches[3].Value = val;
185 attrs->DMABufPlanePitches[3].IsPresent = EGL_TRUE;
186 break;
187 case EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT:
188 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
189 err = EGL_BAD_PARAMETER;
190 attrs->DMABufPlaneModifiersLo[3].Value = val;
191 attrs->DMABufPlaneModifiersLo[3].IsPresent = EGL_TRUE;
192 break;
193 case EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT:
194 if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
195 err = EGL_BAD_PARAMETER;
196 attrs->DMABufPlaneModifiersHi[3].Value = val;
197 attrs->DMABufPlaneModifiersHi[3].IsPresent = EGL_TRUE;
198 break;
199 case EGL_YUV_COLOR_SPACE_HINT_EXT:
200 if (val != EGL_ITU_REC601_EXT && val != EGL_ITU_REC709_EXT &&
201 val != EGL_ITU_REC2020_EXT) {
202 err = EGL_BAD_ATTRIBUTE;
203 } else {
204 attrs->DMABufYuvColorSpaceHint.Value = val;
205 attrs->DMABufYuvColorSpaceHint.IsPresent = EGL_TRUE;
206 }
207 break;
208 case EGL_SAMPLE_RANGE_HINT_EXT:
209 if (val != EGL_YUV_FULL_RANGE_EXT && val != EGL_YUV_NARROW_RANGE_EXT) {
210 err = EGL_BAD_ATTRIBUTE;
211 } else {
212 attrs->DMABufSampleRangeHint.Value = val;
213 attrs->DMABufSampleRangeHint.IsPresent = EGL_TRUE;
214 }
215 break;
216 case EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT:
217 if (val != EGL_YUV_CHROMA_SITING_0_EXT &&
218 val != EGL_YUV_CHROMA_SITING_0_5_EXT) {
219 err = EGL_BAD_ATTRIBUTE;
220 } else {
221 attrs->DMABufChromaHorizontalSiting.Value = val;
222 attrs->DMABufChromaHorizontalSiting.IsPresent = EGL_TRUE;
223 }
224 break;
225 case EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT:
226 if (val != EGL_YUV_CHROMA_SITING_0_EXT &&
227 val != EGL_YUV_CHROMA_SITING_0_5_EXT) {
228 err = EGL_BAD_ATTRIBUTE;
229 } else {
230 attrs->DMABufChromaVerticalSiting.Value = val;
231 attrs->DMABufChromaVerticalSiting.IsPresent = EGL_TRUE;
232 }
233 break;
234
235 default:
236 /* unknown attrs are ignored */
237 break;
238 }
239
240 if (err != EGL_SUCCESS) {
241 _eglLog(_EGL_DEBUG, "bad image attribute 0x%04x", attr);
242 break;
243 }
244 }
245
246 return err;
247 }