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 10static const __EGLapiExports *__eglGLVNDApiExports = NULL; 11 12static const char * EGLAPIENTRY 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 24static const char * 25__eglGLVNDGetVendorString(int name) 26{ 27 if (name == __EGL_VENDOR_STRING_PLATFORM_EXTENSIONS) { 28 const char *str = _eglGlobal.PlatformExtensionString; 29 // The platform extension string may have a leading space. If it does, 30 // then skip over it. 31 while (*str == ' ') { 32 str++; 33 } 34 return str; 35 } 36 37 return NULL; 38} 39 40static EGLDisplay 41__eglGLVNDGetPlatformDisplay(EGLenum platform, void *native_display, 42 const EGLAttrib *attrib_list) 43{ 44 if (platform == EGL_NONE) { 45 assert(native_display == (void *) EGL_DEFAULT_DISPLAY); 46 assert(attrib_list == NULL); 47 return eglGetDisplay((EGLNativeDisplayType) native_display); 48 } else { 49 return eglGetPlatformDisplay(platform, native_display, attrib_list); 50 } 51} 52 53static void * 54__eglGLVNDGetProcAddress(const char *procName) 55{ 56 if (strcmp(procName, "eglQueryString") == 0) 57 return (void *) __eglGLVNDQueryString; 58 59 return (void *) eglGetProcAddress(procName); 60} 61 62EGLAPI EGLBoolean 63__egl_Main(uint32_t version, const __EGLapiExports *exports, 64 __EGLvendorInfo *vendor, __EGLapiImports *imports) 65{ 66 if (EGL_VENDOR_ABI_GET_MAJOR_VERSION(version) != 67 EGL_VENDOR_ABI_MAJOR_VERSION) 68 return EGL_FALSE; 69 70 __eglGLVNDApiExports = exports; 71 __eglInitDispatchStubs(exports); 72 73 imports->getPlatformDisplay = __eglGLVNDGetPlatformDisplay; 74 imports->getSupportsAPI = _eglIsApiValid; 75 imports->getVendorString = __eglGLVNDGetVendorString; 76 imports->getProcAddress = __eglGLVNDGetProcAddress; 77 imports->getDispatchAddress = __eglDispatchFindDispatchFunction; 78 imports->setDispatchIndex = __eglSetDispatchIndex; 79 80 return EGL_TRUE; 81} 82 83