1/* 2 * (C) Copyright 2016, NVIDIA CORPORATION. 3 * All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * on the rights to use, copy, modify, merge, publish, distribute, sub 9 * license, and/or sell copies of the Software, and to permit persons to whom 10 * the Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19 * IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 * 24 * Authors: 25 * Kyle Brenneman <kbrenneman@nvidia.com> 26 */ 27 28#include <string.h> 29#include <assert.h> 30 31#include <glvnd/libeglabi.h> 32 33#include "eglcurrent.h" 34#include "egldispatchstubs.h" 35#include "eglglobals.h" 36 37static const __EGLapiExports *__eglGLVNDApiExports = NULL; 38 39static const char * EGLAPIENTRY 40__eglGLVNDQueryString(EGLDisplay dpy, EGLenum name) 41{ 42 // For client extensions, return the list of non-platform extensions. The 43 // platform extensions are returned by __eglGLVNDGetVendorString. 44 if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) 45 return _eglGlobal.ClientOnlyExtensionString; 46 47 // For everything else, forward to the normal eglQueryString function. 48 return eglQueryString(dpy, name); 49} 50 51static const char * 52__eglGLVNDGetVendorString(int name) 53{ 54 if (name == __EGL_VENDOR_STRING_PLATFORM_EXTENSIONS) 55 return _eglGlobal.PlatformExtensionString; 56 57 return NULL; 58} 59 60static EGLDisplay 61__eglGLVNDGetPlatformDisplay(EGLenum platform, void *native_display, 62 const EGLAttrib *attrib_list) 63{ 64 if (platform == EGL_NONE) { 65 assert(native_display == (void *) EGL_DEFAULT_DISPLAY); 66 assert(attrib_list == NULL); 67 return eglGetDisplay((EGLNativeDisplayType) native_display); 68 } else { 69 return eglGetPlatformDisplay(platform, native_display, attrib_list); 70 } 71} 72 73static void * 74__eglGLVNDGetProcAddress(const char *procName) 75{ 76 if (strcmp(procName, "eglQueryString") == 0) 77 return (void *) __eglGLVNDQueryString; 78 79 return (void *) eglGetProcAddress(procName); 80} 81 82EGLAPI EGLBoolean 83__egl_Main(uint32_t version, const __EGLapiExports *exports, 84 __EGLvendorInfo *vendor, __EGLapiImports *imports) 85{ 86 if (EGL_VENDOR_ABI_GET_MAJOR_VERSION(version) != 87 EGL_VENDOR_ABI_MAJOR_VERSION) 88 return EGL_FALSE; 89 90 __eglGLVNDApiExports = exports; 91 __eglInitDispatchStubs(exports); 92 93 imports->getPlatformDisplay = __eglGLVNDGetPlatformDisplay; 94 imports->getSupportsAPI = _eglIsApiValid; 95 imports->getVendorString = __eglGLVNDGetVendorString; 96 imports->getProcAddress = __eglGLVNDGetProcAddress; 97 imports->getDispatchAddress = __eglDispatchFindDispatchFunction; 98 imports->setDispatchIndex = __eglSetDispatchIndex; 99 100 return EGL_TRUE; 101} 102 103