glxglvnd.c revision 01e04c3f
101e04c3fSmrg#include <string.h>
201e04c3fSmrg#include <stdlib.h>
301e04c3fSmrg#include <X11/Xlib.h>
401e04c3fSmrg
501e04c3fSmrg#include "glvnd/libglxabi.h"
601e04c3fSmrg
701e04c3fSmrg#include "glxglvnd.h"
801e04c3fSmrg
901e04c3fSmrgstatic Bool __glXGLVNDIsScreenSupported(Display *dpy, int screen)
1001e04c3fSmrg{
1101e04c3fSmrg    /* TODO: Think of a better heuristic... */
1201e04c3fSmrg    return True;
1301e04c3fSmrg}
1401e04c3fSmrg
1501e04c3fSmrgstatic void *__glXGLVNDGetProcAddress(const GLubyte *procName)
1601e04c3fSmrg{
1701e04c3fSmrg    return glXGetProcAddressARB(procName);
1801e04c3fSmrg}
1901e04c3fSmrg
2001e04c3fSmrgstatic int
2101e04c3fSmrgcompare(const void *l, const void *r)
2201e04c3fSmrg{
2301e04c3fSmrg    const char *s = *(const char **)r;
2401e04c3fSmrg    return strcmp(l, s);
2501e04c3fSmrg}
2601e04c3fSmrg
2701e04c3fSmrgstatic unsigned FindGLXFunction(const GLubyte *name)
2801e04c3fSmrg{
2901e04c3fSmrg    const char **match;
3001e04c3fSmrg
3101e04c3fSmrg    match = bsearch(name, __glXDispatchTableStrings, DI_FUNCTION_COUNT,
3201e04c3fSmrg                    sizeof(const char *), compare);
3301e04c3fSmrg
3401e04c3fSmrg    if (match == NULL)
3501e04c3fSmrg        return DI_FUNCTION_COUNT;
3601e04c3fSmrg
3701e04c3fSmrg    return match - __glXDispatchTableStrings;
3801e04c3fSmrg}
3901e04c3fSmrg
4001e04c3fSmrgstatic void *__glXGLVNDGetDispatchAddress(const GLubyte *procName)
4101e04c3fSmrg{
4201e04c3fSmrg    unsigned internalIndex = FindGLXFunction(procName);
4301e04c3fSmrg
4401e04c3fSmrg    return __glXDispatchFunctions[internalIndex];
4501e04c3fSmrg}
4601e04c3fSmrg
4701e04c3fSmrgstatic void __glXGLVNDSetDispatchIndex(const GLubyte *procName, int index)
4801e04c3fSmrg{
4901e04c3fSmrg    unsigned internalIndex = FindGLXFunction(procName);
5001e04c3fSmrg
5101e04c3fSmrg    if (internalIndex == DI_FUNCTION_COUNT)
5201e04c3fSmrg        return; /* unknown or static dispatch */
5301e04c3fSmrg
5401e04c3fSmrg    __glXDispatchTableIndices[internalIndex] = index;
5501e04c3fSmrg}
5601e04c3fSmrg
5701e04c3fSmrg_X_EXPORT Bool __glx_Main(uint32_t version, const __GLXapiExports *exports,
5801e04c3fSmrg                          __GLXvendorInfo *vendor, __GLXapiImports *imports)
5901e04c3fSmrg{
6001e04c3fSmrg    static Bool initDone = False;
6101e04c3fSmrg
6201e04c3fSmrg    if (GLX_VENDOR_ABI_GET_MAJOR_VERSION(version) !=
6301e04c3fSmrg        GLX_VENDOR_ABI_MAJOR_VERSION ||
6401e04c3fSmrg        GLX_VENDOR_ABI_GET_MINOR_VERSION(version) <
6501e04c3fSmrg        GLX_VENDOR_ABI_MINOR_VERSION)
6601e04c3fSmrg        return False;
6701e04c3fSmrg
6801e04c3fSmrg    if (!initDone) {
6901e04c3fSmrg        initDone = True;
7001e04c3fSmrg        __glXGLVNDAPIExports = exports;
7101e04c3fSmrg
7201e04c3fSmrg        imports->isScreenSupported = __glXGLVNDIsScreenSupported;
7301e04c3fSmrg        imports->getProcAddress = __glXGLVNDGetProcAddress;
7401e04c3fSmrg        imports->getDispatchAddress = __glXGLVNDGetDispatchAddress;
7501e04c3fSmrg        imports->setDispatchIndex = __glXGLVNDSetDispatchIndex;
7601e04c3fSmrg        imports->notifyError = NULL;
7701e04c3fSmrg        imports->isPatchSupported = NULL;
7801e04c3fSmrg        imports->initiatePatch = NULL;
7901e04c3fSmrg    }
8001e04c3fSmrg
8101e04c3fSmrg    return True;
8201e04c3fSmrg}
83