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

Split `running_animations` into two lists, one for keyframes and one for transitions #14419

Closed
notriddle opened this issue Nov 30, 2016 · 5 comments
Closed

Comments

@notriddle
Copy link
Contributor

@notriddle notriddle commented Nov 30, 2016

Instead of this:

#[derive(Clone, Debug)]
pub enum Animation {
    Transition(OpaqueNode, UnsafeNode, f64, AnimationFrame, bool),
    Keyframes(OpaqueNode, Atom, KeyframesAnimationState),
}

// ...

pub fn update_animation_state(constellation_chan: &IpcSender<ConstellationMsg>,
                              script_chan: &IpcSender<ConstellationControlMsg>,
                              running_animations: &mut HashMap<OpaqueNode, Vec<Animation>>,
                              expired_animations: &mut HashMap<OpaqueNode, Vec<Animation>>,
                              new_animations_receiver: &Receiver<Animation>,
                              pipeline_id: PipelineId,
                              timer: &Timer) {

The data should be defined like this:

#[derive(Clone, Debug)]
pub enum Animation {
    Transition(TransitionAnimation),
    Keyframes(KeyframesAnimation),
}
#[derive(Clone, Debug)]
pub struct TransitionAnimation {
    opaque: OpaqueNode,
    node: UnsafeNode,
    start_time: f64,
    frame: AnimationFrame,
    is_expired: bool,
}
#[derive(Clone, Debug)]
pub struct KeyframesAnimation {
    opaque: OpaqueNode,
    name: Atom,
    state: KeyframesAnimationState,
}

// ...

pub fn update_animation_state(constellation_chan: &IpcSender<ConstellationMsg>,
                              script_chan: &IpcSender<ConstellationControlMsg>,
                              running_keyframes_animations: &mut HashMap<OpaqueNode, Vec<KeyframesAnimation>>,
                              running_transition_animations: &mut HashMap<OpaqueNode, Vec<TransitionAnimation>>,
                              expired_keyframes_animations: &mut HashMap<OpaqueNode, Vec<KeyframesAnimation>>,
                              expired_transition_animations: &mut HashMap<OpaqueNode, Vec<TransitionAnimation>>,
                              new_animations_receiver: &Receiver<Animation>,
                              pipeline_id: PipelineId,
                              timer: &Timer) {

Making this change (there are more spots that will need to be changed than the ones shown, of course) should reduce the rightward drift that comes from having to loop and then match (instead, it's just two loops). It should also save RAM, by only allocating the space we need instead of the space of the largest variant (in this case, Animation::Keyframes). The enum can still be used for sending over the animation channel.

@KiChjang
Copy link
Member

@KiChjang KiChjang commented Nov 30, 2016

Perhaps using struct variants would make more sense? I.e.

#[derive(Clone, Debug)]
pub enum Animation {
    Transition {
        opaque: OpaqueNode,
        node: UnsafeNode,
        start_time: f64,
        frame: AnimationFrame,
        is_expired: bool
    },
    Keyframes {
        opaque: OpaqueNode,
        name: Atom,
        state: KeyframesAnimationState
    }
}
@KiChjang
Copy link
Member

@KiChjang KiChjang commented Nov 30, 2016

Oh, I see what's happening here. The only thing that doesn't quite make sense to me is that you're essentially creating 2 different structs that have no relation with each other, except in the case where you have to send data over a channel and you have to wrap them with the Animation enum. If the receiver also handles these two animations differently, you might as well create another channel altogether and keep them completely separate.

@notriddle
Copy link
Contributor Author

@notriddle notriddle commented Nov 30, 2016

If the receiver also handles these two animations differently, you might as well create another channel altogether and keep them completely separate.

We probably could have two separate channels, since the receiver just runs try_recv after every restyle, it could just as easily run try_recv on two separate channels.

@nox
Copy link
Member

@nox nox commented Oct 7, 2017

Is this still relevant? Given much stuff changed around animations since last year.

@mrobinson
Copy link
Member

@mrobinson mrobinson commented Apr 27, 2020

Transitions and animations are currently not sent over a channel, but they are still represented by an enum. It may make sense to fully separate these into two different structs as the number of situations where animations and transitions need to be handled differently (such as applying them in the proper order or one having precedence over the other) is only going to increase.

@mrobinson mrobinson self-assigned this Apr 27, 2020
mrobinson added a commit to mrobinson/servo that referenced this issue May 6, 2020
This change splits the list of animations and transitions, which are
almost always handled differently. It also renames
`ElementAnimationState` to `ElementAnimationSet` and establishes an
`AnimationState` for every transition and animation. This allows us to
stop continually reallocating lists every time a transition or animation
needs to be canceled.

Fixes servo#14419.
bors-servo added a commit that referenced this issue May 6, 2020
Split animations and transitions into separate lists

This change splits the list of animations and transitions, which are
almost always handled differently. It also renames
`ElementAnimationState` to `ElementAnimationSet` and establishes an
`AnimationState` for every transition and animation. This allows us to
stop continually reallocating lists every time a transition or animation
needs to be canceled.

Fixes #14419.

<!-- Please describe your changes on the following line: -->

---
<!-- 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
- [ ] These changes fix #14419

<!-- Either: -->
- [ ] There are tests for these changes OR
- [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 added a commit that referenced this issue May 6, 2020
Split animations and transitions into separate lists

This change splits the list of animations and transitions, which are
almost always handled differently. It also renames
`ElementAnimationState` to `ElementAnimationSet` and establishes an
`AnimationState` for every transition and animation. This allows us to
stop continually reallocating lists every time a transition or animation
needs to be canceled.

Fixes #14419.

<!-- Please describe your changes on the following line: -->

---
<!-- 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
- [ ] These changes fix #14419

<!-- Either: -->
- [ ] There are tests for these changes OR
- [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 bors-servo closed this in b8874ad May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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