1 #include <string.h>
2 #include <assert.h>
3
4 #include <glvnd/libeglabi.h>
5
6 #include "eglcurrent.h"
7 #include "egldispatchstubs.h"
8 #include "eglglobals.h"
9
10 static const __EGLapiExports *__eglGLVNDApiExports = NULL;
11
12 static const char * EGLAPIENTRY
__eglGLVNDQueryString(EGLDisplay dpy,EGLenum name)13 __eglGLVNDQueryString(EGLDisplay dpy, EGLenum name)
14 {
15 // For client extensions, return the list of non-platform extensions. The
16 // platform extensions are returned by __eglGLVNDGetVendorString.
17 if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS)
18 return _eglGlobal.ClientOnlyExtensionString;
19
20 // For everything else, forward to the normal eglQueryString function.
21 return eglQueryString(dpy, name);
22 }
23
24 static const char *
__eglGLVNDGetVendorString(int name)25 __eglGLVNDGetVendorString(int name)
26 {
27 if (name == __EGL_VENDOR_STRING_PLATFORM_EXTENSIONS)
28 return _eglGlobal.PlatformExtensionString;
29
30 return NULL;
31 }
32
33 static EGLDisplay
__eglGLVNDGetPlatformDisplay(EGLenum platform,void * native_display,const EGLAttrib * attrib_list)34 __eglGLVNDGetPlatformDisplay(EGLenum platform, void *native_display,
35 const EGLAttrib *attrib_list)
36 {
37 if (platform == EGL_NONE) {
38 assert(native_display == (void *) EGL_DEFAULT_DISPLAY);
39 assert(attrib_list == NULL);
40 return eglGetDisplay((EGLNativeDisplayType) native_display);
41 } else {
42 return eglGetPlatformDisplay(platform, native_display, attrib_list);
43 }
44 }
45
46 static void *
__eglGLVNDGetProcAddress(const char * procName)47 __eglGLVNDGetProcAddress(const char *procName)
48 {
49 if (strcmp(procName, "eglQueryString") == 0)
50 return (void *) __eglGLVNDQueryString;
51
52 return (void *) eglGetProcAddress(procName);
53 }
54
55 EGLAPI EGLBoolean
__egl_Main(uint32_t version,const __EGLapiExports * exports,__EGLvendorInfo * vendor,__EGLapiImports * imports)56 __egl_Main(uint32_t version, const __EGLapiExports *exports,
57 __EGLvendorInfo *vendor, __EGLapiImports *imports)
58 {
59 if (EGL_VENDOR_ABI_GET_MAJOR_VERSION(version) !=
60 EGL_VENDOR_ABI_MAJOR_VERSION)
61 return EGL_FALSE;
62
63 __eglGLVNDApiExports = exports;
64 __eglInitDispatchStubs(exports);
65
66 imports->getPlatformDisplay = __eglGLVNDGetPlatformDisplay;
67 imports->getSupportsAPI = _eglIsApiValid;
68 imports->getVendorString = __eglGLVNDGetVendorString;
69 imports->getProcAddress = __eglGLVNDGetProcAddress;
70 imports->getDispatchAddress = __eglDispatchFindDispatchFunction;
71 imports->setDispatchIndex = __eglSetDispatchIndex;
72
73 return EGL_TRUE;
74 }
75
76