From 0c04ce5f0d9c4fb7311edf0ae7bdf1eef0f61235 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 2 Oct 2017 17:30:27 +0200 Subject: vo_gpu: gl: implement proper extension string search The existing code in check_ext() avoided false positive due to sub-strings, but allowed false negatives. Fix this with slightly better search code, and make it available as function to other source files. (There are some cases of strstr() still around.) --- video/out/opengl/common.c | 13 +++---------- video/out/opengl/utils.c | 18 ++++++++++++++++++ video/out/opengl/utils.h | 2 ++ 3 files changed, 23 insertions(+), 10 deletions(-) (limited to 'video/out') diff --git a/video/out/opengl/common.c b/video/out/opengl/common.c index db317ee843..be3ff8e438 100644 --- a/video/out/opengl/common.c +++ b/video/out/opengl/common.c @@ -31,6 +31,7 @@ #include "common.h" #include "common/common.h" +#include "utils.h" // This guesses if the current GL context is a suspected software renderer. static bool is_software_gl(GL *gl) @@ -49,14 +50,6 @@ static void GLAPIENTRY dummy_glBindFramebuffer(GLenum target, GLuint framebuffer assert(framebuffer == 0); } -static bool check_ext(GL *gl, const char *name) -{ - const char *exts = gl->extensions; - char *s = strstr(exts, name); - char *e = s ? s + strlen(name) : NULL; - return s && (s == exts || s[-1] == ' ') && (e[0] == ' ' || !e[0]); -} - #define FN_OFFS(name) offsetof(GL, name) #define DEF_FN(name) {FN_OFFS(name), "gl" # name} @@ -581,8 +574,8 @@ void mpgl_load_functions2(GL *gl, void *(*get_fn)(void *ctx, const char *n), if (ver_core) must_exist = version >= ver_core; - if (section->extension && check_ext(gl, section->extension)) - exists = true; + if (section->extension) + exists = gl_check_extension(gl->extensions, section->extension); exists |= must_exist; if (!exists) diff --git a/video/out/opengl/utils.c b/video/out/opengl/utils.c index 3b296d52de..38982e501e 100644 --- a/video/out/opengl/utils.c +++ b/video/out/opengl/utils.c @@ -267,3 +267,21 @@ void gl_set_debug_logger(GL *gl, struct mp_log *log) if (gl->DebugMessageCallback) gl->DebugMessageCallback(log ? gl_debug_cb : NULL, log); } + +// Given a GL combined extension string in extensions, find out whether ext +// is included in it. Basically, a word search. +bool gl_check_extension(const char *extensions, const char *ext) +{ + int len = strlen(ext); + const char *cur = extensions; + while (cur) { + cur = strstr(cur, ext); + if (!cur) + break; + if ((cur == extensions || cur[-1] == ' ') && + (cur[len] == '\0' || cur[len] == ' ')) + return true; + cur += len; + } + return false; +} diff --git a/video/out/opengl/utils.h b/video/out/opengl/utils.h index 18cab476ed..53127e479e 100644 --- a/video/out/opengl/utils.h +++ b/video/out/opengl/utils.h @@ -51,4 +51,6 @@ void gl_vao_draw_data(struct gl_vao *vao, GLenum prim, void *ptr, size_t num); void gl_set_debug_logger(GL *gl, struct mp_log *log); +bool gl_check_extension(const char *extensions, const char *ext); + #endif -- cgit v1.2.3