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
));
49 attrs
->ImagePreserved
= EGL_FALSE
;
50 attrs
->GLTextureLevel
= 0;
51 attrs
->GLTextureZOffset
= 0;
56 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
++) {
57 EGLint attr
= attrib_list
[i
++];
58 EGLint val
= attrib_list
[i
];
61 /* EGL_KHR_image_base */
62 case EGL_IMAGE_PRESERVED_KHR
:
63 attrs
->ImagePreserved
= val
;
66 /* EGL_KHR_gl_image */
67 case EGL_GL_TEXTURE_LEVEL_KHR
:
68 attrs
->GLTextureLevel
= val
;
70 case EGL_GL_TEXTURE_ZOFFSET_KHR
:
71 attrs
->GLTextureZOffset
= val
;
74 /* EGL_MESA_drm_image */
81 case EGL_DRM_BUFFER_FORMAT_MESA
:
82 attrs
->DRMBufferFormatMESA
= val
;
84 case EGL_DRM_BUFFER_USE_MESA
:
85 attrs
->DRMBufferUseMESA
= val
;
87 case EGL_DRM_BUFFER_STRIDE_MESA
:
88 attrs
->DRMBufferStrideMESA
= val
;
91 /* EGL_WL_bind_wayland_display */
92 case EGL_WAYLAND_PLANE_WL
:
96 case EGL_LINUX_DRM_FOURCC_EXT
:
97 attrs
->DMABufFourCC
.Value
= val
;
98 attrs
->DMABufFourCC
.IsPresent
= EGL_TRUE
;
100 case EGL_DMA_BUF_PLANE0_FD_EXT
:
101 attrs
->DMABufPlaneFds
[0].Value
= val
;
102 attrs
->DMABufPlaneFds
[0].IsPresent
= EGL_TRUE
;
104 case EGL_DMA_BUF_PLANE0_OFFSET_EXT
:
105 attrs
->DMABufPlaneOffsets
[0].Value
= val
;
106 attrs
->DMABufPlaneOffsets
[0].IsPresent
= EGL_TRUE
;
108 case EGL_DMA_BUF_PLANE0_PITCH_EXT
:
109 attrs
->DMABufPlanePitches
[0].Value
= val
;
110 attrs
->DMABufPlanePitches
[0].IsPresent
= EGL_TRUE
;
112 case EGL_DMA_BUF_PLANE1_FD_EXT
:
113 attrs
->DMABufPlaneFds
[1].Value
= val
;
114 attrs
->DMABufPlaneFds
[1].IsPresent
= EGL_TRUE
;
116 case EGL_DMA_BUF_PLANE1_OFFSET_EXT
:
117 attrs
->DMABufPlaneOffsets
[1].Value
= val
;
118 attrs
->DMABufPlaneOffsets
[1].IsPresent
= EGL_TRUE
;
120 case EGL_DMA_BUF_PLANE1_PITCH_EXT
:
121 attrs
->DMABufPlanePitches
[1].Value
= val
;
122 attrs
->DMABufPlanePitches
[1].IsPresent
= EGL_TRUE
;
124 case EGL_DMA_BUF_PLANE2_FD_EXT
:
125 attrs
->DMABufPlaneFds
[2].Value
= val
;
126 attrs
->DMABufPlaneFds
[2].IsPresent
= EGL_TRUE
;
128 case EGL_DMA_BUF_PLANE2_OFFSET_EXT
:
129 attrs
->DMABufPlaneOffsets
[2].Value
= val
;
130 attrs
->DMABufPlaneOffsets
[2].IsPresent
= EGL_TRUE
;
132 case EGL_DMA_BUF_PLANE2_PITCH_EXT
:
133 attrs
->DMABufPlanePitches
[2].Value
= val
;
134 attrs
->DMABufPlanePitches
[2].IsPresent
= EGL_TRUE
;
136 case EGL_YUV_COLOR_SPACE_HINT_EXT
:
137 if (val
!= EGL_ITU_REC601_EXT
&& val
!= EGL_ITU_REC709_EXT
&&
138 val
!= EGL_ITU_REC2020_EXT
) {
139 err
= EGL_BAD_ATTRIBUTE
;
141 attrs
->DMABufYuvColorSpaceHint
.Value
= val
;
142 attrs
->DMABufYuvColorSpaceHint
.IsPresent
= EGL_TRUE
;
145 case EGL_SAMPLE_RANGE_HINT_EXT
:
146 if (val
!= EGL_YUV_FULL_RANGE_EXT
&& val
!= EGL_YUV_NARROW_RANGE_EXT
) {
147 err
= EGL_BAD_ATTRIBUTE
;
149 attrs
->DMABufSampleRangeHint
.Value
= val
;
150 attrs
->DMABufSampleRangeHint
.IsPresent
= EGL_TRUE
;
153 case EGL_YUV_CHROMA_HORIZONTAL_SITING_HINT_EXT
:
154 if (val
!= EGL_YUV_CHROMA_SITING_0_EXT
&&
155 val
!= EGL_YUV_CHROMA_SITING_0_5_EXT
) {
156 err
= EGL_BAD_ATTRIBUTE
;
158 attrs
->DMABufChromaHorizontalSiting
.Value
= val
;
159 attrs
->DMABufChromaHorizontalSiting
.IsPresent
= EGL_TRUE
;
162 case EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT
:
163 if (val
!= EGL_YUV_CHROMA_SITING_0_EXT
&&
164 val
!= EGL_YUV_CHROMA_SITING_0_5_EXT
) {
165 err
= EGL_BAD_ATTRIBUTE
;
167 attrs
->DMABufChromaVerticalSiting
.Value
= val
;
168 attrs
->DMABufChromaVerticalSiting
.IsPresent
= EGL_TRUE
;
173 /* unknown attrs are ignored */
177 if (err
!= EGL_SUCCESS
) {
178 _eglLog(_EGL_DEBUG
, "bad image attribute 0x%04x", attr
);
188 _eglInitImage(_EGLImage
*img
, _EGLDisplay
*dpy
)
190 _eglInitResource(&img
->Resource
, sizeof(*img
), dpy
);