1 /**************************************************************************
3 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
4 * Copyright 2010-2011 LunarG, Inc.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
27 **************************************************************************/
33 #include "eglcurrent.h"
39 * Parse the list of image attributes.
41 * Returns EGL_TRUE on success and EGL_FALSE otherwise.
42 * Function calls _eglError to set the correct error code.
45 _eglParseImageAttribList(_EGLImageAttribs
*attrs
, _EGLDisplay
*dpy
,
46 const EGLint
*attrib_list
)
48 EGLint i
, err
= EGL_SUCCESS
;
52 memset(attrs
, 0, sizeof(*attrs
));
57 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
++) {
58 EGLint attr
= attrib_list
[i
++];
59 EGLint val
= attrib_list
[i
];
62 /* EGL_KHR_image_base */
63 case EGL_IMAGE_PRESERVED_KHR
:
64 attrs
->ImagePreserved
= val
;
67 /* EGL_KHR_gl_image */
68 case EGL_GL_TEXTURE_LEVEL_KHR
:
69 attrs
->GLTextureLevel
= val
;
71 case EGL_GL_TEXTURE_ZOFFSET_KHR
:
72 attrs
->GLTextureZOffset
= val
;
75 /* EGL_MESA_drm_image */
82 case EGL_DRM_BUFFER_FORMAT_MESA
:
83 attrs
->DRMBufferFormatMESA
= val
;
85 case EGL_DRM_BUFFER_USE_MESA
:
86 attrs
->DRMBufferUseMESA
= val
;
88 case EGL_DRM_BUFFER_STRIDE_MESA
:
89 attrs
->DRMBufferStrideMESA
= val
;
92 /* EGL_WL_bind_wayland_display */
93 case EGL_WAYLAND_PLANE_WL
:
97 case EGL_LINUX_DRM_FOURCC_EXT
:
98 attrs
->DMABufFourCC
.Value
= val
;
99 attrs
->DMABufFourCC
.IsPresent
= EGL_TRUE
;
101 case EGL_DMA_BUF_PLANE0_FD_EXT
:
102 attrs
->DMABufPlaneFds
[0].Value
= val
;
103 attrs
->DMABufPlaneFds
[0].IsPresent
= EGL_TRUE
;
105 case EGL_DMA_BUF_PLANE0_OFFSET_EXT
:
106 attrs
->DMABufPlaneOffsets
[0].Value
= val
;
107 attrs
->DMABufPlaneOffsets
[0].IsPresent
= EGL_TRUE
;
109 case EGL_DMA_BUF_PLANE0_PITCH_EXT
:
110 attrs
->DMABufPlanePitches
[0].Value
= val
;
111 attrs
->DMABufPlanePitches
[0].IsPresent
= EGL_TRUE
;
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
;
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
;
125 case EGL_DMA_BUF_PLANE1_FD_EXT
:
126 attrs
->DMABufPlaneFds
[1].Value
= val
;
127 attrs
->DMABufPlaneFds
[1].IsPresent
= EGL_TRUE
;
129 case EGL_DMA_BUF_PLANE1_OFFSET_EXT
:
130 attrs
->DMABufPlaneOffsets
[1].Value
= val
;
131 attrs
->DMABufPlaneOffsets
[1].IsPresent
= EGL_TRUE
;
133 case EGL_DMA_BUF_PLANE1_PITCH_EXT
:
134 attrs
->DMABufPlanePitches
[1].Value
= val
;
135 attrs
->DMABufPlanePitches
[1].IsPresent
= EGL_TRUE
;
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
;
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
;
149 case EGL_DMA_BUF_PLANE2_FD_EXT
:
150 attrs
->DMABufPlaneFds
[2].Value
= val
;
151 attrs
->DMABufPlaneFds
[2].IsPresent
= EGL_TRUE
;
153 case EGL_DMA_BUF_PLANE2_OFFSET_EXT
:
154 attrs
->DMABufPlaneOffsets
[2].Value
= val
;
155 attrs
->DMABufPlaneOffsets
[2].IsPresent
= EGL_TRUE
;
157 case EGL_DMA_BUF_PLANE2_PITCH_EXT
:
158 attrs
->DMABufPlanePitches
[2].Value
= val
;
159 attrs
->DMABufPlanePitches
[2].IsPresent
= EGL_TRUE
;
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
;
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
;
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
;
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
;
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
;
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
;
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
;
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
;
208 attrs
->DMABufYuvColorSpaceHint
.Value
= val
;
209 attrs
->DMABufYuvColorSpaceHint
.IsPresent
= EGL_TRUE
;
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
;
216 attrs
->DMABufSampleRangeHint
.Value
= val
;
217 attrs
->DMABufSampleRangeHint
.IsPresent
= EGL_TRUE
;
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
;
225 attrs
->DMABufChromaHorizontalSiting
.Value
= val
;
226 attrs
->DMABufChromaHorizontalSiting
.IsPresent
= EGL_TRUE
;
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
;
234 attrs
->DMABufChromaVerticalSiting
.Value
= val
;
235 attrs
->DMABufChromaVerticalSiting
.IsPresent
= EGL_TRUE
;
240 return _eglError(EGL_BAD_ATTRIBUTE
, __func__
);
243 if (err
!= EGL_SUCCESS
)
244 return _eglError(err
, __func__
);