mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
style: Slim down SharedStyleContext.
This slims down SharedStyleContext, in preparation for a few things. First, I would like to eventually move the stylist to the document in Servo, in order for it to hold the StyleSheetSet. Also, this gets rid of a fair amount of overhead while creating it in stylo. Fixes bug 1363245.
This commit is contained in:
parent
f579405510
commit
ebd9bf8181
6 changed files with 104 additions and 85 deletions
|
@ -4,7 +4,8 @@
|
|||
|
||||
//! The context within which style is calculated.
|
||||
|
||||
use animation::{Animation, PropertyAnimation};
|
||||
#[cfg(feature = "servo")] use animation::Animation;
|
||||
use animation::PropertyAnimation;
|
||||
use app_units::Au;
|
||||
use bit_vec::BitVec;
|
||||
use bloom::StyleBloom;
|
||||
|
@ -17,18 +18,18 @@ use fnv::FnvHashMap;
|
|||
use font_metrics::FontMetricsProvider;
|
||||
#[cfg(feature = "gecko")] use gecko_bindings::structs;
|
||||
use matching::StyleSharingCandidateCache;
|
||||
use parking_lot::RwLock;
|
||||
#[cfg(feature = "servo")] use parking_lot::RwLock;
|
||||
#[cfg(feature = "gecko")] use properties::ComputedValues;
|
||||
use selector_parser::SnapshotMap;
|
||||
use selectors::matching::ElementSelectorFlags;
|
||||
#[cfg(feature = "servo")] use servo_config::opts;
|
||||
use shared_lock::StylesheetGuards;
|
||||
use std::collections::HashMap;
|
||||
#[cfg(not(feature = "servo"))] use std::env;
|
||||
#[cfg(feature = "servo")] use std::collections::HashMap;
|
||||
#[cfg(feature = "gecko")] use std::env;
|
||||
use std::fmt;
|
||||
use std::ops::Add;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::mpsc::Sender;
|
||||
#[cfg(feature = "servo")] use std::sync::Mutex;
|
||||
#[cfg(feature = "servo")] use std::sync::mpsc::Sender;
|
||||
use stylearc::Arc;
|
||||
use stylist::Stylist;
|
||||
use thread_state;
|
||||
|
@ -37,10 +38,12 @@ use timer::Timer;
|
|||
use traversal::{DomTraversal, TraversalFlags};
|
||||
|
||||
/// 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 {
|
||||
|
@ -106,7 +109,7 @@ impl Default for StyleSystemOptions {
|
|||
/// shared among the worker threads.
|
||||
pub struct SharedStyleContext<'a> {
|
||||
/// The CSS selector stylist.
|
||||
pub stylist: Arc<Stylist>,
|
||||
pub stylist: &'a Stylist,
|
||||
|
||||
/// Configuration options.
|
||||
pub options: StyleSystemOptions,
|
||||
|
@ -114,17 +117,8 @@ pub struct SharedStyleContext<'a> {
|
|||
/// Guards for pre-acquired locks
|
||||
pub guards: StylesheetGuards<'a>,
|
||||
|
||||
/// The animations that are currently running.
|
||||
pub running_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
|
||||
|
||||
/// The list of animations that have expired since the last style recalculation.
|
||||
pub expired_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
|
||||
|
||||
///The CSS error reporter for all CSS loaded in this layout thread
|
||||
pub error_reporter: Box<ParseErrorReporter>,
|
||||
|
||||
/// Data needed to create the thread-local style context from the shared one.
|
||||
pub local_context_creation_data: Mutex<ThreadLocalStyleContextCreationInfo>,
|
||||
pub error_reporter: &'a ParseErrorReporter,
|
||||
|
||||
/// The current timer for transitions and animations. This is needed to test
|
||||
/// them.
|
||||
|
@ -138,6 +132,19 @@ 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.
|
||||
#[cfg(feature = "servo")]
|
||||
pub running_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
|
||||
|
||||
/// The list of animations that have expired since the last style recalculation.
|
||||
#[cfg(feature = "servo")]
|
||||
pub expired_animations: Arc<RwLock<HashMap<OpaqueNode, Vec<Animation>>>>,
|
||||
|
||||
/// 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> {
|
||||
|
@ -400,6 +407,7 @@ pub struct ThreadLocalStyleContext<E: TElement> {
|
|||
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
|
||||
|
@ -421,6 +429,7 @@ pub struct ThreadLocalStyleContext<E: TElement> {
|
|||
|
||||
impl<E: TElement> ThreadLocalStyleContext<E> {
|
||||
/// Creates a new `ThreadLocalStyleContext` from a shared one.
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn new(shared: &SharedStyleContext) -> Self {
|
||||
ThreadLocalStyleContext {
|
||||
style_sharing_candidate_cache: StyleSharingCandidateCache::new(),
|
||||
|
@ -434,6 +443,20 @@ impl<E: TElement> ThreadLocalStyleContext<E> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
/// Creates a new `ThreadLocalStyleContext` from a shared one.
|
||||
pub fn new(shared: &SharedStyleContext) -> Self {
|
||||
ThreadLocalStyleContext {
|
||||
style_sharing_candidate_cache: StyleSharingCandidateCache::new(),
|
||||
bloom_filter: StyleBloom::new(),
|
||||
tasks: Vec::new(),
|
||||
selector_flags: SelectorFlagsMap::new(),
|
||||
statistics: TraversalStatistics::default(),
|
||||
current_element_info: None,
|
||||
font_metrics_provider: E::FontMetricsProvider::create_from(shared),
|
||||
}
|
||||
}
|
||||
|
||||
/// Notes when the style system starts traversing an element.
|
||||
pub fn begin_element(&mut self, element: E, data: &ElementData) {
|
||||
debug_assert!(self.current_element_info.is_none());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue