985d1e0069d723f6d3571de77c930e34bbfb3427
[mesa.git] / src / egl / main / eglmisc.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 /**
30 * Small/misc EGL functions
31 */
32
33
34 #include <assert.h>
35 #include <string.h>
36 #include "eglcurrent.h"
37 #include "eglmisc.h"
38 #include "egldisplay.h"
39
40
41 /**
42 * Copy the extension into the string and update the string pointer.
43 */
44 static EGLint
45 _eglAppendExtension(char **str, const char *ext)
46 {
47 char *s = *str;
48 size_t len = strlen(ext);
49
50 if (s) {
51 memcpy(s, ext, len);
52 s[len++] = ' ';
53 s[len] = '\0';
54
55 *str += len;
56 }
57 else {
58 len++;
59 }
60
61 return (EGLint) len;
62 }
63
64
65 /**
66 * Examine the individual extension enable/disable flags and recompute
67 * the driver's Extensions string.
68 */
69 static void
70 _eglUpdateExtensionsString(_EGLDisplay *dpy)
71 {
72 #define _EGL_CHECK_EXTENSION(ext) \
73 do { \
74 if (dpy->Extensions.ext) { \
75 _eglAppendExtension(&exts, "EGL_" #ext); \
76 assert(exts <= dpy->Extensions.String + _EGL_MAX_EXTENSIONS_LEN); \
77 } \
78 } while (0)
79
80 char *exts = dpy->Extensions.String;
81
82 if (exts[0])
83 return;
84
85 _EGL_CHECK_EXTENSION(MESA_screen_surface);
86 _EGL_CHECK_EXTENSION(MESA_copy_context);
87 _EGL_CHECK_EXTENSION(MESA_drm_display);
88
89 _EGL_CHECK_EXTENSION(KHR_image_base);
90 _EGL_CHECK_EXTENSION(KHR_image_pixmap);
91 if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap)
92 _eglAppendExtension(&exts, "EGL_KHR_image");
93
94 _EGL_CHECK_EXTENSION(KHR_vg_parent_image);
95 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image);
96 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image);
97 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image);
98 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image);
99
100 _EGL_CHECK_EXTENSION(KHR_surfaceless_gles1);
101 _EGL_CHECK_EXTENSION(KHR_surfaceless_gles2);
102 _EGL_CHECK_EXTENSION(KHR_surfaceless_opengl);
103
104 _EGL_CHECK_EXTENSION(NOK_swap_region);
105 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
106 #undef _EGL_CHECK_EXTENSION
107 }
108
109
110 static void
111 _eglUpdateAPIsString(_EGLDisplay *dpy)
112 {
113 char *apis = dpy->ClientAPIs;
114
115 if (apis[0] || !dpy->ClientAPIsMask)
116 return;
117
118 if (dpy->ClientAPIsMask & EGL_OPENGL_BIT)
119 strcat(apis, "OpenGL ");
120
121 if (dpy->ClientAPIsMask & EGL_OPENGL_ES_BIT)
122 strcat(apis, "OpenGL_ES ");
123
124 if (dpy->ClientAPIsMask & EGL_OPENGL_ES2_BIT)
125 strcat(apis, "OpenGL_ES2 ");
126
127 if (dpy->ClientAPIsMask & EGL_OPENVG_BIT)
128 strcat(apis, "OpenVG ");
129
130 assert(strlen(apis) < sizeof(dpy->ClientAPIs));
131 }
132
133
134 const char *
135 _eglQueryString(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name)
136 {
137 (void) drv;
138 (void) dpy;
139 switch (name) {
140 case EGL_VENDOR:
141 return _EGL_VENDOR_STRING;
142 case EGL_VERSION:
143 return dpy->Version;
144 case EGL_EXTENSIONS:
145 _eglUpdateExtensionsString(dpy);
146 return dpy->Extensions.String;
147 #ifdef EGL_VERSION_1_2
148 case EGL_CLIENT_APIS:
149 _eglUpdateAPIsString(dpy);
150 return dpy->ClientAPIs;
151 #endif
152 default:
153 _eglError(EGL_BAD_PARAMETER, "eglQueryString");
154 return NULL;
155 }
156 }
157
158
159 EGLBoolean
160 _eglWaitClient(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
161 {
162 /* just a placeholder */
163 (void) drv;
164 (void) dpy;
165 (void) ctx;
166 return EGL_TRUE;
167 }
168
169
170 EGLBoolean
171 _eglWaitNative(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine)
172 {
173 /* just a placeholder */
174 (void) drv;
175 (void) dpy;
176 switch (engine) {
177 case EGL_CORE_NATIVE_ENGINE:
178 break;
179 default:
180 _eglError(EGL_BAD_PARAMETER, "eglWaitNative(engine)");
181 return EGL_FALSE;
182 }
183
184 return EGL_TRUE;
185 }