From 8ab8f0000543c5f0b6c0700fac07a05c5e29941c Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Sat, 10 Apr 2021 20:20:49 +0200 Subject: [PATCH] examples/glupload: Allow EGL and Wayland features to coexist If EGL and Wayland were both set the Wayland bit of code would never be build-tested nor used. Now if both are enabled try to acquire a GLDisplay through both handles before bailing. The methods can still be tested in isolation by not enabling one or the other feature. --- examples/Cargo.toml | 1 - examples/src/bin/glupload.rs | 40 ++++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index ddd34b717..79ff3abf9 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -26,7 +26,6 @@ gtk = { git = "https://github.com/gtk-rs/gtk-rs", optional = true } gdk = { git = "https://github.com/gtk-rs/gtk-rs", optional = true } gio = { git = "https://github.com/gtk-rs/gtk-rs", optional = true } anyhow = "1.0" -cfg-if = "1.0" derive_more = "0.99.5" futures = "0.3" byte-slice-cast = "1" diff --git a/examples/src/bin/glupload.rs b/examples/src/bin/glupload.rs index b86e28f8e..f94f4d4da 100644 --- a/examples/src/bin/glupload.rs +++ b/examples/src/bin/glupload.rs @@ -356,27 +356,31 @@ impl App { { #[cfg(any(feature = "gst-gl-egl", feature = "gst-gl-wayland"))] RawHandle::Egl(egl_context) => { - cfg_if::cfg_if! { - if #[cfg(feature = "gst-gl-egl")] { - let gl_display = if let Some(display) = - unsafe { windowed_context.get_egl_display() } - { - unsafe { gst_gl_egl::GLDisplayEGL::with_egl_display(display as usize) }.unwrap() - } else { - panic!("EGL context without EGL display"); - }; - } else if #[cfg(feature = "gst-gl-wayland")] { - let gl_display = if let Some(display) = inner_window.get_wayland_display() { - unsafe { gst_gl_wayland::GLDisplayWayland::with_display(display as usize) }.unwrap() - } else { - panic!("Wayland window without Wayland display"); - }; - } - } + let mut gl_display = None; + + #[cfg(feature = "gst-gl-egl")] + if let Some(display) = unsafe { windowed_context.get_egl_display() } { + gl_display = Some( + unsafe { gst_gl_egl::GLDisplayEGL::with_egl_display(display as usize) } + .unwrap() + .upcast::(), + ) + }; + + #[cfg(feature = "gst-gl-wayland")] + if let Some(display) = inner_window.get_wayland_display() { + gl_display = Some( + unsafe { + gst_gl_wayland::GLDisplayWayland::with_display(display as usize) + } + .unwrap() + .upcast::(), + ) + }; ( egl_context as usize, - gl_display.upcast::(), + gl_display.expect("Could not retrieve GLDisplay through EGL context and/or Wayland display"), gst_gl::GLPlatform::EGL, ) }