Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to animation keyframe computation #26562

Merged
merged 2 commits into from Jun 5, 2020

Conversation

@mrobinson
Copy link
Member

mrobinson commented May 18, 2020

This pull request contains two changes:

Caching computed keyframes between animation changes:
Instead of recomputing keyframe data for 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.

Better computation of keyframe data:
Instead of naively using apply_declarations to compute the style of
each keyframe, use an approach more like Gecko's where we carefully
walk through the animation keyframes and try to extract AnimationValues
for each computed keyframe. In this approach we respect the order with
which the properties are set in the keyframe source and try to deal with
CSS custom properties.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • There are tests for these changes.
@mrobinson mrobinson requested a review from emilio May 18, 2020
@highfive
Copy link

highfive commented May 18, 2020

Heads up! This PR modifies the following files:

  • @emilio: components/style/properties/properties.mako.rs, components/style/animation.rs, components/style/matching.rs
@highfive
Copy link

highfive commented May 18, 2020

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!
@mrobinson
Copy link
Member Author

mrobinson commented May 18, 2020

@bors-servo try=wpt

bors-servo added a commit that referenced this pull request May 18, 2020
Cache animation computed values when animations change

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.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes do not require tests because they should not change behavior.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
@bors-servo
Copy link
Contributor

bors-servo commented May 18, 2020

Trying commit f4b736a with merge b6c8424...

@bors-servo
Copy link
Contributor

bors-servo commented May 18, 2020

☀️ Test successful - status-taskcluster
State: approved= try=True

@mrobinson mrobinson force-pushed the mrobinson:reanimator-style branch from f4b736a to 7a37a1f May 19, 2020
@bors-servo
Copy link
Contributor

bors-servo commented May 19, 2020

The latest upstream changes (presumably #26486) made this pull request unmergeable. Please resolve the merge conflicts.

@mrobinson mrobinson force-pushed the mrobinson:reanimator-style branch from 7a37a1f to 21e1c4e May 21, 2020
@mrobinson mrobinson force-pushed the mrobinson:reanimator-style branch from 21e1c4e to 84242d6 May 29, 2020
@mrobinson mrobinson changed the title Cache animation computed values when animations change Improvements to animation keyframe computation May 29, 2020
@mrobinson
Copy link
Member Author

mrobinson commented May 29, 2020

I've added a closely related change to this PR which improves the computation of keyframe data and ditches Servo's use of apply_declarations for this.

@mrobinson mrobinson changed the title Improvements to animation keyframe computation [WIP] Improvements to animation keyframe computation May 29, 2020
@mrobinson
Copy link
Member Author

mrobinson commented May 29, 2020

This needs a little bit more work.

@jdm
Copy link
Member

jdm commented May 29, 2020

I read through 9173503 and it looks sensible.

@mrobinson mrobinson force-pushed the mrobinson:reanimator-style branch from 84242d6 to b208d04 May 30, 2020
@mrobinson
Copy link
Member Author

mrobinson commented May 30, 2020

@jdm Thanks for looking at the first commit. That should be unchanged in the newest version of the branch. The second commit is unfortunately a bit large, which means it's probably harder to review. I wasn't sure how to split it into simpler chunks. 😕 I'm happy to walk through it with anyone or do whatever else is necessary to make it easier to review.

@mrobinson
Copy link
Member Author

mrobinson commented May 30, 2020

@bors-servo try=wpt

@bors-servo
Copy link
Contributor

bors-servo commented May 30, 2020

Trying commit b208d04 with merge 643a386...

bors-servo added a commit that referenced this pull request May 30, 2020
[WIP] Improvements to animation keyframe computation

This pull request contains two changes:

**Caching computed keyframes between animation changes**:
Instead of recomputing keyframe data for 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.

**Better computation of keyframe data**:
Instead of naively using `apply_declarations` to compute the style of
each keyframe, use an approach more like Gecko's where we carefully
walk through the animation keyframes and try to extract `AnimationValue`s
for each computed keyframe. In this approach we respect the order with
which the properties are set in the keyframe source.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes do not require tests because they should not change behavior.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
@mrobinson mrobinson changed the title [WIP] Improvements to animation keyframe computation Improvements to animation keyframe computation May 30, 2020
@bors-servo
Copy link
Contributor

bors-servo commented May 30, 2020

💔 Test failed - status-taskcluster

@mrobinson mrobinson force-pushed the mrobinson:reanimator-style branch from b208d04 to 4307b63 May 30, 2020
@mrobinson
Copy link
Member Author

mrobinson commented May 30, 2020

@bors-servo try=wpt

@mrobinson
Copy link
Member Author

mrobinson commented Jun 1, 2020

@bors-servo try=wpt-2020

@jdm
Copy link
Member

jdm commented Jun 1, 2020

@bors-servo retry

@bors-servo
Copy link
Contributor

bors-servo commented Jun 1, 2020

Trying commit 4307b63 with merge d22fd6c...

bors-servo added a commit that referenced this pull request Jun 1, 2020
Improvements to animation keyframe computation

This pull request contains two changes:

**Caching computed keyframes between animation changes**:
Instead of recomputing keyframe data for 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.

**Better computation of keyframe data**:
Instead of naively using `apply_declarations` to compute the style of
each keyframe, use an approach more like Gecko's where we carefully
walk through the animation keyframes and try to extract `AnimationValue`s
for each computed keyframe. In this approach we respect the order with
which the properties are set in the keyframe source and try to deal with
CSS custom properties.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] There are tests for these changes.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 1, 2020

