From 65673b02ef28884da3267fe1be579c20e2cddfa6 Mon Sep 17 00:00:00 2001 From: Tony Lindgren Date: Tue, 1 Dec 2020 12:54:36 +0200 Subject: [PATCH] xwayland: fix GL version check for GLES only devices We currently bail out early for GLES only devices, and call epoxy_gl_version() too early for GLES only that will make GLES only devices return NULL for glGetString(GL_RENDERER). Let's also add a check to see if we need to recreate the context to avoid pointless warnings for GLES only devices as suggested by Olivier Fourdan . Fixes: a506b4ec - xwayland: make context current to check GL version Signed-off-by: Tony Lindgren --- hw/xwayland/xwayland-glamor-gbm.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c index 802e0f65d..f5718b80b 100644 --- a/hw/xwayland/xwayland-glamor-gbm.c +++ b/hw/xwayland/xwayland-glamor-gbm.c @@ -973,30 +973,32 @@ xwl_glamor_gbm_init_egl(struct xwl_screen *xwl_screen) xwl_screen->egl_display, NULL, EGL_NO_CONTEXT, NULL); } - if (xwl_screen->egl_context == EGL_NO_CONTEXT) { - ErrorF("Failed to create EGL context with GL\n"); - goto error; - } - - if (!eglMakeCurrent(xwl_screen->egl_display, + if (xwl_screen->egl_context != EGL_NO_CONTEXT && + !eglMakeCurrent(xwl_screen->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, xwl_screen->egl_context)) { ErrorF("Failed to make EGL context current with GL\n"); goto error; } - /* glamor needs either big-GL 2.1 or GLES2 */ - if (epoxy_gl_version() < 21) { + /* glamor needs either big-GL 2.1 or GLES2. Note that we can't rely only + * on calling epoxy_gl_version() here if eglBindAPI(EGL_OPENGL_API) above + * failed. Calling epoxy_gl_version() here makes GLES only devices fail + * below + */ + if (xwl_screen->egl_context == EGL_NO_CONTEXT || epoxy_gl_version() < 21) { const EGLint gles_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, }; - /* Recreate the context with GLES2 instead */ - eglMakeCurrent(xwl_screen->egl_display,EGL_NO_SURFACE, - EGL_NO_SURFACE, EGL_NO_CONTEXT); - eglDestroyContext(xwl_screen->egl_display, xwl_screen->egl_context); + if (xwl_screen->egl_context != EGL_NO_CONTEXT) { + /* Recreate the context with GLES2 instead */ + eglMakeCurrent(xwl_screen->egl_display,EGL_NO_SURFACE, + EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglDestroyContext(xwl_screen->egl_display, xwl_screen->egl_context); + } eglBindAPI(EGL_OPENGL_ES_API); xwl_screen->egl_context = eglCreateContext(xwl_screen->egl_display,