mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-29 15:01:07 +00:00
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: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1309>
This commit is contained in:
parent
3423d05f77
commit
d8a61edca0
1 changed files with 50 additions and 3 deletions
|
@ -34,6 +34,9 @@ pub struct Paintable {
|
|||
cached_textures: RefCell<HashMap<usize, gdk::Texture>>,
|
||||
gl_context: RefCell<Option<gdk::GLContext>>,
|
||||
background_color: Cell<gdk::RGBA>,
|
||||
#[cfg(feature = "gtk_v4_10")]
|
||||
scaling_filter: Cell<gsk::ScalingFilter>,
|
||||
use_scaling_filter: Cell<bool>,
|
||||
#[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::<gsk::ScalingFilter>(
|
||||
"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::<gdk::GLTexture>() && *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
|
||||
|
|
Loading…
Reference in a new issue