17ec681f3Smrg/*
27ec681f3Smrg * (C) Copyright 2016, NVIDIA CORPORATION.
37ec681f3Smrg * All Rights Reserved.
47ec681f3Smrg *
57ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
67ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
77ec681f3Smrg * to deal in the Software without restriction, including without limitation
87ec681f3Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
97ec681f3Smrg * license, and/or sell copies of the Software, and to permit persons to whom
107ec681f3Smrg * the Software is furnished to do so, subject to the following conditions:
117ec681f3Smrg *
127ec681f3Smrg * The above copyright notice and this permission notice (including the next
137ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
147ec681f3Smrg * Software.
157ec681f3Smrg *
167ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
177ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
187ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
197ec681f3Smrg * IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
207ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
217ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
227ec681f3Smrg * IN THE SOFTWARE.
237ec681f3Smrg *
247ec681f3Smrg * Authors:
257ec681f3Smrg *    Kyle Brenneman <kbrenneman@nvidia.com>
267ec681f3Smrg */
277ec681f3Smrg
2801e04c3fSmrg#include <string.h>
2901e04c3fSmrg#include <assert.h>
3001e04c3fSmrg
3101e04c3fSmrg#include <glvnd/libeglabi.h>
3201e04c3fSmrg
3301e04c3fSmrg#include "eglcurrent.h"
3401e04c3fSmrg#include "egldispatchstubs.h"
3501e04c3fSmrg#include "eglglobals.h"
3601e04c3fSmrg
3701e04c3fSmrgstatic const __EGLapiExports *__eglGLVNDApiExports = NULL;
3801e04c3fSmrg
3901e04c3fSmrgstatic const char * EGLAPIENTRY
4001e04c3fSmrg__eglGLVNDQueryString(EGLDisplay dpy, EGLenum name)
4101e04c3fSmrg{
4201e04c3fSmrg   // For client extensions, return the list of non-platform extensions. The
4301e04c3fSmrg   // platform extensions are returned by __eglGLVNDGetVendorString.
4401e04c3fSmrg   if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS)
4501e04c3fSmrg      return _eglGlobal.ClientOnlyExtensionString;
4601e04c3fSmrg
4701e04c3fSmrg   // For everything else, forward to the normal eglQueryString function.
4801e04c3fSmrg   return eglQueryString(dpy, name);
4901e04c3fSmrg}
5001e04c3fSmrg
5101e04c3fSmrgstatic const char *
5201e04c3fSmrg__eglGLVNDGetVendorString(int name)
5301e04c3fSmrg{
547ec681f3Smrg   if (name == __EGL_VENDOR_STRING_PLATFORM_EXTENSIONS)
557ec681f3Smrg      return _eglGlobal.PlatformExtensionString;
5601e04c3fSmrg
5701e04c3fSmrg   return NULL;
5801e04c3fSmrg}
5901e04c3fSmrg
6001e04c3fSmrgstatic EGLDisplay
6101e04c3fSmrg__eglGLVNDGetPlatformDisplay(EGLenum platform, void *native_display,
6201e04c3fSmrg      const EGLAttrib *attrib_list)
6301e04c3fSmrg{
6401e04c3fSmrg   if (platform == EGL_NONE) {
6501e04c3fSmrg      assert(native_display == (void *) EGL_DEFAULT_DISPLAY);
6601e04c3fSmrg      assert(attrib_list == NULL);
6701e04c3fSmrg      return eglGetDisplay((EGLNativeDisplayType) native_display);
6801e04c3fSmrg   } else {
6901e04c3fSmrg      return eglGetPlatformDisplay(platform, native_display, attrib_list);
7001e04c3fSmrg   }
7101e04c3fSmrg}
7201e04c3fSmrg
7301e04c3fSmrgstatic void *
7401e04c3fSmrg__eglGLVNDGetProcAddress(const char *procName)
7501e04c3fSmrg{
7601e04c3fSmrg   if (strcmp(procName, "eglQueryString") == 0)
7701e04c3fSmrg      return (void *) __eglGLVNDQueryString;
7801e04c3fSmrg
7901e04c3fSmrg   return (void *) eglGetProcAddress(procName);
8001e04c3fSmrg}
8101e04c3fSmrg
8201e04c3fSmrgEGLAPI EGLBoolean
8301e04c3fSmrg__egl_Main(uint32_t version, const __EGLapiExports *exports,
8401e04c3fSmrg     __EGLvendorInfo *vendor, __EGLapiImports *imports)
8501e04c3fSmrg{
8601e04c3fSmrg   if (EGL_VENDOR_ABI_GET_MAJOR_VERSION(version) !=
8701e04c3fSmrg       EGL_VENDOR_ABI_MAJOR_VERSION)
8801e04c3fSmrg      return EGL_FALSE;
8901e04c3fSmrg
9001e04c3fSmrg   __eglGLVNDApiExports = exports;
9101e04c3fSmrg   __eglInitDispatchStubs(exports);
9201e04c3fSmrg
9301e04c3fSmrg   imports->getPlatformDisplay = __eglGLVNDGetPlatformDisplay;
9401e04c3fSmrg   imports->getSupportsAPI = _eglIsApiValid;
9501e04c3fSmrg   imports->getVendorString = __eglGLVNDGetVendorString;
9601e04c3fSmrg   imports->getProcAddress = __eglGLVNDGetProcAddress;
9701e04c3fSmrg   imports->getDispatchAddress = __eglDispatchFindDispatchFunction;
9801e04c3fSmrg   imports->setDispatchIndex = __eglSetDispatchIndex;
9901e04c3fSmrg
10001e04c3fSmrg   return EGL_TRUE;
10101e04c3fSmrg}
10201e04c3fSmrg
103