Skip to content

Commit

Permalink
egl: adjust how we load symbols in SDL_EGL_GetProcAddress.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
icculus committed Oct 18, 2019
1 parent 4f304fd commit 3ecce84
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/video/SDL_egl.c
Expand Up @@ -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;
}

Expand Down

0 comments on commit 3ecce84

Please sign in to comment.