summaryrefslogtreecommitdiff
path: root/lib/mesa/src/glx/glxglvnd.c
blob: bf5c2a06b0cfd845196de4491987cc464ff2c870 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <string.h>
#include <stdlib.h>
#include <X11/Xlib.h>

#include "glvnd/libglxabi.h"

#include "glxglvnd.h"

static Bool __glXGLVNDIsScreenSupported(Display *dpy, int screen)
{
    /* TODO: Think of a better heuristic... */
    return True;
}

static void *__glXGLVNDGetProcAddress(const GLubyte *procName)
{
    return glXGetProcAddressARB(procName);
}

static int
compare(const void *l, const void *r)
{
    const char *s = *(const char **)r;
    return strcmp(l, s);
}

static unsigned FindGLXFunction(const GLubyte *name)
{
    const char **match;

    match = bsearch(name, __glXDispatchTableStrings, DI_FUNCTION_COUNT,
                    sizeof(const char *), compare);

    if (match == NULL)
        return DI_FUNCTION_COUNT;

    return match - __glXDispatchTableStrings;
}

static void *__glXGLVNDGetDispatchAddress(const GLubyte *procName)
{
    unsigned internalIndex = FindGLXFunction(procName);

    return (void*)__glXDispatchFunctions[internalIndex];
}

static void __glXGLVNDSetDispatchIndex(const GLubyte *procName, int index)
{
    unsigned internalIndex = FindGLXFunction(procName);

    if (internalIndex == DI_FUNCTION_COUNT)
        return; /* unknown or static dispatch */

    __glXDispatchTableIndices[internalIndex] = index;
}

_X_EXPORT Bool __glx_Main(uint32_t version, const __GLXapiExports *exports,
                          __GLXvendorInfo *vendor, __GLXapiImports *imports)
{
    static Bool initDone = False;

    if (GLX_VENDOR_ABI_GET_MAJOR_VERSION(version) !=
        GLX_VENDOR_ABI_MAJOR_VERSION ||
        GLX_VENDOR_ABI_GET_MINOR_VERSION(version) <
        GLX_VENDOR_ABI_MINOR_VERSION)
        return False;

    if (!initDone) {
        initDone = True;
        __glXGLVNDAPIExports = exports;

        imports->isScreenSupported = __glXGLVNDIsScreenSupported;
        imports->getProcAddress = __glXGLVNDGetProcAddress;
        imports->getDispatchAddress = __glXGLVNDGetDispatchAddress;
        imports->setDispatchIndex = __glXGLVNDSetDispatchIndex;
        imports->notifyError = NULL;
        imports->isPatchSupported = NULL;
        imports->initiatePatch = NULL;
    }

    return True;
}