diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2023-01-07 13:42:42 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2023-01-07 13:42:42 +0300 |
commit | 58c21d98680d5cab8e809b2a66a5eb448046be50 (patch) | |
tree | 5c75d7d1ac3a14bc323c512e60dd42235b9c8214 /video | |
parent | e9bbf804bae4c0faba67f6160c56390f0ad91bf3 (diff) |
gtk4: Propagate the GL display to the remainder of the pipeline
This allows sharing it with other parts of the pipeline and avoids
creating different, incompatible displays/contexts in different parts of
the pipeline.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1037>
Diffstat (limited to 'video')
-rw-r--r-- | video/gtk4/src/sink/imp.rs | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/video/gtk4/src/sink/imp.rs b/video/gtk4/src/sink/imp.rs index fd78b497..db4d64cf 100644 --- a/video/gtk4/src/sink/imp.rs +++ b/video/gtk4/src/sink/imp.rs @@ -212,9 +212,14 @@ impl ElementImpl for PaintableSink { #[cfg(any(target_os = "macos", feature = "gst_gl"))] { - if self.have_gl_context.load(Ordering::Relaxed) && !self.initialize_gl_wrapper() - { - self.have_gl_context.store(false, Ordering::Relaxed); + if self.have_gl_context.load(Ordering::Relaxed) { + if self.initialize_gl_wrapper() { + // We must have a display at this point. + let display = self.gst_display.lock().unwrap().clone().unwrap(); + gst_gl::gl_element_propagate_display_context(&*self.obj(), &display); + } else { + self.have_gl_context.store(false, Ordering::Relaxed); + } } } } @@ -715,15 +720,25 @@ impl PaintableSink { "Successfully deactivated GL Context after fill_info" ); - match display.create_context(app_ctx) { - Ok(gst_context) => { + let gst_context = match display.create_context(app_ctx) { + Ok(gst_context) => gst_context, + Err(err) => { + gst::error!(CAT, imp: self, "Could not create GL context: {err}"); + *app_ctx_guard = None; + *display_guard = None; + return false; + } + }; + + match display.add_context(&gst_context) { + Ok(_) => { let mut gst_ctx_guard = self.gst_context.lock().unwrap(); gst::info!(CAT, imp: self, "Successfully initialized GL Context"); gst_ctx_guard.replace(gst_context); true } - Err(err) => { - gst::error!(CAT, imp: self, "Could not create GL context: {err}"); + Err(_) => { + gst::error!(CAT, imp: self, "Could not add GL context to display"); *app_ctx_guard = None; *display_guard = None; false |