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