st/xa: Fix crosscompile builds with nonstandard ld locations
[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 #include "egldriver.h"
40 #include "eglstring.h"
41
42
43 /**
44 * Copy the extension into the string and update the string pointer.
45 */
46 static EGLint
47 _eglAppendExtension(char **str, const char *ext)
48 {
49 char *s = *str;
50 size_t len = strlen(ext);
51
52 if (s) {
53 memcpy(s, ext, len);
54 s[len++] = ' ';
55 s[len] = '\0';
56
57 *str += len;
58 }
59 else {
60 len++;
61 }
62
63 return (EGLint) len;
64 }
65
66
67 /**
68 * Examine the individual extension enable/disable flags and recompute
69 * the driver's Extensions string.
70 */
71 static void
72 _eglUpdateExtensionsString(_EGLDisplay *dpy)
73 {
74 #define _EGL_CHECK_EXTENSION(ext) \
75 do { \
76 if (dpy->Extensions.ext) { \
77 _eglAppendExtension(&exts, "EGL_" #ext); \
78 assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
79 } \
80 } while (0)
81
82 char *exts = dpy->ExtensionsString;
83
84 if (exts[0])
85 return;
86
87 _EGL_CHECK_EXTENSION(MESA_screen_surface);
88 _EGL_CHECK_EXTENSION(MESA_copy_context);
89 _EGL_CHECK_EXTENSION(MESA_drm_display);
90 _EGL_CHECK_EXTENSION(MESA_drm_image);
91
92 _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
93
94 _EGL_CHECK_EXTENSION(KHR_image_base);
95 _EGL_CHECK_EXTENSION(KHR_image_pixmap);
96 if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap)
97 _eglAppendExtension(&exts, "EGL_KHR_image");
98
99 _EGL_CHECK_EXTENSION(KHR_vg_parent_image);
100 _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image);
101 _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image);
102 _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image);
103 _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image);
104
105 _EGL_CHECK_EXTENSION(KHR_reusable_sync);
106 _EGL_CHECK_EXTENSION(KHR_fence_sync);
107
108 _EGL_CHECK_EXTENSION(KHR_surfaceless_gles1);
109 _EGL_CHECK_EXTENSION(KHR_surfaceless_gles2);
110 _EGL_CHECK_EXTENSION(KHR_surfaceless_opengl);
111
112 _EGL_CHECK_EXTENSION(NOK_swap_region);
113 _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
114 #undef _EGL_CHECK_EXTENSION
115 }
116
117
118 static void
119 _eglUpdateAPIsString(_EGLDisplay *dpy)
120 {
121 char *apis = dpy->ClientAPIsString;
122
123 if (apis[0] || !dpy->ClientAPIs)
124 return;
125
126 if (dpy->ClientAPIs & EGL_OPENGL_BIT)
127 strcat(apis, "OpenGL ");
128
129 if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT)
130 strcat(apis, "OpenGL_ES ");
131
132 if (dpy->ClientAPIs & EGL_OPENGL_ES2_BIT)
133 strcat(apis, "OpenGL_ES2 ");
134
135 if (dpy->ClientAPIs & EGL_OPENVG_BIT)
136 strcat(apis, "OpenVG ");
137
138 assert(strlen(apis) < sizeof(dpy->ClientAPIsString));
139 }
140
141
142 const char *
143 _eglQueryString(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name)
144 {
145 (void) drv;
146
147 switch (name) {
148 case EGL_VENDOR:
149 return _EGL_VENDOR_STRING;
150 case EGL_VERSION:
151 _eglsnprintf(dpy->VersionString, sizeof(dpy->VersionString),
152 "%d.%d (%s)", dpy->VersionMajor, dpy->VersionMinor,
153 dpy->Driver->Name);
154 return dpy->VersionString;
155 case EGL_EXTENSIONS:
156 _eglUpdateExtensionsString(dpy);
157 return dpy->ExtensionsString;
158 case EGL_CLIENT_APIS:
159 _eglUpdateAPIsString(dpy);
160 return dpy->ClientAPIsString;
161 default:
162 _eglError(EGL_BAD_PARAMETER, "eglQueryString");
163 return NULL;
164 }
165 }