Animation: Aggregate Animated Image Info to Document (#36141)

Signed-off-by: rayguo17 <rayguo17@gmail.com>
This commit is contained in:
TIN TUN AUNG 2025-03-29 07:19:49 +08:00 committed by GitHub
parent 53f7c7b1de
commit ed3dd8fbe0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 145 additions and 9 deletions

View file

@ -199,6 +199,7 @@ use crate::dom::xpathevaluator::XPathEvaluator;
use crate::drag_data_store::{DragDataStore, Kind, Mode};
use crate::fetch::FetchCanceller;
use crate::iframe_collection::IFrameCollection;
use crate::image_animation::ImageAnimationManager;
use crate::messaging::{CommonScriptMsg, MainThreadScriptMsg};
use crate::network_listener::{NetworkListener, PreInvoke};
use crate::realms::{AlreadyInRealm, InRealm, enter_realm};
@ -484,6 +485,8 @@ pub(crate) struct Document {
animation_timeline: DomRefCell<AnimationTimeline>,
/// Animations for this Document
animations: DomRefCell<Animations>,
/// Image Animation Manager for this Document
image_animation_manager: DomRefCell<ImageAnimationManager>,
/// The nearest inclusive ancestors to all the nodes that require a restyle.
dirty_root: MutNullableDom<Element>,
/// <https://html.spec.whatwg.org/multipage/#will-declaratively-refresh>
@ -3877,6 +3880,7 @@ impl Document {
DomRefCell::new(AnimationTimeline::new())
},
animations: DomRefCell::new(Animations::new()),
image_animation_manager: DomRefCell::new(ImageAnimationManager::new()),
dirty_root: Default::default(),
declarative_refresh: Default::default(),
pending_animation_ticks: Default::default(),
@ -4715,6 +4719,13 @@ impl Document {
self.animations().send_pending_events(self.window(), can_gc);
}
pub(crate) fn image_animation_manager(&self) -> Ref<ImageAnimationManager> {
self.image_animation_manager.borrow()
}
pub(crate) fn image_animation_manager_mut(&self) -> RefMut<ImageAnimationManager> {
self.image_animation_manager.borrow_mut()
}
pub(crate) fn will_declaratively_refresh(&self) -> bool {
self.declarative_refresh.borrow().is_some()
}

View file

@ -1967,6 +1967,9 @@ impl Window {
pending_restyles,
animation_timeline_value: document.current_animation_timeline_value(),
animations: document.animations().sets.clone(),
node_to_image_animation_map: document
.image_animation_manager_mut()
.take_image_animate_set(),
theme: self.theme.get(),
};
@ -2017,7 +2020,9 @@ impl Window {
if !size_messages.is_empty() {
self.send_to_constellation(ScriptMsg::IFrameSizes(size_messages));
}
document
.image_animation_manager_mut()
.restore_image_animate_set(results.node_to_image_animation_map);
document.update_animations_post_reflow();
self.update_constellation_epoch();

View file

@ -0,0 +1,29 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use fxhash::FxHashMap;
use script_layout_interface::ImageAnimationState;
use style::dom::OpaqueNode;
#[derive(Clone, Debug, Default, JSTraceable, MallocSizeOf)]
pub struct ImageAnimationManager {
#[no_trace]
pub node_to_image_map: FxHashMap<OpaqueNode, ImageAnimationState>,
}
impl ImageAnimationManager {
pub fn new() -> Self {
ImageAnimationManager {
node_to_image_map: Default::default(),
}
}
pub fn take_image_animate_set(&mut self) -> FxHashMap<OpaqueNode, ImageAnimationState> {
std::mem::take(&mut self.node_to_image_map)
}
pub fn restore_image_animate_set(&mut self, map: FxHashMap<OpaqueNode, ImageAnimationState>) {
let _ = std::mem::replace(&mut self.node_to_image_map, map);
}
}

View file

@ -43,6 +43,7 @@ mod layout_image;
pub(crate) mod document_collection;
pub(crate) mod iframe_collection;
pub(crate) mod image_animation;
pub mod layout_dom;
mod mem;
#[allow(unsafe_code)]