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 **************************************************************************/
38 * Parse the list of image attributes and return the proper error code.
41 _eglParseImageAttribList(_EGLImageAttribs
*attrs
, _EGLDisplay
*dpy
,
42 const EGLint
*attrib_list
)
44 EGLint i
, err
= EGL_SUCCESS
;
48 memset(attrs
, 0, sizeof(*attrs
));
53 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
++) {
54 EGLint attr
= attrib_list
[i
++];
55 EGLint val
= attrib_list
[i
];
58 /* EGL_KHR_image_base */
59 case EGL_IMAGE_PRESERVED_KHR
:
60 attrs
->ImagePreserved
= val
;
63 /* EGL_KHR_gl_image */
64 case EGL_GL_TEXTURE_LEVEL_KHR
:
65 attrs
->GLTextureLevel
= val
;
67 case EGL_GL_TEXTURE_ZOFFSET_KHR
:
68 attrs
->GLTextureZOffset
= val
;
71 /* EGL_MESA_drm_image */
78 case EGL_DRM_BUFFER_FORMAT_MESA
:
79 attrs
->DRMBufferFormatMESA
= val
;
81 case EGL_DRM_BUFFER_USE_MESA
:
82 attrs
->DRMBufferUseMESA
= val
;
84 case EGL_DRM_BUFFER_STRIDE_MESA
:
85 attrs
->DRMBufferStrideMESA
= val
;
88 /* EGL_WL_bind_wayland_display */
89 case EGL_WAYLAND_PLANE_WL
:
93 case EGL_LINUX_DRM_FOURCC_EXT
:
94 attrs
->DMABufFourCC
.Value
= val
;
95 attrs
->DMABufFourCC
.IsPresent
= EGL_TRUE
;
97 case EGL_DMA_BUF_PLANE0_FD_EXT
:
98 attrs
->DMABufPlaneFds
[0].Value
= val
;
99 attrs
->DMABufPlaneFds
[0].IsPresent
= EGL_TRUE
;
101 case EGL_DMA_BUF_PLANE0_OFFSET_EXT
:
102 attrs
->DMABufPlaneOffsets
[0].Value
= val
;
103 attrs
->DMABufPlaneOffsets
[0].IsPresent
= EGL_TRUE
;
105 case EGL_DMA_BUF_PLANE0_PITCH_EXT
:
106 attrs
->DMABufPlanePitches
[0].Value
= val
;
107 attrs
->DMABufPlanePitches
[0].IsPresent
= EGL_TRUE
;
109 case EGL_DMA_BUF_PLANE1_FD_EXT
:
110 attrs
->DMABufPlaneFds
[1].Value
= val
;
111 attrs
->DMABufPlaneFds
[1].IsPresent
= EGL_TRUE
;
113 case EGL_DMA_BUF_PLANE1_OFFSET_EXT
:
114 attrs
->DMABufPlaneOffsets
[1].Value
= val
;
115 attrs
->DMABufPlaneOffsets
[1].IsPresent
= EGL_TRUE
;
117 case EGL_DMA_BUF_PLANE1_PITCH_EXT
:
118 attrs
->DMABufPlanePitches
[1].Value
= val
;
119 attrs
->DMABufPlanePitches
[1].IsPresent
= EGL_TRUE
;
121 case EGL_DMA_BUF_PLANE2_FD_EXT
:
122 attrs
->DMABufPlaneFds
[2].Value
= val
;
123 attrs
->DMABufPlaneFds
[2].IsPresent
= EGL_TRUE
;
125 case EGL_DMA_BUF_PLANE2_OFFSET_EXT
:
126 attrs
->DMABufPlaneOffsets
[2].Value
= val
;
127 attrs
->DMABufPlaneOffsets
[2].IsPresent
= EGL_TRUE
;
129 case EGL_DMA_BUF_PLANE2_PITCH_EXT
:
130 attrs
->DMABufPlanePitches
[2].Value
= val
;
131 attrs
->DMABufPlanePitches
[2].IsPresent
= EGL_TRUE
;
133 case EGL_YUV_COLOR_SPACE_HINT_EXT
:
134 if (val
!= EGL_ITU_REC601_EXT
&& val
!= EGL_ITU_REC709_EXT
&&
135 val
!= EGL_ITU_REC2020_EXT
) {
136 err
= EGL_BAD_ATTRIBUTE
;
138 attrs
->DMABufYuvColorSpaceHint
.Value
= val
;
139 attrs
->DMABufYuvColorSpaceHint
.IsPresent
= EGL_TRUE
;
142 case EGL_SAMPLE_RANGE_HINT_EXT
:
143 if (val
!= EGL_YUV_FULL_RANGE_EXT
&& val
!= EGL_YUV_NARROW_RANGE_EXT
) {
144 err
= EGL_BAD_ATTRIBUTE
;
146 attrs
->DMABufSampleRangeHint
.Value
= val
;
147 attrs
->DMABufSampleRangeHint
.IsPresent
= EGL_TRUE
;
150 case EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT
:
151 if (val
!= EGL_YUV_CHROMA_SITING_0_EXT
&&
152 val
!= EGL_YUV_CHROMA_SITING_0_5_EXT
) {
153 err
= EGL_BAD_ATTRIBUTE
;
155 attrs
->DMABufChromaHorizontalSiting
.Value
= val
;
156 attrs
->DMABufChromaHorizontalSiting
.IsPresent
= EGL_TRUE
;
159 case EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT
:
160 if (val
!= EGL_YUV_CHROMA_SITING_0_EXT
&&
161 val
!= EGL_YUV_CHROMA_SITING_0_5_EXT
) {
162 err
= EGL_BAD_ATTRIBUTE
;
164 attrs
->DMABufChromaVerticalSiting
.Value
= val
;
165 attrs
->DMABufChromaVerticalSiting
.IsPresent
= EGL_TRUE
;
170 /* unknown attrs are ignored */
174 if (err
!= EGL_SUCCESS
) {
175 _eglLog(_EGL_DEBUG
, "bad image attribute 0x%04x", attr
);
185 _eglInitImage(_EGLImage
*img
, _EGLDisplay
*dpy
)
187 _eglInitResource(&img
->Resource
, sizeof(*img
), dpy
);