egl: remove duplicate 0 assignment
[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_PLANE1_FD_EXT:
110 attrs->DMABufPlaneFds[1].Value = val;
111 attrs->DMABufPlaneFds[1].IsPresent = EGL_TRUE;
112 break;
113 case EGL_DMA_BUF_PLANE1_OFFSET_EXT:
114 attrs->DMABufPlaneOffsets[1].Value = val;
115 attrs->DMABufPlaneOffsets[1].IsPresent = EGL_TRUE;
116 break;
117 case EGL_DMA_BUF_PLANE1_PITCH_EXT:
118 attrs->DMABufPlanePitches[1].Value = val;
119 attrs->DMABufPlanePitches[1].IsPresent = EGL_TRUE;
120 break;
121 case EGL_DMA_BUF_PLANE2_FD_EXT:
122 attrs->DMABufPlaneFds[2].Value = val;
123 attrs->DMABufPlaneFds[2].IsPresent = EGL_TRUE;
124 break;
125 case EGL_DMA_BUF_PLANE2_OFFSET_EXT:
126 attrs->DMABufPlaneOffsets[2].Value = val;
127 attrs->DMABufPlaneOffsets[2].IsPresent = EGL_TRUE;
128 break;
129 case EGL_DMA_BUF_PLANE2_PITCH_EXT:
130 attrs->DMABufPlanePitches[2].Value = val;
131 attrs->DMABufPlanePitches[2].IsPresent = EGL_TRUE;
132 break;
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;
137 } else {
138 attrs->DMABufYuvColorSpaceHint.Value = val;
139 attrs->DMABufYuvColorSpaceHint.IsPresent = EGL_TRUE;
140 }
141 break;
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;
145 } else {
146 attrs->DMABufSampleRangeHint.Value = val;
147 attrs->DMABufSampleRangeHint.IsPresent = EGL_TRUE;
148 }
149 break;
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;
154 } else {
155 attrs->DMABufChromaHorizontalSiting.Value = val;
156 attrs->DMABufChromaHorizontalSiting.IsPresent = EGL_TRUE;
157 }
158 break;
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;
163 } else {
164 attrs->DMABufChromaVerticalSiting.Value = val;
165 attrs->DMABufChromaVerticalSiting.IsPresent = EGL_TRUE;
166 }
167 break;
168
169 default:
170 /* unknown attrs are ignored */
171 break;
172 }
173
174 if (err != EGL_SUCCESS) {
175 _eglLog(_EGL_DEBUG, "bad image attribute 0x%04x", attr);
176 break;
177 }
178 }
179
180 return err;
181 }
182
183
184 EGLBoolean
185 _eglInitImage(_EGLImage *img, _EGLDisplay *dpy)
186 {
187 _eglInitResource(&img->Resource, sizeof(*img), dpy);
188
189 return EGL_TRUE;
190 }