forge
Explore
Log in

Don't you dare go Hollow

Add alpha parameter to shaders

Browse files at this commit

4f05a74aa84bca74b650cffdc7ad889413f621cfIvan MolodetskikhParent: c30f522
Lets us add extra opacity.
niri-visual-tests/src/cases/gradient_angle.rsmodified+1 -0
@@ -63,6 +63,7 @@ impl TestCase for GradientAngle {
6363 0.,
6464 CornerRadius::default(),
6565 1.,
66+ 1.,
6667 )
6768 .with_location(area.loc)]
6869 .into_iter()
niri-visual-tests/src/cases/gradient_area.rsmodified+2 -0
@@ -84,6 +84,7 @@ impl TestCase for GradientArea {
8484 Rectangle::default(),
8585 CornerRadius::default(),
8686 1.,
87+ 1.,
8788 );
8889 rv.extend(
8990 self.border
@@ -103,6 +104,7 @@ impl TestCase for GradientArea {
103104 0.,
104105 CornerRadius::default(),
105106 1.,
107+ 1.,
106108 )
107109 .with_location(area.loc)]
108110 .into_iter()
niri-visual-tests/src/cases/gradient_oklab.rsmodified+1 -0
@@ -44,6 +44,7 @@ impl TestCase for GradientOklab {
4444 0.,
4545 CornerRadius::default(),
4646 1.,
47+ 1.,
4748 )
4849 .with_location(area.loc)]
4950 .into_iter()
niri-visual-tests/src/cases/gradient_oklab_alpha.rsmodified+1 -0
@@ -42,6 +42,7 @@ impl TestCase for GradientOklabAlpha {
4242 0.,
4343 CornerRadius::default(),
4444 1.,
45+ 1.,
4546 )
4647 .with_location(area.loc)]
4748 .into_iter()
niri-visual-tests/src/cases/gradient_oklch_alpha.rsmodified+1 -0
@@ -44,6 +44,7 @@ impl TestCase for GradientOklchAlpha {
4444 0.,
4545 CornerRadius::default(),
4646 1.,
47+ 1.,
4748 )
4849 .with_location(area.loc)]
4950 .into_iter()
niri-visual-tests/src/cases/gradient_oklch_decreasing.rsmodified+1 -0
@@ -44,6 +44,7 @@ impl TestCase for GradientOklchDecreasing {
4444 0.,
4545 CornerRadius::default(),
4646 1.,
47+ 1.,
4748 )
4849 .with_location(area.loc)]
4950 .into_iter()
niri-visual-tests/src/cases/gradient_oklch_increasing.rsmodified+1 -0
@@ -44,6 +44,7 @@ impl TestCase for GradientOklchIncreasing {
4444 0.,
4545 CornerRadius::default(),
4646 1.,
47+ 1.,
4748 )
4849 .with_location(area.loc)]
4950 .into_iter()
niri-visual-tests/src/cases/gradient_oklch_longer.rsmodified+1 -0
@@ -44,6 +44,7 @@ impl TestCase for GradientOklchLonger {
4444 0.,
4545 CornerRadius::default(),
4646 1.,
47+ 1.,
4748 )
4849 .with_location(area.loc)]
4950 .into_iter()
niri-visual-tests/src/cases/gradient_oklch_shorter.rsmodified+1 -0
@@ -44,6 +44,7 @@ impl TestCase for GradientOklchShorter {
4444 0.,
4545 CornerRadius::default(),
4646 1.,
47+ 1.,
4748 )
4849 .with_location(area.loc)]
4950 .into_iter()
niri-visual-tests/src/cases/gradient_srgb.rsmodified+1 -0
@@ -44,6 +44,7 @@ impl TestCase for GradientSrgb {
4444 0.,
4545 CornerRadius::default(),
4646 1.,
47+ 1.,
4748 )
4849 .with_location(area.loc)]
4950 .into_iter()
niri-visual-tests/src/cases/gradient_srgb_alpha.rsmodified+1 -0
@@ -42,6 +42,7 @@ impl TestCase for GradientSrgbAlpha {
4242 0.,
4343 CornerRadius::default(),
4444 1.,
45+ 1.,
4546 )
4647 .with_location(area.loc)]
4748 .into_iter()
niri-visual-tests/src/cases/gradient_srgblinear.rsmodified+1 -0
@@ -44,6 +44,7 @@ impl TestCase for GradientSrgbLinear {
4444 0.,
4545 CornerRadius::default(),
4646 1.,
47+ 1.,
4748 )
4849 .with_location(area.loc)]
4950 .into_iter()
niri-visual-tests/src/cases/gradient_srgblinear_alpha.rsmodified+1 -0
@@ -42,6 +42,7 @@ impl TestCase for GradientSrgbLinearAlpha {
4242 0.,
4343 CornerRadius::default(),
4444 1.,
45+ 1.,
4546 )
4647 .with_location(area.loc)]
4748 .into_iter()
src/layer/mapped.rsmodified+1 -1
@@ -74,7 +74,7 @@ impl MappedLayer {
7474 let radius = self.rules.geometry_corner_radius.unwrap_or_default();
7575 // FIXME: is_active based on keyboard focus?
7676 self.shadow
77- .update_render_elements(size, true, radius, scale.x);
77+ .update_render_elements(size, true, radius, scale.x, 1.);
7878 }
7979
8080 pub fn surface(&self) -> &LayerSurface {
src/layout/focus_ring.rsmodified+8 -2
@@ -2,7 +2,7 @@ use std::iter::zip;
22
33 use arrayvec::ArrayVec;
44 use niri_config::{CornerRadius, Gradient, GradientRelativeTo};
5-use smithay::backend::renderer::element::Kind;
5+use smithay::backend::renderer::element::{Element as _, Kind};
66 use smithay::utils::{Logical, Point, Rectangle, Size};
77
88 use crate::niri_render_elements;
@@ -53,6 +53,7 @@ impl FocusRing {
5353 }
5454 }
5555
56+ #[allow(clippy::too_many_arguments)]
5657 pub fn update_render_elements(
5758 &mut self,
5859 win_size: Size<f64, Logical>,
@@ -61,6 +62,7 @@ impl FocusRing {
6162 view_rect: Rectangle<f64, Logical>,
6263 radius: CornerRadius,
6364 scale: f64,
65+ alpha: f32,
6466 ) {
6567 let width = self.config.width.0;
6668 self.full_size = win_size + Size::from((width, width)).upscale(2.);
@@ -181,6 +183,7 @@ impl FocusRing {
181183 rounded_corner_border_width,
182184 radius,
183185 scale as f32,
186+ alpha,
184187 );
185188 }
186189 } else {
@@ -199,6 +202,7 @@ impl FocusRing {
199202 rounded_corner_border_width,
200203 radius,
201204 scale as f32,
205+ alpha,
202206 );
203207 }
204208
@@ -229,7 +233,9 @@ impl FocusRing {
229233 let elem = if self.use_border_shader && has_border_shader {
230234 border.clone().with_location(location).into()
231235 } 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()
233239 };
234240 rv.push(elem);
235241 };
src/layout/insert_hint_element.rsmodified+1 -1
@@ -48,7 +48,7 @@ impl InsertHintElement {
4848 scale: f64,
4949 ) {
5050 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.);
5252 }
5353
5454 pub fn render(
src/layout/shadow.rsmodified+3 -0
@@ -38,6 +38,7 @@ impl Shadow {
3838 is_active: bool,
3939 radius: CornerRadius,
4040 scale: f64,
41+ alpha: f32,
4142 ) {
4243 let ceil = |logical: f64| (logical * scale).ceil() / scale;
4344
@@ -129,6 +130,7 @@ impl Shadow {
129130 scale as f32,
130131 Rectangle::new(window_geo.loc - offset - rect.loc, window_geo.size),
131132 win_radius,
133+ alpha,
132134 );
133135
134136 rect.loc += offset;
@@ -147,6 +149,7 @@ impl Shadow {
147149 scale as f32,
148150 Rectangle::zero(),
149151 Default::default(),
152+ alpha,
150153 );
151154
152155 self.shader_rects[0].loc += offset;
src/layout/tile.rsmodified+4 -0
@@ -336,6 +336,7 @@ impl<W: LayoutElement> Tile<W> {
336336 ),
337337 radius,
338338 self.scale,
339+ 1.,
339340 );
340341
341342 let radius = if self.is_fullscreen {
@@ -350,6 +351,7 @@ impl<W: LayoutElement> Tile<W> {
350351 is_active,
351352 radius,
352353 self.scale,
354+ 1.,
353355 );
354356
355357 let draw_focus_ring_with_background = if self.effective_border_width().is_some() {
@@ -365,6 +367,7 @@ impl<W: LayoutElement> Tile<W> {
365367 view_rect,
366368 radius,
367369 self.scale,
370+ 1.,
368371 );
369372 }
370373
@@ -880,6 +883,7 @@ impl<W: LayoutElement> Tile<W> {
880883 0.,
881884 radius,
882885 scale.x as f32,
886+ 1.,
883887 )
884888 .with_location(geo.loc)
885889 .into();
src/render_helpers/border.rsmodified+8 -0
@@ -39,6 +39,7 @@ struct Parameters {
3939 corner_radius: CornerRadius,
4040 // Should only be used for visual improvements, i.e. corner radius anti-aliasing.
4141 scale: f32,
42+ alpha: f32,
4243 }
4344
4445 impl BorderRenderElement {
@@ -54,6 +55,7 @@ impl BorderRenderElement {
5455 border_width: f32,
5556 corner_radius: CornerRadius,
5657 scale: f32,
58+ alpha: f32,
5759 ) -> Self {
5860 let inner = ShaderRenderElement::empty(ProgramType::Border, Kind::Unspecified);
5961 let mut rv = Self {
@@ -69,6 +71,7 @@ impl BorderRenderElement {
6971 border_width,
7072 corner_radius,
7173 scale,
74+ alpha,
7275 },
7376 };
7477 rv.update_inner();
@@ -90,6 +93,7 @@ impl BorderRenderElement {
9093 border_width: 0.,
9194 corner_radius: Default::default(),
9295 scale: 1.,
96+ alpha: 1.,
9397 },
9498 }
9599 }
@@ -111,6 +115,7 @@ impl BorderRenderElement {
111115 border_width: f32,
112116 corner_radius: CornerRadius,
113117 scale: f32,
118+ alpha: f32,
114119 ) {
115120 let params = Parameters {
116121 size,
@@ -123,6 +128,7 @@ impl BorderRenderElement {
123128 border_width,
124129 corner_radius,
125130 scale,
131+ alpha,
126132 };
127133 if self.params == params {
128134 return;
@@ -144,6 +150,7 @@ impl BorderRenderElement {
144150 border_width,
145151 corner_radius,
146152 scale,
153+ alpha,
147154 } = self.params;
148155
149156 let grad_offset = geometry.loc - gradient_area.loc;
@@ -189,6 +196,7 @@ impl BorderRenderElement {
189196 size,
190197 None,
191198 scale,
199+ alpha,
192200 vec![
193201 Uniform::new("colorspace", colorspace),
194202 Uniform::new("hue_interpolation", hue_interpolation),
src/render_helpers/shader_element.rsmodified+2 -0
@@ -227,12 +227,14 @@ impl ShaderRenderElement {
227227 size: Size<f64, Logical>,
228228 opaque_regions: Option<Vec<Rectangle<f64, Logical>>>,
229229 scale: f32,
230+ alpha: f32,
230231 uniforms: Vec<Uniform<'static>>,
231232 textures: HashMap<String, GlesTexture>,
232233 ) {
233234 self.area.size = size;
234235 self.opaque_regions = opaque_regions.unwrap_or_default();
235236 self.scale = scale;
237+ self.alpha = alpha;
236238 self.additional_uniforms = uniforms;
237239 self.textures = textures;
238240
src/render_helpers/shadow.rsmodified+8 -0
@@ -28,6 +28,7 @@ struct Parameters {
2828 corner_radius: CornerRadius,
2929 // Should only be used for visual improvements, i.e. corner radius anti-aliasing.
3030 scale: f32,
31+ alpha: f32,
3132
3233 window_geometry: Rectangle<f64, Logical>,
3334 window_corner_radius: CornerRadius,
@@ -44,6 +45,7 @@ impl ShadowRenderElement {
4445 scale: f32,
4546 window_geometry: Rectangle<f64, Logical>,
4647 window_corner_radius: CornerRadius,
48+ alpha: f32,
4749 ) -> Self {
4850 let inner = ShaderRenderElement::empty(ProgramType::Shadow, Kind::Unspecified);
4951 let mut rv = Self {
@@ -55,6 +57,7 @@ impl ShadowRenderElement {
5557 sigma,
5658 corner_radius,
5759 scale,
60+ alpha,
5861 window_geometry,
5962 window_corner_radius,
6063 },
@@ -74,6 +77,7 @@ impl ShadowRenderElement {
7477 sigma: 0.,
7578 corner_radius: Default::default(),
7679 scale: 1.,
80+ alpha: 1.,
7781 window_geometry: Default::default(),
7882 window_corner_radius: Default::default(),
7983 },
@@ -95,12 +99,14 @@ impl ShadowRenderElement {
9599 scale: f32,
96100 window_geometry: Rectangle<f64, Logical>,
97101 window_corner_radius: CornerRadius,
102+ alpha: f32,
98103 ) {
99104 let params = Parameters {
100105 size,
101106 geometry,
102107 color,
103108 sigma,
109+ alpha,
104110 corner_radius,
105111 scale,
106112 window_geometry,
@@ -120,6 +126,7 @@ impl ShadowRenderElement {
120126 geometry,
121127 color,
122128 sigma,
129+ alpha,
123130 corner_radius,
124131 scale,
125132 window_geometry,
@@ -145,6 +152,7 @@ impl ShadowRenderElement {
145152 size,
146153 None,
147154 scale,
155+ alpha,
148156 vec![
149157 Uniform::new("shadow_color", color.to_array_premul()),
150158 Uniform::new("sigma", sigma),
src/window/mapped.rsmodified+1 -0
@@ -403,6 +403,7 @@ impl Mapped {
403403 0.,
404404 radius,
405405 scale.x as f32,
406+ 1.,
406407 )
407408 .with_location(geo.loc)
408409 .into();