Skip to content

Commit

Permalink
examples/glupload: Allow EGL and Wayland features to coexist
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MarijnS95 committed Apr 10, 2021
1 parent 28cfa91 commit 8ab8f00
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
1 change: 0 additions & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
40 changes: 22 additions & 18 deletions examples/src/bin/glupload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Expand Down

0 comments on commit 8ab8f00

Please sign in to comment.