egl: adjust how we load symbols in SDL_EGL_GetProcAddress. Use eglGetProcAddress for everything on EGL >= 1.5. Try SDL_LoadFunction first for EGL <= 1.4 in case it's a core symbol, and as a fallback if eglGetProcAddress fails. Finally, for EGL <= 1.4, fallback to eglGetProcAddress to catch extensions not exported from the shared library. (Maybe) Fixes Bugzilla #4794.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 98bb400..ce05646 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -222,25 +222,41 @@ static SDL_bool SDL_EGL_HasExtension(_THIS, SDL_EGL_ExtensionType type, const ch
void *
SDL_EGL_GetProcAddress(_THIS, const char *proc)
{
- static char procname[1024];
- void *retval;
-
+ const Uint32 eglver = (((Uint32) _this->egl_data->egl_version_major) << 16) | ((Uint32) _this->egl_data->egl_version_minor);
+ const SDL_bool is_egl_15_or_later = eglver >= ((((Uint32) 1) << 16) | 5);
+ void *retval = NULL;
+
+ /* eglGetProcAddress is busted on Android http://code.google.com/p/android/issues/detail?id=7681 */
+#if !defined(SDL_VIDEO_DRIVER_ANDROID)
+ /* EGL 1.5 can use eglGetProcAddress() for any symbol. 1.4 and earlier can't use it for core entry points. */
+ if (!retval && is_egl_15_or_later && _this->egl_data->eglGetProcAddress) {
+ retval = _this->egl_data->eglGetProcAddress(proc);
+ }
+#endif
+
+ /* Try SDL_LoadFunction() first for EGL <= 1.4, or as a fallback for >= 1.5. */
+ if (!retval) {
+ static char procname[64];
+ retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, proc);
+ /* just in case you need an underscore prepended... */
+ if (!retval && (SDL_strlen(proc) < (sizeof (procname) - 1))) {
+ procname[0] = '_';
+ SDL_strlcpy(procname + 1, proc, sizeof (procname) - 1);
+ retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, procname);
+ }
+ }
+
/* eglGetProcAddress is busted on Android http://code.google.com/p/android/issues/detail?id=7681 */
#if !defined(SDL_VIDEO_DRIVER_ANDROID)
- if (_this->egl_data->eglGetProcAddress) {
+ /* Try eglGetProcAddress if we on <= 1.4 and still searching... */
+ if (!retval && !is_egl_15_or_later && _this->egl_data->eglGetProcAddress) {
retval = _this->egl_data->eglGetProcAddress(proc);
if (retval) {
return retval;
}
}
#endif
-
- retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, proc);
- if (!retval && SDL_strlen(proc) <= 1022) {
- procname[0] = '_';
- SDL_strlcpy(procname + 1, proc, 1022);
- retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, procname);
- }
+
return retval;
}