From baebc81432756d5a8df142cfcaecfa1370a48c65 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 13 Oct 2020 19:18:29 -0700 Subject: [PATCH] egl: try all configs one by one in case first choice fails It's not clear why the first choice isn't always the right choice for some users. This commit changes the logic to try all potential configs, one after the other, until we find one that sticks. I don't know if this will work in practice: I suspect that trying to configure one of them may prevent later configs from being used. But maybe it will, and it may reveal more information about what the real cause of the problem is. refs: #272 --- window/src/egl.rs | 60 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/window/src/egl.rs b/window/src/egl.rs index 92c1cf256..c7c96fb83 100644 --- a/window/src/egl.rs +++ b/window/src/egl.rs @@ -239,7 +239,7 @@ impl EglWrapper { .map(surface_bits), }; - log::info!("{:?}", info); + log::info!("{:x?}", info); } pub fn choose_config( @@ -498,27 +498,49 @@ impl GlState { ], )?; - let first_config = *configs - .first() - .ok_or_else(|| anyhow!("no compatible EGL configuration was found"))?; + if configs.is_empty() { + anyhow::bail!("no compatible EGL configuration was found"); + } + let mut errors = String::new(); - let surface = - connection - .egl - .create_window_surface(connection.display, first_config, window)?; + for config in configs { + let surface = + match connection + .egl + .create_window_surface(connection.display, config, window) + { + Ok(s) => s, + Err(e) => { + errors.push_str(&format!("{:#} {:x?}\n", e, config)); + continue; + } + }; - let context = connection.egl.create_context( - connection.display, - first_config, - std::ptr::null(), - &[ffi::CONTEXT_MAJOR_VERSION, 3, ffi::NONE], - )?; + let context = match connection.egl.create_context( + connection.display, + config, + std::ptr::null(), + &[ffi::CONTEXT_MAJOR_VERSION, 3, ffi::NONE], + ) { + Ok(c) => c, + Err(e) => { + errors.push_str(&format!("{:#} {:x?}\n", e, config)); + continue; + } + }; - Ok(Self { - connection: Rc::clone(connection), - context, - surface, - }) + log::trace!( + "Successfully created a surface using configuration {:x?}", + config + ); + return Ok(Self { + connection: Rc::clone(connection), + context, + surface, + }); + } + + Err(anyhow!(errors)) } }