forked from mirrors/gstreamer-rs
Support GLX on glupload example
This commit is contained in:
parent
b99c582a88
commit
4b3a011882
2 changed files with 46 additions and 19 deletions
|
@ -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 }
|
pango = { git = "https://github.com/gtk-rs/pango", optional = true }
|
||||||
pangocairo = { git = "https://github.com/gtk-rs/pangocairo", optional = true }
|
pangocairo = { git = "https://github.com/gtk-rs/pangocairo", optional = true }
|
||||||
glutin = { version = "0.20", optional = true }
|
glutin = { version = "0.20", optional = true }
|
||||||
|
winit = { version = "0.19", optional = true }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
gl_generator = { version = "0.10", optional = true }
|
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"]
|
gst-rtsp-server-record = ["gstreamer-rtsp-server-sys", "gstreamer-rtsp-server", "gstreamer-rtsp", "gio"]
|
||||||
v1_10 = ["gstreamer/v1_10"]
|
v1_10 = ["gstreamer/v1_10"]
|
||||||
pango-cairo = ["pango", "pangocairo", "cairo-rs"]
|
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]]
|
[[bin]]
|
||||||
name = "appsink"
|
name = "appsink"
|
||||||
|
@ -137,3 +140,4 @@ required-features = ["ges"]
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "glupload"
|
name = "glupload"
|
||||||
required-features = ["gl"]
|
required-features = ["gl"]
|
||||||
|
features = ["gl-egl", "gl-x11"]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// This example demostrates how to output GL textures, within an EGL
|
// This example demostrates how to output GL textures, within an
|
||||||
// context provided by the application, and render those textures in
|
// EGL/X11 context provided by the application, and render those
|
||||||
// the GL application.
|
// textures in the GL application.
|
||||||
|
|
||||||
// {videotestsrc} - { glsinkbin }
|
// {videotestsrc} - { glsinkbin }
|
||||||
|
|
||||||
|
@ -355,27 +355,52 @@ impl App {
|
||||||
|
|
||||||
let windowed_context_ = windowed_context.clone();
|
let windowed_context_ = windowed_context.clone();
|
||||||
let context = windowed_context_.context();
|
let context = windowed_context_.context();
|
||||||
|
let inner_window = windowed_context_.window();
|
||||||
|
|
||||||
let shared_context: gst_gl::GLContext;
|
let shared_context: gst_gl::GLContext;
|
||||||
if cfg!(target_os = "linux") {
|
if cfg!(target_os = "linux") {
|
||||||
use glutin::os::unix::RawHandle;
|
use glutin::os::unix::RawHandle;
|
||||||
use glutin::os::ContextTraitExt;
|
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 api = App::map_gl_api(context.get_api());
|
||||||
let platform = gst_gl::GLPlatform::EGL;
|
|
||||||
|
|
||||||
let gl_display =
|
let (gl_context, gl_display, platform) = match unsafe { context.raw_handle() } {
|
||||||
unsafe { gst_gl::GLDisplayEGL::new_with_egl_display(egl_display) }.unwrap();
|
#[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::GLDisplay>(),
|
||||||
|
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::GLDisplay>(),
|
||||||
|
gst_gl::GLPlatform::GLX,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
_ => panic!("Unsupported platform"),
|
||||||
|
};
|
||||||
|
|
||||||
shared_context =
|
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();
|
.unwrap();
|
||||||
|
|
||||||
shared_context
|
shared_context
|
||||||
|
@ -388,10 +413,8 @@ impl App {
|
||||||
|
|
||||||
#[allow(clippy::single_match)]
|
#[allow(clippy::single_match)]
|
||||||
bus.set_sync_handler(move |_, msg| {
|
bus.set_sync_handler(move |_, msg| {
|
||||||
use gst::MessageView;
|
|
||||||
|
|
||||||
match msg.view() {
|
match msg.view() {
|
||||||
MessageView::NeedContext(ctxt) => {
|
gst::MessageView::NeedContext(ctxt) => {
|
||||||
let context_type = ctxt.get_context_type();
|
let context_type = ctxt.get_context_type();
|
||||||
if context_type == *gst_gl::GL_DISPLAY_CONTEXT_TYPE {
|
if context_type == *gst_gl::GL_DISPLAY_CONTEXT_TYPE {
|
||||||
if let Some(el) =
|
if let Some(el) =
|
||||||
|
|
Loading…
Reference in a new issue