Skip to content

Commit

Permalink
Add DocumentAnimationSet and AnimationSetKey
Browse files Browse the repository at this point in the history
This will be used in order to hold animations for pseudo elements in the
DocumentAnimationSet. Also no longer store the OpaqueNode in the
animation and transition data structures. This is already part of the
DocumentAnimationSet key.
  • Loading branch information
mrobinson committed Jun 15, 2020
1 parent 6b0d9af commit 4a3995b
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 162 deletions.
5 changes: 3 additions & 2 deletions components/layout_2020/flow/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use gfx_traits::print_tree::PrintTree;
use script_layout_interface::wrapper_traits::LayoutNode;
use script_layout_interface::{LayoutElementType, LayoutNodeType};
use servo_arc::Arc;
use style::animation::AnimationSetKey;
use style::dom::OpaqueNode;
use style::properties::ComputedValues;
use style::values::computed::Length;
Expand Down Expand Up @@ -446,10 +447,10 @@ impl FragmentTree {
})
}

pub fn remove_nodes_in_fragment_tree_from_set(&self, set: &mut FxHashSet<OpaqueNode>) {
pub fn remove_nodes_in_fragment_tree_from_set(&self, set: &mut FxHashSet<AnimationSetKey>) {
self.find(|fragment, _| {
if let Some(tag) = fragment.tag().as_ref() {
set.remove(&tag.node());
set.remove(&AnimationSetKey(tag.node()));
}
None::<()>
});
Expand Down
55 changes: 15 additions & 40 deletions components/layout_thread/dom_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ use std::fmt::Debug;
use std::hash::{Hash, Hasher};
use std::sync::atomic::Ordering;
use std::sync::Arc as StdArc;
use style::animation::AnimationSetKey;
use style::applicable_declarations::ApplicableDeclarationBlock;
use style::attr::AttrValue;
use style::context::SharedStyleContext;
Expand Down Expand Up @@ -474,20 +475,11 @@ impl<'le> TElement for ServoLayoutElement<'le> {
) -> Option<Arc<StyleLocked<PropertyDeclarationBlock>>> {
let node = self.as_node();
let document = node.owner_doc();
context
.animation_states
.read()
.get(&node.opaque())
.and_then(|set| {
set.get_value_map_for_active_animations(context.current_time_for_animations)
})
.map(|map| {
Arc::new(
document
.style_shared_lock()
.wrap(PropertyDeclarationBlock::from_animation_value_map(&map)),
)
})
context.animations.get_animation_declarations(
&AnimationSetKey(node.opaque()),
context.current_time_for_animations,
document.style_shared_lock(),
)
}

fn transition_rule(
Expand All @@ -496,20 +488,11 @@ impl<'le> TElement for ServoLayoutElement<'le> {
) -> Option<Arc<StyleLocked<PropertyDeclarationBlock>>> {
let node = self.as_node();
let document = node.owner_doc();
context
.animation_states
.read()
.get(&node.opaque())
.and_then(|set| {
set.get_value_map_for_active_transitions(context.current_time_for_animations)
})
.map(|map| {
Arc::new(
document
.style_shared_lock()
.wrap(PropertyDeclarationBlock::from_animation_value_map(&map)),
)
})
context.animations.get_transition_declarations(
&AnimationSetKey(node.opaque()),
context.current_time_for_animations,
document.style_shared_lock(),
)
}

fn state(&self) -> ElementState {
Expand Down Expand Up @@ -634,21 +617,13 @@ impl<'le> TElement for ServoLayoutElement<'le> {
}

fn has_css_animations(&self, context: &SharedStyleContext) -> bool {
context
.animation_states
.read()
.get(&self.as_node().opaque())
.map(|set| set.has_active_animation())
.unwrap_or(false)
let key = AnimationSetKey(self.as_node().opaque());
context.animations.has_active_animations(&key)
}

fn has_css_transitions(&self, context: &SharedStyleContext) -> bool {
context
.animation_states
.read()
.get(&self.as_node().opaque())
.map(|set| set.has_active_transition())
.unwrap_or(false)
let key = AnimationSetKey(self.as_node().opaque());
context.animations.has_active_transitions(&key)
}

#[inline]
Expand Down
24 changes: 13 additions & 11 deletions components/layout_thread/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use layout::context::malloc_size_of_persistent_local_context;
use layout::context::LayoutContext;
use layout::context::RegisteredPainter;
use layout::context::RegisteredPainters;
use layout::display_list::items::{OpaqueNode, WebRenderImageInfo};
use layout::display_list::items::WebRenderImageInfo;
use layout::display_list::{IndexableText, ToLayout};
use layout::flow::{Flow, GetBaseFlow, ImmutableFlowUtils, MutableOwnedFlowUtils};
use layout::flow_ref::FlowRef;
Expand Down Expand Up @@ -98,7 +98,7 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::{Arc, Mutex, MutexGuard};
use std::thread;
use std::time::Duration;
use style::animation::ElementAnimationSet;
use style::animation::{AnimationSetKey, DocumentAnimationSet, ElementAnimationSet};
use style::context::SharedStyleContext;
use style::context::{QuirksMode, RegisteredSpeculativePainter, RegisteredSpeculativePainters};
use style::dom::{ShowSubtree, ShowSubtreeDataAndPrimaryValues, TDocument, TElement, TNode};
Expand Down Expand Up @@ -604,7 +604,7 @@ impl LayoutThread {
snapshot_map: &'a SnapshotMap,
origin: ImmutableOrigin,
animation_timeline_value: f64,
animation_states: ServoArc<RwLock<FxHashMap<OpaqueNode, ElementAnimationSet>>>,
animations: &DocumentAnimationSet,
stylesheets_changed: bool,
) -> LayoutContext<'a> {
let traversal_flags = match stylesheets_changed {
Expand All @@ -620,7 +620,7 @@ impl LayoutThread {
options: GLOBAL_STYLE_DATA.options.clone(),
guards,
visited_styles_enabled: false,
animation_states,
animations: animations.clone(),
registered_speculative_painters: &self.registered_painters,
current_time_for_animations: animation_timeline_value,
traversal_flags,
Expand Down Expand Up @@ -1402,7 +1402,7 @@ impl LayoutThread {
&map,
origin,
data.animation_timeline_value,
data.animations.clone(),
&data.animations,
data.stylesheets_changed,
);

Expand Down Expand Up @@ -1643,24 +1643,26 @@ impl LayoutThread {
/// TODO(mrobinson): We should look into a way of doing this during flow tree construction.
/// This also doesn't yet handles nodes that have been reparented.
fn cancel_animations_for_nodes_not_in_flow_tree(
animation_states: &mut FxHashMap<OpaqueNode, ElementAnimationSet>,
animations: &mut FxHashMap<AnimationSetKey, ElementAnimationSet>,
root_flow: &mut dyn Flow,
) {
// Assume all nodes have been removed until proven otherwise.
let mut invalid_nodes: FxHashSet<OpaqueNode> = animation_states.keys().cloned().collect();
fn traverse_flow(flow: &mut dyn Flow, invalid_nodes: &mut FxHashSet<OpaqueNode>) {
let mut invalid_nodes = animations.keys().cloned().collect();

fn traverse_flow(flow: &mut dyn Flow, invalid_nodes: &mut FxHashSet<AnimationSetKey>) {
flow.mutate_fragments(&mut |fragment| {
invalid_nodes.remove(&fragment.node);
invalid_nodes.remove(&AnimationSetKey(fragment.node));
});
for kid in flow.mut_base().children.iter_mut() {
traverse_flow(kid, invalid_nodes)
}
}

traverse_flow(root_flow, &mut invalid_nodes);

// Cancel animations for any nodes that are no longer in the flow tree.
for node in &invalid_nodes {
if let Some(state) = animation_states.get_mut(node) {
if let Some(state) = animations.get_mut(node) {
state.cancel_all_animations();
}
}
Expand All @@ -1676,7 +1678,7 @@ impl LayoutThread {
context: &mut LayoutContext,
) {
Self::cancel_animations_for_nodes_not_in_flow_tree(
&mut *(context.style_context.animation_states.write()),
&mut *(context.style_context.animations.sets.write()),
FlowRef::deref_mut(root_flow),
);

Expand Down
55 changes: 15 additions & 40 deletions components/layout_thread_2020/dom_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ use std::fmt::Debug;
use std::hash::{Hash, Hasher};
use std::sync::atomic::Ordering;
use std::sync::Arc as StdArc;
use style::animation::AnimationSetKey;
use style::applicable_declarations::ApplicableDeclarationBlock;
use style::attr::AttrValue;
use style::context::SharedStyleContext;
Expand Down Expand Up @@ -482,20 +483,11 @@ impl<'le> TElement for ServoLayoutElement<'le> {
) -> Option<Arc<StyleLocked<PropertyDeclarationBlock>>> {
let node = self.as_node();
let document = node.owner_doc();
context
.animation_states
.read()
.get(&node.opaque())
.and_then(|set| {
set.get_value_map_for_active_animations(context.current_time_for_animations)
})
.map(|map| {
Arc::new(
document
.style_shared_lock()
.wrap(PropertyDeclarationBlock::from_animation_value_map(&map)),
)
})
context.animations.get_animation_declarations(
&AnimationSetKey(node.opaque()),
context.current_time_for_animations,
document.style_shared_lock(),
)
}

fn transition_rule(
Expand All @@ -504,20 +496,11 @@ impl<'le> TElement for ServoLayoutElement<'le> {
) -> Option<Arc<StyleLocked<PropertyDeclarationBlock>>> {
let node = self.as_node();
let document = node.owner_doc();
context
.animation_states
.read()
.get(&node.opaque())
.and_then(|set| {
set.get_value_map_for_active_transitions(context.current_time_for_animations)
})
.map(|map| {
Arc::new(
document
.style_shared_lock()
.wrap(PropertyDeclarationBlock::from_animation_value_map(&map)),
)
})
context.animations.get_transition_declarations(
&AnimationSetKey(node.opaque()),
context.current_time_for_animations,
document.style_shared_lock(),
)
}

fn state(&self) -> ElementState {
Expand Down Expand Up @@ -642,21 +625,13 @@ impl<'le> TElement for ServoLayoutElement<'le> {
}

fn has_css_animations(&self, context: &SharedStyleContext) -> bool {
context
.animation_states
.read()
.get(&self.as_node().opaque())
.map(|set| set.has_active_animation())
.unwrap_or(false)
let key = AnimationSetKey(self.as_node().opaque());
context.animations.has_active_animations(&key)
}

fn has_css_transitions(&self, context: &SharedStyleContext) -> bool {
context
.animation_states
.read()
.get(&self.as_node().opaque())
.map(|set| set.has_active_transition())
.unwrap_or(false)
let key = AnimationSetKey(self.as_node().opaque());
context.animations.has_active_transitions(&key)
}

#[inline]
Expand Down
20 changes: 10 additions & 10 deletions components/layout_thread_2020/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crossbeam_channel::{Receiver, Sender};
use embedder_traits::resources::{self, Resource};
use euclid::{default::Size2D as UntypedSize2D, Point2D, Rect, Scale, Size2D};
use fnv::FnvHashMap;
use fxhash::{FxHashMap, FxHashSet};
use fxhash::FxHashMap;
use gfx::font_cache_thread::FontCacheThread;
use gfx::font_context;
use gfx_traits::{node_id_from_scroll_id, Epoch};
Expand Down Expand Up @@ -81,11 +81,10 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::{Arc, Mutex, MutexGuard};
use std::thread;
use std::time::Duration;
use style::animation::ElementAnimationSet;
use style::animation::DocumentAnimationSet;
use style::context::{
QuirksMode, RegisteredSpeculativePainter, RegisteredSpeculativePainters, SharedStyleContext,
};
use style::dom::OpaqueNode;
use style::dom::{TDocument, TElement, TNode};
use style::driver;
use style::error_reporting::RustLogReporter;
Expand Down Expand Up @@ -568,7 +567,7 @@ impl LayoutThread {
snapshot_map: &'a SnapshotMap,
origin: ImmutableOrigin,
animation_timeline_value: f64,
animation_states: ServoArc<RwLock<FxHashMap<OpaqueNode, ElementAnimationSet>>>,
animations: &DocumentAnimationSet,
stylesheets_changed: bool,
) -> LayoutContext<'a> {
let traversal_flags = match stylesheets_changed {
Expand All @@ -584,7 +583,7 @@ impl LayoutThread {
options: GLOBAL_STYLE_DATA.options.clone(),
guards,
visited_styles_enabled: false,
animation_states,
animations: animations.clone(),
registered_speculative_painters: &self.registered_painters,
current_time_for_animations: animation_timeline_value,
traversal_flags,
Expand Down Expand Up @@ -1065,7 +1064,7 @@ impl LayoutThread {
&map,
origin,
data.animation_timeline_value,
data.animations.clone(),
&data.animations,
data.stylesheets_changed,
);

Expand Down Expand Up @@ -1292,7 +1291,7 @@ impl LayoutThread {
context: &mut LayoutContext,
) {
Self::cancel_animations_for_nodes_not_in_fragment_tree(
&mut *(context.style_context.animation_states.write()),
&context.style_context.animations,
&fragment_tree,
);

Expand Down Expand Up @@ -1380,16 +1379,17 @@ impl LayoutThread {
/// TODO(mrobinson): We should look into a way of doing this during flow tree construction.
/// This also doesn't yet handles nodes that have been reparented.
fn cancel_animations_for_nodes_not_in_fragment_tree(
animation_states: &mut FxHashMap<OpaqueNode, ElementAnimationSet>,
animations: &DocumentAnimationSet,
root: &FragmentTree,
) {
// Assume all nodes have been removed until proven otherwise.
let mut invalid_nodes: FxHashSet<OpaqueNode> = animation_states.keys().cloned().collect();
let mut animations = animations.sets.write();
let mut invalid_nodes = animations.keys().cloned().collect();
root.remove_nodes_in_fragment_tree_from_set(&mut invalid_nodes);

// Cancel animations for any nodes that are no longer in the fragment tree.
for node in &invalid_nodes {
if let Some(state) = animation_states.get_mut(node) {
if let Some(state) = animations.get_mut(node) {
state.cancel_all_animations();
}
}
Expand Down
Loading

0 comments on commit 4a3995b

Please sign in to comment.