gtk4: Add support for GL on macOS

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1025>
This commit is contained in:
Sebastian Dröge 2022-12-23 10:16:17 +02:00 committed by Nirbheek Chauhan
parent 5f0ff8348f
commit 4fe0786bbd
2 changed files with 44 additions and 0 deletions

View file

@ -24,6 +24,10 @@ gst_gl_egl = { package = "gstreamer-gl-egl", git = "https://gitlab.freedesktop.o
once_cell = "1.0" 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] [lib]
name = "gstgtk4" name = "gstgtk4"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib"]

View file

@ -598,6 +598,8 @@ impl PaintableSink {
"GdkX11GLContextGLX" => (), "GdkX11GLContextGLX" => (),
#[cfg(all(target_os = "linux", feature = "wayland"))] #[cfg(all(target_os = "linux", feature = "wayland"))]
"GdkWaylandGLContext" => (), "GdkWaylandGLContext" => (),
#[cfg(all(target_os = "macos", feature = "gst_gl"))]
"GdkMacosGLContext" => (),
display => { display => {
gst::error!(CAT, imp: self_, "Unsupported GDK display {display} for GL"); gst::error!(CAT, imp: self_, "Unsupported GDK display {display} for GL");
return None; return None;
@ -654,6 +656,10 @@ impl PaintableSink {
"GdkWaylandGLContext" => { "GdkWaylandGLContext" => {
self.initialize_waylandegl(display, &mut display_ctx_guard, &mut app_ctx_guard); 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"); unreachable!("Unsupported GDK display {display} for GL");
} }
@ -851,4 +857,38 @@ impl PaintableSink {
app_ctx_guard.replace(gst_app_context.unwrap()); 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());
}
}
} }