diff options
author | 2024-03-24 08:04:28 +0100 | |
---|---|---|
committer | 2024-03-24 08:04:28 +0100 | |
commit | 4f5b63f1f4cd7d3ab72289c697f4abc767114eca (patch) | |
tree | 876f9502936b24f63ef21bb2b41e16b222750444 /renderer | |
parent | 441e9237cd1c9c9b61d9b144b5b4dafa236ace28 (diff) | |
download | iced-4f5b63f1f4cd7d3ab72289c697f4abc767114eca.tar.gz iced-4f5b63f1f4cd7d3ab72289c697f4abc767114eca.tar.bz2 iced-4f5b63f1f4cd7d3ab72289c697f4abc767114eca.zip |
Reintroduce backend selection through `ICED_BACKEND` env var
Diffstat (limited to 'renderer')
-rw-r--r-- | renderer/src/fallback.rs | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/renderer/src/fallback.rs b/renderer/src/fallback.rs index ca445746..ef9cc9a9 100644 --- a/renderer/src/fallback.rs +++ b/renderer/src/fallback.rs @@ -204,18 +204,55 @@ where type Renderer = Renderer<L::Renderer, R::Renderer>; type Surface = Surface<L::Surface, R::Surface>; - async fn new<W: compositor::Window + Clone>( + async fn with_backend<W: compositor::Window + Clone>( settings: graphics::Settings, compatible_window: W, + backend: Option<&str>, ) -> Result<Self, graphics::Error> { - if let Ok(left) = L::new(settings, compatible_window.clone()) - .await - .map(Self::Left) - { - return Ok(left); + use std::env; + + let backends = backend + .map(str::to_owned) + .or_else(|| env::var("ICED_BACKEND").ok()); + + let mut candidates: Vec<_> = backends + .map(|backends| { + backends + .split(',') + .filter(|candidate| !candidate.is_empty()) + .map(str::to_owned) + .map(Some) + .collect() + }) + .unwrap_or_default(); + + if candidates.is_empty() { + candidates.push(None); } - R::new(settings, compatible_window).await.map(Self::Right) + let mut errors = vec![]; + + for backend in candidates.iter().map(Option::as_deref) { + match L::with_backend(settings, compatible_window.clone(), backend) + .await + { + Ok(compositor) => return Ok(Self::Left(compositor)), + Err(error) => { + errors.push(error); + } + } + + match R::with_backend(settings, compatible_window.clone(), backend) + .await + { + Ok(compositor) => return Ok(Self::Right(compositor)), + Err(error) => { + errors.push(error); + } + } + } + + Err(graphics::Error::List(errors)) } fn create_renderer(&self) -> Self::Renderer { |