Skip to content

Commit

Permalink
backend: gl: use libepoxy's has_*_extension
Browse files Browse the repository at this point in the history
So we don't need maintain our own version.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
  • Loading branch information
yshui committed Feb 11, 2024
1 parent eb723ee commit 755996a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 98 deletions.
39 changes: 4 additions & 35 deletions src/backend/gl/egl.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,48 +395,17 @@ struct backend_operations egl_ops = {
.max_buffer_age = 5, // Why?
};

/**
* Check if a EGL extension exists.
*/
static inline bool egl_has_extension(EGLDisplay dpy, const char *ext) {
const char *egl_exts = eglQueryString(dpy, EGL_EXTENSIONS);
if (!egl_exts) {
log_error("Failed get EGL extension list.");
return false;
}

auto inlen = strlen(ext);
const char *curr = egl_exts;
bool match = false;
while (curr && !match) {
const char *end = strchr(curr, ' ');
if (!end) {
// Last extension string
match = strcmp(ext, curr) == 0;
} else if (curr + inlen == end) {
// Length match, do match string
match = strncmp(ext, curr, (unsigned long)(end - curr)) == 0;
}
curr = end ? end + 1 : NULL;
}

if (!match) {
log_info("Missing EGL extension %s.", ext);
} else {
log_info("Found EGL extension %s.", ext);
}

return match;
}

struct eglext_info eglext = {0};

void eglext_init(EGLDisplay dpy) {
if (eglext.initialized) {
return;
}
eglext.initialized = true;
#define check_ext(name) eglext.has_##name = egl_has_extension(dpy, #name)
#define check_ext(name) \
eglext.has_##name = epoxy_has_egl_extension(dpy, #name); \
log_info("Extension " #name " - %s", eglext.has_##name ? "present" : "absent")

check_ext(EGL_EXT_buffer_age);
check_ext(EGL_EXT_create_context_robustness);
check_ext(EGL_KHR_image_pixmap);
Expand Down
4 changes: 2 additions & 2 deletions src/backend/gl/gl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,8 @@ bool gl_init(struct gl_data *gd, session_t *ps) {
} else {
gd->is_nvidia = false;
}
gd->has_robustness = gl_has_extension("GL_ARB_robustness");
gd->has_egl_image_storage = gl_has_extension("GL_EXT_EGL_image_storage");
gd->has_robustness = epoxy_has_gl_extension("GL_ARB_robustness");
gd->has_egl_image_storage = epoxy_has_gl_extension("GL_EXT_EGL_image_storage");
gl_check_err();

return true;
Expand Down
20 changes: 0 additions & 20 deletions src/backend/gl/gl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,6 @@ static inline bool gl_check_fb_complete_(const char *func, int line, GLenum fb)

#define gl_check_fb_complete(fb) gl_check_fb_complete_(__func__, __LINE__, (fb))

/**
* Check if a GL extension exists.
*/
static inline bool gl_has_extension(const char *ext) {
int nexts = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &nexts);
for (int i = 0; i < nexts || !nexts; i++) {
const char *exti = (const char *)glGetStringi(GL_EXTENSIONS, (GLuint)i);
if (exti == NULL) {
break;
}
if (strcmp(ext, exti) == 0) {
return true;
}
}
gl_clear_err();
log_info("Missing GL extension %s.", ext);
return false;
}

static const GLuint vert_coord_loc = 0;
static const GLuint vert_in_texcoord_loc = 1;

Expand Down
43 changes: 4 additions & 39 deletions src/backend/gl/glx.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,52 +545,17 @@ struct backend_operations glx_ops = {
.max_buffer_age = 5, // Why?
};

/**
* Check if a GLX extension exists.
*/
static inline bool glx_has_extension(Display *dpy, int screen, const char *ext) {
const char *glx_exts = glXQueryExtensionsString(dpy, screen);
if (!glx_exts) {
log_error("Failed get GLX extension list.");
return false;
}

auto inlen = strlen(ext);
const char *curr = glx_exts;
bool match = false;
while (curr && !match) {
const char *end = strchr(curr, ' ');
if (!end) {
// Last extension string
match = strcmp(ext, curr) == 0;
} else if (curr + inlen == end) {
// Length match, do match string
match = strncmp(ext, curr, (unsigned long)(end - curr)) == 0;
}
curr = end ? end + 1 : NULL;
}

if (!match) {
log_info("Missing GLX extension %s.", ext);
} else {
log_info("Found GLX extension %s.", ext);
}

return match;
}

struct glxext_info glxext = {0};

#ifdef GLX_MESA_query_renderer
PFNGLXQUERYCURRENTRENDERERINTEGERMESAPROC glXQueryCurrentRendererIntegerMESA;
#endif

void glxext_init(Display *dpy, int screen) {
if (glxext.initialized) {
return;
}
glxext.initialized = true;
#define check_ext(name) glxext.has_##name = glx_has_extension(dpy, screen, #name)
#define check_ext(name) \
glxext.has_##name = epoxy_has_glx_extension(dpy, screen, #name); \
log_info("Extension " #name " - %s", glxext.has_##name ? "present" : "absent")

check_ext(GLX_SGI_video_sync);
check_ext(GLX_SGI_swap_control);
check_ext(GLX_OML_sync_control);
Expand Down
2 changes: 1 addition & 1 deletion src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ static const struct log_ops gl_string_marker_logger_ops = {
/// Create an opengl logger that can be used for logging into opengl debugging tools,
/// such as apitrace
struct log_target *gl_string_marker_logger_new(void) {
if (!gl_has_extension("GL_GREMEDY_string_marker")) {
if (!epoxy_has_gl_extension("GL_GREMEDY_string_marker")) {
return NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion src/opengl.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ bool glx_init(session_t *ps, bool need_render) {
// must precede FBConfig fetching
if (need_render) {
psglx->has_texture_non_power_of_two =
gl_has_extension("GL_ARB_texture_non_power_of_two");
epoxy_has_gl_extension("GL_ARB_texture_non_power_of_two");
}

// Render preparations
Expand Down

0 comments on commit 755996a

Please sign in to comment.