video/gtk4: Remove cfg flag for gst-gl

GTK 4 hard depends on GL on all platforms, and now both
windows and macos have codepaths for the paintable sink to
produce GLTextures.

This we can now drop the cfg build flag we have making it optional.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1708>
This commit is contained in:
Jordan Petridis 2024-08-01 15:37:26 +03:00 committed by GStreamer Marge Bot
parent 320f36a462
commit 602760d0d8
3 changed files with 11 additions and 76 deletions

View file

@ -16,7 +16,7 @@ gdk-x11 = { workspace = true, features = ["v4_4"], optional = true}
gst = { workspace = true, features = ["v1_16"] }
gst-base.workspace = true
gst-video.workspace = true
gst-gl = { workspace = true, features = ["v1_16"], optional = true }
gst-gl = { workspace = true, features = ["v1_16"] }
gst-allocators = { workspace = true, features = ["v1_24"], optional = true }
gst-gl-wayland = { workspace = true, features = ["v1_16"], optional = true }
@ -47,9 +47,9 @@ gst-plugin-version-helper.workspace = true
[features]
default = []
static = []
wayland = ["gtk/v4_6", "gdk-wayland", "gst-gl", "gst-gl-wayland"]
x11glx = ["gtk/v4_6", "gdk-x11", "gst-gl", "gst-gl-x11"]
x11egl = ["gtk/v4_6", "gdk-x11", "gst-gl", "gst-gl-egl"]
wayland = ["gtk/v4_6", "gdk-wayland", "gst-gl-wayland"]
x11glx = ["gtk/v4_6", "gdk-x11", "gst-gl-x11"]
x11egl = ["gtk/v4_6", "gdk-x11", "gst-gl-egl"]
winegl = ["gdk-win32/egl", "gst-gl-egl"]
dmabuf = ["gst-allocators", "wayland", "gtk_v4_14", "gst-video/v1_24"]
capi = []

View file

