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"
38 _eglParseKHRImageAttribs(_EGLImageAttribs
*attrs
, _EGLDisplay
*disp
,
39 EGLint attr
, EGLint val
)
42 case EGL_IMAGE_PRESERVED_KHR
:
43 if (!disp
->Extensions
.KHR_image_base
)
44 return EGL_BAD_PARAMETER
;
46 attrs
->ImagePreserved
= val
;
49 case EGL_GL_TEXTURE_LEVEL_KHR
:
50 if (!disp
->Extensions
.KHR_gl_texture_2D_image
)
51 return EGL_BAD_PARAMETER
;
53 attrs
->GLTextureLevel
= val
;
55 case EGL_GL_TEXTURE_ZOFFSET_KHR
:
56 if (!disp
->Extensions
.KHR_gl_texture_3D_image
)
57 return EGL_BAD_PARAMETER
;
59 attrs
->GLTextureZOffset
= val
;
62 return EGL_BAD_PARAMETER
;
69 _eglParseMESADrmImageAttribs(_EGLImageAttribs
*attrs
, _EGLDisplay
*disp
,
70 EGLint attr
, EGLint val
)
72 if (!disp
->Extensions
.MESA_drm_image
)
73 return EGL_BAD_PARAMETER
;
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 return EGL_BAD_PARAMETER
;
99 _eglParseWLBindWaylandDisplayAttribs(_EGLImageAttribs
*attrs
, _EGLDisplay
*disp
,
100 EGLint attr
, EGLint val
)
102 if (!disp
->Extensions
.WL_bind_wayland_display
)
103 return EGL_BAD_PARAMETER
;
106 case EGL_WAYLAND_PLANE_WL
:
107 attrs
->PlaneWL
= val
;
110 return EGL_BAD_PARAMETER
;
117 _eglParseEXTImageDmaBufImportAttribs(_EGLImageAttribs
*attrs
, _EGLDisplay
*disp
,
118 EGLint attr
, EGLint val
)
120 if (!disp
->Extensions
.EXT_image_dma_buf_import
)
121 return EGL_BAD_PARAMETER
;
130 case EGL_LINUX_DRM_FOURCC_EXT
:
131 attrs
->DMABufFourCC
.Value
= val
;
132 attrs
->DMABufFourCC
.IsPresent
= EGL_TRUE
;
134 case EGL_DMA_BUF_PLANE0_FD_EXT
:
135 attrs
->DMABufPlaneFds
[0].Value
= val
;
136 attrs
->DMABufPlaneFds
[0].IsPresent
= EGL_TRUE
;
138 case EGL_DMA_BUF_PLANE0_OFFSET_EXT
:
139 attrs
->DMABufPlaneOffsets
[0].Value
= val
;
140 attrs
->DMABufPlaneOffsets
[0].IsPresent
= EGL_TRUE
;
142 case EGL_DMA_BUF_PLANE0_PITCH_EXT
:
143 attrs
->DMABufPlanePitches
[0].Value
= val
;
144 attrs
->DMABufPlanePitches
[0].IsPresent
= EGL_TRUE
;
146 case EGL_DMA_BUF_PLANE1_FD_EXT
:
147 attrs
->DMABufPlaneFds
[1].Value
= val
;
148 attrs
->DMABufPlaneFds
[1].IsPresent
= EGL_TRUE
;
150 case EGL_DMA_BUF_PLANE1_OFFSET_EXT
:
151 attrs
->DMABufPlaneOffsets
[1].Value
= val
;
152 attrs
->DMABufPlaneOffsets
[1].IsPresent
= EGL_TRUE
;
154 case EGL_DMA_BUF_PLANE1_PITCH_EXT
:
155 attrs
->DMABufPlanePitches
[1].Value
= val
;
156 attrs
->DMABufPlanePitches
[1].IsPresent
= EGL_TRUE
;
158 case EGL_DMA_BUF_PLANE2_FD_EXT
:
159 attrs
->DMABufPlaneFds
[2].Value
= val
;
160 attrs
->DMABufPlaneFds
[2].IsPresent
= EGL_TRUE
;
162 case EGL_DMA_BUF_PLANE2_OFFSET_EXT
:
163 attrs
->DMABufPlaneOffsets
[2].Value
= val
;
164 attrs
->DMABufPlaneOffsets
[2].IsPresent
= EGL_TRUE
;
166 case EGL_DMA_BUF_PLANE2_PITCH_EXT
:
167 attrs
->DMABufPlanePitches
[2].Value
= val
;
168 attrs
->DMABufPlanePitches
[2].IsPresent
= EGL_TRUE
;
170 case EGL_YUV_COLOR_SPACE_HINT_EXT
:
171 if (val
!= EGL_ITU_REC601_EXT
&& val
!= EGL_ITU_REC709_EXT
&&
172 val
!= EGL_ITU_REC2020_EXT
)
173 return EGL_BAD_ATTRIBUTE
;
175 attrs
->DMABufYuvColorSpaceHint
.Value
= val
;
176 attrs
->DMABufYuvColorSpaceHint
.IsPresent
= EGL_TRUE
;
178 case EGL_SAMPLE_RANGE_HINT_EXT
:
179 if (val
!= EGL_YUV_FULL_RANGE_EXT
&& val
!= EGL_YUV_NARROW_RANGE_EXT
)
180 return EGL_BAD_ATTRIBUTE
;
182 attrs
->DMABufSampleRangeHint
.Value
= val
;
183 attrs
->DMABufSampleRangeHint
.IsPresent
= EGL_TRUE
;
185 case EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT
:
186 if (val
!= EGL_YUV_CHROMA_SITING_0_EXT
&&
187 val
!= EGL_YUV_CHROMA_SITING_0_5_EXT
)
188 return EGL_BAD_ATTRIBUTE
;
190 attrs
->DMABufChromaHorizontalSiting
.Value
= val
;
191 attrs
->DMABufChromaHorizontalSiting
.IsPresent
= EGL_TRUE
;
193 case EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT
:
194 if (val
!= EGL_YUV_CHROMA_SITING_0_EXT
&&
195 val
!= EGL_YUV_CHROMA_SITING_0_5_EXT
)
196 return EGL_BAD_ATTRIBUTE
;
198 attrs
->DMABufChromaVerticalSiting
.Value
= val
;
199 attrs
->DMABufChromaVerticalSiting
.IsPresent
= EGL_TRUE
;
202 return EGL_BAD_PARAMETER
;
209 _eglParseEXTImageDmaBufImportModifiersAttribs(_EGLImageAttribs
*attrs
,
211 EGLint attr
, EGLint val
)
213 if (!disp
->Extensions
.EXT_image_dma_buf_import_modifiers
)
214 return EGL_BAD_PARAMETER
;
217 case EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT
:
218 attrs
->DMABufPlaneModifiersLo
[0].Value
= val
;
219 attrs
->DMABufPlaneModifiersLo
[0].IsPresent
= EGL_TRUE
;
221 case EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT
:
222 attrs
->DMABufPlaneModifiersHi
[0].Value
= val
;
223 attrs
->DMABufPlaneModifiersHi
[0].IsPresent
= EGL_TRUE
;
225 case EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT
:
226 attrs
->DMABufPlaneModifiersLo
[1].Value
= val
;
227 attrs
->DMABufPlaneModifiersLo
[1].IsPresent
= EGL_TRUE
;
229 case EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT
:
230 attrs
->DMABufPlaneModifiersHi
[1].Value
= val
;
231 attrs
->DMABufPlaneModifiersHi
[1].IsPresent
= EGL_TRUE
;
233 case EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT
:
234 attrs
->DMABufPlaneModifiersLo
[2].Value
= val
;
235 attrs
->DMABufPlaneModifiersLo
[2].IsPresent
= EGL_TRUE
;
237 case EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT
:
238 attrs
->DMABufPlaneModifiersHi
[2].Value
= val
;
239 attrs
->DMABufPlaneModifiersHi
[2].IsPresent
= EGL_TRUE
;
241 case EGL_DMA_BUF_PLANE3_FD_EXT
:
242 attrs
->DMABufPlaneFds
[3].Value
= val
;
243 attrs
->DMABufPlaneFds
[3].IsPresent
= EGL_TRUE
;
245 case EGL_DMA_BUF_PLANE3_OFFSET_EXT
:
246 attrs
->DMABufPlaneOffsets
[3].Value
= val
;
247 attrs
->DMABufPlaneOffsets
[3].IsPresent
= EGL_TRUE
;
249 case EGL_DMA_BUF_PLANE3_PITCH_EXT
:
250 attrs
->DMABufPlanePitches
[3].Value
= val
;
251 attrs
->DMABufPlanePitches
[3].IsPresent
= EGL_TRUE
;
253 case EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT
:
254 attrs
->DMABufPlaneModifiersLo
[3].Value
= val
;
255 attrs
->DMABufPlaneModifiersLo
[3].IsPresent
= EGL_TRUE
;
257 case EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT
:
258 attrs
->DMABufPlaneModifiersHi
[3].Value
= val
;
259 attrs
->DMABufPlaneModifiersHi
[3].IsPresent
= EGL_TRUE
;
262 return EGL_BAD_PARAMETER
;
269 * Parse the list of image attributes.
271 * Returns EGL_TRUE on success and EGL_FALSE otherwise.
272 * Function calls _eglError to set the correct error code.
275 _eglParseImageAttribList(_EGLImageAttribs
*attrs
, _EGLDisplay
*disp
,
276 const EGLint
*attrib_list
)
280 memset(attrs
, 0, sizeof(*attrs
));
285 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
++) {
286 EGLint attr
= attrib_list
[i
++];
287 EGLint val
= attrib_list
[i
];
289 err
= _eglParseKHRImageAttribs(attrs
, disp
, attr
, val
);
290 if (err
== EGL_SUCCESS
)
293 err
= _eglParseMESADrmImageAttribs(attrs
, disp
, attr
, val
);
294 if (err
== EGL_SUCCESS
)
297 err
= _eglParseWLBindWaylandDisplayAttribs(attrs
, disp
, attr
, val
);
298 if (err
== EGL_SUCCESS
)
301 err
= _eglParseEXTImageDmaBufImportAttribs(attrs
, disp
, attr
, val
);
302 if (err
== EGL_SUCCESS
)
305 /* EXT_image_dma_buf_import states that if invalid value is provided for
306 * its attributes, we should return EGL_BAD_ATTRIBUTE.
307 * Bail out ASAP, since follow-up calls can return another EGL_BAD error.
309 if (err
== EGL_BAD_ATTRIBUTE
)
310 return _eglError(err
, __func__
);
312 err
= _eglParseEXTImageDmaBufImportModifiersAttribs(attrs
, disp
, attr
, val
);
313 if (err
== EGL_SUCCESS
)
316 return _eglError(err
, __func__
);