1 #include "egldispatchstubs.h"
2 #include "g_egldispatchstubs.h"
6 #include "eglcurrent.h"
8 static const __EGLapiExports
*exports
;
10 const int __EGL_DISPATCH_FUNC_COUNT
= __EGL_DISPATCH_COUNT
;
11 int __EGL_DISPATCH_FUNC_INDICES
[__EGL_DISPATCH_COUNT
+ 1];
13 static int FindProcIndex(const char *name
)
16 unsigned last
= __EGL_DISPATCH_COUNT
- 1;
18 while (first
<= last
) {
19 unsigned middle
= (first
+ last
) / 2;
20 int comp
= strcmp(name
,
21 __EGL_DISPATCH_FUNC_NAMES
[middle
]);
31 /* Just point to the dummy entry at the end of the respective table */
32 return __EGL_DISPATCH_COUNT
;
35 void __eglInitDispatchStubs(const __EGLapiExports
*exportsTable
)
38 exports
= exportsTable
;
39 for (i
=0; i
<__EGL_DISPATCH_FUNC_COUNT
; i
++) {
40 __EGL_DISPATCH_FUNC_INDICES
[i
] = -1;
44 void __eglSetDispatchIndex(const char *name
, int dispatchIndex
)
46 int index
= FindProcIndex(name
);
47 __EGL_DISPATCH_FUNC_INDICES
[index
] = dispatchIndex
;
50 void *__eglDispatchFindDispatchFunction(const char *name
)
52 int index
= FindProcIndex(name
);
53 return (void *) __EGL_DISPATCH_FUNCS
[index
];
56 static __eglMustCastToProperFunctionPointerType
FetchVendorFunc(__EGLvendorInfo
*vendor
,
57 int index
, EGLint errorCode
)
59 __eglMustCastToProperFunctionPointerType func
= NULL
;
62 func
= exports
->fetchDispatchEntry(vendor
, __EGL_DISPATCH_FUNC_INDICES
[index
]);
65 if (errorCode
!= EGL_SUCCESS
) {
66 _eglError(errorCode
, __EGL_DISPATCH_FUNC_NAMES
[index
]);
71 if (!exports
->setLastVendor(vendor
)) {
72 // Don't bother trying to set an error code in libglvnd. If
73 // setLastVendor failed, then setEGLError would also fail.
74 _eglError(errorCode
, __EGL_DISPATCH_FUNC_NAMES
[index
]);
81 __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByCurrent(int index
)
83 __EGLvendorInfo
*vendor
;
85 // Note: This is only used for the eglWait* functions. For those, if
86 // there's no current context, then they're supposed to do nothing but
88 exports
->threadInit();
89 vendor
= exports
->getCurrentVendor();
90 return FetchVendorFunc(vendor
, index
, EGL_SUCCESS
);
93 __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDisplay(EGLDisplay dpy
, int index
)
95 __EGLvendorInfo
*vendor
;
97 exports
->threadInit();
98 vendor
= exports
->getVendorFromDisplay(dpy
);
99 return FetchVendorFunc(vendor
, index
, EGL_BAD_DISPLAY
);
102 __eglMustCastToProperFunctionPointerType
__eglDispatchFetchByDevice(EGLDeviceEXT dev
, int index
)
104 __EGLvendorInfo
*vendor
;
106 exports
->threadInit();
107 vendor
= exports
->getVendorFromDevice(dev
);
108 return FetchVendorFunc(vendor
, index
, EGL_BAD_DEVICE_EXT
);