Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/video
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2022-12-23 11:16:17 +0300
committerSebastian Dröge <sebastian@centricular.com>2023-01-07 14:23:53 +0300
commit34434bd8777a74a6cdf0f4657b070f92c953a634 (patch)
treead0078bd8bfb1052d83bebc579a3df8bf18c699b /video
parentd67baa766842a156ef2faf11e8c6e0afd732854c (diff)
gtk4: Add support for GL on macOS
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1038>
Diffstat (limited to 'video')
-rw-r--r--video/gtk4/Cargo.toml4
-rw-r--r--video/gtk4/src/sink/imp.rs40
2 files changed, 44 insertions, 0 deletions
diff --git a/video/gtk4/Cargo.toml b/video/gtk4/Cargo.toml
index d391708da..0ed38dbec 100644
--- a/video/gtk4/Cargo.toml
+++ b/video/gtk4/Cargo.toml
@@ -24,6 +24,10 @@ gst_gl_egl = { package = "gstreamer-gl-egl", git = "https://gitlab.freedesktop.o
once_cell = "1.0"
+[target.'cfg(target_os = "macos")'.dependencies]
+gtk = { package = "gtk4", git = "https://github.com/gtk-rs/gtk4-rs", features = ["v4_6"] }
+gst_gl = { package = "gstreamer-gl", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_16"] }
+
[lib]
name = "gstgtk4"
crate-type = ["cdylib", "rlib"]
diff --git a/video/gtk4/src/sink/imp.rs b/video/gtk4/src/sink/imp.rs
index 158aff37a..3dd4a759f 100644
--- a/video/gtk4/src/sink/imp.rs
+++ b/video/gtk4/src/sink/imp.rs
@@ -598,6 +598,8 @@ impl PaintableSink {
"GdkX11GLContextGLX" => (),
#[cfg(all(target_os = "linux", feature = "wayland"))]
"GdkWaylandGLContext" => (),
+ #[cfg(all(target_os = "macos", feature = "gst_gl"))]
+ "GdkMacosGLContext" => (),
display => {
gst::error!(CAT, imp: self_, "Unsupported GDK display {display} for GL");
return None;
@@ -654,6 +656,10 @@ impl PaintableSink {
"GdkWaylandGLContext" => {
self.initialize_waylandegl(display, &mut display_ctx_guard, &mut app_ctx_guard);
}
+ #[cfg(all(target_os = "macos", feature = "gst_gl"))]
+ "GdkMacosGLContext" => {
+ self.initialize_macosgl(display, &mut display_ctx_guard, &mut app_ctx_guard);
+ }
_ => {
unreachable!("Unsupported GDK display {display} for GL");
}
@@ -851,4 +857,38 @@ impl PaintableSink {
app_ctx_guard.replace(gst_app_context.unwrap());
}
}
+
+ #[cfg(all(target_os = "macos", feature = "gst_gl"))]
+ fn initialize_macosgl(
+ &self,
+ display: gdk::Display,
+ display_ctx_guard: &mut Option<gst_gl::GLDisplay>,
+ app_ctx_guard: &mut Option<gst_gl::GLContext>,
+ ) {
+ gst::info!(
+ CAT,
+ imp: self,
+ "Initializing GL with for macOS backend and display."
+ );
+
+ let platform = gst_gl::GLPlatform::CGL;
+ let (gl_api, _, _) = gst_gl::GLContext::current_gl_api(platform);
+ let gl_ctx = gst_gl::GLContext::current_gl_context(platform);
+
+ if gl_ctx == 0 {
+ gst::error!(CAT, imp: self, "Failed to get handle from GdkGLContext",);
+ return;
+ }
+
+ let gst_display = gst_gl::GLDisplay::new();
+ unsafe {
+ let gst_app_context =
+ gst_gl::GLContext::new_wrapped(&gst_display, gl_ctx, platform, gl_api);
+
+ assert!(gst_app_context.is_some());
+
+ display_ctx_guard.replace(gst_display);
+ app_ctx_guard.replace(gst_app_context.unwrap());
+ }
+ }
}