From 49774f0f3606d175ee2e110f6bca88196ee09dc2 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Mon, 8 Jul 2024 19:00:31 +0200 Subject: [PATCH] gtk4: Support RGBx formats in SW paths GTK4 has matching enums and thus should handle them fine. Further more it should allow renderers to reduce memory bandwidth by applying occlusion culling. Part-of: --- video/gtk4/src/sink/frame.rs | 12 ++++++++++++ video/gtk4/src/sink/imp.rs | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/video/gtk4/src/sink/frame.rs b/video/gtk4/src/sink/frame.rs index f9f1c61b..a2607748 100644 --- a/video/gtk4/src/sink/frame.rs +++ b/video/gtk4/src/sink/frame.rs @@ -169,6 +169,14 @@ impl AsRef<[u8]> for FrameWrapper { fn video_format_to_memory_format(f: gst_video::VideoFormat) -> gdk::MemoryFormat { match f { + #[cfg(feature = "gtk_v4_14")] + gst_video::VideoFormat::Bgrx => gdk::MemoryFormat::B8g8r8x8, + #[cfg(feature = "gtk_v4_14")] + gst_video::VideoFormat::Xrgb => gdk::MemoryFormat::X8r8g8b8, + #[cfg(feature = "gtk_v4_14")] + gst_video::VideoFormat::Rgbx => gdk::MemoryFormat::R8g8b8x8, + #[cfg(feature = "gtk_v4_14")] + gst_video::VideoFormat::Xbgr => gdk::MemoryFormat::X8b8g8r8, gst_video::VideoFormat::Bgra => gdk::MemoryFormat::B8g8r8a8, gst_video::VideoFormat::Argb => gdk::MemoryFormat::A8r8g8b8, gst_video::VideoFormat::Rgba => gdk::MemoryFormat::R8g8b8a8, @@ -256,6 +264,10 @@ fn video_frame_to_gl_texture( gdk::MemoryFormat::R8g8b8a8 => gdk::MemoryFormat::R8g8b8a8Premultiplied, gdk::MemoryFormat::A8b8g8r8 => gdk::MemoryFormat::A8r8g8b8Premultiplied, gdk::MemoryFormat::R8g8b8 | gdk::MemoryFormat::B8g8r8 => format, + gdk::MemoryFormat::B8g8r8x8 + | gdk::MemoryFormat::X8r8g8b8 + | gdk::MemoryFormat::R8g8b8x8 + | gdk::MemoryFormat::X8b8g8r8 => format, _ => unreachable!(), } } else { diff --git a/video/gtk4/src/sink/imp.rs b/video/gtk4/src/sink/imp.rs index 8b4f2048..2d2dbba4 100644 --- a/video/gtk4/src/sink/imp.rs +++ b/video/gtk4/src/sink/imp.rs @@ -223,6 +223,14 @@ impl ElementImpl for PaintableSink { const GL_FORMATS: &[gst_video::VideoFormat] = &[gst_video::VideoFormat::Rgba, gst_video::VideoFormat::Rgb]; const NON_GL_FORMATS: &[gst_video::VideoFormat] = &[ + #[cfg(feature = "gtk_v4_14")] + gst_video::VideoFormat::Bgrx, + #[cfg(feature = "gtk_v4_14")] + gst_video::VideoFormat::Xrgb, + #[cfg(feature = "gtk_v4_14")] + gst_video::VideoFormat::Rgbx, + #[cfg(feature = "gtk_v4_14")] + gst_video::VideoFormat::Xbgr, gst_video::VideoFormat::Bgra, gst_video::VideoFormat::Argb, gst_video::VideoFormat::Rgba,