Add alpha parameter to shaders
Browse files at this commit4f05a74aa84bca74b650cffdc7ad889413f621cfParent: c30f52222 changed files +50 -4
- niri-visual-tests/src/cases/gradient_angle.rs +1 -0
- niri-visual-tests/src/cases/gradient_area.rs +2 -0
- niri-visual-tests/src/cases/gradient_oklab.rs +1 -0
- niri-visual-tests/src/cases/gradient_oklab_alpha.rs +1 -0
- niri-visual-tests/src/cases/gradient_oklch_alpha.rs +1 -0
- niri-visual-tests/src/cases/gradient_oklch_decreasing.rs +1 -0
- niri-visual-tests/src/cases/gradient_oklch_increasing.rs +1 -0
- niri-visual-tests/src/cases/gradient_oklch_longer.rs +1 -0
- niri-visual-tests/src/cases/gradient_oklch_shorter.rs +1 -0
- niri-visual-tests/src/cases/gradient_srgb.rs +1 -0
- niri-visual-tests/src/cases/gradient_srgb_alpha.rs +1 -0
- niri-visual-tests/src/cases/gradient_srgblinear.rs +1 -0
- niri-visual-tests/src/cases/gradient_srgblinear_alpha.rs +1 -0
- src/layer/mapped.rs +1 -1
- src/layout/focus_ring.rs +8 -2
- src/layout/insert_hint_element.rs +1 -1
- src/layout/shadow.rs +3 -0
- src/layout/tile.rs +4 -0
- src/render_helpers/border.rs +8 -0
- src/render_helpers/shader_element.rs +2 -0
- src/render_helpers/shadow.rs +8 -0
- src/window/mapped.rs +1 -0
niri-visual-tests/src/cases/gradient_angle.rsmodified+1 -0
| @@ -63,6 +63,7 @@ impl TestCase for GradientAngle { | ||
| 63 | 63 | 0., |
| 64 | 64 | CornerRadius::default(), |
| 65 | 65 | 1., |
| 66 | + 1., | |
| 66 | 67 | ) |
| 67 | 68 | .with_location(area.loc)] |
| 68 | 69 | .into_iter() |
niri-visual-tests/src/cases/gradient_area.rsmodified+2 -0
| @@ -84,6 +84,7 @@ impl TestCase for GradientArea { | ||
| 84 | 84 | Rectangle::default(), |
| 85 | 85 | CornerRadius::default(), |
| 86 | 86 | 1., |
| 87 | + 1., | |
| 87 | 88 | ); |
| 88 | 89 | rv.extend( |
| 89 | 90 | self.border |
| @@ -103,6 +104,7 @@ impl TestCase for GradientArea { | ||
| 103 | 104 | 0., |
| 104 | 105 | CornerRadius::default(), |
| 105 | 106 | 1., |
| 107 | + 1., | |
| 106 | 108 | ) |
| 107 | 109 | .with_location(area.loc)] |
| 108 | 110 | .into_iter() |
niri-visual-tests/src/cases/gradient_oklab.rsmodified+1 -0
| @@ -44,6 +44,7 @@ impl TestCase for GradientOklab { | ||
| 44 | 44 | 0., |
| 45 | 45 | CornerRadius::default(), |
| 46 | 46 | 1., |
| 47 | + 1., | |
| 47 | 48 | ) |
| 48 | 49 | .with_location(area.loc)] |
| 49 | 50 | .into_iter() |
niri-visual-tests/src/cases/gradient_oklab_alpha.rsmodified+1 -0
| @@ -42,6 +42,7 @@ impl TestCase for GradientOklabAlpha { | ||
| 42 | 42 | 0., |
| 43 | 43 | CornerRadius::default(), |
| 44 | 44 | 1., |
| 45 | + 1., | |
| 45 | 46 | ) |
| 46 | 47 | .with_location(area.loc)] |
| 47 | 48 | .into_iter() |
niri-visual-tests/src/cases/gradient_oklch_alpha.rsmodified+1 -0
| @@ -44,6 +44,7 @@ impl TestCase for GradientOklchAlpha { | ||
| 44 | 44 | 0., |
| 45 | 45 | CornerRadius::default(), |
| 46 | 46 | 1., |
| 47 | + 1., | |
| 47 | 48 | ) |
| 48 | 49 | .with_location(area.loc)] |
| 49 | 50 | .into_iter() |
niri-visual-tests/src/cases/gradient_oklch_decreasing.rsmodified+1 -0
| @@ -44,6 +44,7 @@ impl TestCase for GradientOklchDecreasing { | ||
| 44 | 44 | 0., |
| 45 | 45 | CornerRadius::default(), |
| 46 | 46 | 1., |
| 47 | + 1., | |
| 47 | 48 | ) |
| 48 | 49 | .with_location(area.loc)] |
| 49 | 50 | .into_iter() |
niri-visual-tests/src/cases/gradient_oklch_increasing.rsmodified+1 -0
| @@ -44,6 +44,7 @@ impl TestCase for GradientOklchIncreasing { | ||
| 44 | 44 | 0., |
| 45 | 45 | CornerRadius::default(), |
| 46 | 46 | 1., |
| 47 | + 1., | |
| 47 | 48 | ) |
| 48 | 49 | .with_location(area.loc)] |
| 49 | 50 | .into_iter() |
niri-visual-tests/src/cases/gradient_oklch_longer.rsmodified+1 -0
| @@ -44,6 +44,7 @@ impl TestCase for GradientOklchLonger { | ||
| 44 | 44 | 0., |
| 45 | 45 | CornerRadius::default(), |
| 46 | 46 | 1., |
| 47 | + 1., | |
| 47 | 48 | ) |
| 48 | 49 | .with_location(area.loc)] |
| 49 | 50 | .into_iter() |
niri-visual-tests/src/cases/gradient_oklch_shorter.rsmodified+1 -0
| @@ -44,6 +44,7 @@ impl TestCase for GradientOklchShorter { | ||
| 44 | 44 | 0., |
| 45 | 45 | CornerRadius::default(), |
| 46 | 46 | 1., |
| 47 | + 1., | |
| 47 | 48 | ) |
| 48 | 49 | .with_location(area.loc)] |
| 49 | 50 | .into_iter() |
niri-visual-tests/src/cases/gradient_srgb.rsmodified+1 -0
| @@ -44,6 +44,7 @@ impl TestCase for GradientSrgb { | ||
| 44 | 44 | 0., |
| 45 | 45 | CornerRadius::default(), |
| 46 | 46 | 1., |
| 47 | + 1., | |
| 47 | 48 | ) |
| 48 | 49 | .with_location(area.loc)] |
| 49 | 50 | .into_iter() |
niri-visual-tests/src/cases/gradient_srgb_alpha.rsmodified+1 -0
| @@ -42,6 +42,7 @@ impl TestCase for GradientSrgbAlpha { | ||
| 42 | 42 | 0., |
| 43 | 43 | CornerRadius::default(), |
| 44 | 44 | 1., |
| 45 | + 1., | |
| 45 | 46 | ) |
| 46 | 47 | .with_location(area.loc)] |
| 47 | 48 | .into_iter() |
niri-visual-tests/src/cases/gradient_srgblinear.rsmodified+1 -0
| @@ -44,6 +44,7 @@ impl TestCase for GradientSrgbLinear { | ||
| 44 | 44 | 0., |
| 45 | 45 | CornerRadius::default(), |
| 46 | 46 | 1., |
| 47 | + 1., | |
| 47 | 48 | ) |
| 48 | 49 | .with_location(area.loc)] |
| 49 | 50 | .into_iter() |
niri-visual-tests/src/cases/gradient_srgblinear_alpha.rsmodified+1 -0
| @@ -42,6 +42,7 @@ impl TestCase for GradientSrgbLinearAlpha { | ||
| 42 | 42 | 0., |
| 43 | 43 | CornerRadius::default(), |
| 44 | 44 | 1., |
| 45 | + 1., | |
| 45 | 46 | ) |
| 46 | 47 | .with_location(area.loc)] |
| 47 | 48 | .into_iter() |
src/layer/mapped.rsmodified+1 -1
| @@ -74,7 +74,7 @@ impl MappedLayer { | ||
| 74 | 74 | let radius = self.rules.geometry_corner_radius.unwrap_or_default(); |
| 75 | 75 | // FIXME: is_active based on keyboard focus? |
| 76 | 76 | self.shadow |
| 77 | - .update_render_elements(size, true, radius, scale.x); | |
| 77 | + .update_render_elements(size, true, radius, scale.x, 1.); | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | pub fn surface(&self) -> &LayerSurface { |
src/layout/focus_ring.rsmodified+8 -2
| @@ -2,7 +2,7 @@ use std::iter::zip; | ||
| 2 | 2 | |
| 3 | 3 | use arrayvec::ArrayVec; |
| 4 | 4 | use niri_config::{CornerRadius, Gradient, GradientRelativeTo}; |
| 5 | -use smithay::backend::renderer::element::Kind; | |
| 5 | +use smithay::backend::renderer::element::{Element as _, Kind}; | |
| 6 | 6 | use smithay::utils::{Logical, Point, Rectangle, Size}; |
| 7 | 7 | |
| 8 | 8 | use crate::niri_render_elements; |
| @@ -53,6 +53,7 @@ impl FocusRing { | ||
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | + #[allow(clippy::too_many_arguments)] | |
| 56 | 57 | pub fn update_render_elements( |
| 57 | 58 | &mut self, |
| 58 | 59 | win_size: Size<f64, Logical>, |
| @@ -61,6 +62,7 @@ impl FocusRing { | ||
| 61 | 62 | view_rect: Rectangle<f64, Logical>, |
| 62 | 63 | radius: CornerRadius, |
| 63 | 64 | scale: f64, |
| 65 | + alpha: f32, | |
| 64 | 66 | ) { |
| 65 | 67 | let width = self.config.width.0; |
| 66 | 68 | self.full_size = win_size + Size::from((width, width)).upscale(2.); |
| @@ -181,6 +183,7 @@ impl FocusRing { | ||
| 181 | 183 | rounded_corner_border_width, |
| 182 | 184 | radius, |
| 183 | 185 | scale as f32, |
| 186 | + alpha, | |
| 184 | 187 | ); |
| 185 | 188 | } |
| 186 | 189 | } else { |
| @@ -199,6 +202,7 @@ impl FocusRing { | ||
| 199 | 202 | rounded_corner_border_width, |
| 200 | 203 | radius, |
| 201 | 204 | scale as f32, |
| 205 | + alpha, | |
| 202 | 206 | ); |
| 203 | 207 | } |
| 204 | 208 | |
| @@ -229,7 +233,9 @@ impl FocusRing { | ||
| 229 | 233 | let elem = if self.use_border_shader && has_border_shader { |
| 230 | 234 | border.clone().with_location(location).into() |
| 231 | 235 | } else { |
| 232 | - SolidColorRenderElement::from_buffer(buffer, location, 1., Kind::Unspecified).into() | |
| 236 | + let alpha = border.alpha(); | |
| 237 | + SolidColorRenderElement::from_buffer(buffer, location, alpha, Kind::Unspecified) | |
| 238 | + .into() | |
| 233 | 239 | }; |
| 234 | 240 | rv.push(elem); |
| 235 | 241 | }; |
src/layout/insert_hint_element.rsmodified+1 -1
| @@ -48,7 +48,7 @@ impl InsertHintElement { | ||
| 48 | 48 | scale: f64, |
| 49 | 49 | ) { |
| 50 | 50 | self.inner |
| 51 | - .update_render_elements(size, true, false, view_rect, radius, scale); | |
| 51 | + .update_render_elements(size, true, false, view_rect, radius, scale, 1.); | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | pub fn render( |
src/layout/shadow.rsmodified+3 -0
| @@ -38,6 +38,7 @@ impl Shadow { | ||
| 38 | 38 | is_active: bool, |
| 39 | 39 | radius: CornerRadius, |
| 40 | 40 | scale: f64, |
| 41 | + alpha: f32, | |
| 41 | 42 | ) { |
| 42 | 43 | let ceil = |logical: f64| (logical * scale).ceil() / scale; |
| 43 | 44 | |
| @@ -129,6 +130,7 @@ impl Shadow { | ||
| 129 | 130 | scale as f32, |
| 130 | 131 | Rectangle::new(window_geo.loc - offset - rect.loc, window_geo.size), |
| 131 | 132 | win_radius, |
| 133 | + alpha, | |
| 132 | 134 | ); |
| 133 | 135 | |
| 134 | 136 | rect.loc += offset; |
| @@ -147,6 +149,7 @@ impl Shadow { | ||
| 147 | 149 | scale as f32, |
| 148 | 150 | Rectangle::zero(), |
| 149 | 151 | Default::default(), |
| 152 | + alpha, | |
| 150 | 153 | ); |
| 151 | 154 | |
| 152 | 155 | self.shader_rects[0].loc += offset; |
src/layout/tile.rsmodified+4 -0
| @@ -336,6 +336,7 @@ impl<W: LayoutElement> Tile<W> { | ||
| 336 | 336 | ), |
| 337 | 337 | radius, |
| 338 | 338 | self.scale, |
| 339 | + 1., | |
| 339 | 340 | ); |
| 340 | 341 | |
| 341 | 342 | let radius = if self.is_fullscreen { |
| @@ -350,6 +351,7 @@ impl<W: LayoutElement> Tile<W> { | ||
| 350 | 351 | is_active, |
| 351 | 352 | radius, |
| 352 | 353 | self.scale, |
| 354 | + 1., | |
| 353 | 355 | ); |
| 354 | 356 | |
| 355 | 357 | let draw_focus_ring_with_background = if self.effective_border_width().is_some() { |
| @@ -365,6 +367,7 @@ impl<W: LayoutElement> Tile<W> { | ||
| 365 | 367 | view_rect, |
| 366 | 368 | radius, |
| 367 | 369 | self.scale, |
| 370 | + 1., | |
| 368 | 371 | ); |
| 369 | 372 | } |
| 370 | 373 | |
| @@ -880,6 +883,7 @@ impl<W: LayoutElement> Tile<W> { | ||
| 880 | 883 | 0., |
| 881 | 884 | radius, |
| 882 | 885 | scale.x as f32, |
| 886 | + 1., | |
| 883 | 887 | ) |
| 884 | 888 | .with_location(geo.loc) |
| 885 | 889 | .into(); |
src/render_helpers/border.rsmodified+8 -0
| @@ -39,6 +39,7 @@ struct Parameters { | ||
| 39 | 39 | corner_radius: CornerRadius, |
| 40 | 40 | // Should only be used for visual improvements, i.e. corner radius anti-aliasing. |
| 41 | 41 | scale: f32, |
| 42 | + alpha: f32, | |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | 45 | impl BorderRenderElement { |
| @@ -54,6 +55,7 @@ impl BorderRenderElement { | ||
| 54 | 55 | border_width: f32, |
| 55 | 56 | corner_radius: CornerRadius, |
| 56 | 57 | scale: f32, |
| 58 | + alpha: f32, | |
| 57 | 59 | ) -> Self { |
| 58 | 60 | let inner = ShaderRenderElement::empty(ProgramType::Border, Kind::Unspecified); |
| 59 | 61 | let mut rv = Self { |
| @@ -69,6 +71,7 @@ impl BorderRenderElement { | ||
| 69 | 71 | border_width, |
| 70 | 72 | corner_radius, |
| 71 | 73 | scale, |
| 74 | + alpha, | |
| 72 | 75 | }, |
| 73 | 76 | }; |
| 74 | 77 | rv.update_inner(); |
| @@ -90,6 +93,7 @@ impl BorderRenderElement { | ||
| 90 | 93 | border_width: 0., |
| 91 | 94 | corner_radius: Default::default(), |
| 92 | 95 | scale: 1., |
| 96 | + alpha: 1., | |
| 93 | 97 | }, |
| 94 | 98 | } |
| 95 | 99 | } |
| @@ -111,6 +115,7 @@ impl BorderRenderElement { | ||
| 111 | 115 | border_width: f32, |
| 112 | 116 | corner_radius: CornerRadius, |
| 113 | 117 | scale: f32, |
| 118 | + alpha: f32, | |
| 114 | 119 | ) { |
| 115 | 120 | let params = Parameters { |
| 116 | 121 | size, |
| @@ -123,6 +128,7 @@ impl BorderRenderElement { | ||
| 123 | 128 | border_width, |
| 124 | 129 | corner_radius, |
| 125 | 130 | scale, |
| 131 | + alpha, | |
| 126 | 132 | }; |
| 127 | 133 | if self.params == params { |
| 128 | 134 | return; |
| @@ -144,6 +150,7 @@ impl BorderRenderElement { | ||
| 144 | 150 | border_width, |
| 145 | 151 | corner_radius, |
| 146 | 152 | scale, |
| 153 | + alpha, | |
| 147 | 154 | } = self.params; |
| 148 | 155 | |
| 149 | 156 | let grad_offset = geometry.loc - gradient_area.loc; |
| @@ -189,6 +196,7 @@ impl BorderRenderElement { | ||
| 189 | 196 | size, |
| 190 | 197 | None, |
| 191 | 198 | scale, |
| 199 | + alpha, | |
| 192 | 200 | vec![ |
| 193 | 201 | Uniform::new("colorspace", colorspace), |
| 194 | 202 | Uniform::new("hue_interpolation", hue_interpolation), |
src/render_helpers/shader_element.rsmodified+2 -0
| @@ -227,12 +227,14 @@ impl ShaderRenderElement { | ||
| 227 | 227 | size: Size<f64, Logical>, |
| 228 | 228 | opaque_regions: Option<Vec<Rectangle<f64, Logical>>>, |
| 229 | 229 | scale: f32, |
| 230 | + alpha: f32, | |
| 230 | 231 | uniforms: Vec<Uniform<'static>>, |
| 231 | 232 | textures: HashMap<String, GlesTexture>, |
| 232 | 233 | ) { |
| 233 | 234 | self.area.size = size; |
| 234 | 235 | self.opaque_regions = opaque_regions.unwrap_or_default(); |
| 235 | 236 | self.scale = scale; |
| 237 | + self.alpha = alpha; | |
| 236 | 238 | self.additional_uniforms = uniforms; |
| 237 | 239 | self.textures = textures; |
| 238 | 240 |
src/render_helpers/shadow.rsmodified+8 -0
| @@ -28,6 +28,7 @@ struct Parameters { | ||
| 28 | 28 | corner_radius: CornerRadius, |
| 29 | 29 | // Should only be used for visual improvements, i.e. corner radius anti-aliasing. |
| 30 | 30 | scale: f32, |
| 31 | + alpha: f32, | |
| 31 | 32 | |
| 32 | 33 | window_geometry: Rectangle<f64, Logical>, |
| 33 | 34 | window_corner_radius: CornerRadius, |
| @@ -44,6 +45,7 @@ impl ShadowRenderElement { | ||
| 44 | 45 | scale: f32, |
| 45 | 46 | window_geometry: Rectangle<f64, Logical>, |
| 46 | 47 | window_corner_radius: CornerRadius, |
| 48 | + alpha: f32, | |
| 47 | 49 | ) -> Self { |
| 48 | 50 | let inner = ShaderRenderElement::empty(ProgramType::Shadow, Kind::Unspecified); |
| 49 | 51 | let mut rv = Self { |
| @@ -55,6 +57,7 @@ impl ShadowRenderElement { | ||
| 55 | 57 | sigma, |
| 56 | 58 | corner_radius, |
| 57 | 59 | scale, |
| 60 | + alpha, | |
| 58 | 61 | window_geometry, |
| 59 | 62 | window_corner_radius, |
| 60 | 63 | }, |
| @@ -74,6 +77,7 @@ impl ShadowRenderElement { | ||
| 74 | 77 | sigma: 0., |
| 75 | 78 | corner_radius: Default::default(), |
| 76 | 79 | scale: 1., |
| 80 | + alpha: 1., | |
| 77 | 81 | window_geometry: Default::default(), |
| 78 | 82 | window_corner_radius: Default::default(), |
| 79 | 83 | }, |
| @@ -95,12 +99,14 @@ impl ShadowRenderElement { | ||
| 95 | 99 | scale: f32, |
| 96 | 100 | window_geometry: Rectangle<f64, Logical>, |
| 97 | 101 | window_corner_radius: CornerRadius, |
| 102 | + alpha: f32, | |
| 98 | 103 | ) { |
| 99 | 104 | let params = Parameters { |
| 100 | 105 | size, |
| 101 | 106 | geometry, |
| 102 | 107 | color, |
| 103 | 108 | sigma, |
| 109 | + alpha, | |
| 104 | 110 | corner_radius, |
| 105 | 111 | scale, |
| 106 | 112 | window_geometry, |
| @@ -120,6 +126,7 @@ impl ShadowRenderElement { | ||
| 120 | 126 | geometry, |
| 121 | 127 | color, |
| 122 | 128 | sigma, |
| 129 | + alpha, | |
| 123 | 130 | corner_radius, |
| 124 | 131 | scale, |
| 125 | 132 | window_geometry, |
| @@ -145,6 +152,7 @@ impl ShadowRenderElement { | ||
| 145 | 152 | size, |
| 146 | 153 | None, |
| 147 | 154 | scale, |
| 155 | + alpha, | |
| 148 | 156 | vec![ |
| 149 | 157 | Uniform::new("shadow_color", color.to_array_premul()), |
| 150 | 158 | Uniform::new("sigma", sigma), |
src/window/mapped.rsmodified+1 -0
| @@ -403,6 +403,7 @@ impl Mapped { | ||
| 403 | 403 | 0., |
| 404 | 404 | radius, |
| 405 | 405 | scale.x as f32, |
| 406 | + 1., | |
| 406 | 407 | ) |
| 407 | 408 | .with_location(geo.loc) |
| 408 | 409 | .into(); |