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
_eglParseImageAttribList(_EGLImageAttribs * attrs,_EGLDisplay * dpy,const EGLint * attrib_list)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 default:
97 /* unknown attrs are ignored */
98 break;
99 }
100
101 if (err != EGL_SUCCESS) {
102 _eglLog(_EGL_DEBUG, "bad image attribute 0x%04x", attr);
103 break;
104 }
105 }
106
107 return err;
108 }
109
110
111 EGLBoolean
_eglInitImage(_EGLImage * img,_EGLDisplay * dpy)112 _eglInitImage(_EGLImage *img, _EGLDisplay *dpy)
113 {
114 _eglInitResource(&img->Resource, sizeof(*img), dpy);
115
116 return EGL_TRUE;
117 }
118