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.
This commit is contained in:
Marijn Suijten 2021-04-10 20:20:49 +02:00
parent 28cfa91b40
commit 8ab8f00005
2 changed files with 22 additions and 19 deletions

View file

@ -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"

View file

@ -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::<gst_gl::GLDisplay>(),
)
};
#[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::<gst_gl::GLDisplay>(),
)
};
(
egl_context as usize,
gl_display.upcast::<gst_gl::GLDisplay>(),
gl_display.expect("Could not retrieve GLDisplay through EGL context and/or Wayland display"),
gst_gl::GLPlatform::EGL,
)
}