diff options
author | TIN TUN AUNG <62133983+rayguo17@users.noreply.github.com> | 2025-05-23 11:13:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-23 03:13:35 +0000 |
commit | 23ce7b31ac3b3257c3b604a15b92b85d2baf26ce (patch) | |
tree | acfba0c6631dcf5bc579b4d291c30bad2bc40663 /components/script/dom | |
parent | 2353c0089febdc067fe306db846245c7bcb52684 (diff) | |
download | servo-23ce7b31ac3b3257c3b604a15b92b85d2baf26ce.tar.gz servo-23ce7b31ac3b3257c3b604a15b92b85d2baf26ce.zip |
Animation: update image active frame when update the rendering (#36286)
When no CSS animation exist, register timer for image animation, update
animated image active image frame as part of update_the_rendering, mark
node as dirty if the corresponding image need update. Added unit test to
test ImageAnimationState.
Part of https://github.com/servo/servo/issues/36057, the last step to
let the Animated Image "Move".
Testing: Introduced new WPT RefTest for animated image, but fail because
of https://github.com/servo/servo/issues/36931. New unit test for
`ImageAnimationState`.
Fixes: https://github.com/servo/servo/issues/22903
https://github.com/servo/servo/issues/36057
[Try](https://github.com/rayguo17/servo/actions/runs/14724729664)
---------
Signed-off-by: rayguo17 <rayguo17@gmail.com>
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/document.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 78cb2c33075..6056f1f1e5a 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -5051,6 +5051,35 @@ impl Document { self.image_animation_manager.borrow_mut() } + pub(crate) fn update_animating_images(&self) { + let mut image_animation_manager = self.image_animation_manager.borrow_mut(); + if !image_animation_manager.image_animations_present() { + return; + } + image_animation_manager + .update_active_frames(&self.window, self.current_animation_timeline_value()); + + if !self.animations().animations_present() { + let next_scheduled_time = + image_animation_manager.next_schedule_time(self.current_animation_timeline_value()); + // TODO: Once we have refresh signal from the compositor, + // we should get rid of timer for animated image update. + if let Some(next_scheduled_time) = next_scheduled_time { + self.schedule_image_animation_update(next_scheduled_time); + } + } + } + + fn schedule_image_animation_update(&self, next_scheduled_time: f64) { + let callback = ImageAnimationUpdateCallback { + document: Trusted::new(self), + }; + self.global().schedule_callback( + OneshotTimerCallback::ImageAnimationUpdate(callback), + Duration::from_secs_f64(next_scheduled_time), + ); + } + /// <https://html.spec.whatwg.org/multipage/#shared-declarative-refresh-steps> pub(crate) fn shared_declarative_refresh_steps(&self, content: &[u8]) { // 1. If document's will declaratively refresh is true, then return. @@ -6747,6 +6776,21 @@ impl FakeRequestAnimationFrameCallback { } } +/// This is a temporary workaround to update animated images, +/// we should get rid of this after we have refresh driver #3406 +#[derive(JSTraceable, MallocSizeOf)] +pub(crate) struct ImageAnimationUpdateCallback { + /// The document. + #[ignore_malloc_size_of = "non-owning"] + document: Trusted<Document>, +} + +impl ImageAnimationUpdateCallback { + pub(crate) fn invoke(self, can_gc: CanGc) { + with_script_thread(|script_thread| script_thread.update_the_rendering(true, can_gc)) + } +} + #[derive(JSTraceable, MallocSizeOf)] pub(crate) enum AnimationFrameCallback { DevtoolsFramerateTick { |