@ -11,7 +11,6 @@
use gst_video::prelude::*;
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
use gst_gl::prelude::*;
use gtk::{gdk, glib};
use std::{
@ -64,7 +63,6 @@ impl VideoInfo {
#[derive(Debug, PartialEq, Eq, Hash)]
pub enum TextureCacheId {
Memory(usize),
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
GL(usize),
#[cfg(all(target_os = "linux", feature = "dmabuf"))]
DmaBuf([i32; 4]),
@ -76,7 +74,6 @@ enum MappedFrame {
frame: gst_video::VideoFrame<gst_video::video_frame::Readable>,
orientation: Orientation,
},
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
GL {
frame: gst_gl::GLVideoFrame<gst_gl::gl_video_frame::Readable>,
wrapped_context: gst_gl::GLContext,
@ -100,7 +97,6 @@ impl MappedFrame {
fn buffer(&self) -> &gst::BufferRef {
match self {
MappedFrame::SysMem { frame, .. } => frame.buffer(),
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
MappedFrame::GL { frame, .. } => frame.buffer(),
#[cfg(all(target_os = "linux", feature = "dmabuf"))]
MappedFrame::DmaBuf { buffer, .. } => buffer,
@ -110,7 +106,6 @@ impl MappedFrame {
fn width(&self) -> u32 {
match self {
MappedFrame::SysMem { frame, .. } => frame.width(),
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
MappedFrame::GL { frame, .. } => frame.width(),
#[cfg(all(target_os = "linux", feature = "dmabuf"))]
MappedFrame::DmaBuf { info, .. } => info.width(),
@ -120,7 +115,6 @@ impl MappedFrame {
fn height(&self) -> u32 {
match self {
MappedFrame::SysMem { frame, .. } => frame.height(),
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
MappedFrame::GL { frame, .. } => frame.height(),
#[cfg(all(target_os = "linux", feature = "dmabuf"))]
MappedFrame::DmaBuf { info, .. } => info.height(),
@ -130,7 +124,6 @@ impl MappedFrame {
fn format_info(&self) -> gst_video::VideoFormatInfo {
match self {
MappedFrame::SysMem { frame, .. } => frame.format_info(),
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
MappedFrame::GL { frame, .. } => frame.format_info(),
#[cfg(all(target_os = "linux", feature = "dmabuf"))]
MappedFrame::DmaBuf { info, .. } => info.format_info(),
@ -140,7 +133,6 @@ impl MappedFrame {
fn orientation(&self) -> Orientation {
match self {
MappedFrame::SysMem { orientation, .. } => *orientation,
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
MappedFrame::GL { orientation, .. } => *orientation,
#[cfg(all(target_os = "linux", feature = "dmabuf"))]
MappedFrame::DmaBuf { orientation, .. } => *orientation,
@ -284,7 +276,6 @@ fn video_frame_to_memory_texture(
(texture, pixel_aspect_ratio)
}
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
fn video_frame_to_gl_texture(
frame: gst_gl::GLVideoFrame<gst_gl::gl_video_frame::Readable>,
cached_textures: &mut HashMap<TextureCacheId, gdk::Texture>,
@ -453,7 +444,6 @@ impl Frame {
MappedFrame::SysMem { frame, .. } => {
video_frame_to_memory_texture(frame, cached_textures, &mut used_textures)
}
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
MappedFrame::GL {
frame,
wrapped_context,
@ -538,12 +528,7 @@ impl Frame {
buffer: &gst::Buffer,
info: &VideoInfo,
orientation: Orientation,
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))] wrapped_context: Option<
&gst_gl::GLContext,
>,
#[allow(unused_variables)]
#[cfg(not(any(target_os = "macos", target_os = "windows", feature = "gst-gl")))]
wrapped_context: Option<&()>,
wrapped_context: Option<&gst_gl::GLContext>,
) -> Result<Self, gst::FlowError> {
// Empty buffers get filtered out in show_frame
debug_assert!(buffer.n_memory() > 0);
@ -606,7 +591,7 @@ impl Frame {
}
}
}
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
{
if frame.is_none() {
// Check we received a buffer with GL memory and if the context of that memory

View file

@ -17,9 +17,7 @@ use glib::thread_guard::ThreadGuard;
use gtk::prelude::*;
use gtk::{gdk, glib};
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
use gst_gl::prelude::GLContextExt as GstGLContextExt;
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
use gst_gl::prelude::*;
#[allow(unused_imports)]
@ -39,7 +37,6 @@ use crate::utils;
// Global GL context that is created by the first sink and kept around until the end of the
// process. This is provided to other elements in the pipeline to make sure they create GL contexts
// that are sharing with the GTK GL context.
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
enum GLContext {
Uninitialized,
Unsupported,
@ -50,7 +47,6 @@ enum GLContext {
},
}
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
static GL_CONTEXT: Mutex<GLContext> = Mutex::new(GLContext::Uninitialized);
pub(crate) static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
@ -269,12 +265,10 @@ impl ElementImpl for PaintableSink {
}
for features in [
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
Some(gst::CapsFeatures::new([
gst_gl::CAPS_FEATURE_MEMORY_GL_MEMORY,
gst_video::CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION,
])),
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
Some(gst::CapsFeatures::new([
gst_gl::CAPS_FEATURE_MEMORY_GL_MEMORY,
])),
@ -287,7 +281,6 @@ impl ElementImpl for PaintableSink {
])),
None,
] {
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
{
const GL_FORMATS: &[gst_video::VideoFormat] =
&[gst_video::VideoFormat::Rgba, gst_video::VideoFormat::Rgb];
@ -328,29 +321,6 @@ impl ElementImpl for PaintableSink {
}
caps.append(c);
}
#[cfg(not(any(
target_os = "macos",
target_os = "windows",
feature = "gst-gl"
)))]
{
const FORMATS: &[gst_video::VideoFormat] = &[
gst_video::VideoFormat::Bgra,
gst_video::VideoFormat::Argb,
gst_video::VideoFormat::Rgba,
gst_video::VideoFormat::Abgr,
gst_video::VideoFormat::Rgb,
gst_video::VideoFormat::Bgr,
];
let mut c = gst_video::video_make_raw_caps(FORMATS).build();
if let Some(features) = features {
let c = c.get_mut().unwrap();
c.set_features_simple(Some(features));
}
caps.append(c);
}
}
}
@ -415,7 +385,6 @@ impl ElementImpl for PaintableSink {
// Notify the pipeline about the GL display and wrapped context so that any other
// elements in the pipeline ideally use the same / create GL contexts that are
// sharing with this one.
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
{
let gl_context = GL_CONTEXT.lock().unwrap();
if let GLContext::Initialized {
@ -573,7 +542,6 @@ impl BaseSinkImpl for PaintableSink {
query.add_allocation_meta::<gst_video::VideoOverlayCompositionMeta>(s.as_deref());
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
{
if let GLContext::Initialized {
wrapped_context, ..
@ -594,7 +562,6 @@ impl BaseSinkImpl for PaintableSink {
gst::log!(CAT, imp = self, "Handling query {:?}", query);
match query.view_mut() {
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
gst::QueryViewMut::Context(q) => {
// Avoid holding the locks while we respond to the query
// The objects are ref-counted anyway.
@ -685,11 +652,6 @@ impl VideoSinkImpl for PaintableSink {
.unwrap_or(config.global_orientation);
let wrapped_context = {
#[cfg(not(any(target_os = "macos", target_os = "windows", feature = "gst-gl")))]
{
None
}
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
{
let gl_context = GL_CONTEXT.lock().unwrap();
if let GLContext::Initialized {
@ -803,7 +765,6 @@ impl PaintableSink {
}
}
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
{
// Filter out GL caps from the template pads if we have no context
if !matches!(&*GL_CONTEXT.lock().unwrap(), GLContext::Initialized { .. }) {
@ -863,7 +824,6 @@ impl PaintableSink {
}
fn create_paintable(&self, paintable_storage: &mut MutexGuard<Option<ThreadGuard<Paintable>>>) {
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
{
self.initialize_gl_context();
}
@ -897,21 +857,13 @@ impl PaintableSink {
// Create the paintable from the main thread
let paintable = utils::invoke_on_main_thread(move || {
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
{
let gdk_context = if let GLContext::Initialized { gdk_context, .. } =
&*GL_CONTEXT.lock().unwrap()
{
let gdk_context =
if let GLContext::Initialized { gdk_context, .. } = &*GL_CONTEXT.lock().unwrap() {
Some(gdk_context.get_ref().clone())
} else {
None
};
ThreadGuard::new(Paintable::new(gdk_context))
}
#[cfg(not(any(target_os = "macos", target_os = "windows", feature = "gst-gl")))]
{
ThreadGuard::new(Paintable::new(None))
}
ThreadGuard::new(Paintable::new(gdk_context))
});
**paintable_storage = Some(paintable);
@ -919,7 +871,6 @@ impl PaintableSink {
*self.sender.lock().unwrap() = Some(sender);
}
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
fn initialize_gl_context(&self) {
gst::debug!(CAT, imp = self, "Realizing GDK GL Context");
@ -929,7 +880,6 @@ impl PaintableSink {
});
}
#[cfg(any(target_os = "macos", target_os = "windows", feature = "gst-gl"))]
fn initialize_gl_context_main(&self) {
gst::debug!(CAT, imp = self, "Realizing GDK GL Context from main thread");
@ -998,7 +948,7 @@ impl PaintableSink {
gdk_context.make_current();
let res = match gdk_context.type_().name() {
let res: Option<(gst_gl::GLDisplay, gst_gl::GLContext)> = match gdk_context.type_().name() {
#[cfg(feature = "x11egl")]
"GdkX11GLContextEGL" => self.initialize_x11egl(gdk_display),
#[cfg(feature = "x11glx")]
@ -1012,7 +962,7 @@ impl PaintableSink {
#[cfg(all(target_os = "windows", feature = "winegl"))]
"GdkWin32GLContextEGL" => self.initialize_winegl(gdk_display),
display_type => {
unreachable!("Unsupported GDK display {display_type} for GL");
unreachable!("Unsupported GDK display {display_type} for GL. This might be due to not having enabled a backend for GL when building the plugin");
}
};
let (display, wrapped_context) = res.unwrap();