gl_common: Replace strstr() for extension checks with a helper function

The helper incorporates NULL checks, and we love those, so it's better.
This commit is contained in:
Derek Foreman 2018-03-08 13:33:32 -06:00
parent c7b44dfa2c
commit 464d0ca9bb
2 changed files with 33 additions and 25 deletions

View File

@ -563,6 +563,7 @@ EAPI void evas_gl_preload_render_lock(evas_gl_make_current_cb make_curre
EAPI void evas_gl_preload_render_unlock(evas_gl_make_current_cb make_current, void *engine_data); EAPI void evas_gl_preload_render_unlock(evas_gl_make_current_cb make_current, void *engine_data);
EAPI void evas_gl_preload_render_relax(evas_gl_make_current_cb make_current, void *engine_data); EAPI void evas_gl_preload_render_relax(evas_gl_make_current_cb make_current, void *engine_data);
EAPI void evas_gl_symbols(void *(*GetProcAddress)(const char *name), const char *extsn); EAPI void evas_gl_symbols(void *(*GetProcAddress)(const char *name), const char *extsn);
EAPI Eina_Bool evas_gl_extension_string_check(const char *ext, const char *exts);
EAPI void evas_gl_common_error_set(int error_enum); EAPI void evas_gl_common_error_set(int error_enum);
EAPI int evas_gl_common_error_get(void); EAPI int evas_gl_common_error_get(void);
@ -577,6 +578,7 @@ typedef Evas_Engine_GL_Context *(*Evas_GL_Common_Context_New)(void);
typedef void (*Evas_GL_Common_Context_Resize_Call)(Evas_Engine_GL_Context *gc, int w, int h, int rot); typedef void (*Evas_GL_Common_Context_Resize_Call)(Evas_Engine_GL_Context *gc, int w, int h, int rot);
typedef int (*Evas_GL_Common_Buffer_Dump_Call)(Evas_Engine_GL_Context *gc,const char* dname, const char* fname, int frame, const char* suffix); typedef int (*Evas_GL_Common_Buffer_Dump_Call)(Evas_Engine_GL_Context *gc,const char* dname, const char* fname, int frame, const char* suffix);
typedef void (*Evas_Gl_Symbols)(void *(*GetProcAddress)(const char *sym), const char *extsn); typedef void (*Evas_Gl_Symbols)(void *(*GetProcAddress)(const char *sym), const char *extsn);
typedef Eina_Bool (*Evas_Gl_Extension_String_Check)(const char *exts, const char *ext);
EAPI void __evas_gl_err(int err, const char *file, const char *func, int line, const char *op); EAPI void __evas_gl_err(int err, const char *file, const char *func, int line, const char *op);

View File

@ -84,6 +84,18 @@ sym_missing(void)
ERR("GL symbols missing!"); ERR("GL symbols missing!");
} }
EAPI Eina_Bool
evas_gl_extension_string_check(const char *exts, const char *ext)
{
if (!exts || !ext) return EINA_FALSE;
return strstr(exts, ext) != NULL;
}
/* Totally gross, but I didn't want to reindent all the
* strstr() callers :(
*/
static Evas_Gl_Extension_String_Check _ckext = evas_gl_extension_string_check;
static int static int
_has_ext(const char *ext, const char **pexts, int *pnum) _has_ext(const char *ext, const char **pexts, int *pnum)
{ {
@ -114,17 +126,11 @@ _has_ext(const char *ext, const char **pexts, int *pnum)
if (!exts) return EINA_FALSE; if (!exts) return EINA_FALSE;
*pexts = exts; *pexts = exts;
} }
return strstr(exts, ext) != NULL; return _ckext(exts, ext);
} }
} }
#ifdef GL_GLES #ifdef GL_GLES
static int
_has_extn(const char *ext, const char *exts)
{
if (!exts || !ext) return EINA_FALSE;
return strstr(exts, ext) != NULL;
}
EAPI void * EAPI void *
evas_gl_common_eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list) evas_gl_common_eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list)
@ -312,7 +318,7 @@ evas_gl_symbols(void *(*GetProcAddress)(const char *name), const char *extsn)
#ifdef GL_GLES #ifdef GL_GLES
#define FINDSYMN(dst, sym, ext, typ) do { \ #define FINDSYMN(dst, sym, ext, typ) do { \
if (!dst) { \ if (!dst) { \
if (_has_extn(ext, extsn) && GetProcAddress) \ if (_ckext(extsn, ext) && GetProcAddress) \
dst = (typ) GetProcAddress(sym); \ dst = (typ) GetProcAddress(sym); \
if (!dst) \ if (!dst) \
dst = (typ) dlsym(RTLD_DEFAULT, sym); \ dst = (typ) dlsym(RTLD_DEFAULT, sym); \
@ -887,41 +893,41 @@ evas_gl_common_context_new(void)
{ {
if (getenv("EVAS_GL_INFO")) if (getenv("EVAS_GL_INFO"))
fprintf(stderr, "EXT:\n%s\n", ext); fprintf(stderr, "EXT:\n%s\n", ext);
if ((strstr(ext, "GL_ARB_texture_non_power_of_two")) || if ((_ckext(ext, "GL_ARB_texture_non_power_of_two")) ||
(strstr(ext, "OES_texture_npot")) || (_ckext(ext, "OES_texture_npot")) ||
(strstr(ext, "GL_IMG_texture_npot"))) (_ckext(ext, "GL_IMG_texture_npot")))
shared->info.tex_npo2 = 1; shared->info.tex_npo2 = 1;
if ((strstr(ext, "GL_NV_texture_rectangle")) || if ((_ckext(ext, "GL_NV_texture_rectangle")) ||
(strstr(ext, "GL_EXT_texture_rectangle")) || (_ckext(ext, "GL_EXT_texture_rectangle")) ||
(strstr(ext, "GL_ARB_texture_rectangle"))) (_ckext(ext, "GL_ARB_texture_rectangle")))
shared->info.tex_rect = 1; shared->info.tex_rect = 1;
if ((strstr(ext, "GL_ARB_get_program_binary")) || if ((_ckext(ext, "GL_ARB_get_program_binary")) ||
(strstr(ext, "GL_OES_get_program_binary"))) (_ckext(ext, "GL_OES_get_program_binary")))
shared->info.bin_program = 1; shared->info.bin_program = 1;
else else
glsym_glGetProgramBinary = NULL; glsym_glGetProgramBinary = NULL;
#ifdef GL_UNPACK_ROW_LENGTH #ifdef GL_UNPACK_ROW_LENGTH
shared->info.unpack_row_length = 1; shared->info.unpack_row_length = 1;
# ifdef GL_GLES # ifdef GL_GLES
if (!strstr(ext, "_unpack_subimage")) if (!_ckext(ext, "_unpack_subimage"))
shared->info.unpack_row_length = 0; shared->info.unpack_row_length = 0;
# endif # endif
#endif #endif
#ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT #ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
if ((strstr(ext, "GL_EXT_texture_filter_anisotropic"))) if ((_ckext(ext, "GL_EXT_texture_filter_anisotropic")))
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,
&(shared->info.anisotropic)); &(shared->info.anisotropic));
#endif #endif
#ifdef GL_BGRA #ifdef GL_BGRA
if ((strstr(ext, "GL_EXT_bgra")) || if ((_ckext(ext, "GL_EXT_bgra")) ||
(strstr(ext, "GL_EXT_texture_format_BGRA8888"))) (_ckext(ext, "GL_EXT_texture_format_BGRA8888")))
shared->info.bgra = 1; shared->info.bgra = 1;
#endif #endif
if (strstr(ext, "OES_compressed_ETC1_RGB8_texture")) if (_ckext(ext, "OES_compressed_ETC1_RGB8_texture"))
shared->info.etc1 = 1; shared->info.etc1 = 1;
if (strstr(ext, "GL_EXT_texture_compression_s3tc") || if (_ckext(ext, "GL_EXT_texture_compression_s3tc") ||
strstr(ext, "GL_S3_s3tc")) _ckext(ext, "GL_S3_s3tc"))
shared->info.s3tc = 1; shared->info.s3tc = 1;
#ifdef GL_GLES #ifdef GL_GLES
// FIXME: there should be an extension name/string to check for // FIXME: there should be an extension name/string to check for
@ -949,7 +955,7 @@ evas_gl_common_context_new(void)
(secsym_tbm_surface_get_info)) (secsym_tbm_surface_get_info))
shared->info.sec_tbm_surface = 1; shared->info.sec_tbm_surface = 1;
#endif #endif
if (!strstr(ext, "GL_QCOM_tiled_rendering")) if (!_ckext(ext, "GL_QCOM_tiled_rendering"))
{ {
glsym_glStartTiling = NULL; glsym_glStartTiling = NULL;
glsym_glEndTiling = NULL; glsym_glEndTiling = NULL;
@ -1046,7 +1052,7 @@ evas_gl_common_context_new(void)
// Note: If we support ETC2 we'll try to always use ETC2 even when the // Note: If we support ETC2 we'll try to always use ETC2 even when the
// image has colorspace ETC1 (backwards compatibility). // image has colorspace ETC1 (backwards compatibility).
if (ext && strstr(ext, "GL_EXT_compressed_ETC1_RGB8_sub_texture")) if (_ckext(ext, "GL_EXT_compressed_ETC1_RGB8_sub_texture"))
shared->info.etc1_subimage = 1; shared->info.etc1_subimage = 1;
else else
shared->info.etc1_subimage = shared->info.etc2; shared->info.etc1_subimage = shared->info.etc2;