mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-02-16 21:05:15 +00:00
gtk4: Use GL implicitly without the gst_gl feature on macOS
We already require gstreamer-gl as a dependency on macOS, so reflect that in the code too. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1025>
This commit is contained in:
parent
4fe0786bbd
commit
06123d74ba
4 changed files with 32 additions and 32 deletions
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
use gst_video::prelude::*;
|
use gst_video::prelude::*;
|
||||||
|
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
use gst_gl::prelude::*;
|
use gst_gl::prelude::*;
|
||||||
use gtk::{gdk, glib};
|
use gtk::{gdk, glib};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
@ -20,7 +20,7 @@ use std::collections::{HashMap, HashSet};
|
||||||
pub(crate) struct Frame {
|
pub(crate) struct Frame {
|
||||||
frame: gst_video::VideoFrame<gst_video::video_frame::Readable>,
|
frame: gst_video::VideoFrame<gst_video::video_frame::Readable>,
|
||||||
overlays: Vec<Overlay>,
|
overlays: Vec<Overlay>,
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
gst_context: Option<gst_gl::GLContext>,
|
gst_context: Option<gst_gl::GLContext>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ fn video_frame_to_memory_texture(
|
||||||
(texture, pixel_aspect_ratio)
|
(texture, pixel_aspect_ratio)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
fn video_frame_to_gl_texture(
|
fn video_frame_to_gl_texture(
|
||||||
frame: &gst_video::VideoFrame<gst_video::video_frame::Readable>,
|
frame: &gst_video::VideoFrame<gst_video::video_frame::Readable>,
|
||||||
cached_textures: &mut HashMap<usize, gdk::Texture>,
|
cached_textures: &mut HashMap<usize, gdk::Texture>,
|
||||||
|
@ -141,11 +141,11 @@ impl Frame {
|
||||||
let width = self.frame.width();
|
let width = self.frame.width();
|
||||||
let height = self.frame.height();
|
let height = self.frame.height();
|
||||||
let (texture, pixel_aspect_ratio) = {
|
let (texture, pixel_aspect_ratio) = {
|
||||||
#[cfg(not(feature = "gst_gl"))]
|
#[cfg(not(any(target_os = "macos", feature = "gst_gl")))]
|
||||||
{
|
{
|
||||||
video_frame_to_memory_texture(self.frame, cached_textures, &mut used_textures)
|
video_frame_to_memory_texture(self.frame, cached_textures, &mut used_textures)
|
||||||
}
|
}
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
{
|
{
|
||||||
if let (Some(gdk_ctx), Some(gst_ctx)) = (gdk_context, self.gst_context.as_ref()) {
|
if let (Some(gdk_ctx), Some(gst_ctx)) = (gdk_context, self.gst_context.as_ref()) {
|
||||||
video_frame_to_gl_texture(
|
video_frame_to_gl_texture(
|
||||||
|
@ -206,7 +206,7 @@ impl Frame {
|
||||||
|
|
||||||
let mut frame;
|
let mut frame;
|
||||||
|
|
||||||
#[cfg(not(feature = "gst_gl"))]
|
#[cfg(not(any(target_os = "macos", feature = "gst_gl")))]
|
||||||
{
|
{
|
||||||
frame = Self {
|
frame = Self {
|
||||||
frame: gst_video::VideoFrame::from_buffer_readable(buffer.clone(), info)
|
frame: gst_video::VideoFrame::from_buffer_readable(buffer.clone(), info)
|
||||||
|
@ -214,7 +214,7 @@ impl Frame {
|
||||||
overlays: vec![],
|
overlays: vec![],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
{
|
{
|
||||||
let is_buffer_gl = buffer
|
let is_buffer_gl = buffer
|
||||||
.peek_memory(0)
|
.peek_memory(0)
|
||||||
|
|
|
@ -26,13 +26,13 @@ use std::sync::{Mutex, MutexGuard};
|
||||||
|
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
|
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
use glib::translate::*;
|
use glib::translate::*;
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
use gst_gl::prelude::GLContextExt as GstGLContextExt;
|
use gst_gl::prelude::GLContextExt as GstGLContextExt;
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
use gst_gl::prelude::*;
|
use gst_gl::prelude::*;
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
|
||||||
static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
|
static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
|
||||||
|
@ -49,14 +49,14 @@ pub struct PaintableSink {
|
||||||
info: Mutex<Option<gst_video::VideoInfo>>,
|
info: Mutex<Option<gst_video::VideoInfo>>,
|
||||||
sender: Mutex<Option<Sender<SinkEvent>>>,
|
sender: Mutex<Option<Sender<SinkEvent>>>,
|
||||||
pending_frame: Mutex<Option<Frame>>,
|
pending_frame: Mutex<Option<Frame>>,
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
gst_display: Mutex<Option<gst_gl::GLDisplay>>,
|
gst_display: Mutex<Option<gst_gl::GLDisplay>>,
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
gst_app_context: Mutex<Option<gst_gl::GLContext>>,
|
gst_app_context: Mutex<Option<gst_gl::GLContext>>,
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
gst_context: Mutex<Option<gst_gl::GLContext>>,
|
gst_context: Mutex<Option<gst_gl::GLContext>>,
|
||||||
cached_caps: Mutex<Option<gst::Caps>>,
|
cached_caps: Mutex<Option<gst::Caps>>,
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
have_gl_context: AtomicBool,
|
have_gl_context: AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ impl ElementImpl for PaintableSink {
|
||||||
|
|
||||||
drop(paintable);
|
drop(paintable);
|
||||||
|
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
{
|
{
|
||||||
if self.have_gl_context.load(Ordering::Relaxed) && !self.initialize_gl_wrapper()
|
if self.have_gl_context.load(Ordering::Relaxed) && !self.initialize_gl_wrapper()
|
||||||
{
|
{
|
||||||
|
@ -238,7 +238,7 @@ impl ElementImpl for PaintableSink {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
gst::StateChange::ReadyToNull => {
|
gst::StateChange::ReadyToNull => {
|
||||||
let _ = self.gst_context.lock().unwrap().take();
|
let _ = self.gst_context.lock().unwrap().take();
|
||||||
let _ = self.gst_app_context.lock().unwrap().take();
|
let _ = self.gst_app_context.lock().unwrap().take();
|
||||||
|
@ -304,12 +304,12 @@ impl BaseSinkImpl for PaintableSink {
|
||||||
// TODO: Provide a preferred "window size" here for higher-resolution rendering
|
// TODO: Provide a preferred "window size" here for higher-resolution rendering
|
||||||
query.add_allocation_meta::<gst_video::VideoOverlayCompositionMeta>(None);
|
query.add_allocation_meta::<gst_video::VideoOverlayCompositionMeta>(None);
|
||||||
|
|
||||||
#[cfg(not(feature = "gst_gl"))]
|
#[cfg(not(any(target_os = "macos", feature = "gst_gl")))]
|
||||||
{
|
{
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
// Early return if there is no context initialized
|
// Early return if there is no context initialized
|
||||||
|
@ -384,7 +384,7 @@ impl BaseSinkImpl for PaintableSink {
|
||||||
gst::log!(CAT, imp: self, "Handling query {:?}", query);
|
gst::log!(CAT, imp: self, "Handling query {:?}", query);
|
||||||
|
|
||||||
match query.view_mut() {
|
match query.view_mut() {
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
gst::QueryViewMut::Context(q) => {
|
gst::QueryViewMut::Context(q) => {
|
||||||
// Avoid holding the locks while we respond to the query
|
// Avoid holding the locks while we respond to the query
|
||||||
// The objects are ref-counted anyway.
|
// The objects are ref-counted anyway.
|
||||||
|
@ -436,11 +436,11 @@ impl VideoSinkImpl for PaintableSink {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let have_gl_context = {
|
let have_gl_context = {
|
||||||
#[cfg(not(feature = "gst_gl"))]
|
#[cfg(not(any(target_os = "macos", feature = "gst_gl")))]
|
||||||
{
|
{
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
{
|
{
|
||||||
self.have_gl_context.load(Ordering::Relaxed)
|
self.have_gl_context.load(Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
@ -494,7 +494,7 @@ impl PaintableSink {
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
let mut tmp_caps = Self::pad_templates()[0].caps().clone();
|
let mut tmp_caps = Self::pad_templates()[0].caps().clone();
|
||||||
|
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
{
|
{
|
||||||
// Filter out GL caps from the template pads if we have no context
|
// Filter out GL caps from the template pads if we have no context
|
||||||
if !self.have_gl_context.load(Ordering::Relaxed) {
|
if !self.have_gl_context.load(Ordering::Relaxed) {
|
||||||
|
@ -516,7 +516,7 @@ impl PaintableSink {
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
let mut ctx = None;
|
let mut ctx = None;
|
||||||
|
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
{
|
{
|
||||||
if let Some(c) = self.realize_context() {
|
if let Some(c) = self.realize_context() {
|
||||||
self.have_gl_context.store(true, Ordering::Relaxed);
|
self.have_gl_context.store(true, Ordering::Relaxed);
|
||||||
|
@ -557,7 +557,7 @@ impl PaintableSink {
|
||||||
*self.sender.lock().unwrap() = Some(sender);
|
*self.sender.lock().unwrap() = Some(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
fn realize_context(&self) -> Option<ThreadGuard<gdk::GLContext>> {
|
fn realize_context(&self) -> Option<ThreadGuard<gdk::GLContext>> {
|
||||||
gst::debug!(CAT, imp: self, "Realizing GDK GL Context");
|
gst::debug!(CAT, imp: self, "Realizing GDK GL Context");
|
||||||
|
|
||||||
|
@ -598,7 +598,7 @@ 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"))]
|
#[cfg(target_os = "macos")]
|
||||||
"GdkMacosGLContext" => (),
|
"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");
|
||||||
|
@ -621,14 +621,14 @@ impl PaintableSink {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
fn initialize_gl_wrapper(&self) -> bool {
|
fn initialize_gl_wrapper(&self) -> bool {
|
||||||
gst::info!(CAT, imp: self, "Initializing GDK GL Context");
|
gst::info!(CAT, imp: self, "Initializing GDK GL Context");
|
||||||
let self_ = self.to_owned();
|
let self_ = self.to_owned();
|
||||||
utils::invoke_on_main_thread(move || self_.initialize_gl())
|
utils::invoke_on_main_thread(move || self_.initialize_gl())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
fn initialize_gl(&self) -> bool {
|
fn initialize_gl(&self) -> bool {
|
||||||
let ctx = {
|
let ctx = {
|
||||||
let paintable = self.paintable.lock().unwrap();
|
let paintable = self.paintable.lock().unwrap();
|
||||||
|
@ -656,7 +656,7 @@ 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"))]
|
#[cfg(target_os = "macos")]
|
||||||
"GdkMacosGLContext" => {
|
"GdkMacosGLContext" => {
|
||||||
self.initialize_macosgl(display, &mut display_ctx_guard, &mut app_ctx_guard);
|
self.initialize_macosgl(display, &mut display_ctx_guard, &mut app_ctx_guard);
|
||||||
}
|
}
|
||||||
|
@ -858,7 +858,7 @@ impl PaintableSink {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(target_os = "macos", feature = "gst_gl"))]
|
#[cfg(target_os = "macos")]
|
||||||
fn initialize_macosgl(
|
fn initialize_macosgl(
|
||||||
&self,
|
&self,
|
||||||
display: gdk::Display,
|
display: gdk::Display,
|
||||||
|
|
|
@ -165,7 +165,7 @@ impl PaintableImpl for Paintable {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Paintable {
|
impl Paintable {
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
pub(super) fn context(&self) -> Option<gdk::GLContext> {
|
pub(super) fn context(&self) -> Option<gdk::GLContext> {
|
||||||
self.gl_context.borrow().clone()
|
self.gl_context.borrow().clone()
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ impl Paintable {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Paintable {
|
impl Paintable {
|
||||||
#[cfg(feature = "gst_gl")]
|
#[cfg(any(target_os = "macos", feature = "gst_gl"))]
|
||||||
pub(crate) fn context(&self) -> Option<gdk::GLContext> {
|
pub(crate) fn context(&self) -> Option<gdk::GLContext> {
|
||||||
self.imp().context()
|
self.imp().context()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue