glx/glvnd: Don't modify the dummy slot in the dispatch table
[mesa.git] / src / glx / glxglvnd.c
1 #include <string.h>
2 #include <X11/Xlib.h>
3
4 #include "glvnd/libglxabi.h"
5
6 #include "glxglvnd.h"
7
8
9 static Bool __glXGLVNDIsScreenSupported(Display *dpy, int screen)
10 {
11 /* TODO: Think of a better heuristic... */
12 return True;
13 }
14
15 static void *__glXGLVNDGetProcAddress(const GLubyte *procName)
16 {
17 return glXGetProcAddressARB(procName);
18 }
19
20 static unsigned FindGLXFunction(const GLubyte *name)
21 {
22 int first = 0;
23 int last = DI_FUNCTION_COUNT - 1;
24
25 while (first <= last) {
26 int middle = (first + last) / 2;
27 int comp = strcmp(__glXDispatchTableStrings[middle],
28 (const char *) name);
29
30 if (comp < 0)
31 first = middle + 1;
32 else if (comp > 0)
33 last = middle - 1;
34 else
35 return middle;
36 }
37
38 /* Just point to the dummy entry at the end of the respective table */
39 return DI_FUNCTION_COUNT;
40 }
41
42 static void *__glXGLVNDGetDispatchAddress(const GLubyte *procName)
43 {
44 unsigned internalIndex = FindGLXFunction(procName);
45
46 return __glXDispatchFunctions[internalIndex];
47 }
48
49 static void __glXGLVNDSetDispatchIndex(const GLubyte *procName, int index)
50 {
51 unsigned internalIndex = FindGLXFunction(procName);
52
53 if (internalIndex == DI_FUNCTION_COUNT)
54 return; /* unknown or static dispatch */
55
56 __glXDispatchTableIndices[internalIndex] = index;
57 }
58
59 _X_EXPORT Bool __glx_Main(uint32_t version, const __GLXapiExports *exports,
60 __GLXvendorInfo *vendor, __GLXapiImports *imports)
61 {
62 static Bool initDone = False;
63
64 if (GLX_VENDOR_ABI_GET_MAJOR_VERSION(version) !=
65 GLX_VENDOR_ABI_MAJOR_VERSION ||
66 GLX_VENDOR_ABI_GET_MINOR_VERSION(version) <
67 GLX_VENDOR_ABI_MINOR_VERSION)
68 return False;
69
70 if (!initDone) {
71 initDone = True;
72 __glXGLVNDAPIExports = exports;
73
74 imports->isScreenSupported = __glXGLVNDIsScreenSupported;
75 imports->getProcAddress = __glXGLVNDGetProcAddress;
76 imports->getDispatchAddress = __glXGLVNDGetDispatchAddress;
77 imports->setDispatchIndex = __glXGLVNDSetDispatchIndex;
78 imports->notifyError = NULL;
79 imports->isPatchSupported = NULL;
80 imports->initiatePatch = NULL;
81 }
82
83 return True;
84 }