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

@ -24,7 +24,7 @@ use euclid::{Point2D, Scale, Size2D, Vector2D};
use fnv::FnvHashMap;
use fonts::{FontContext, FontContextWebFontMethods};
use fonts_traits::StylesheetWebFontLoadFinishedCallback;
use fxhash::FxHashMap;
use fxhash::{FxHashMap, FxHashSet};
use ipc_channel::ipc::IpcSender;
use layout::context::LayoutContext;
use layout::display_list::{DisplayList, WebRenderImageInfo};
@ -46,15 +46,15 @@ use profile_traits::time::{
use profile_traits::{path, time_profile};
use script::layout_dom::{ServoLayoutElement, ServoLayoutNode};
use script_layout_interface::{
Layout, LayoutConfig, LayoutFactory, NodesFromPointQueryType, OffsetParentResponse, ReflowGoal,
ReflowRequest, ReflowResult, TrustedNodeAddress,
ImageAnimationState, Layout, LayoutConfig, LayoutFactory, NodesFromPointQueryType,
OffsetParentResponse, ReflowGoal, ReflowRequest, ReflowResult, TrustedNodeAddress,
};
use script_traits::{DrawAPaintImageResult, PaintWorkletError, Painter, ScriptThreadMessage};
use servo_arc::Arc as ServoArc;
use servo_config::opts::{self, DebugOptions};
use servo_config::pref;
use servo_url::ServoUrl;
use style::animation::DocumentAnimationSet;
use style::animation::{AnimationSetKey, DocumentAnimationSet};
use style::context::{
QuirksMode, RegisteredSpeculativePainter, RegisteredSpeculativePainters, SharedStyleContext,
};
@ -536,7 +536,7 @@ impl LayoutThread {
&'a self,
guards: StylesheetGuards<'a>,
snapshot_map: &'a SnapshotMap,
reflow_request: &ReflowRequest,
reflow_request: &mut ReflowRequest,
use_rayon: bool,
) -> LayoutContext<'a> {
let traversal_flags = match reflow_request.stylesheets_changed {
@ -558,6 +558,9 @@ impl LayoutThread {
font_context: self.font_context.clone(),
webrender_image_cache: self.webrender_image_cache.clone(),
pending_images: Mutex::default(),
node_image_animation_map: Arc::new(RwLock::new(std::mem::take(
&mut reflow_request.node_to_image_animation_map,
))),
iframe_sizes: Mutex::default(),
use_rayon,
}
@ -696,8 +699,12 @@ impl LayoutThread {
let rayon_pool = rayon_pool.as_ref();
// Create a layout context for use throughout the following passes.
let mut layout_context =
self.build_layout_context(guards.clone(), &map, &reflow_request, rayon_pool.is_some());
let mut layout_context = self.build_layout_context(
guards.clone(),
&map,
&mut reflow_request,
rayon_pool.is_some(),
);
let dirty_root = unsafe {
ServoLayoutNode::new(&reflow_request.dirty_root.unwrap())
@ -791,9 +798,12 @@ impl LayoutThread {
let pending_images = std::mem::take(&mut *layout_context.pending_images.lock());
let iframe_sizes = std::mem::take(&mut *layout_context.iframe_sizes.lock());
let node_to_image_animation_map =
std::mem::take(&mut *layout_context.node_image_animation_map.write());
Some(ReflowResult {
pending_images,
iframe_sizes,
node_to_image_animation_map,
})
}
@ -821,6 +831,11 @@ impl LayoutThread {
&fragment_tree,
);
Self::cancel_image_animation_for_nodes_not_in_fragment_tree(
context.node_image_animation_map.clone(),
&fragment_tree,
);
if !reflow_goal.needs_display_list() {
return;
}
@ -920,6 +935,22 @@ impl LayoutThread {
}
}
fn cancel_image_animation_for_nodes_not_in_fragment_tree(
image_animation_set: Arc<RwLock<FxHashMap<OpaqueNode, ImageAnimationState>>>,
root: &FragmentTree,
) {
let mut image_animations = image_animation_set.write().to_owned();
let mut invalid_nodes: FxHashSet<AnimationSetKey> = image_animations
.keys()
.cloned()
.map(|node| AnimationSetKey::new(node, None))
.collect();
root.remove_nodes_in_fragment_tree_from_set(&mut invalid_nodes);
for node in &invalid_nodes {
image_animations.remove(&node.node);
}
}
fn viewport_did_change(&mut self, window_size_data: WindowSizeData) -> bool {
let new_pixel_ratio = window_size_data.device_pixel_ratio.get();
let new_viewport_size = Size2D::new(