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