Add ElementAnimationState and PossibleElementAnimationState

This refactor is preparation for implementing a specification
compliant transitions and animations processing model.

These data structures hold all the animation information about a single
node. Since adding, updating, and modifying animations for a single node
are all interdependent, it makes sense to start encapsulating animation
data and functionality into a single data structure. This also opens up
the possibility for easier concurrency in the future by more easily
allowing per-node mutexes.
This commit is contained in:
Martin Robinson 2020-04-22 16:55:24 +02:00
parent 5504d9259d
commit 8f988be18a
9 changed files with 332 additions and 454 deletions

View file

@ -5,7 +5,7 @@
//! The context within which style is calculated.
#[cfg(feature = "servo")]
use crate::animation::Animation;
use crate::animation::ElementAnimationState;
use crate::bloom::StyleBloom;
use crate::data::{EagerPseudoStyles, ElementData};
#[cfg(feature = "servo")]
@ -29,8 +29,6 @@ use crate::timer::Timer;
use crate::traversal::DomTraversal;
use crate::traversal_flags::TraversalFlags;
use app_units::Au;
#[cfg(feature = "servo")]
use crossbeam_channel::Sender;
use euclid::default::Size2D;
use euclid::Scale;
use fxhash::FxHashMap;
@ -43,8 +41,6 @@ use servo_arc::Arc;
use servo_atoms::Atom;
use std::fmt;
use std::ops;
#[cfg(feature = "servo")]
use std::sync::Mutex;
use style_traits::CSSPixel;
use style_traits::DevicePixel;
#[cfg(feature = "servo")]
@ -54,22 +50,6 @@ use uluru::{Entry, LRUCache};
pub use selectors::matching::QuirksMode;
/// This structure is used to create a local style context from a shared one.
#[cfg(feature = "servo")]
pub struct ThreadLocalStyleContextCreationInfo {
new_animations_sender: Sender<Animation>,
}
#[cfg(feature = "servo")]
impl ThreadLocalStyleContextCreationInfo {
/// Trivially constructs a `ThreadLocalStyleContextCreationInfo`.
pub fn new(animations_sender: Sender<Animation>) -> Self {
ThreadLocalStyleContextCreationInfo {
new_animations_sender: animations_sender,
}
}
}
/// A global options structure for the style system. We use this instead of
/// opts to abstract across Gecko and Servo.
#[derive(Clone)]
@ -186,25 +166,13 @@ pub struct SharedStyleContext<'a> {
/// A map with our snapshots in order to handle restyle hints.
pub snapshot_map: &'a SnapshotMap,
/// The animations that are currently running.
/// The state of all animations for our styled elements.
#[cfg(feature = "servo")]
pub running_animations: Arc<RwLock<FxHashMap<OpaqueNode, Vec<Animation>>>>,
/// The list of animations that have expired since the last style recalculation.
#[cfg(feature = "servo")]
pub expired_animations: Arc<RwLock<FxHashMap<OpaqueNode, Vec<Animation>>>>,
/// The list of animations that have expired since the last style recalculation.
#[cfg(feature = "servo")]
pub cancelled_animations: Arc<RwLock<FxHashMap<OpaqueNode, Vec<Animation>>>>,
pub animation_states: Arc<RwLock<FxHashMap<OpaqueNode, ElementAnimationState>>>,
/// Paint worklets
#[cfg(feature = "servo")]
pub registered_speculative_painters: &'a dyn RegisteredSpeculativePainters,
/// Data needed to create the thread-local style context from the shared one.
#[cfg(feature = "servo")]
pub local_context_creation_data: Mutex<ThreadLocalStyleContextCreationInfo>,
}
impl<'a> SharedStyleContext<'a> {
@ -741,10 +709,6 @@ pub struct ThreadLocalStyleContext<E: TElement> {
pub rule_cache: RuleCache,
/// The bloom filter used to fast-reject selector-matching.
pub bloom_filter: StyleBloom<E>,
/// A channel on which new animations that have been triggered by style
/// recalculation can be sent.
#[cfg(feature = "servo")]
pub new_animations_sender: Sender<Animation>,
/// A set of tasks to be run (on the parent thread) in sequential mode after
/// the rest of the styling is complete. This is useful for
/// infrequently-needed non-threadsafe operations.
@ -778,12 +742,6 @@ impl<E: TElement> ThreadLocalStyleContext<E> {
sharing_cache: StyleSharingCache::new(),
rule_cache: RuleCache::new(),
bloom_filter: StyleBloom::new(),
new_animations_sender: shared
.local_context_creation_data
.lock()
.unwrap()
.new_animations_sender
.clone(),
tasks: SequentialTaskList(Vec::new()),
selector_flags: SelectorFlagsMap::new(),
statistics: PerThreadTraversalStatistics::default(),