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 // Since we have no vendor, the follow-up eglGetError() call will
63 // end up using the GLVND error code. Set it here.
65 exports
->setEGLError(errorCode
);
67 _eglError(errorCode
, __EGL_DISPATCH_FUNC_NAMES
[index
]);
72 if (!exports
->setLastVendor(vendor
)) {
73 // Don't bother trying to set an error code in libglvnd. If
74 // setLastVendor failed, then setEGLError would also fail.
75 _eglError(errorCode
, __EGL_DISPATCH_FUNC_NAMES
[index
]);
82 __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByCurrent(int index
)
84 __EGLvendorInfo
*vendor
;
86 // Note: This is only used for the eglWait* functions. For those, if
87 // there's no current context, then they're supposed to do nothing but
89 exports
->threadInit();
90 vendor
= exports
->getCurrentVendor();
91 return FetchVendorFunc(vendor
, index
, EGL_SUCCESS
);
94 __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDisplay(EGLDisplay dpy
, int index
)
96 __EGLvendorInfo
*vendor
;
98 exports
->threadInit();
99 vendor
= exports
->getVendorFromDisplay(dpy
);
100 return FetchVendorFunc(vendor
, index
, EGL_BAD_DISPLAY
);
103 __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDevice(EGLDeviceEXT dev
, int index
)
105 __EGLvendorInfo
*vendor
;
107 exports
->threadInit();
108 vendor
= exports
->getVendorFromDevice(dev
);
109 return FetchVendorFunc(vendor
, index
, EGL_BAD_DEVICE_EXT
);