Fix crop + crossfade artifacts
Browse files at this commit0fcd981b86029ce4a554bf4805221a104a9228a7Parent: 5c4153e2 changed files +21 -8
- src/render_helpers/crossfade.rs +6 -0
- src/render_helpers/primary_gpu_pixel_shader_with_textures.rs +15 -8
src/render_helpers/crossfade.rsmodified+6 -0
| @@ -36,6 +36,11 @@ impl CrossfadeRenderElement { | ||
| 36 | 36 | let tex_to_geo = texture_to_geo.to_f64().upscale(scale_to); |
| 37 | 37 | let combined_geo = tex_from_geo.merge(tex_to_geo); |
| 38 | 38 | |
| 39 | + let size = combined_geo | |
| 40 | + .size | |
| 41 | + .to_logical(1.) | |
| 42 | + .to_buffer(1., Transform::Normal); | |
| 43 | + | |
| 39 | 44 | let area = Rectangle::from_loc_and_size( |
| 40 | 45 | area.loc + combined_geo.loc.to_logical(scale).to_i32_round(), |
| 41 | 46 | combined_geo.size.to_logical(scale).to_i32_round(), |
| @@ -57,6 +62,7 @@ impl CrossfadeRenderElement { | ||
| 57 | 62 | (String::from("tex_to"), texture_to), |
| 58 | 63 | ]), |
| 59 | 64 | area, |
| 65 | + size, | |
| 60 | 66 | None, |
| 61 | 67 | result_alpha, |
| 62 | 68 | vec![ |
src/render_helpers/primary_gpu_pixel_shader_with_textures.rsmodified+15 -8
| @@ -9,7 +9,7 @@ use smithay::backend::renderer::gles::{ | ||
| 9 | 9 | UniformDesc, UniformName, |
| 10 | 10 | }; |
| 11 | 11 | use smithay::backend::renderer::utils::CommitCounter; |
| 12 | -use smithay::utils::{Buffer, Logical, Physical, Rectangle, Scale, Transform}; | |
| 12 | +use smithay::utils::{Buffer, Logical, Physical, Rectangle, Scale, Size}; | |
| 13 | 13 | |
| 14 | 14 | use super::renderer::AsGlesFrame; |
| 15 | 15 | use super::resources::Resources; |
| @@ -25,6 +25,7 @@ pub struct PrimaryGpuPixelShaderWithTexturesRenderElement { | ||
| 25 | 25 | id: Id, |
| 26 | 26 | commit_counter: CommitCounter, |
| 27 | 27 | area: Rectangle<i32, Logical>, |
| 28 | + size: Size<f64, Buffer>, | |
| 28 | 29 | opaque_regions: Vec<Rectangle<i32, Logical>>, |
| 29 | 30 | alpha: f32, |
| 30 | 31 | additional_uniforms: Vec<Uniform<'static>>, |
| @@ -122,10 +123,12 @@ impl PixelWithTexturesProgram { | ||
| 122 | 123 | } |
| 123 | 124 | |
| 124 | 125 | impl PrimaryGpuPixelShaderWithTexturesRenderElement { |
| 126 | + #[allow(clippy::too_many_arguments)] | |
| 125 | 127 | pub fn new( |
| 126 | 128 | shader: PixelWithTexturesProgram, |
| 127 | 129 | textures: HashMap<String, GlesTexture>, |
| 128 | 130 | area: Rectangle<i32, Logical>, |
| 131 | + size: Size<f64, Buffer>, | |
| 129 | 132 | opaque_regions: Option<Vec<Rectangle<i32, Logical>>>, |
| 130 | 133 | alpha: f32, |
| 131 | 134 | additional_uniforms: Vec<Uniform<'_>>, |
| @@ -137,6 +140,7 @@ impl PrimaryGpuPixelShaderWithTexturesRenderElement { | ||
| 137 | 140 | id: Id::new(), |
| 138 | 141 | commit_counter: CommitCounter::default(), |
| 139 | 142 | area, |
| 143 | + size, | |
| 140 | 144 | opaque_regions: opaque_regions.unwrap_or_default(), |
| 141 | 145 | alpha, |
| 142 | 146 | additional_uniforms: additional_uniforms |
| @@ -158,9 +162,7 @@ impl Element for PrimaryGpuPixelShaderWithTexturesRenderElement { | ||
| 158 | 162 | } |
| 159 | 163 | |
| 160 | 164 | fn src(&self) -> Rectangle<f64, Buffer> { |
| 161 | - self.area | |
| 162 | - .to_f64() | |
| 163 | - .to_buffer(1.0, Transform::Normal, &self.area.size.to_f64()) | |
| 165 | + Rectangle::from_loc_and_size((0., 0.), self.size.to_f64()) | |
| 164 | 166 | } |
| 165 | 167 | |
| 166 | 168 | fn geometry(&self, scale: Scale<f64>) -> Rectangle<i32, Physical> { |
| @@ -187,7 +189,7 @@ impl RenderElement<GlesRenderer> for PrimaryGpuPixelShaderWithTexturesRenderElem | ||
| 187 | 189 | fn draw( |
| 188 | 190 | &self, |
| 189 | 191 | frame: &mut GlesFrame<'_>, |
| 190 | - _src: Rectangle<f64, Buffer>, | |
| 192 | + src: Rectangle<f64, Buffer>, | |
| 191 | 193 | dest: Rectangle<i32, Physical>, |
| 192 | 194 | damage: &[Rectangle<i32, Physical>], |
| 193 | 195 | ) -> Result<(), GlesError> { |
| @@ -253,10 +255,15 @@ impl RenderElement<GlesRenderer> for PrimaryGpuPixelShaderWithTexturesRenderElem | ||
| 253 | 255 | |
| 254 | 256 | // dest position and scale |
| 255 | 257 | let mut matrix = Mat3::from_translation(Vec2::new(dest.loc.x as f32, dest.loc.y as f32)); |
| 258 | + | |
| 259 | + let scale = src.size.to_f64() / dest.size.to_f64(); | |
| 260 | + let tex_matrix = Mat3::from_scale(Vec2::new(scale.x as f32, scale.y as f32)); | |
| 261 | + let tex_matrix = | |
| 262 | + Mat3::from_translation(Vec2::new(src.loc.x as f32, src.loc.y as f32)) * tex_matrix; | |
| 256 | 263 | let tex_matrix = Mat3::from_scale(Vec2::new( |
| 257 | - (1.0f64 / dest.size.w as f64) as f32, | |
| 258 | - (1.0f64 / dest.size.h as f64) as f32, | |
| 259 | - )); | |
| 264 | + (1.0f64 / self.size.w) as f32, | |
| 265 | + (1.0f64 / self.size.h) as f32, | |
| 266 | + )) * tex_matrix; | |
| 260 | 267 | |
| 261 | 268 | //apply output transformation |
| 262 | 269 | matrix = Mat3::from_cols_array(frame.projection()) * matrix; |