From d5c2a4d3f55a873fe6ba0fc77a42f8d1510bcb3d Mon Sep 17 00:00:00 2001 From: Konstantin Date: Tue, 31 Oct 2023 19:52:07 +0300 Subject: [PATCH] glamor_egl: add helper functions for contexts This is just a split big glamor_egl_init to 3 smaller functions. No functional change. Signed-off-by: Konstantin --- glamor/glamor_egl.c | 150 +++++++++++++++++++++++++------------------- 1 file changed, 87 insertions(+), 63 deletions(-) diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c index c35b10d83..65cf1ecf5 100644 --- a/glamor/glamor_egl.c +++ b/glamor/glamor_egl.c @@ -955,6 +955,86 @@ glamor_egl_free_screen(ScrnInfoPtr scrn) } } +static Bool +glamor_egl_try_big_gl_api(ScrnInfoPtr scrn) +{ + struct glamor_egl_screen_private *glamor_egl = + glamor_egl_get_screen_private(scrn); + + if (eglBindAPI(EGL_OPENGL_API)) { + static const EGLint config_attribs_core[] = { + EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, + EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR, + EGL_CONTEXT_MAJOR_VERSION_KHR, + GLAMOR_GL_CORE_VER_MAJOR, + EGL_CONTEXT_MINOR_VERSION_KHR, + GLAMOR_GL_CORE_VER_MINOR, + EGL_NONE + }; + static const EGLint config_attribs[] = { + EGL_NONE + }; + + glamor_egl->context = eglCreateContext(glamor_egl->display, + EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, + config_attribs_core); + + if (glamor_egl->context == EGL_NO_CONTEXT) + glamor_egl->context = eglCreateContext(glamor_egl->display, + EGL_NO_CONFIG_KHR, + EGL_NO_CONTEXT, + config_attribs); + } + + if (glamor_egl->context != EGL_NO_CONTEXT) { + if (!eglMakeCurrent(glamor_egl->display, + EGL_NO_SURFACE, EGL_NO_SURFACE, glamor_egl->context)) { + xf86DrvMsg(scrn->scrnIndex, X_ERROR, + "Failed to make GL context current\n"); + return FALSE; + } + + if (epoxy_gl_version() < 21) { + xf86DrvMsg(scrn->scrnIndex, X_INFO, + "glamor: Ignoring GL < 2.1, falling back to GLES.\n"); + eglDestroyContext(glamor_egl->display, glamor_egl->context); + glamor_egl->context = EGL_NO_CONTEXT; + } + } + return TRUE; +} + +static Bool +glamor_egl_try_gles_api(ScrnInfoPtr scrn) +{ + struct glamor_egl_screen_private *glamor_egl = + glamor_egl_get_screen_private(scrn); + + static const EGLint config_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + if (!eglBindAPI(EGL_OPENGL_ES_API)) { + xf86DrvMsg(scrn->scrnIndex, X_ERROR, + "glamor: Failed to bind GLES API.\n"); + return FALSE; + } + + glamor_egl->context = eglCreateContext(glamor_egl->display, + EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, + config_attribs); + + if (glamor_egl->context != EGL_NO_CONTEXT) { + if (!eglMakeCurrent(glamor_egl->display, + EGL_NO_SURFACE, EGL_NO_SURFACE, glamor_egl->context)) { + xf86DrvMsg(scrn->scrnIndex, X_ERROR, + "Failed to make GLES context current\n"); + return FALSE; + } + } + return TRUE; +} + Bool glamor_egl_init(ScrnInfoPtr scrn, int fd) { @@ -1004,74 +1084,18 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd) GLAMOR_CHECK_EGL_EXTENSION(KHR_surfaceless_context); GLAMOR_CHECK_EGL_EXTENSION(KHR_no_config_context); - if (eglBindAPI(EGL_OPENGL_API)) { - static const EGLint config_attribs_core[] = { - EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, - EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR, - EGL_CONTEXT_MAJOR_VERSION_KHR, - GLAMOR_GL_CORE_VER_MAJOR, - EGL_CONTEXT_MINOR_VERSION_KHR, - GLAMOR_GL_CORE_VER_MINOR, - EGL_NONE - }; - static const EGLint config_attribs[] = { - EGL_NONE - }; + if(!glamor_egl_try_big_gl_api(scrn)) + goto error; - glamor_egl->context = eglCreateContext(glamor_egl->display, - EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, - config_attribs_core); - - if (glamor_egl->context == EGL_NO_CONTEXT) - glamor_egl->context = eglCreateContext(glamor_egl->display, - EGL_NO_CONFIG_KHR, - EGL_NO_CONTEXT, - config_attribs); - } - - if (glamor_egl->context != EGL_NO_CONTEXT) { - if (!eglMakeCurrent(glamor_egl->display, - EGL_NO_SURFACE, EGL_NO_SURFACE, glamor_egl->context)) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Failed to make GL context current\n"); + if (glamor_egl->context == EGL_NO_CONTEXT) { + if(!glamor_egl_try_gles_api(scrn)) goto error; - } - - if (epoxy_gl_version() < 21) { - xf86DrvMsg(scrn->scrnIndex, X_INFO, - "glamor: Ignoring GL < 2.1, falling back to GLES.\n"); - eglDestroyContext(glamor_egl->display, glamor_egl->context); - glamor_egl->context = EGL_NO_CONTEXT; - } } if (glamor_egl->context == EGL_NO_CONTEXT) { - static const EGLint config_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; - if (!eglBindAPI(EGL_OPENGL_ES_API)) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "glamor: Failed to bind either GL or GLES APIs.\n"); - goto error; - } - - glamor_egl->context = eglCreateContext(glamor_egl->display, - EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, - config_attribs); - - if (glamor_egl->context == EGL_NO_CONTEXT) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "glamor: Failed to create GL or GLES2 contexts\n"); - goto error; - } - - if (!eglMakeCurrent(glamor_egl->display, - EGL_NO_SURFACE, EGL_NO_SURFACE, glamor_egl->context)) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Failed to make GLES2 context current\n"); - goto error; - } + xf86DrvMsg(scrn->scrnIndex, X_ERROR, + "glamor: Failed to create GL or GLES2 contexts\n"); + goto error; } renderer = glGetString(GL_RENDERER);