diff options
author | Eric Anholt <eric@anholt.net> | 2014-03-19 18:24:29 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2014-03-19 18:43:19 -0700 |
commit | b670c840390859d20c478b9494e09b0c99aaab51 (patch) | |
tree | 0dfe28315d5f50905082ddff0adf6679ce945c83 /src | |
parent | e6d9bb971bfeb9e3990ee54bdc84b701e1eaabd8 (diff) | |
download | libepoxy-b670c840390859d20c478b9494e09b0c99aaab51.tar.gz |
Refactor dispatch_common's EGL context detection code.
I want to reuse this from get_core_proc_address().
Diffstat (limited to 'src')
-rw-r--r-- | src/dispatch_common.c | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/src/dispatch_common.c b/src/dispatch_common.c index 2bb7799..79aa9fc 100644 --- a/src/dispatch_common.c +++ b/src/dispatch_common.c @@ -424,6 +424,38 @@ epoxy_get_core_proc_address(const char *name, int core_version) } } +#if PLATFORM_HAS_EGL +static EGLenum +epoxy_egl_get_current_gl_context_api(void) +{ + EGLenum save_api = eglQueryAPI(); + EGLContext ctx; + + if (eglBindAPI(EGL_OPENGL_API)) { + ctx = eglGetCurrentContext(); + if (ctx) { + eglBindAPI(save_api); + return EGL_OPENGL_API; + } + } else { + (void)eglGetError(); + } + + if (eglBindAPI(EGL_OPENGL_ES_API)) { + ctx = eglGetCurrentContext(); + eglBindAPI(save_api); + if (ctx) { + eglBindAPI(save_api); + return EGL_OPENGL_ES_API; + } + } else { + (void)eglGetError(); + } + + return EGL_NONE; +} +#endif /* PLATFORM_HAS_EGL */ + /** * Performs the dlsym() for the core GL 1.0 functions that we use for * determining version and extension support for deciding on dlsym @@ -453,36 +485,20 @@ epoxy_get_bootstrap_proc_address(const char *name) #if PLATFORM_HAS_EGL get_dlopen_handle(&api.egl_handle, "libEGL.so.1", false); if (api.egl_handle) { - EGLenum save_api = eglQueryAPI(); - EGLContext ctx; - - if (eglBindAPI(EGL_OPENGL_API)) { - ctx = eglGetCurrentContext(); - if (ctx) { - eglBindAPI(save_api); - return epoxy_gl_dlsym(name); - } - } else { - (void)eglGetError(); - } - - if (eglBindAPI(EGL_OPENGL_ES_API)) { - ctx = eglGetCurrentContext(); - eglBindAPI(save_api); - if (ctx) { - /* We can't resolve the GL version, because - * epoxy_glGetString() is one of the two things calling - * us. Try the GLES2 implementation first, and fall back - * to GLES1 otherwise. - */ - get_dlopen_handle(&api.gles2_handle, "libGLESv2.so.2", false); - if (api.gles2_handle) - return epoxy_gles2_dlsym(name); - else - return epoxy_gles1_dlsym(name); - } - } else { - (void)eglGetError(); + switch (epoxy_egl_get_current_gl_context_api()) { + case EGL_OPENGL_API: + return epoxy_gl_dlsym(name); + case EGL_OPENGL_ES_API: + /* We can't resolve the GL version, because + * epoxy_glGetString() is one of the two things calling + * us. Try the GLES2 implementation first, and fall back + * to GLES1 otherwise. + */ + get_dlopen_handle(&api.gles2_handle, "libGLESv2.so.2", false); + if (api.gles2_handle) + return epoxy_gles2_dlsym(name); + else + return epoxy_gles1_dlsym(name); } } #endif /* PLATFORM_HAS_EGL */ |