1cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)/**************************************************************************
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * Copyright 2010-2011 LunarG, Inc.
6cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * All Rights Reserved.
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) * Permission is hereby granted, free of charge, to any person obtaining a
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * copy of this software and associated documentation files (the
10cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * "Software"), to deal in the Software without restriction, including
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * without limitation the rights to use, copy, modify, merge, publish,
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * distribute, sub license, and/or sell copies of the Software, and to
13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * permit persons to whom the Software is furnished to do so, subject to
14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * the following conditions:
15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) *
16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * The above copyright notice and this permission notice (including the
17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * next paragraph) shall be included in all copies or substantial portions
18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * of the Software.
19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) *
20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * DEALINGS IN THE SOFTWARE.
27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) *
28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) **************************************************************************/
29cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)/**
32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) * Small/misc EGL functions
33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) */
34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include <assert.h>
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include <string.h>
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "eglcurrent.h"
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "eglmisc.h"
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "egldisplay.h"
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "egldriver.h"
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "eglstring.h"
437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copy the extension into the string and update the string pointer.
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static EGLint
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)_eglAppendExtension(char **str, const char *ext)
5068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles){
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   char *s = *str;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   size_t len = strlen(ext);
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   if (s) {
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      memcpy(s, ext, len);
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      s[len++] = ' ';
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      s[len] = '\0';
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      *str += len;
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   }
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   else {
62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      len++;
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   }
64cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
65   return (EGLint) len;
66}
67
68
69/**
70 * Examine the individual extension enable/disable flags and recompute
71 * the driver's Extensions string.
72 */
73static void
74_eglUpdateExtensionsString(_EGLDisplay *dpy)
75{
76#define _EGL_CHECK_EXTENSION(ext)                                          \
77   do {                                                                    \
78      if (dpy->Extensions.ext) {                                           \
79         _eglAppendExtension(&exts, "EGL_" #ext);                          \
80         assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN);  \
81      }                                                                    \
82   } while (0)
83
84   char *exts = dpy->ExtensionsString;
85
86   if (exts[0])
87      return;
88
89   _EGL_CHECK_EXTENSION(MESA_screen_surface);
90   _EGL_CHECK_EXTENSION(MESA_copy_context);
91   _EGL_CHECK_EXTENSION(MESA_drm_display);
92   _EGL_CHECK_EXTENSION(MESA_drm_image);
93
94   _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
95
96   _EGL_CHECK_EXTENSION(KHR_image_base);
97   _EGL_CHECK_EXTENSION(KHR_image_pixmap);
98   if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap)
99      _eglAppendExtension(&exts, "EGL_KHR_image");
100
101   _EGL_CHECK_EXTENSION(KHR_vg_parent_image);
102   _EGL_CHECK_EXTENSION(KHR_gl_texture_2D_image);
103   _EGL_CHECK_EXTENSION(KHR_gl_texture_cubemap_image);
104   _EGL_CHECK_EXTENSION(KHR_gl_texture_3D_image);
105   _EGL_CHECK_EXTENSION(KHR_gl_renderbuffer_image);
106
107   _EGL_CHECK_EXTENSION(KHR_reusable_sync);
108   _EGL_CHECK_EXTENSION(KHR_fence_sync);
109
110   _EGL_CHECK_EXTENSION(KHR_surfaceless_context);
111   _EGL_CHECK_EXTENSION(KHR_create_context);
112
113   _EGL_CHECK_EXTENSION(NOK_swap_region);
114   _EGL_CHECK_EXTENSION(NOK_texture_from_pixmap);
115
116   _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer);
117
118   _EGL_CHECK_EXTENSION(EXT_create_context_robustness);
119
120   _EGL_CHECK_EXTENSION(NV_post_sub_buffer);
121#undef _EGL_CHECK_EXTENSION
122}
123
124
125static void
126_eglUpdateAPIsString(_EGLDisplay *dpy)
127{
128   char *apis = dpy->ClientAPIsString;
129
130   if (apis[0] || !dpy->ClientAPIs)
131      return;
132
133   if (dpy->ClientAPIs & EGL_OPENGL_BIT)
134      strcat(apis, "OpenGL ");
135
136   if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT)
137      strcat(apis, "OpenGL_ES ");
138
139   if (dpy->ClientAPIs & EGL_OPENGL_ES2_BIT)
140      strcat(apis, "OpenGL_ES2 ");
141
142   if (dpy->ClientAPIs & EGL_OPENVG_BIT)
143      strcat(apis, "OpenVG ");
144
145   assert(strlen(apis) < sizeof(dpy->ClientAPIsString));
146}
147
148
149const char *
150_eglQueryString(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name)
151{
152   (void) drv;
153
154   switch (name) {
155   case EGL_VENDOR:
156      return _EGL_VENDOR_STRING;
157   case EGL_VERSION:
158      _eglsnprintf(dpy->VersionString, sizeof(dpy->VersionString),
159              "%d.%d (%s)", dpy->VersionMajor, dpy->VersionMinor,
160              dpy->Driver->Name);
161      return dpy->VersionString;
162   case EGL_EXTENSIONS:
163      _eglUpdateExtensionsString(dpy);
164      return dpy->ExtensionsString;
165   case EGL_CLIENT_APIS:
166      _eglUpdateAPIsString(dpy);
167      return dpy->ClientAPIsString;
168   default:
169      _eglError(EGL_BAD_PARAMETER, "eglQueryString");
170      return NULL;
171   }
172}
173