Skip to content

Commit

Permalink
Cache animation computed values when animations change
Browse files Browse the repository at this point in the history
Instead of recalculating the animation style every tick of an animation,
cache the computed values when animations change. In addition to being
more efficient, this will allow us to return animation rules as property
declarations because we don't need to consult the final style to produce
them.
  • Loading branch information
mrobinson committed Jun 5, 2020
1 parent 7df4655 commit 83fa1b9
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 170 deletions.
9 changes: 7 additions & 2 deletions components/layout_thread/dom_wrapper.rs
Expand Up @@ -584,8 +584,13 @@ impl<'le> TElement for ServoLayoutElement<'le> {
false
}

fn has_css_animations(&self) -> bool {
unreachable!("this should be only called on gecko");
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)
}

fn has_css_transitions(&self) -> bool {
Expand Down
9 changes: 8 additions & 1 deletion components/layout_thread/lib.rs
Expand Up @@ -610,7 +610,13 @@ impl LayoutThread {
origin: ImmutableOrigin,
animation_timeline_value: f64,
animation_states: ServoArc<RwLock<FxHashMap<OpaqueNode, ElementAnimationSet>>>,
stylesheets_changed: bool,
) -> LayoutContext<'a> {
let traversal_flags = match stylesheets_changed {
true => TraversalFlags::ForCSSRuleChanges,
false => TraversalFlags::empty(),
};

LayoutContext {
id: self.id,
origin,
Expand All @@ -622,7 +628,7 @@ impl LayoutThread {
animation_states,
registered_speculative_painters: &self.registered_painters,
current_time_for_animations: animation_timeline_value,
traversal_flags: TraversalFlags::empty(),
traversal_flags,
snapshot_map: snapshot_map,
},
image_cache: self.image_cache.clone(),
Expand Down Expand Up @@ -1405,6 +1411,7 @@ impl LayoutThread {
origin,
data.animation_timeline_value,
data.animations.clone(),
data.stylesheets_changed,
);

let pool;
Expand Down
9 changes: 7 additions & 2 deletions components/layout_thread_2020/dom_wrapper.rs
Expand Up @@ -592,8 +592,13 @@ impl<'le> TElement for ServoLayoutElement<'le> {
false
}

fn has_css_animations(&self) -> bool {
unreachable!("this should be only called on gecko");
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)
}

fn has_css_transitions(&self) -> bool {
Expand Down
9 changes: 8 additions & 1 deletion components/layout_thread_2020/lib.rs
Expand Up @@ -574,7 +574,13 @@ impl LayoutThread {
origin: ImmutableOrigin,
animation_timeline_value: f64,
animation_states: ServoArc<RwLock<FxHashMap<OpaqueNode, ElementAnimationSet>>>,
stylesheets_changed: bool,
) -> LayoutContext<'a> {
let traversal_flags = match stylesheets_changed {
true => TraversalFlags::ForCSSRuleChanges,
false => TraversalFlags::empty(),
};

LayoutContext {
id: self.id,
origin,
Expand All @@ -586,7 +592,7 @@ impl LayoutThread {
animation_states,
registered_speculative_painters: &self.registered_painters,
current_time_for_animations: animation_timeline_value,
traversal_flags: TraversalFlags::empty(),
traversal_flags,
snapshot_map: snapshot_map,
},
image_cache: self.image_cache.clone(),
Expand Down Expand Up @@ -1064,6 +1070,7 @@ impl LayoutThread {
origin,
data.animation_timeline_value,
data.animations.clone(),
data.stylesheets_changed,
);

let dirty_root = unsafe {
Expand Down

0 comments on commit 83fa1b9

Please sign in to comment.