forge
Explore
Log in

Don't you dare go Hollow

Offscreen semitransparent tiles

Browse files at this commit

4f5c8e745bec6395105138c83468bccb4ab27ea9Ivan MolodetskikhParent: f30413a
Now that offscreen does damage tracking, we can reasonably do this. Note this
only affects full-tile opacity, not window opacity.
src/layout/opening_window.rsmodified+3 -2
@@ -54,6 +54,7 @@ impl OpenAnimation {
54 geo_size: Size<f64, Logical>,54 geo_size: Size<f64, Logical>,
55 location: Point<f64, Logical>,55 location: Point<f64, Logical>,
56 scale: Scale<f64>,56 scale: Scale<f64>,
57+ alpha: f32,
57 ) -> anyhow::Result<OpeningWindowRenderElement> {58 ) -> anyhow::Result<OpeningWindowRenderElement> {
58 let progress = self.anim.value();59 let progress = self.anim.value();
59 let clamped_progress = self.anim.clamped_value().clamp(0., 1.);60 let clamped_progress = self.anim.clamped_value().clamp(0., 1.);
@@ -102,7 +103,7 @@ impl OpenAnimation {
102 area.size,103 area.size,
103 None,104 None,
104 scale.x as f32,105 scale.x as f32,
105- 1.,106+ alpha,
106 vec![107 vec![
107 mat3_uniform("niri_input_to_geo", input_to_geo),108 mat3_uniform("niri_input_to_geo", input_to_geo),
108 Uniform::new("niri_geo_size", geo_size.to_array()),109 Uniform::new("niri_geo_size", geo_size.to_array()),
@@ -118,7 +119,7 @@ impl OpenAnimation {
118 .into());119 .into());
119 }120 }
120 121
121- let elem = elem.with_alpha(clamped_progress as f32);122+ let elem = elem.with_alpha(clamped_progress as f32 * alpha);
122 123
123 let center = geo_size.to_point().downscale(2.);124 let center = geo_size.to_point().downscale(2.);
124 let elem = RescaleRenderElement::from_element(125 let elem = RescaleRenderElement::from_element(
src/layout/tile.rsmodified+54 -23
@@ -18,6 +18,7 @@ use crate::niri_render_elements;
18 use crate::render_helpers::border::BorderRenderElement;18 use crate::render_helpers::border::BorderRenderElement;
19 use crate::render_helpers::clipped_surface::{ClippedSurfaceRenderElement, RoundedCornerDamage};19 use crate::render_helpers::clipped_surface::{ClippedSurfaceRenderElement, RoundedCornerDamage};
20 use crate::render_helpers::damage::ExtraDamage;20 use crate::render_helpers::damage::ExtraDamage;
21+use crate::render_helpers::offscreen::{OffscreenBuffer, OffscreenRenderElement};
21 use crate::render_helpers::renderer::NiriRenderer;22 use crate::render_helpers::renderer::NiriRenderer;
22 use crate::render_helpers::resize::ResizeRenderElement;23 use crate::render_helpers::resize::ResizeRenderElement;
23 use crate::render_helpers::shadow::ShadowRenderElement;24 use crate::render_helpers::shadow::ShadowRenderElement;
@@ -86,7 +87,7 @@ pub struct Tile<W: LayoutElement> {
86 move_y_animation: Option<MoveAnimation>,87 move_y_animation: Option<MoveAnimation>,
87 88
88 /// The animation of the tile's opacity.89 /// The animation of the tile's opacity.
89- pub(super) alpha_animation: Option<Animation>,90+ pub(super) alpha_animation: Option<AlphaAnimation>,
90 91
91 /// Offset during the initial interactive move rubberband.92 /// Offset during the initial interactive move rubberband.
92 pub(super) interactive_move_offset: Point<f64, Logical>,93 pub(super) interactive_move_offset: Point<f64, Logical>,
@@ -122,6 +123,7 @@ niri_render_elements! {
122 Border = BorderRenderElement,123 Border = BorderRenderElement,
123 Shadow = ShadowRenderElement,124 Shadow = ShadowRenderElement,
124 ClippedSurface = ClippedSurfaceRenderElement<R>,125 ClippedSurface = ClippedSurfaceRenderElement<R>,
126+ Offscreen = OffscreenRenderElement,
125 ExtraDamage = ExtraDamage,127 ExtraDamage = ExtraDamage,
126 }128 }
127 }129 }
@@ -143,6 +145,12 @@ struct MoveAnimation {
143 from: f64,145 from: f64,
144 }146 }
145 147
148+#[derive(Debug)]
149+pub(super) struct AlphaAnimation {
150+ pub(super) anim: Animation,
151+ offscreen: OffscreenBuffer,
152+}
153+
146 impl<W: LayoutElement> Tile<W> {154 impl<W: LayoutElement> Tile<W> {
147 pub fn new(155 pub fn new(
148 window: W,156 window: W,
@@ -311,7 +319,7 @@ impl<W: LayoutElement> Tile<W> {
311 }319 }
312 320
313 if let Some(alpha) = &mut self.alpha_animation {321 if let Some(alpha) = &mut self.alpha_animation {
314- if alpha.is_done() {322+ if alpha.anim.is_done() {
315 self.alpha_animation = None;323 self.alpha_animation = None;
316 }324 }
317 }325 }
@@ -331,7 +339,6 @@ impl<W: LayoutElement> Tile<W> {
331 339
332 pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<f64, Logical>) {340 pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<f64, Logical>) {
333 let rules = self.window.rules();341 let rules = self.window.rules();
334- let alpha = self.tile_alpha();
335 342
336 let draw_border_with_background = rules343 let draw_border_with_background = rules
337 .draw_border_with_background344 .draw_border_with_background
@@ -356,7 +363,7 @@ impl<W: LayoutElement> Tile<W> {
356 ),363 ),
357 radius,364 radius,
358 self.scale,365 self.scale,
359- alpha,366+ 1.,
360 );367 );
361 368
362 let radius = if self.is_fullscreen {369 let radius = if self.is_fullscreen {
@@ -371,7 +378,7 @@ impl<W: LayoutElement> Tile<W> {
371 is_active,378 is_active,
372 radius,379 radius,
373 self.scale,380 self.scale,
374- alpha,381+ 1.,
375 );382 );
376 383
377 let draw_focus_ring_with_background = if self.effective_border_width().is_some() {384 let draw_focus_ring_with_background = if self.effective_border_width().is_some() {
@@ -387,7 +394,7 @@ impl<W: LayoutElement> Tile<W> {
387 view_rect,394 view_rect,
388 radius,395 radius,
389 self.scale,396 self.scale,
390- alpha,397+ 1.,
391 );398 );
392 }399 }
393 400
@@ -475,14 +482,22 @@ impl<W: LayoutElement> Tile<W> {
475 pub fn animate_alpha(&mut self, from: f64, to: f64, config: niri_config::Animation) {482 pub fn animate_alpha(&mut self, from: f64, to: f64, config: niri_config::Animation) {
476 let from = from.clamp(0., 1.);483 let from = from.clamp(0., 1.);
477 let to = to.clamp(0., 1.);484 let to = to.clamp(0., 1.);
478- let current = self.alpha_animation.take().map(|anim| anim.clamped_value());485+
479- let current = current.unwrap_or(from);486+ let (current, offscreen) = if let Some(alpha) = self.alpha_animation.take() {
480- self.alpha_animation = Some(Animation::new(self.clock.clone(), current, to, 0., config));487+ (alpha.anim.clamped_value(), alpha.offscreen)
488+ } else {
489+ (from, OffscreenBuffer::default())
490+ };
491+
492+ self.alpha_animation = Some(AlphaAnimation {
493+ anim: Animation::new(self.clock.clone(), current, to, 0., config),
494+ offscreen,
495+ });
481 }496 }
482 497
483 pub fn ensure_alpha_animates_to_1(&mut self) {498 pub fn ensure_alpha_animates_to_1(&mut self) {
484- if let Some(anim) = &self.alpha_animation {499+ if let Some(alpha) = &self.alpha_animation {
485- if anim.to() != 1. {500+ if alpha.anim.to() != 1. {
486 // Cancel animation instead of starting a new one because the user likely wants to501 // Cancel animation instead of starting a new one because the user likely wants to
487 // see the tile right away.502 // see the tile right away.
488 self.alpha_animation = None;503 self.alpha_animation = None;
@@ -490,13 +505,6 @@ impl<W: LayoutElement> Tile<W> {
490 }505 }
491 }506 }
492 507
493- /// Opacity that applies to both window and decorations.
494- fn tile_alpha(&self) -> f32 {
495- self.alpha_animation
496- .as_ref()
497- .map_or(1., |anim| anim.clamped_value()) as f32
498- }
499-
500 pub fn window(&self) -> &W {508 pub fn window(&self) -> &W {
501 &self.window509 &self.window
502 }510 }
@@ -802,9 +810,6 @@ impl<W: LayoutElement> Tile<W> {
802 self.window.rules().opacity.unwrap_or(1.).clamp(0., 1.)810 self.window.rules().opacity.unwrap_or(1.).clamp(0., 1.)
803 };811 };
804 812
805- let tile_alpha = self.tile_alpha();
806- let win_alpha = win_alpha * tile_alpha;
807-
808 // This is here rather than in render_offset() because render_offset() is currently assumed813 // This is here rather than in render_offset() because render_offset() is currently assumed
809 // by the code to be temporary. So, for example, interactive move will try to "grab" the814 // by the code to be temporary. So, for example, interactive move will try to "grab" the
810 // tile at its current render offset and reset the render offset to zero by cancelling the815 // tile at its current render offset and reset the render offset to zero by cancelling the
@@ -998,7 +1003,7 @@ impl<W: LayoutElement> Tile<W> {
998 SolidColorRenderElement::from_buffer(1003 SolidColorRenderElement::from_buffer(
999 &self.fullscreen_backdrop,1004 &self.fullscreen_backdrop,
1000 location,1005 location,
1001- tile_alpha,1006+ 1.,
1002 Kind::Unspecified,1007 Kind::Unspecified,
1003 )1008 )
1004 .into()1009 .into()
@@ -1028,7 +1033,13 @@ impl<W: LayoutElement> Tile<W> {
1028 ) -> impl Iterator<Item = TileRenderElement<R>> + 'a {1033 ) -> impl Iterator<Item = TileRenderElement<R>> + 'a {
1029 let _span = tracy_client::span!("Tile::render");1034 let _span = tracy_client::span!("Tile::render");
1030 1035
1036+ let tile_alpha = self
1037+ .alpha_animation
1038+ .as_ref()
1039+ .map_or(1., |alpha| alpha.anim.clamped_value()) as f32;
1040+
1031 let mut open_anim_elem = None;1041 let mut open_anim_elem = None;
1042+ let mut alpha_anim_elem = None;
1032 let mut window_elems = None;1043 let mut window_elems = None;
1033 1044
1034 if let Some(open) = &self.open_animation {1045 if let Some(open) = &self.open_animation {
@@ -1042,6 +1053,7 @@ impl<W: LayoutElement> Tile<W> {
1042 self.animated_tile_size(),1053 self.animated_tile_size(),
1043 location,1054 location,
1044 scale,1055 scale,
1056+ tile_alpha,
1045 ) {1057 ) {
1046 Ok(elem) => {1058 Ok(elem) => {
1047 self.window()1059 self.window()
@@ -1052,15 +1064,34 @@ impl<W: LayoutElement> Tile<W> {
1052 warn!("error rendering window opening animation: {err:?}");1064 warn!("error rendering window opening animation: {err:?}");
1053 }1065 }
1054 }1066 }
1067+ } else if let Some(alpha) = &self.alpha_animation {
1068+ let renderer = renderer.as_gles_renderer();
1069+ let elements =
1070+ self.render_inner(renderer, Point::from((0., 0.)), scale, focus_ring, target);
1071+ let elements = elements.collect::<Vec<TileRenderElement<_>>>();
1072+ match alpha.offscreen.render(renderer, scale, &elements) {
1073+ Ok((elem, _sync)) => {
1074+ let offset = elem.offset();
1075+ let elem = elem.with_alpha(tile_alpha).with_offset(location + offset);
1076+
1077+ self.window()
1078+ .set_offscreen_element_id(Some(elem.id().clone()));
1079+ alpha_anim_elem = Some(elem.into());
1080+ }
1081+ Err(err) => {
1082+ warn!("error rendering tile to offscreen for alpha animation: {err:?}");
1083+ }
1084+ }
1055 }1085 }
1056 1086
1057- if open_anim_elem.is_none() {1087+ if open_anim_elem.is_none() && alpha_anim_elem.is_none() {
1058 self.window().set_offscreen_element_id(None);1088 self.window().set_offscreen_element_id(None);
1059 window_elems = Some(self.render_inner(renderer, location, scale, focus_ring, target));1089 window_elems = Some(self.render_inner(renderer, location, scale, focus_ring, target));
1060 }1090 }
1061 1091
1062 open_anim_elem1092 open_anim_elem
1063 .into_iter()1093 .into_iter()
1094+ .chain(alpha_anim_elem)
1064 .chain(window_elems.into_iter().flatten())1095 .chain(window_elems.into_iter().flatten())
1065 }1096 }
1066 1097
src/layout/workspace.rsmodified+2 -1
@@ -1752,7 +1752,8 @@ impl<W: LayoutElement> Workspace<W> {
1752 assert_abs_diff_eq!(tile_pos.x, rounded_pos.x, epsilon = 1e-5);1752 assert_abs_diff_eq!(tile_pos.x, rounded_pos.x, epsilon = 1e-5);
1753 assert_abs_diff_eq!(tile_pos.y, rounded_pos.y, epsilon = 1e-5);1753 assert_abs_diff_eq!(tile_pos.y, rounded_pos.y, epsilon = 1e-5);
1754 1754
1755- if let Some(anim) = &tile.alpha_animation {1755+ if let Some(alpha) = &tile.alpha_animation {
1756+ let anim = &alpha.anim;
1756 if visible {1757 if visible {
1757 assert_eq!(anim.to(), 1., "visible tiles can animate alpha only to 1");1758 assert_eq!(anim.to(), 1., "visible tiles can animate alpha only to 1");
1758 }1759 }
src/render_helpers/offscreen.rsmodified+5 -0
@@ -206,6 +206,11 @@ impl OffscreenRenderElement {
206 self206 self
207 }207 }
208 208
209+ pub fn with_offset(mut self, offset: Point<f64, Logical>) -> Self {
210+ self.offset = offset;
211+ self
212+ }
213+
209 pub fn logical_size(&self) -> Size<f64, Logical> {214 pub fn logical_size(&self) -> Size<f64, Logical> {
210 self.src_size215 self.src_size
211 .to_f64()216 .to_f64()