From d8a61edca0c1c51e15fc5592073aced6fc90708d Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Tue, 22 Aug 2023 12:44:35 +0400 Subject: [PATCH] gtk4: Add scaling-filter and use-scaling-filter properties The property is added under the gtk_v4_10 feature because it requires GTK 4.10. Part-of: --- video/gtk4/src/sink/paintable/imp.rs | 53 ++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/video/gtk4/src/sink/paintable/imp.rs b/video/gtk4/src/sink/paintable/imp.rs index 49b2c268..1ce38dfa 100644 --- a/video/gtk4/src/sink/paintable/imp.rs +++ b/video/gtk4/src/sink/paintable/imp.rs @@ -34,6 +34,9 @@ pub struct Paintable { cached_textures: RefCell>, gl_context: RefCell>, background_color: Cell, + #[cfg(feature = "gtk_v4_10")] + scaling_filter: Cell, + use_scaling_filter: Cell, #[cfg(not(feature = "gtk_v4_10"))] premult_shader: gsk::GLShader, } @@ -45,6 +48,9 @@ impl Default for Paintable { cached_textures: Default::default(), gl_context: Default::default(), background_color: Cell::new(gdk::RGBA::BLACK), + #[cfg(feature = "gtk_v4_10")] + scaling_filter: Cell::new(gsk::ScalingFilter::Linear), + use_scaling_filter: Cell::new(false), #[cfg(not(feature = "gtk_v4_10"))] premult_shader: gsk::GLShader::from_bytes(&glib::Bytes::from_static(include_bytes!( "premult.glsl" @@ -74,6 +80,20 @@ impl ObjectImpl for Paintable { .blurb("Background color to render behind the video frame and in the borders") .default_value(0) .build(), + #[cfg(feature = "gtk_v4_10")] + glib::ParamSpecEnum::builder_with_default::( + "scaling-filter", + gsk::ScalingFilter::Linear, + ) + .nick("Scaling Filter") + .blurb("Scaling filter to use for rendering") + .build(), + #[cfg(feature = "gtk_v4_10")] + glib::ParamSpecBoolean::builder("use-scaling-filter") + .nick("Use Scaling Filter") + .blurb("Use selected scaling filter or GTK default for rendering") + .default_value(false) + .build(), ] }); @@ -93,6 +113,10 @@ impl ObjectImpl for Paintable { v.to_value() } + #[cfg(feature = "gtk_v4_10")] + "scaling-filter" => self.scaling_filter.get().to_value(), + #[cfg(feature = "gtk_v4_10")] + "use-scaling-filter" => self.use_scaling_filter.get().to_value(), _ => unimplemented!(), } } @@ -111,6 +135,10 @@ impl ObjectImpl for Paintable { self.background_color .set(gdk::RGBA::new(red, green, blue, alpha)) } + #[cfg(feature = "gtk_v4_10")] + "scaling-filter" => self.scaling_filter.set(value.get().unwrap()), + #[cfg(feature = "gtk_v4_10")] + "use-scaling-filter" => self.use_scaling_filter.set(value.get().unwrap()), _ => unimplemented!(), } } @@ -224,7 +252,16 @@ impl PaintableImpl for Paintable { context_requires_premult && texture.is::() && *has_alpha; if do_premult { snapshot.push_mask(gsk::MaskMode::Alpha); - snapshot.append_texture(texture, &bounds); + if self.use_scaling_filter.get() { + #[cfg(feature = "gtk_v4_10")] + snapshot.append_scaled_texture( + texture, + self.scaling_filter.get(), + &bounds, + ); + } else { + snapshot.append_texture(texture, &bounds); + } snapshot.pop(); // pop mask // color matrix to set alpha of the source to 1.0 as it was @@ -242,7 +279,12 @@ impl PaintableImpl for Paintable { ); } - snapshot.append_texture(texture, &bounds); + if self.use_scaling_filter.get() { + #[cfg(feature = "gtk_v4_10")] + snapshot.append_scaled_texture(texture, self.scaling_filter.get(), &bounds); + } else { + snapshot.append_texture(texture, &bounds); + } if do_premult { snapshot.pop(); // pop color matrix @@ -261,7 +303,12 @@ impl PaintableImpl for Paintable { ); } - snapshot.append_texture(texture, &bounds); + if self.use_scaling_filter.get() { + #[cfg(feature = "gtk_v4_10")] + snapshot.append_scaled_texture(texture, self.scaling_filter.get(), &bounds); + } else { + snapshot.append_texture(texture, &bounds); + } if do_premult { snapshot.gl_shader_pop_texture(); // pop texture appended above from the shader