Path: blob/21.2-virgl/src/egl/main/egldispatchstubs.c
4560 views
#include "egldispatchstubs.h"1#include "g_egldispatchstubs.h"23#include <string.h>4#include <stdlib.h>56#include "eglcurrent.h"78static const __EGLapiExports *exports;910const int __EGL_DISPATCH_FUNC_COUNT = __EGL_DISPATCH_COUNT;11int __EGL_DISPATCH_FUNC_INDICES[__EGL_DISPATCH_COUNT + 1];1213static int Compare(const void *l, const void *r)14{15const char *s = *(const char **)r;16return strcmp(l, s);17}1819static int FindProcIndex(const char *name)20{21const char **match = bsearch(name, __EGL_DISPATCH_FUNC_NAMES,22__EGL_DISPATCH_COUNT, sizeof(const char *), Compare);2324if (match == NULL)25return __EGL_DISPATCH_COUNT;2627return match - __EGL_DISPATCH_FUNC_NAMES;28}2930void __eglInitDispatchStubs(const __EGLapiExports *exportsTable)31{32int i;33exports = exportsTable;34for (i=0; i<__EGL_DISPATCH_FUNC_COUNT; i++) {35__EGL_DISPATCH_FUNC_INDICES[i] = -1;36}37}3839void __eglSetDispatchIndex(const char *name, int dispatchIndex)40{41int index = FindProcIndex(name);42__EGL_DISPATCH_FUNC_INDICES[index] = dispatchIndex;43}4445void *__eglDispatchFindDispatchFunction(const char *name)46{47int index = FindProcIndex(name);48return (void *) __EGL_DISPATCH_FUNCS[index];49}5051static __eglMustCastToProperFunctionPointerType FetchVendorFunc(__EGLvendorInfo *vendor,52int index, EGLint errorCode)53{54__eglMustCastToProperFunctionPointerType func = NULL;5556if (vendor != NULL) {57func = exports->fetchDispatchEntry(vendor, __EGL_DISPATCH_FUNC_INDICES[index]);58}59if (func == NULL) {60if (errorCode != EGL_SUCCESS) {61// Since we have no vendor, the follow-up eglGetError() call will62// end up using the GLVND error code. Set it here.63if (vendor == NULL) {64exports->setEGLError(errorCode);65}66_eglError(errorCode, __EGL_DISPATCH_FUNC_NAMES[index]);67}68return NULL;69}7071if (!exports->setLastVendor(vendor)) {72// Don't bother trying to set an error code in libglvnd. If73// setLastVendor failed, then setEGLError would also fail.74_eglError(errorCode, __EGL_DISPATCH_FUNC_NAMES[index]);75return NULL;76}7778return func;79}8081__eglMustCastToProperFunctionPointerType __eglDispatchFetchByCurrent(int index)82{83__EGLvendorInfo *vendor;8485// Note: This is only used for the eglWait* functions. For those, if86// there's no current context, then they're supposed to do nothing but87// return success.88exports->threadInit();89vendor = exports->getCurrentVendor();90return FetchVendorFunc(vendor, index, EGL_SUCCESS);91}9293__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDisplay(EGLDisplay dpy, int index)94{95__EGLvendorInfo *vendor;9697exports->threadInit();98vendor = exports->getVendorFromDisplay(dpy);99return FetchVendorFunc(vendor, index, EGL_BAD_DISPLAY);100}101102__eglMustCastToProperFunctionPointerType __eglDispatchFetchByDevice(EGLDeviceEXT dev, int index)103{104__EGLvendorInfo *vendor;105106exports->threadInit();107vendor = exports->getVendorFromDevice(dev);108return FetchVendorFunc(vendor, index, EGL_BAD_DEVICE_EXT);109}110111112113