diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 85c48b254..f00b9689e 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -27,6 +27,7 @@ cairo-rs = { git = "https://github.com/gtk-rs/cairo", features=["use_glib"], opt pango = { git = "https://github.com/gtk-rs/pango", optional = true } pangocairo = { git = "https://github.com/gtk-rs/pangocairo", optional = true } glutin = { version = "0.20", optional = true } +winit = { version = "0.19", optional = true } [build-dependencies] gl_generator = { version = "0.10", optional = true } @@ -45,7 +46,9 @@ gst-rtsp-server = ["gstreamer-rtsp-server"] gst-rtsp-server-record = ["gstreamer-rtsp-server-sys", "gstreamer-rtsp-server", "gstreamer-rtsp", "gio"] v1_10 = ["gstreamer/v1_10"] pango-cairo = ["pango", "pangocairo", "cairo-rs"] -gl = ["gstreamer-gl/egl", "gl_generator", "glutin"] +gl = ["gl_generator", "glutin"] +gl-egl = ["gstreamer-gl/egl"] +gl-x11 = ["gstreamer-gl/x11"] [[bin]] name = "appsink" @@ -137,3 +140,4 @@ required-features = ["ges"] [[bin]] name = "glupload" required-features = ["gl"] +features = ["gl-egl", "gl-x11"] diff --git a/examples/src/bin/glupload.rs b/examples/src/bin/glupload.rs index ea9aa967c..3e9d5f919 100644 --- a/examples/src/bin/glupload.rs +++ b/examples/src/bin/glupload.rs @@ -1,6 +1,6 @@ -// This example demostrates how to output GL textures, within an EGL -// context provided by the application, and render those textures in -// the GL application. +// This example demostrates how to output GL textures, within an +// EGL/X11 context provided by the application, and render those +// textures in the GL application. // {videotestsrc} - { glsinkbin } @@ -355,27 +355,52 @@ impl App { let windowed_context_ = windowed_context.clone(); let context = windowed_context_.context(); + let inner_window = windowed_context_.window(); let shared_context: gst_gl::GLContext; if cfg!(target_os = "linux") { use glutin::os::unix::RawHandle; use glutin::os::ContextTraitExt; - let egl_context = match unsafe { context.raw_handle() } { - RawHandle::Egl(egl_context) => egl_context as usize, - _ => panic!("Invalid platform"), - }; - let egl_display = match unsafe { context.get_egl_display() } { - Some(display) => display as usize, - _ => panic!("Invalid platform"), - }; let api = App::map_gl_api(context.get_api()); - let platform = gst_gl::GLPlatform::EGL; - let gl_display = - unsafe { gst_gl::GLDisplayEGL::new_with_egl_display(egl_display) }.unwrap(); + let (gl_context, gl_display, platform) = match unsafe { context.raw_handle() } { + #[cfg(feature = "gl-egl")] + RawHandle::Egl(egl_context) => { + let gl_display = if let Some(display) = unsafe { context.get_egl_display() } { + unsafe { gst_gl::GLDisplayEGL::new_with_egl_display(display as usize) } + .unwrap() + } else { + panic!("EGL context without EGL display"); + }; + + ( + egl_context as usize, + gl_display.upcast::(), + gst_gl::GLPlatform::EGL, + ) + } + #[cfg(feature = "gl-x11")] + RawHandle::Glx(glx_context) => { + use glutin::os::unix::WindowExt; + + let gl_display = if let Some(display) = inner_window.get_xlib_display() { + unsafe { gst_gl::GLDisplayX11::new_with_display(display as usize) }.unwrap() + } else { + panic!("X11 window without X Display"); + }; + + ( + glx_context as usize, + gl_display.upcast::(), + gst_gl::GLPlatform::GLX, + ) + } + _ => panic!("Unsupported platform"), + }; + shared_context = - unsafe { gst_gl::GLContext::new_wrapped(&gl_display, egl_context, platform, api) } + unsafe { gst_gl::GLContext::new_wrapped(&gl_display, gl_context, platform, api) } .unwrap(); shared_context @@ -388,10 +413,8 @@ impl App { #[allow(clippy::single_match)] bus.set_sync_handler(move |_, msg| { - use gst::MessageView; - match msg.view() { - MessageView::NeedContext(ctxt) => { + gst::MessageView::NeedContext(ctxt) => { let context_type = ctxt.get_context_type(); if context_type == *gst_gl::GL_DISPLAY_CONTEXT_TYPE { if let Some(el) =