☀️ Test successful - status-taskcluster
State: approved= try=True

@jdm
jdm approved these changes Jun 4, 2020
Copy link
Member

jdm left a comment

These changes look sensible to me.

for (index, from) in prev_keyframe.values.iter().enumerate() {
PropertyAnimation {
from,
to,
from: from.clone(),
to: next_keyframe.values[index].clone(),
Comment on lines 712 to 715

This comment has been minimized.

Copy link
@jdm

jdm Jun 4, 2020

Member

Is there any benefit to writing this as:

for (from, to) in prev_keyframe.values.iter().zip(next_keyframe.values.iter()) {
    PropertyAnimation {
        from: from.clone(),
        to: to.clone(),
        ...
    }
    ...
}

This comment has been minimized.

Copy link
@mrobinson

mrobinson Jun 5, 2020

Author Member

Your suggestion is a lot clearer.

@emilio
emilio approved these changes Jun 4, 2020
Copy link
Member

emilio left a comment

Yeah, nice progression :)

self.timing_function = Some(timing_function.to_computed_value_without_context());
}

match step.value {

This comment has been minimized.

Copy link
@emilio

emilio Jun 4, 2020

Member

Maybe let block = match setep.value { ... };, then de-indent the rest?

This comment has been minimized.

Copy link
@mrobinson

mrobinson Jun 5, 2020

Author Member

👍

&mut self,
step: &KeyframesStep,
context: &SharedStyleContext,
base_style: &Arc<ComputedValues>,

This comment has been minimized.

Copy link
@emilio

emilio Jun 4, 2020

Member

I think this can just be &ComputedValues, and same in the caller.

This comment has been minimized.

Copy link
@mrobinson

mrobinson Jun 5, 2020

Author Member

Oh, nice.

mrobinson added 2 commits May 18, 2020
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.
This begins to address #26625 by properly applying CSS variables during
keyframe computation and no longer using `apply_declarations`. Instead,
walk the declarations, combining them into IntermediateComputedKeyframe,
maintaining declarations that modify CSS custom properties. Then compute
a set of AnimationValues for each keyframe and use those to produce
interpolated animation values.
@mrobinson mrobinson force-pushed the mrobinson:reanimator-style branch from 4307b63 to b875f14 Jun 5, 2020
@mrobinson
Copy link
Member Author

mrobinson commented Jun 5, 2020

@bors-servo r=jdm,emilio

Thank you both for the reviews!

@bors-servo
Copy link
Contributor

bors-servo commented Jun 5, 2020

📌 Commit b875f14 has been approved by jdm,emilio

@bors-servo
Copy link
Contributor

bors-servo commented Jun 5, 2020

Testing commit b875f14 with merge ec49ebb...

@bors-servo
Copy link
Contributor

bors-servo commented Jun 5, 2020

☀️ Test successful - status-taskcluster
Approved by: jdm,emilio
Pushing ec49ebb to master...

@bors-servo bors-servo merged commit ec49ebb into servo:master Jun 5, 2020
2 checks passed
2 checks passed
Community-TC (pull_request) TaskGroup: success
Details
homu Test successful
Details
@mrobinson mrobinson deleted the mrobinson:reanimator-style branch Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.