Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
/**************************************************************************
2
 *
3
 * Copyright 2009-2010 Chia-I Wu 
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 
31
#include 
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
   attrs->ImagePreserved = EGL_FALSE;
50
   attrs->GLTextureLevel = 0;
51
   attrs->GLTextureZOffset = 0;
52
 
53
   if (!attrib_list)
54
      return err;
55
 
56
   for (i = 0; attrib_list[i] != EGL_NONE; i++) {
57
      EGLint attr = attrib_list[i++];
58
      EGLint val = attrib_list[i];
59
 
60
      switch (attr) {
61
      /* EGL_KHR_image_base */
62
      case EGL_IMAGE_PRESERVED_KHR:
63
         attrs->ImagePreserved = val;
64
         break;
65
 
66
      /* EGL_KHR_gl_image */
67
      case EGL_GL_TEXTURE_LEVEL_KHR:
68
         attrs->GLTextureLevel = val;
69
         break;
70
      case EGL_GL_TEXTURE_ZOFFSET_KHR:
71
         attrs->GLTextureZOffset = val;
72
         break;
73
 
74
      /* EGL_MESA_drm_image */
75
      case EGL_WIDTH:
76
         attrs->Width = val;
77
         break;
78
      case EGL_HEIGHT:
79
         attrs->Height = val;
80
         break;
81
      case EGL_DRM_BUFFER_FORMAT_MESA:
82
         attrs->DRMBufferFormatMESA = val;
83
         break;
84
      case EGL_DRM_BUFFER_USE_MESA:
85
         attrs->DRMBufferUseMESA = val;
86
         break;
87
      case EGL_DRM_BUFFER_STRIDE_MESA:
88
         attrs->DRMBufferStrideMESA = val;
89
         break;
90
 
91
      /* EGL_WL_bind_wayland_display */
92
      case EGL_WAYLAND_PLANE_WL:
93
         attrs->PlaneWL = val;
94
         break;
95
 
96
      case EGL_LINUX_DRM_FOURCC_EXT:
97
         attrs->DMABufFourCC.Value = val;
98
         attrs->DMABufFourCC.IsPresent = EGL_TRUE;
99
         break;
100
      case EGL_DMA_BUF_PLANE0_FD_EXT:
101
         attrs->DMABufPlaneFds[0].Value = val;
102
         attrs->DMABufPlaneFds[0].IsPresent = EGL_TRUE;
103
         break;
104
      case EGL_DMA_BUF_PLANE0_OFFSET_EXT:
105
         attrs->DMABufPlaneOffsets[0].Value = val;
106
         attrs->DMABufPlaneOffsets[0].IsPresent = EGL_TRUE;
107
         break;
108
      case EGL_DMA_BUF_PLANE0_PITCH_EXT:
109
         attrs->DMABufPlanePitches[0].Value = val;
110
         attrs->DMABufPlanePitches[0].IsPresent = EGL_TRUE;
111
         break;
112
      case EGL_DMA_BUF_PLANE1_FD_EXT:
113
         attrs->DMABufPlaneFds[1].Value = val;
114
         attrs->DMABufPlaneFds[1].IsPresent = EGL_TRUE;
115
         break;
116
      case EGL_DMA_BUF_PLANE1_OFFSET_EXT:
117
         attrs->DMABufPlaneOffsets[1].Value = val;
118
         attrs->DMABufPlaneOffsets[1].IsPresent = EGL_TRUE;
119
         break;
120
      case EGL_DMA_BUF_PLANE1_PITCH_EXT:
121
         attrs->DMABufPlanePitches[1].Value = val;
122
         attrs->DMABufPlanePitches[1].IsPresent = EGL_TRUE;
123
         break;
124
      case EGL_DMA_BUF_PLANE2_FD_EXT:
125
         attrs->DMABufPlaneFds[2].Value = val;
126
         attrs->DMABufPlaneFds[2].IsPresent = EGL_TRUE;
127
         break;
128
      case EGL_DMA_BUF_PLANE2_OFFSET_EXT:
129
         attrs->DMABufPlaneOffsets[2].Value = val;
130
         attrs->DMABufPlaneOffsets[2].IsPresent = EGL_TRUE;
131
         break;
132
      case EGL_DMA_BUF_PLANE2_PITCH_EXT:
133
         attrs->DMABufPlanePitches[2].Value = val;
134
         attrs->DMABufPlanePitches[2].IsPresent = EGL_TRUE;
135
         break;
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;
140
         } else {
141
            attrs->DMABufYuvColorSpaceHint.Value = val;
142
            attrs->DMABufYuvColorSpaceHint.IsPresent = EGL_TRUE;
143
         }
144
         break;
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;
148
         } else {
149
            attrs->DMABufSampleRangeHint.Value = val;
150
            attrs->DMABufSampleRangeHint.IsPresent = EGL_TRUE;
151
         }
152
         break;
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;
157
         } else {
158
            attrs->DMABufChromaHorizontalSiting.Value = val;
159
            attrs->DMABufChromaHorizontalSiting.IsPresent = EGL_TRUE;
160
         }
161
         break;
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;
166
         } else {
167
            attrs->DMABufChromaVerticalSiting.Value = val;
168
            attrs->DMABufChromaVerticalSiting.IsPresent = EGL_TRUE;
169
         }
170
         break;
171
 
172
      default:
173
         /* unknown attrs are ignored */
174
         break;
175
      }
176
 
177
      if (err != EGL_SUCCESS) {
178
         _eglLog(_EGL_DEBUG, "bad image attribute 0x%04x", attr);
179
         break;
180
      }
181
   }
182
 
183
   return err;
184
}
185
 
186
 
187
EGLBoolean
188
_eglInitImage(_EGLImage *img, _EGLDisplay *dpy)
189
{
190
   _eglInitResource(&img->Resource, sizeof(*img), dpy);
191
 
192
   return EGL_TRUE;
193
}