aboutsummaryrefslogtreecommitdiff
path: root/src/ui/screen_transition.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-11-24 09:41:43 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2024-11-25 04:07:59 -0800
commit4c22c3285d8b10fbcef1c45a0788c3ddca03ec62 (patch)
tree506174fe9962a91598ac25d4d2dee1cdaa3d5292 /src/ui/screen_transition.rs
parent93cee2994ab9ccf59a09f61d5b8acf6cd937d654 (diff)
downloadniri-4c22c3285d8b10fbcef1c45a0788c3ddca03ec62.tar.gz
niri-4c22c3285d8b10fbcef1c45a0788c3ddca03ec62.tar.bz2
niri-4c22c3285d8b10fbcef1c45a0788c3ddca03ec62.zip
Refactor animation timing to use lazy clocks
Diffstat (limited to 'src/ui/screen_transition.rs')
-rw-r--r--src/ui/screen_transition.rs40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/ui/screen_transition.rs b/src/ui/screen_transition.rs
index 3b5c2159..7d26f85f 100644
--- a/src/ui/screen_transition.rs
+++ b/src/ui/screen_transition.rs
@@ -4,6 +4,7 @@ use smithay::backend::renderer::element::Kind;
use smithay::backend::renderer::gles::GlesTexture;
use smithay::utils::{Scale, Transform};
+use crate::animation::Clock;
use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement};
use crate::render_helpers::RenderTarget;
@@ -17,31 +18,25 @@ pub struct ScreenTransition {
from_texture: [TextureBuffer<GlesTexture>; 3],
/// Monotonic time when to start the crossfade.
start_at: Duration,
- /// Current crossfade alpha.
- alpha: f32,
+ /// Clock to drive animations.
+ clock: Clock,
}
impl ScreenTransition {
- pub fn new(from_texture: [TextureBuffer<GlesTexture>; 3], start_at: Duration) -> Self {
+ pub fn new(
+ from_texture: [TextureBuffer<GlesTexture>; 3],
+ delay: Duration,
+ clock: Clock,
+ ) -> Self {
Self {
from_texture,
- start_at,
- alpha: 1.,
- }
- }
-
- pub fn advance_animations(&mut self, current_time: Duration) {
- if self.start_at + DURATION <= current_time {
- self.alpha = 0.;
- } else if self.start_at <= current_time {
- self.alpha = 1. - (current_time - self.start_at).as_secs_f32() / DURATION.as_secs_f32();
- } else {
- self.alpha = 1.;
+ start_at: clock.now_unadjusted() + delay,
+ clock,
}
}
pub fn is_done(&self) -> bool {
- self.alpha == 0.
+ self.start_at + DURATION <= self.clock.now_unadjusted()
}
pub fn update_render_elements(&mut self, scale: Scale<f64>, transform: Transform) {
@@ -53,6 +48,17 @@ impl ScreenTransition {
}
pub fn render(&self, target: RenderTarget) -> PrimaryGpuTextureRenderElement {
+ // Screen transition ignores animation slowdown.
+ let now = self.clock.now_unadjusted();
+
+ let alpha = if self.start_at + DURATION <= now {
+ 0.
+ } else if self.start_at <= now {
+ 1. - (now - self.start_at).as_secs_f32() / DURATION.as_secs_f32()
+ } else {
+ 1.
+ };
+
let idx = match target {
RenderTarget::Output => 0,
RenderTarget::Screencast => 1,
@@ -62,7 +68,7 @@ impl ScreenTransition {
PrimaryGpuTextureRenderElement(TextureRenderElement::from_texture_buffer(
self.from_texture[idx].clone(),
(0., 0.),
- self.alpha,
+ alpha,
None,
None,
Kind::Unspecified,