1 #include "egldispatchstubs.h"
2 #include "g_egldispatchstubs.h"
7 #include "eglcurrent.h"
9 static const __EGLapiExports
*exports
;
11 const int __EGL_DISPATCH_FUNC_COUNT
= __EGL_DISPATCH_COUNT
;
12 int __EGL_DISPATCH_FUNC_INDICES
[__EGL_DISPATCH_COUNT
+ 1];
14 static int Compare(const void *l
, const void *r
)
16 const char *s
= *(const char **)r
;
20 static int FindProcIndex(const char *name
)
22 const char **match
= bsearch(name
, __EGL_DISPATCH_FUNC_NAMES
,
23 __EGL_DISPATCH_COUNT
, sizeof(const char *), Compare
);
26 return __EGL_DISPATCH_COUNT
;
28 return match
- __EGL_DISPATCH_FUNC_NAMES
;
31 void __eglInitDispatchStubs(const __EGLapiExports
*exportsTable
)
34 exports
= exportsTable
;
35 for (i
=0; i
<__EGL_DISPATCH_FUNC_COUNT
; i
++) {
36 __EGL_DISPATCH_FUNC_INDICES
[i
] = -1;
40 void __eglSetDispatchIndex(const char *name
, int dispatchIndex
)
42 int index
= FindProcIndex(name
);
43 __EGL_DISPATCH_FUNC_INDICES
[index
] = dispatchIndex
;
46 void *__eglDispatchFindDispatchFunction(const char *name
)
48 int index
= FindProcIndex(name
);
49 return (void *) __EGL_DISPATCH_FUNCS
[index
];
52 static __eglMustCastToProperFunctionPointerType
FetchVendorFunc(__EGLvendorInfo
*vendor
,
53 int index
, EGLint errorCode
)
55 __eglMustCastToProperFunctionPointerType func
= NULL
;
58 func
= exports
->fetchDispatchEntry(vendor
, __EGL_DISPATCH_FUNC_INDICES
[index
]);
61 if (errorCode
!= EGL_SUCCESS
) {
62 _eglError(errorCode
, __EGL_DISPATCH_FUNC_NAMES
[index
]);
67 if (!exports
->setLastVendor(vendor
)) {
68 // Don't bother trying to set an error code in libglvnd. If
69 // setLastVendor failed, then setEGLError would also fail.
70 _eglError(errorCode
, __EGL_DISPATCH_FUNC_NAMES
[index
]);
77 __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByCurrent(int index
)
79 __EGLvendorInfo
*vendor
;
81 // Note: This is only used for the eglWait* functions. For those, if
82 // there's no current context, then they're supposed to do nothing but
84 exports
->threadInit();
85 vendor
= exports
->getCurrentVendor();
86 return FetchVendorFunc(vendor
, index
, EGL_SUCCESS
);
89 __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDisplay(EGLDisplay dpy
, int index
)
91 __EGLvendorInfo
*vendor
;
93 exports
->threadInit();
94 vendor
= exports
->getVendorFromDisplay(dpy
);
95 return FetchVendorFunc(vendor
, index
, EGL_BAD_DISPLAY
);
98 __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDevice(EGLDeviceEXT dev
, int index
)
100 __EGLvendorInfo
*vendor
;
102 exports
->threadInit();
103 vendor
= exports
->getVendorFromDevice(dev
);
104 return FetchVendorFunc(vendor
, index
, EGL_BAD_DEVICE_EXT
);