diff options
author | Eric Anholt <eric@anholt.net> | 2017-05-17 17:06:44 -0700 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2017-05-18 11:33:38 -0400 |
commit | c36f56808ffbefc4a3dcf61dfad17f62aeb8e16c (patch) | |
tree | 4e07da01e56b04218683fbb2a5a74bcc81021c20 | |
parent | f6bf5f1c7475ff1b19b0e8c3e71c1224d5b6bc82 (diff) |
glamor_egl: Automatically choose a GLES2 context if desktop GL fails.
GLES2 support has been requested multiple times, and we've had this
code laying around trying to implement it. The GLES2 implementation
is not quite there yet (some pixel transfer failures), but it
shouldn't take much fixing at this point.
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
-rw-r--r-- | glamor/glamor_egl.c | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c index 9527caad2..4043dcfe8 100644 --- a/glamor/glamor_egl.c +++ b/glamor/glamor_egl.c @@ -635,22 +635,6 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd) { struct glamor_egl_screen_private *glamor_egl; - EGLint config_attribs[] = { -#ifdef GLAMOR_GLES2 - EGL_CONTEXT_CLIENT_VERSION, 2, -#endif - EGL_NONE - }; - 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 - }; - glamor_egl = calloc(sizeof(*glamor_egl), 1); if (glamor_egl == NULL) return FALSE; @@ -679,12 +663,6 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd) goto error; } -#ifndef GLAMOR_GLES2 - eglBindAPI(EGL_OPENGL_API); -#else - eglBindAPI(EGL_OPENGL_ES_API); -#endif - #define GLAMOR_CHECK_EGL_EXTENSION(EXT) \ if (!epoxy_has_egl_extension(glamor_egl->display, "EGL_" #EXT)) { \ ErrorF("EGL_" #EXT " required.\n"); \ @@ -701,21 +679,49 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd) GLAMOR_CHECK_EGL_EXTENSION(KHR_gl_texture_2D_image); GLAMOR_CHECK_EGL_EXTENSION(KHR_surfaceless_context); -#ifndef GLAMOR_GLES2 - glamor_egl->context = eglCreateContext(glamor_egl->display, - NULL, EGL_NO_CONTEXT, - config_attribs_core); -#else - glamor_egl->context = NULL; -#endif - if (!glamor_egl->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 + }; + glamor_egl->context = eglCreateContext(glamor_egl->display, NULL, EGL_NO_CONTEXT, - config_attribs); - if (glamor_egl->context == EGL_NO_CONTEXT) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, "Failed to create EGL context\n"); + config_attribs_core); + + if (glamor_egl->context == EGL_NO_CONTEXT) + glamor_egl->context = eglCreateContext(glamor_egl->display, + NULL, EGL_NO_CONTEXT, + config_attribs); + } + + 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, + NULL, 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, |