Skip to main content

style/
context.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! The context within which style is calculated.
6
7#[cfg(feature = "servo")]
8use crate::animation::DocumentAnimationSet;
9use crate::bloom::StyleBloom;
10use crate::computed_value_flags::ComputedValueFlags;
11use crate::data::{EagerPseudoStyles, ElementData};
12use crate::derives::*;
13use crate::dom::{SendElement, TElement};
14#[cfg(feature = "gecko")]
15use crate::gecko_bindings::structs;
16use crate::parallel::{STACK_SAFETY_MARGIN_KB, STYLE_THREAD_STACK_SIZE_KB};
17use crate::properties::ComputedValues;
18#[cfg(feature = "servo")]
19use crate::properties::PropertyId;
20use crate::rule_cache::RuleCache;
21use crate::rule_tree::{RuleCascadeFlags, StrongRuleNode};
22use crate::selector_parser::{SnapshotMap, EAGER_PSEUDO_COUNT};
23use crate::shared_lock::StylesheetGuards;
24use crate::sharing::StyleSharingCache;
25use crate::stylist::Stylist;
26use crate::thread_state::{self, ThreadState};
27use crate::traversal::DomTraversal;
28use crate::traversal_flags::TraversalFlags;
29use app_units::Au;
30use euclid::default::Size2D;
31use euclid::Scale;
32#[cfg(feature = "servo")]
33use rustc_hash::FxHashMap;
34use selectors::context::SelectorCaches;
35#[cfg(feature = "gecko")]
36use servo_arc::Arc;
37use std::fmt;
38use std::ops;
39use std::time::{Duration, Instant};
40use style_traits::CSSPixel;
41use style_traits::DevicePixel;
42#[cfg(feature = "servo")]
43use style_traits::SpeculativePainter;
44#[cfg(feature = "servo")]
45use stylo_atoms::Atom;
46
47pub use selectors::matching::QuirksMode;
48
49/// A global options structure for the style system. We use this instead of
50/// opts to abstract across Gecko and Servo.
51#[derive(Clone)]
52pub struct StyleSystemOptions {
53    /// Whether the style sharing cache is disabled.
54    pub disable_style_sharing_cache: bool,
55    /// Whether we should dump statistics about the style system.
56    pub dump_style_statistics: bool,
57    /// The minimum number of elements that must be traversed to trigger a dump
58    /// of style statistics.
59    pub style_statistics_threshold: usize,
60}
61
62#[cfg(feature = "gecko")]
63fn get_env_bool(name: &str) -> bool {
64    use std::env;
65    match env::var(name) {
66        Ok(s) => !s.is_empty(),
67        Err(_) => false,
68    }
69}
70
71const DEFAULT_STATISTICS_THRESHOLD: usize = 50;
72
73#[cfg(feature = "gecko")]
74fn get_env_usize(name: &str) -> Option<usize> {
75    use std::env;
76    env::var(name).ok().map(|s| {
77        s.parse::<usize>()
78            .expect("Couldn't parse environmental variable as usize")
79    })
80}
81
82/// A global variable holding the state of
83/// `StyleSystemOptions::default().disable_style_sharing_cache`.
84/// See [#22854](https://github.com/servo/servo/issues/22854).
85#[cfg(feature = "servo")]
86pub static DEFAULT_DISABLE_STYLE_SHARING_CACHE: std::sync::atomic::AtomicBool =
87    std::sync::atomic::AtomicBool::new(false);
88
89/// A global variable holding the state of
90/// `StyleSystemOptions::default().dump_style_statistics`.
91/// See [#22854](https://github.com/servo/servo/issues/22854).
92#[cfg(feature = "servo")]
93pub static DEFAULT_DUMP_STYLE_STATISTICS: std::sync::atomic::AtomicBool =
94    std::sync::atomic::AtomicBool::new(false);
95
96impl Default for StyleSystemOptions {
97    #[cfg(feature = "servo")]
98    fn default() -> Self {
99        use std::sync::atomic::Ordering;
100
101        StyleSystemOptions {
102            disable_style_sharing_cache: DEFAULT_DISABLE_STYLE_SHARING_CACHE
103                .load(Ordering::Relaxed),
104            dump_style_statistics: DEFAULT_DUMP_STYLE_STATISTICS.load(Ordering::Relaxed),
105            style_statistics_threshold: DEFAULT_STATISTICS_THRESHOLD,
106        }
107    }
108
109    #[cfg(feature = "gecko")]
110    fn default() -> Self {
111        StyleSystemOptions {
112            disable_style_sharing_cache: get_env_bool("DISABLE_STYLE_SHARING_CACHE"),
113            dump_style_statistics: get_env_bool("DUMP_STYLE_STATISTICS"),
114            style_statistics_threshold: get_env_usize("STYLE_STATISTICS_THRESHOLD")
115                .unwrap_or(DEFAULT_STATISTICS_THRESHOLD),
116        }
117    }
118}
119
120/// A shared style context.
121///
122/// There's exactly one of these during a given restyle traversal, and it's
123/// shared among the worker threads.
124pub struct SharedStyleContext<'a> {
125    /// The CSS selector stylist.
126    pub stylist: &'a Stylist,
127
128    /// Whether visited styles are enabled.
129    ///
130    /// They may be disabled when Gecko's pref layout.css.visited_links_enabled
131    /// is false, or when in private browsing mode.
132    pub visited_styles_enabled: bool,
133
134    /// Configuration options.
135    pub options: StyleSystemOptions,
136
137    /// Guards for pre-acquired locks
138    pub guards: StylesheetGuards<'a>,
139
140    /// The current time for transitions and animations. This is needed to ensure
141    /// a consistent sampling time and also to adjust the time for testing.
142    pub current_time_for_animations: f64,
143
144    /// Flags controlling how we traverse the tree.
145    pub traversal_flags: TraversalFlags,
146
147    /// A map with our snapshots in order to handle restyle hints.
148    pub snapshot_map: &'a SnapshotMap,
149
150    /// The state of all animations for our styled elements.
151    #[cfg(feature = "servo")]
152    pub animations: DocumentAnimationSet,
153
154    /// Paint worklets
155    #[cfg(feature = "servo")]
156    pub registered_speculative_painters: &'a dyn RegisteredSpeculativePainters,
157}
158
159impl<'a> SharedStyleContext<'a> {
160    /// Return a suitable viewport size in order to be used for viewport units.
161    pub fn viewport_size(&self) -> Size2D<Au> {
162        self.stylist.device().au_viewport_size()
163    }
164
165    /// The device pixel ratio
166    pub fn device_pixel_ratio(&self) -> Scale<f32, CSSPixel, DevicePixel> {
167        self.stylist.device().device_pixel_ratio()
168    }
169
170    /// The quirks mode of the document.
171    pub fn quirks_mode(&self) -> QuirksMode {
172        self.stylist.quirks_mode()
173    }
174}
175
176/// The structure holds various intermediate inputs that are eventually used by
177/// by the cascade.
178///
179/// The matching and cascading process stores them in this format temporarily
180/// within the `CurrentElementInfo`. At the end of the cascade, they are folded
181/// down into the main `ComputedValues` to reduce memory usage per element while
182/// still remaining accessible.
183#[derive(Clone, Debug, Default)]
184pub struct CascadeInputs {
185    /// The rule node representing the ordered list of rules matched for this
186    /// node.
187    pub rules: Option<StrongRuleNode>,
188
189    /// The rule node representing the ordered list of rules matched for this
190    /// node if visited, only computed if there's a relevant link for this
191    /// element. A element's "relevant link" is the element being matched if it
192    /// is a link or the nearest ancestor link.
193    pub visited_rules: Option<StrongRuleNode>,
194
195    /// The set of flags from container queries that we need for invalidation.
196    pub flags: ComputedValueFlags,
197
198    /// The set of RuleCascadeFlags to include in the cascade.
199    pub included_cascade_flags: RuleCascadeFlags,
200}
201
202impl CascadeInputs {
203    /// Construct inputs from previous cascade results, if any.
204    pub fn new_from_style(style: &ComputedValues) -> Self {
205        Self {
206            rules: style.rules.clone(),
207            visited_rules: style.visited_style().and_then(|v| v.rules.clone()),
208            flags: style.flags.for_cascade_inputs(),
209            included_cascade_flags: RuleCascadeFlags::empty(),
210        }
211    }
212}
213
214/// A list of cascade inputs for eagerly-cascaded pseudo-elements.
215/// The list is stored inline.
216#[derive(Debug)]
217pub struct EagerPseudoCascadeInputs(Option<[Option<CascadeInputs>; EAGER_PSEUDO_COUNT]>);
218
219// Manually implement `Clone` here because the derived impl of `Clone` for
220// array types assumes the value inside is `Copy`.
221impl Clone for EagerPseudoCascadeInputs {
222    fn clone(&self) -> Self {
223        if self.0.is_none() {
224            return EagerPseudoCascadeInputs(None);
225        }
226        let self_inputs = self.0.as_ref().unwrap();
227        let mut inputs: [Option<CascadeInputs>; EAGER_PSEUDO_COUNT] = Default::default();
228        for i in 0..EAGER_PSEUDO_COUNT {
229            inputs[i] = self_inputs[i].clone();
230        }
231        EagerPseudoCascadeInputs(Some(inputs))
232    }
233}
234
235impl EagerPseudoCascadeInputs {
236    /// Construct inputs from previous cascade results, if any.
237    fn new_from_style(styles: &EagerPseudoStyles) -> Self {
238        EagerPseudoCascadeInputs(styles.as_optional_array().map(|styles| {
239            let mut inputs: [Option<CascadeInputs>; EAGER_PSEUDO_COUNT] = Default::default();
240            for i in 0..EAGER_PSEUDO_COUNT {
241                inputs[i] = styles[i].as_ref().map(|s| CascadeInputs::new_from_style(s));
242            }
243            inputs
244        }))
245    }
246
247    /// Returns the list of rules, if they exist.
248    pub fn into_array(self) -> Option<[Option<CascadeInputs>; EAGER_PSEUDO_COUNT]> {
249        self.0
250    }
251}
252
253/// The cascade inputs associated with a node, including those for any
254/// pseudo-elements.
255///
256/// The matching and cascading process stores them in this format temporarily
257/// within the `CurrentElementInfo`. At the end of the cascade, they are folded
258/// down into the main `ComputedValues` to reduce memory usage per element while
259/// still remaining accessible.
260#[derive(Clone, Debug)]
261pub struct ElementCascadeInputs {
262    /// The element's cascade inputs.
263    pub primary: CascadeInputs,
264    /// A list of the inputs for the element's eagerly-cascaded pseudo-elements.
265    pub pseudos: EagerPseudoCascadeInputs,
266}
267
268impl ElementCascadeInputs {
269    /// Construct inputs from previous cascade results, if any.
270    #[inline]
271    pub fn new_from_element_data(data: &ElementData) -> Self {
272        debug_assert!(data.has_styles());
273        ElementCascadeInputs {
274            primary: CascadeInputs::new_from_style(data.styles.primary()),
275            pseudos: EagerPseudoCascadeInputs::new_from_style(&data.styles.pseudos),
276        }
277    }
278}
279
280/// Statistics gathered during the traversal. We gather statistics on each
281/// thread and then combine them after the threads join via the Add
282/// implementation below.
283#[derive(AddAssign, Clone, Default)]
284pub struct PerThreadTraversalStatistics {
285    /// The total number of elements traversed.
286    pub elements_traversed: u32,
287    /// The number of elements where has_styles() went from false to true.
288    pub elements_styled: u32,
289    /// The number of elements for which we performed selector matching.
290    pub elements_matched: u32,
291    /// The number of cache hits from the StyleSharingCache.
292    pub styles_shared: u32,
293    /// The number of styles reused via rule node comparison from the
294    /// StyleSharingCache.
295    pub styles_reused: u32,
296}
297
298/// Statistics gathered during the traversal plus some information from
299/// other sources including stylist.
300#[derive(Default)]
301pub struct TraversalStatistics {
302    /// Aggregated statistics gathered during the traversal.
303    pub aggregated: PerThreadTraversalStatistics,
304    /// The number of selectors in the stylist.
305    pub selectors: u32,
306    /// The number of revalidation selectors.
307    pub revalidation_selectors: u32,
308    /// The number of state/attr dependencies in the dependency set.
309    pub dependency_selectors: u32,
310    /// The number of declarations in the stylist.
311    pub declarations: u32,
312    /// The number of times the stylist was rebuilt.
313    pub stylist_rebuilds: u32,
314    /// Time spent in the traversal, in milliseconds.
315    pub traversal_time: Duration,
316    /// Whether this was a parallel traversal.
317    pub is_parallel: bool,
318    /// Whether this is a "large" traversal.
319    pub is_large: bool,
320}
321
322/// Format the statistics in a way that the performance test harness understands.
323/// See https://bugzilla.mozilla.org/show_bug.cgi?id=1331856#c2
324impl fmt::Display for TraversalStatistics {
325    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
326        writeln!(f, "[PERF] perf block start")?;
327        writeln!(
328            f,
329            "[PERF],traversal,{}",
330            if self.is_parallel {
331                "parallel"
332            } else {
333                "sequential"
334            }
335        )?;
336        writeln!(
337            f,
338            "[PERF],elements_traversed,{}",
339            self.aggregated.elements_traversed
340        )?;
341        writeln!(
342            f,
343            "[PERF],elements_styled,{}",
344            self.aggregated.elements_styled
345        )?;
346        writeln!(
347            f,
348            "[PERF],elements_matched,{}",
349            self.aggregated.elements_matched
350        )?;
351        writeln!(f, "[PERF],styles_shared,{}", self.aggregated.styles_shared)?;
352        writeln!(f, "[PERF],styles_reused,{}", self.aggregated.styles_reused)?;
353        writeln!(f, "[PERF],selectors,{}", self.selectors)?;
354        writeln!(
355            f,
356            "[PERF],revalidation_selectors,{}",
357            self.revalidation_selectors
358        )?;
359        writeln!(
360            f,
361            "[PERF],dependency_selectors,{}",
362            self.dependency_selectors
363        )?;
364        writeln!(f, "[PERF],declarations,{}", self.declarations)?;
365        writeln!(f, "[PERF],stylist_rebuilds,{}", self.stylist_rebuilds)?;
366        writeln!(
367            f,
368            "[PERF],traversal_time_ms,{}",
369            self.traversal_time.as_secs_f64() * 1000.
370        )?;
371        writeln!(f, "[PERF] perf block end")
372    }
373}
374
375impl TraversalStatistics {
376    /// Generate complete traversal statistics.
377    ///
378    /// The traversal time is computed given the start time in seconds.
379    pub fn new<E, D>(
380        aggregated: PerThreadTraversalStatistics,
381        traversal: &D,
382        parallel: bool,
383        start: Instant,
384    ) -> TraversalStatistics
385    where
386        E: TElement,
387        D: DomTraversal<E>,
388    {
389        let threshold = traversal
390            .shared_context()
391            .options
392            .style_statistics_threshold;
393        let stylist = traversal.shared_context().stylist;
394        let is_large = aggregated.elements_traversed as usize >= threshold;
395        TraversalStatistics {
396            aggregated,
397            selectors: stylist.num_selectors() as u32,
398            revalidation_selectors: stylist.num_revalidation_selectors() as u32,
399            dependency_selectors: stylist.num_invalidations() as u32,
400            declarations: stylist.num_declarations() as u32,
401            stylist_rebuilds: stylist.num_rebuilds() as u32,
402            traversal_time: Instant::now() - start,
403            is_parallel: parallel,
404            is_large,
405        }
406    }
407}
408
409#[cfg(feature = "gecko")]
410bitflags! {
411    /// Represents which tasks are performed in a SequentialTask of
412    /// UpdateAnimations which is a result of normal restyle.
413    pub struct UpdateAnimationsTasks: u8 {
414        /// Update CSS Animations.
415        const CSS_ANIMATIONS = structs::UpdateAnimationsTasks_CSSAnimations;
416        /// Update CSS Transitions.
417        const CSS_TRANSITIONS = structs::UpdateAnimationsTasks_CSSTransitions;
418        /// Update effect properties.
419        const EFFECT_PROPERTIES = structs::UpdateAnimationsTasks_EffectProperties;
420        /// Update animation cacade results for animations running on the compositor.
421        const CASCADE_RESULTS = structs::UpdateAnimationsTasks_CascadeResults;
422        /// Display property was changed from none.
423        /// Script animations keep alive on display:none elements, so we need to trigger
424        /// the second animation restyles for the script animations in the case where
425        /// the display property was changed from 'none' to others.
426        const DISPLAY_CHANGED_FROM_NONE = structs::UpdateAnimationsTasks_DisplayChangedFromNone;
427        /// Update CSS named scroll progress timelines.
428        const SCROLL_TIMELINES = structs::UpdateAnimationsTasks_ScrollTimelines;
429        /// Update CSS named view progress timelines.
430        const VIEW_TIMELINES = structs::UpdateAnimationsTasks_ViewTimelines;
431        /// Update CSS timeline scopes, which affect visibility of both scroll and view timelines.
432        const TIMELINE_SCOPES = structs::UpdateAnimationsTasks_TimelineScopes;
433    }
434}
435
436/// A task to be run in sequential mode on the parent (non-worker) thread. This
437/// is used by the style system to queue up work which is not safe to do during
438/// the parallel traversal.
439pub enum SequentialTask<E: TElement> {
440    /// Entry to avoid an unused type parameter error on servo.
441    Unused(SendElement<E>),
442
443    /// Performs one of a number of possible tasks related to updating
444    /// animations based on the |tasks| field. These include updating CSS
445    /// animations/transitions that changed as part of the non-animation style
446    /// traversal, and updating the computed effect properties.
447    #[cfg(feature = "gecko")]
448    UpdateAnimations {
449        /// The target element or pseudo-element.
450        el: SendElement<E>,
451        /// The before-change style for transitions. We use before-change style
452        /// as the initial value of its Keyframe. Required if |tasks| includes
453        /// CSSTransitions.
454        before_change_style: Option<Arc<ComputedValues>>,
455        /// The tasks which are performed in this SequentialTask.
456        tasks: UpdateAnimationsTasks,
457    },
458}
459
460impl<E: TElement> SequentialTask<E> {
461    /// Executes this task.
462    pub fn execute(self) {
463        use self::SequentialTask::*;
464        debug_assert!(thread_state::get().contains(ThreadState::LAYOUT));
465        match self {
466            Unused(_) => unreachable!(),
467            #[cfg(feature = "gecko")]
468            UpdateAnimations {
469                el,
470                before_change_style,
471                tasks,
472            } => {
473                el.update_animations(before_change_style, tasks);
474            },
475        }
476    }
477
478    /// Creates a task to update various animation-related state on a given
479    /// (pseudo-)element.
480    #[cfg(feature = "gecko")]
481    pub fn update_animations(
482        el: E,
483        before_change_style: Option<Arc<ComputedValues>>,
484        tasks: UpdateAnimationsTasks,
485    ) -> Self {
486        use self::SequentialTask::*;
487        UpdateAnimations {
488            el: unsafe { SendElement::new(el) },
489            before_change_style,
490            tasks,
491        }
492    }
493}
494
495/// A list of SequentialTasks that get executed on Drop.
496pub struct SequentialTaskList<E>(Vec<SequentialTask<E>>)
497where
498    E: TElement;
499
500impl<E> ops::Deref for SequentialTaskList<E>
501where
502    E: TElement,
503{
504    type Target = Vec<SequentialTask<E>>;
505
506    fn deref(&self) -> &Self::Target {
507        &self.0
508    }
509}
510
511impl<E> ops::DerefMut for SequentialTaskList<E>
512where
513    E: TElement,
514{
515    fn deref_mut(&mut self) -> &mut Self::Target {
516        &mut self.0
517    }
518}
519
520impl<E> Drop for SequentialTaskList<E>
521where
522    E: TElement,
523{
524    fn drop(&mut self) {
525        debug_assert!(thread_state::get().contains(ThreadState::LAYOUT));
526        for task in self.0.drain(..) {
527            task.execute()
528        }
529    }
530}
531
532/// A helper type for stack limit checking.  This assumes that stacks grow
533/// down, which is true for all non-ancient CPU architectures.
534pub struct StackLimitChecker {
535    lower_limit: usize,
536}
537
538impl StackLimitChecker {
539    /// Create a new limit checker, for this thread, allowing further use
540    /// of up to |stack_size| bytes beyond (below) the current stack pointer.
541    #[inline(never)]
542    pub fn new(stack_size_limit: usize) -> Self {
543        StackLimitChecker {
544            lower_limit: StackLimitChecker::get_sp() - stack_size_limit,
545        }
546    }
547
548    /// Checks whether the previously stored stack limit has now been exceeded.
549    #[inline(never)]
550    pub fn limit_exceeded(&self) -> bool {
551        let curr_sp = StackLimitChecker::get_sp();
552
553        // Do some sanity-checking to ensure that our invariants hold, even in
554        // the case where we've exceeded the soft limit.
555        //
556        // The correctness of depends on the assumption that no stack wraps
557        // around the end of the address space.
558        if cfg!(debug_assertions) {
559            // Compute the actual bottom of the stack by subtracting our safety
560            // margin from our soft limit. Note that this will be slightly below
561            // the actual bottom of the stack, because there are a few initial
562            // frames on the stack before we do the measurement that computes
563            // the limit.
564            let stack_bottom = self.lower_limit - STACK_SAFETY_MARGIN_KB * 1024;
565
566            // The bottom of the stack should be below the current sp. If it
567            // isn't, that means we've either waited too long to check the limit
568            // and burned through our safety margin (in which case we probably
569            // would have segfaulted by now), or we're using a limit computed for
570            // a different thread.
571            debug_assert!(stack_bottom < curr_sp);
572
573            // Compute the distance between the current sp and the bottom of
574            // the stack, and compare it against the current stack. It should be
575            // no further from us than the total stack size. We allow some slop
576            // to handle the fact that stack_bottom is a bit further than the
577            // bottom of the stack, as discussed above.
578            let distance_to_stack_bottom = curr_sp - stack_bottom;
579            let max_allowable_distance = (STYLE_THREAD_STACK_SIZE_KB + 10) * 1024;
580            debug_assert!(distance_to_stack_bottom <= max_allowable_distance);
581        }
582
583        // The actual bounds check.
584        curr_sp <= self.lower_limit
585    }
586
587    // Technically, rustc can optimize this away, but shouldn't for now.
588    // We should fix this once black_box is stable.
589    #[inline(always)]
590    fn get_sp() -> usize {
591        let mut foo: usize = 42;
592        (&mut foo as *mut usize) as usize
593    }
594}
595
596/// A thread-local style context.
597///
598/// This context contains data that needs to be used during restyling, but is
599/// not required to be unique among worker threads, so we create one per worker
600/// thread in order to be able to mutate it without locking.
601pub struct ThreadLocalStyleContext<E: TElement> {
602    /// A cache to share style among siblings.
603    pub sharing_cache: StyleSharingCache<E>,
604    /// A cache from matched properties to elements that match those.
605    pub rule_cache: RuleCache,
606    /// The bloom filter used to fast-reject selector-matching.
607    pub bloom_filter: StyleBloom<E>,
608    /// A set of tasks to be run (on the parent thread) in sequential mode after
609    /// the rest of the styling is complete. This is useful for
610    /// infrequently-needed non-threadsafe operations.
611    ///
612    /// It's important that goes after the style sharing cache and the bloom
613    /// filter, to ensure they're dropped before we execute the tasks, which
614    /// could create another ThreadLocalStyleContext for style computation.
615    pub tasks: SequentialTaskList<E>,
616    /// Statistics about the traversal.
617    pub statistics: PerThreadTraversalStatistics,
618    /// A checker used to ensure that parallel.rs does not recurse indefinitely
619    /// even on arbitrarily deep trees.  See Gecko bug 1376883.
620    pub stack_limit_checker: StackLimitChecker,
621    /// Collection of caches (And cache-likes) for speeding up expensive selector matches.
622    pub selector_caches: SelectorCaches,
623}
624
625impl<E: TElement> ThreadLocalStyleContext<E> {
626    /// Creates a new `ThreadLocalStyleContext`
627    pub fn new() -> Self {
628        ThreadLocalStyleContext {
629            sharing_cache: StyleSharingCache::new(),
630            rule_cache: RuleCache::new(),
631            bloom_filter: StyleBloom::new(),
632            tasks: SequentialTaskList(Vec::new()),
633            statistics: PerThreadTraversalStatistics::default(),
634            stack_limit_checker: StackLimitChecker::new(
635                (STYLE_THREAD_STACK_SIZE_KB - STACK_SAFETY_MARGIN_KB) * 1024,
636            ),
637            selector_caches: SelectorCaches::default(),
638        }
639    }
640}
641
642/// A `StyleContext` is just a simple container for a immutable reference to a
643/// shared style context, and a mutable reference to a local one.
644pub struct StyleContext<'a, E: TElement + 'a> {
645    /// The shared style context reference.
646    pub shared: &'a SharedStyleContext<'a>,
647    /// The thread-local style context (mutable) reference.
648    pub thread_local: &'a mut ThreadLocalStyleContext<E>,
649}
650
651/// A registered painter
652#[cfg(feature = "servo")]
653pub trait RegisteredSpeculativePainter: SpeculativePainter {
654    /// The name it was registered with
655    fn name(&self) -> Atom;
656    /// The properties it was registered with
657    fn properties(&self) -> &FxHashMap<Atom, PropertyId>;
658}
659
660/// A set of registered painters
661#[cfg(feature = "servo")]
662pub trait RegisteredSpeculativePainters: Sync {
663    /// Look up a speculative painter
664    fn get(&self, name: &Atom) -> Option<&dyn RegisteredSpeculativePainter>;
665}