2015-12-30 08:31:23 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-06-28 01:14:55 +03:00
|
|
|
//! The context within which style is calculated.
|
|
|
|
|
2017-05-12 16:56:47 +03:00
|
|
|
#[cfg(feature = "servo")] use animation::Animation;
|
|
|
|
use animation::PropertyAnimation;
|
2015-12-30 08:31:23 +03:00
|
|
|
use app_units::Au;
|
2016-12-22 23:02:38 +03:00
|
|
|
use bloom::StyleBloom;
|
2017-04-13 16:56:03 +03:00
|
|
|
use cache::LRUCache;
|
2017-01-10 04:26:50 +03:00
|
|
|
use data::ElementData;
|
2017-02-09 06:33:27 +03:00
|
|
|
use dom::{OpaqueNode, TNode, TElement, SendElement};
|
2016-01-12 06:53:31 +03:00
|
|
|
use error_reporting::ParseErrorReporter;
|
2015-12-30 08:31:23 +03:00
|
|
|
use euclid::Size2D;
|
2017-04-13 16:56:03 +03:00
|
|
|
use fnv::FnvHashMap;
|
2017-04-09 14:15:51 +03:00
|
|
|
use font_metrics::FontMetricsProvider;
|
2017-03-27 13:47:47 +03:00
|
|
|
#[cfg(feature = "gecko")] use gecko_bindings::structs;
|
2017-05-12 16:56:47 +03:00
|
|
|
#[cfg(feature = "servo")] use parking_lot::RwLock;
|
2017-04-17 13:07:23 +03:00
|
|
|
#[cfg(feature = "gecko")] use properties::ComputedValues;
|
2017-05-10 23:08:59 +03:00
|
|
|
use selector_parser::SnapshotMap;
|
2017-02-09 06:33:27 +03:00
|
|
|
use selectors::matching::ElementSelectorFlags;
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- 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 #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
use shared_lock::StylesheetGuards;
|
2017-05-30 15:28:06 +03:00
|
|
|
use sharing::{ValidationData, StyleSharingCandidateCache};
|
2017-01-20 02:27:34 +03:00
|
|
|
use std::fmt;
|
|
|
|
use std::ops::Add;
|
2017-05-12 16:56:47 +03:00
|
|
|
#[cfg(feature = "servo")] use std::sync::Mutex;
|
|
|
|
#[cfg(feature = "servo")] use std::sync::mpsc::Sender;
|
2017-05-03 04:01:10 +03:00
|
|
|
use stylearc::Arc;
|
2016-11-20 18:21:52 +03:00
|
|
|
use stylist::Stylist;
|
2017-02-09 06:33:27 +03:00
|
|
|
use thread_state;
|
2017-02-15 14:05:07 +03:00
|
|
|
use time;
|
2016-07-20 21:38:31 +03:00
|
|
|
use timer::Timer;
|
2017-04-09 09:04:57 +03:00
|
|
|
use traversal::{DomTraversal, TraversalFlags};
|
2015-12-30 08:31:23 +03:00
|
|
|
|
2016-07-02 00:12:54 +03:00
|
|
|
/// This structure is used to create a local style context from a shared one.
|
2017-05-12 16:56:47 +03:00
|
|
|
#[cfg(feature = "servo")]
|
2016-12-16 22:38:27 +03:00
|
|
|
pub struct ThreadLocalStyleContextCreationInfo {
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 10:58:34 +03:00
|
|
|
new_animations_sender: Sender<Animation>,
|
2016-07-02 00:12:54 +03:00
|
|
|
}
|
|
|
|
|
2017-05-12 16:56:47 +03:00
|
|
|
#[cfg(feature = "servo")]
|
2016-12-16 22:38:27 +03:00
|
|
|
impl ThreadLocalStyleContextCreationInfo {
|
2017-01-02 15:10:56 +03:00
|
|
|
/// Trivially constructs a `ThreadLocalStyleContextCreationInfo`.
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 10:58:34 +03:00
|
|
|
pub fn new(animations_sender: Sender<Animation>) -> Self {
|
2016-12-16 22:38:27 +03:00
|
|
|
ThreadLocalStyleContextCreationInfo {
|
2016-07-02 00:12:54 +03:00
|
|
|
new_animations_sender: animations_sender,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-02 15:10:56 +03:00
|
|
|
/// Which quirks mode is this document in.
|
|
|
|
///
|
|
|
|
/// See: https://quirks.spec.whatwg.org/
|
2016-12-18 00:25:06 +03:00
|
|
|
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
|
|
|
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
|
|
|
pub enum QuirksMode {
|
2017-01-02 15:10:56 +03:00
|
|
|
/// Quirks mode.
|
2016-12-18 00:25:06 +03:00
|
|
|
Quirks,
|
2017-01-02 15:10:56 +03:00
|
|
|
/// Limited quirks mode.
|
2016-12-18 00:25:06 +03:00
|
|
|
LimitedQuirks,
|
2017-01-02 15:10:56 +03:00
|
|
|
/// No quirks mode.
|
2016-12-18 00:25:06 +03:00
|
|
|
NoQuirks,
|
|
|
|
}
|
|
|
|
|
2017-04-12 10:27:02 +03:00
|
|
|
/// A global options structure for the style system. We use this instead of
|
|
|
|
/// opts to abstract across Gecko and Servo.
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct StyleSystemOptions {
|
|
|
|
/// Whether the style sharing cache is disabled.
|
|
|
|
pub disable_style_sharing_cache: bool,
|
|
|
|
/// Whether we should dump statistics about the style system.
|
|
|
|
pub dump_style_statistics: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "gecko")]
|
|
|
|
fn get_env(name: &str) -> bool {
|
2017-05-30 15:28:06 +03:00
|
|
|
use std::env;
|
2017-04-12 10:27:02 +03:00
|
|
|
match env::var(name) {
|
|
|
|
Ok(s) => !s.is_empty(),
|
|
|
|
Err(_) => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for StyleSystemOptions {
|
|
|
|
#[cfg(feature = "servo")]
|
|
|
|
fn default() -> Self {
|
2017-05-30 15:28:06 +03:00
|
|
|
use servo_config::opts;
|
|
|
|
|
2017-04-12 10:27:02 +03:00
|
|
|
StyleSystemOptions {
|
|
|
|
disable_style_sharing_cache: opts::get().disable_share_style_cache,
|
|
|
|
dump_style_statistics: opts::get().style_sharing_stats,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "gecko")]
|
|
|
|
fn default() -> Self {
|
|
|
|
StyleSystemOptions {
|
2017-05-06 00:29:00 +03:00
|
|
|
disable_style_sharing_cache: get_env("DISABLE_STYLE_SHARING_CACHE"),
|
2017-04-12 10:27:02 +03:00
|
|
|
dump_style_statistics: get_env("DUMP_STYLE_STATISTICS"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-02 15:10:56 +03:00
|
|
|
/// A shared style context.
|
|
|
|
///
|
|
|
|
/// There's exactly one of these during a given restyle traversal, and it's
|
|
|
|
/// shared among the worker threads.
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- 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 #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
pub struct SharedStyleContext<'a> {
|
2015-12-30 08:31:23 +03:00
|
|
|
/// The CSS selector stylist.
|
2017-05-12 16:56:47 +03:00
|
|
|
pub stylist: &'a Stylist,
|
2015-12-30 08:31:23 +03:00
|
|
|
|
2017-04-12 10:27:02 +03:00
|
|
|
/// Configuration options.
|
|
|
|
pub options: StyleSystemOptions,
|
|
|
|
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- 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 #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
/// Guards for pre-acquired locks
|
|
|
|
pub guards: StylesheetGuards<'a>,
|
|
|
|
|
2015-12-30 08:31:23 +03:00
|
|
|
///The CSS error reporter for all CSS loaded in this layout thread
|
2017-05-12 16:56:47 +03:00
|
|
|
pub error_reporter: &'a ParseErrorReporter,
|
2016-07-20 21:38:31 +03:00
|
|
|
|
|
|
|
/// The current timer for transitions and animations. This is needed to test
|
|
|
|
/// them.
|
|
|
|
pub timer: Timer,
|
2016-12-18 00:25:06 +03:00
|
|
|
|
|
|
|
/// The QuirksMode state which the document needs to be rendered with
|
|
|
|
pub quirks_mode: QuirksMode,
|
2017-03-27 07:13:44 +03:00
|
|
|
|
2017-04-09 09:04:57 +03:00
|
|
|
/// Flags controlling how we traverse the tree.
|
|
|
|
pub traversal_flags: TraversalFlags,
|
2017-05-10 23:08:59 +03:00
|
|
|
|
|
|
|
/// A map with our snapshots in order to handle restyle hints.
|
|
|
|
pub snapshot_map: &'a SnapshotMap,
|
2017-05-12 16:56:47 +03:00
|
|
|
|
|
|
|
/// The animations that are currently running.
|
|
|
|
#[cfg(feature = "servo")]
|
2017-05-30 15:28:06 +03:00
|
|
|
pub running_animations: Arc<RwLock<FnvHashMap<OpaqueNode, Vec<Animation>>>>,
|
2017-05-12 16:56:47 +03:00
|
|
|
|
|
|
|
/// The list of animations that have expired since the last style recalculation.
|
|
|
|
#[cfg(feature = "servo")]
|
2017-05-30 15:28:06 +03:00
|
|
|
pub expired_animations: Arc<RwLock<FnvHashMap<OpaqueNode, Vec<Animation>>>>,
|
2017-05-12 16:56:47 +03:00
|
|
|
|
|
|
|
/// Data needed to create the thread-local style context from the shared one.
|
|
|
|
#[cfg(feature = "servo")]
|
|
|
|
pub local_context_creation_data: Mutex<ThreadLocalStyleContextCreationInfo>,
|
|
|
|
|
2016-07-02 00:12:54 +03:00
|
|
|
}
|
|
|
|
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- 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 #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
impl<'a> SharedStyleContext<'a> {
|
2017-03-11 15:40:31 +03:00
|
|
|
/// Return a suitable viewport size in order to be used for viewport units.
|
|
|
|
pub fn viewport_size(&self) -> Size2D<Au> {
|
2017-05-23 04:12:46 +03:00
|
|
|
self.stylist.device().au_viewport_size()
|
2017-03-11 15:40:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 15:28:06 +03:00
|
|
|
/// Information about the current element being processed. We group this
|
|
|
|
/// together into a single struct within ThreadLocalStyleContext so that we can
|
|
|
|
/// instantiate and destroy it easily at the beginning and end of element
|
|
|
|
/// processing.
|
2017-04-07 04:07:48 +03:00
|
|
|
pub struct CurrentElementInfo {
|
2017-05-30 15:28:06 +03:00
|
|
|
/// The element being processed. Currently we use an OpaqueNode since we
|
|
|
|
/// only use this for identity checks, but we could use SendElement if there
|
|
|
|
/// were a good reason to.
|
2017-01-10 04:26:50 +03:00
|
|
|
element: OpaqueNode,
|
|
|
|
/// Whether the element is being styled for the first time.
|
|
|
|
is_initial_style: bool,
|
2017-05-30 15:28:06 +03:00
|
|
|
/// Lazy cache of the different data used for style sharing.
|
|
|
|
pub validation_data: ValidationData,
|
2017-04-07 04:07:48 +03:00
|
|
|
/// A Vec of possibly expired animations. Used only by Servo.
|
|
|
|
#[allow(dead_code)]
|
|
|
|
pub possibly_expired_animations: Vec<PropertyAnimation>,
|
2017-01-10 04:26:50 +03:00
|
|
|
}
|
|
|
|
|
2017-05-30 15:28:06 +03:00
|
|
|
/// Statistics gathered during the traversal. We gather statistics on each
|
|
|
|
/// thread and then combine them after the threads join via the Add
|
|
|
|
/// implementation below.
|
2017-01-20 02:27:34 +03:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct TraversalStatistics {
|
|
|
|
/// The total number of elements traversed.
|
|
|
|
pub elements_traversed: u32,
|
|
|
|
/// The number of elements where has_styles() went from false to true.
|
|
|
|
pub elements_styled: u32,
|
|
|
|
/// The number of elements for which we performed selector matching.
|
|
|
|
pub elements_matched: u32,
|
|
|
|
/// The number of cache hits from the StyleSharingCache.
|
|
|
|
pub styles_shared: u32,
|
2017-04-13 09:44:12 +03:00
|
|
|
/// The number of selectors in the stylist.
|
|
|
|
pub selectors: u32,
|
|
|
|
/// The number of revalidation selectors.
|
|
|
|
pub revalidation_selectors: u32,
|
|
|
|
/// The number of state/attr dependencies in the dependency set.
|
|
|
|
pub dependency_selectors: u32,
|
|
|
|
/// The number of declarations in the stylist.
|
|
|
|
pub declarations: u32,
|
|
|
|
/// The number of times the stylist was rebuilt.
|
|
|
|
pub stylist_rebuilds: u32,
|
2017-02-15 14:05:07 +03:00
|
|
|
/// Time spent in the traversal, in milliseconds.
|
|
|
|
pub traversal_time_ms: f64,
|
2017-03-11 13:31:25 +03:00
|
|
|
/// Whether this was a parallel traversal.
|
|
|
|
pub is_parallel: Option<bool>,
|
2017-01-20 02:27:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Implementation of Add to aggregate statistics across different threads.
|
|
|
|
impl<'a> Add for &'a TraversalStatistics {
|
|
|
|
type Output = TraversalStatistics;
|
|
|
|
fn add(self, other: Self) -> TraversalStatistics {
|
2017-02-15 14:05:07 +03:00
|
|
|
debug_assert!(self.traversal_time_ms == 0.0 && other.traversal_time_ms == 0.0,
|
|
|
|
"traversal_time_ms should be set at the end by the caller");
|
2017-04-13 09:44:12 +03:00
|
|
|
debug_assert!(self.selectors == 0, "set at the end");
|
|
|
|
debug_assert!(self.revalidation_selectors == 0, "set at the end");
|
|
|
|
debug_assert!(self.dependency_selectors == 0, "set at the end");
|
|
|
|
debug_assert!(self.declarations == 0, "set at the end");
|
|
|
|
debug_assert!(self.stylist_rebuilds == 0, "set at the end");
|
2017-01-20 02:27:34 +03:00
|
|
|
TraversalStatistics {
|
|
|
|
elements_traversed: self.elements_traversed + other.elements_traversed,
|
|
|
|
elements_styled: self.elements_styled + other.elements_styled,
|
|
|
|
elements_matched: self.elements_matched + other.elements_matched,
|
|
|
|
styles_shared: self.styles_shared + other.styles_shared,
|
2017-04-13 09:44:12 +03:00
|
|
|
selectors: 0,
|
|
|
|
revalidation_selectors: 0,
|
|
|
|
dependency_selectors: 0,
|
|
|
|
declarations: 0,
|
|
|
|
stylist_rebuilds: 0,
|
2017-02-15 14:05:07 +03:00
|
|
|
traversal_time_ms: 0.0,
|
2017-03-11 13:31:25 +03:00
|
|
|
is_parallel: None,
|
2017-01-20 02:27:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Format the statistics in a way that the performance test harness understands.
|
|
|
|
/// See https://bugzilla.mozilla.org/show_bug.cgi?id=1331856#c2
|
|
|
|
impl fmt::Display for TraversalStatistics {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2017-02-15 14:05:07 +03:00
|
|
|
debug_assert!(self.traversal_time_ms != 0.0, "should have set traversal time");
|
2017-01-20 02:27:34 +03:00
|
|
|
try!(writeln!(f, "[PERF] perf block start"));
|
2017-03-11 13:31:25 +03:00
|
|
|
try!(writeln!(f, "[PERF],traversal,{}", if self.is_parallel.unwrap() {
|
|
|
|
"parallel"
|
|
|
|
} else {
|
|
|
|
"sequential"
|
|
|
|
}));
|
2017-01-20 02:27:34 +03:00
|
|
|
try!(writeln!(f, "[PERF],elements_traversed,{}", self.elements_traversed));
|
|
|
|
try!(writeln!(f, "[PERF],elements_styled,{}", self.elements_styled));
|
|
|
|
try!(writeln!(f, "[PERF],elements_matched,{}", self.elements_matched));
|
|
|
|
try!(writeln!(f, "[PERF],styles_shared,{}", self.styles_shared));
|
2017-04-13 09:44:12 +03:00
|
|
|
try!(writeln!(f, "[PERF],selectors,{}", self.selectors));
|
|
|
|
try!(writeln!(f, "[PERF],revalidation_selectors,{}", self.revalidation_selectors));
|
|
|
|
try!(writeln!(f, "[PERF],dependency_selectors,{}", self.dependency_selectors));
|
|
|
|
try!(writeln!(f, "[PERF],declarations,{}", self.declarations));
|
|
|
|
try!(writeln!(f, "[PERF],stylist_rebuilds,{}", self.stylist_rebuilds));
|
2017-02-15 14:05:07 +03:00
|
|
|
try!(writeln!(f, "[PERF],traversal_time_ms,{}", self.traversal_time_ms));
|
2017-01-20 02:27:34 +03:00
|
|
|
writeln!(f, "[PERF] perf block end")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TraversalStatistics {
|
2017-02-15 14:05:07 +03:00
|
|
|
/// Computes the traversal time given the start time in seconds.
|
2017-03-11 13:31:25 +03:00
|
|
|
pub fn finish<E, D>(&mut self, traversal: &D, start: f64)
|
|
|
|
where E: TElement,
|
|
|
|
D: DomTraversal<E>,
|
|
|
|
{
|
|
|
|
self.is_parallel = Some(traversal.is_parallel());
|
2017-02-15 14:05:07 +03:00
|
|
|
self.traversal_time_ms = (time::precise_time_s() - start) * 1000.0;
|
2017-04-13 09:44:12 +03:00
|
|
|
self.selectors = traversal.shared_context().stylist.num_selectors() as u32;
|
|
|
|
self.revalidation_selectors = traversal.shared_context().stylist.num_revalidation_selectors() as u32;
|
|
|
|
self.dependency_selectors = traversal.shared_context().stylist.num_dependencies() as u32;
|
|
|
|
self.declarations = traversal.shared_context().stylist.num_declarations() as u32;
|
|
|
|
self.stylist_rebuilds = traversal.shared_context().stylist.num_rebuilds() as u32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns whether this traversal is 'large' in order to avoid console spam
|
|
|
|
/// from lots of tiny traversals.
|
|
|
|
pub fn is_large_traversal(&self) -> bool {
|
|
|
|
self.elements_traversed >= 50
|
2017-02-15 14:05:07 +03:00
|
|
|
}
|
2017-02-09 06:33:27 +03:00
|
|
|
}
|
|
|
|
|
2017-03-27 13:47:47 +03:00
|
|
|
#[cfg(feature = "gecko")]
|
|
|
|
bitflags! {
|
2017-04-27 15:39:42 +03:00
|
|
|
/// Represents which tasks are performed in a SequentialTask of
|
|
|
|
/// UpdateAnimations.
|
2017-03-27 13:47:47 +03:00
|
|
|
pub flags UpdateAnimationsTasks: u8 {
|
|
|
|
/// Update CSS Animations.
|
|
|
|
const CSS_ANIMATIONS = structs::UpdateAnimationsTasks_CSSAnimations,
|
|
|
|
/// Update CSS Transitions.
|
|
|
|
const CSS_TRANSITIONS = structs::UpdateAnimationsTasks_CSSTransitions,
|
|
|
|
/// Update effect properties.
|
|
|
|
const EFFECT_PROPERTIES = structs::UpdateAnimationsTasks_EffectProperties,
|
|
|
|
/// Update animation cacade results for animations running on the compositor.
|
|
|
|
const CASCADE_RESULTS = structs::UpdateAnimationsTasks_CascadeResults,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-09 06:33:27 +03:00
|
|
|
/// A task to be run in sequential mode on the parent (non-worker) thread. This
|
|
|
|
/// is used by the style system to queue up work which is not safe to do during
|
|
|
|
/// the parallel traversal.
|
|
|
|
pub enum SequentialTask<E: TElement> {
|
2017-04-13 16:56:03 +03:00
|
|
|
/// Entry to avoid an unused type parameter error on servo.
|
|
|
|
Unused(SendElement<E>),
|
2017-04-17 13:07:23 +03:00
|
|
|
|
|
|
|
/// Performs one of a number of possible tasks related to updating animations based on the
|
|
|
|
/// |tasks| field. These include updating CSS animations/transitions that changed as part
|
|
|
|
/// of the non-animation style traversal, and updating the computed effect properties.
|
2017-03-27 13:47:47 +03:00
|
|
|
#[cfg(feature = "gecko")]
|
2017-04-17 13:07:23 +03:00
|
|
|
UpdateAnimations {
|
2017-04-27 15:39:42 +03:00
|
|
|
/// The target element or pseudo-element.
|
2017-04-17 13:07:23 +03:00
|
|
|
el: SendElement<E>,
|
|
|
|
/// The before-change style for transitions. We use before-change style as the initial
|
|
|
|
/// value of its Keyframe. Required if |tasks| includes CSSTransitions.
|
|
|
|
before_change_style: Option<Arc<ComputedValues>>,
|
|
|
|
/// The tasks which are performed in this SequentialTask.
|
|
|
|
tasks: UpdateAnimationsTasks
|
|
|
|
},
|
2017-02-09 06:33:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<E: TElement> SequentialTask<E> {
|
|
|
|
/// Executes this task.
|
|
|
|
pub fn execute(self) {
|
|
|
|
use self::SequentialTask::*;
|
|
|
|
debug_assert!(thread_state::get() == thread_state::LAYOUT);
|
|
|
|
match self {
|
2017-04-13 16:56:03 +03:00
|
|
|
Unused(_) => unreachable!(),
|
2017-03-27 13:47:47 +03:00
|
|
|
#[cfg(feature = "gecko")]
|
2017-04-27 15:39:42 +03:00
|
|
|
UpdateAnimations { el, before_change_style, tasks } => {
|
|
|
|
unsafe { el.update_animations(before_change_style, tasks) };
|
2017-03-10 07:23:21 +03:00
|
|
|
}
|
2017-02-09 06:33:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-17 13:07:23 +03:00
|
|
|
/// Creates a task to update various animation-related state on
|
|
|
|
/// a given (pseudo-)element.
|
2017-03-27 13:47:47 +03:00
|
|
|
#[cfg(feature = "gecko")]
|
2017-04-17 13:07:23 +03:00
|
|
|
pub fn update_animations(el: E,
|
|
|
|
before_change_style: Option<Arc<ComputedValues>>,
|
2017-03-27 13:47:47 +03:00
|
|
|
tasks: UpdateAnimationsTasks) -> Self {
|
2017-03-10 07:23:21 +03:00
|
|
|
use self::SequentialTask::*;
|
2017-04-27 15:39:42 +03:00
|
|
|
UpdateAnimations {
|
|
|
|
el: unsafe { SendElement::new(el) },
|
|
|
|
before_change_style: before_change_style,
|
|
|
|
tasks: tasks,
|
|
|
|
}
|
2017-03-10 07:23:21 +03:00
|
|
|
}
|
2017-01-20 02:27:34 +03:00
|
|
|
}
|
|
|
|
|
2017-04-13 16:56:03 +03:00
|
|
|
/// Map from Elements to ElementSelectorFlags. Used to defer applying selector
|
|
|
|
/// flags until after the traversal.
|
|
|
|
pub struct SelectorFlagsMap<E: TElement> {
|
|
|
|
/// The hashmap storing the flags to apply.
|
|
|
|
map: FnvHashMap<SendElement<E>, ElementSelectorFlags>,
|
|
|
|
/// An LRU cache to avoid hashmap lookups, which can be slow if the map
|
|
|
|
/// gets big.
|
2017-06-04 23:29:24 +03:00
|
|
|
cache: LRUCache<[(SendElement<E>, ElementSelectorFlags); 4 + 1]>,
|
2017-04-13 16:56:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
impl<E: TElement> Drop for SelectorFlagsMap<E> {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
debug_assert!(self.map.is_empty());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<E: TElement> SelectorFlagsMap<E> {
|
|
|
|
/// Creates a new empty SelectorFlagsMap.
|
|
|
|
pub fn new() -> Self {
|
|
|
|
SelectorFlagsMap {
|
|
|
|
map: FnvHashMap::default(),
|
2017-06-04 23:29:24 +03:00
|
|
|
cache: LRUCache::new(),
|
2017-04-13 16:56:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Inserts some flags into the map for a given element.
|
|
|
|
pub fn insert_flags(&mut self, element: E, flags: ElementSelectorFlags) {
|
|
|
|
let el = unsafe { SendElement::new(element) };
|
|
|
|
// Check the cache. If the flags have already been noted, we're done.
|
|
|
|
if self.cache.iter().find(|x| x.0 == el)
|
|
|
|
.map_or(ElementSelectorFlags::empty(), |x| x.1)
|
|
|
|
.contains(flags) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let f = self.map.entry(el).or_insert(ElementSelectorFlags::empty());
|
|
|
|
*f |= flags;
|
|
|
|
|
|
|
|
// Insert into the cache. We don't worry about duplicate entries,
|
|
|
|
// which lets us avoid reshuffling.
|
|
|
|
self.cache.insert((unsafe { SendElement::new(element) }, *f))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Applies the flags. Must be called on the main thread.
|
|
|
|
pub fn apply_flags(&mut self) {
|
|
|
|
debug_assert!(thread_state::get() == thread_state::LAYOUT);
|
|
|
|
for (el, flags) in self.map.drain() {
|
|
|
|
unsafe { el.set_selector_flags(flags); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-02 15:10:56 +03:00
|
|
|
/// A thread-local style context.
|
|
|
|
///
|
|
|
|
/// This context contains data that needs to be used during restyling, but is
|
|
|
|
/// not required to be unique among worker threads, so we create one per worker
|
|
|
|
/// thread in order to be able to mutate it without locking.
|
2016-12-21 22:11:12 +03:00
|
|
|
pub struct ThreadLocalStyleContext<E: TElement> {
|
2017-01-02 15:10:56 +03:00
|
|
|
/// A cache to share style among siblings.
|
2016-12-21 22:11:12 +03:00
|
|
|
pub style_sharing_candidate_cache: StyleSharingCandidateCache<E>,
|
2017-01-02 15:10:56 +03:00
|
|
|
/// The bloom filter used to fast-reject selector-matching.
|
2016-12-22 23:02:38 +03:00
|
|
|
pub bloom_filter: StyleBloom<E>,
|
2016-07-02 00:12:54 +03:00
|
|
|
/// A channel on which new animations that have been triggered by style
|
|
|
|
/// recalculation can be sent.
|
2017-05-12 16:56:47 +03:00
|
|
|
#[cfg(feature = "servo")]
|
servo: Merge #12515 - Make the style crate more concrete (from servo:concrete-style); r=bholley
Background:
The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).
Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.
----
The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.
The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).
Simplifying code is nice to make it more maintainable, but this is motivated by another change described in https://github.com/servo/servo/pull/12391#issuecomment-232183942. (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)
r? @bholley
---
<!-- 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
- [x] These changes fix #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: 2d01d41a506bcbc7f26a2284b9f42390d6ef96ab
--HG--
rename : servo/ports/geckolib/selector_impl.rs => servo/components/style/gecko_selector_impl.rs
rename : servo/ports/geckolib/values.rs => servo/components/style/gecko_values.rs
rename : servo/ports/geckolib/properties.mako.rs => servo/components/style/properties/gecko.mako.rs
2016-07-20 10:58:34 +03:00
|
|
|
pub new_animations_sender: Sender<Animation>,
|
2017-02-09 06:33:27 +03:00
|
|
|
/// 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.
|
|
|
|
pub tasks: Vec<SequentialTask<E>>,
|
2017-04-13 16:56:03 +03:00
|
|
|
/// ElementSelectorFlags that need to be applied after the traversal is
|
|
|
|
/// complete. This map is used in cases where the matching algorithm needs
|
|
|
|
/// to set flags on elements it doesn't have exclusive access to (i.e. other
|
|
|
|
/// than the current element).
|
|
|
|
pub selector_flags: SelectorFlagsMap<E>,
|
2017-01-20 02:27:34 +03:00
|
|
|
/// Statistics about the traversal.
|
|
|
|
pub statistics: TraversalStatistics,
|
2017-01-10 04:26:50 +03:00
|
|
|
/// Information related to the current element, non-None during processing.
|
2017-04-07 04:07:48 +03:00
|
|
|
pub current_element_info: Option<CurrentElementInfo>,
|
2017-04-09 14:15:51 +03:00
|
|
|
/// The struct used to compute and cache font metrics from style
|
|
|
|
/// for evaluation of the font-relative em/ch units and font-size
|
|
|
|
pub font_metrics_provider: E::FontMetricsProvider,
|
2015-12-30 08:31:23 +03:00
|
|
|
}
|
|
|
|
|
2016-12-21 22:11:12 +03:00
|
|
|
impl<E: TElement> ThreadLocalStyleContext<E> {
|
2017-01-10 04:26:50 +03:00
|
|
|
/// Creates a new `ThreadLocalStyleContext` from a shared one.
|
2017-05-12 16:56:47 +03:00
|
|
|
#[cfg(feature = "servo")]
|
2016-12-21 22:11:12 +03:00
|
|
|
pub fn new(shared: &SharedStyleContext) -> Self {
|
2016-12-16 22:38:27 +03:00
|
|
|
ThreadLocalStyleContext {
|
2016-12-21 22:11:12 +03:00
|
|
|
style_sharing_candidate_cache: StyleSharingCandidateCache::new(),
|
2016-12-22 23:02:38 +03:00
|
|
|
bloom_filter: StyleBloom::new(),
|
2016-12-21 22:11:12 +03:00
|
|
|
new_animations_sender: shared.local_context_creation_data.lock().unwrap().new_animations_sender.clone(),
|
2017-02-09 06:33:27 +03:00
|
|
|
tasks: Vec::new(),
|
2017-04-13 16:56:03 +03:00
|
|
|
selector_flags: SelectorFlagsMap::new(),
|
2017-01-20 02:27:34 +03:00
|
|
|
statistics: TraversalStatistics::default(),
|
2017-01-10 04:26:50 +03:00
|
|
|
current_element_info: None,
|
2017-04-09 14:15:51 +03:00
|
|
|
font_metrics_provider: E::FontMetricsProvider::create_from(shared),
|
2016-07-02 00:12:54 +03:00
|
|
|
}
|
|
|
|
}
|
2017-01-10 04:26:50 +03:00
|
|
|
|
2017-05-12 16:56:47 +03:00
|
|
|
#[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),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-10 04:26:50 +03:00
|
|
|
/// 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());
|
|
|
|
self.current_element_info = Some(CurrentElementInfo {
|
|
|
|
element: element.as_node().opaque(),
|
|
|
|
is_initial_style: !data.has_styles(),
|
2017-05-31 18:07:53 +03:00
|
|
|
validation_data: ValidationData::default(),
|
2017-04-07 04:07:48 +03:00
|
|
|
possibly_expired_animations: Vec::new(),
|
2017-01-10 04:26:50 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Notes when the style system finishes traversing an element.
|
|
|
|
pub fn end_element(&mut self, element: E) {
|
|
|
|
debug_assert!(self.current_element_info.is_some());
|
|
|
|
debug_assert!(self.current_element_info.as_ref().unwrap().element ==
|
|
|
|
element.as_node().opaque());
|
|
|
|
self.current_element_info = None;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if the current element being traversed is being styled for
|
|
|
|
/// the first time.
|
|
|
|
///
|
|
|
|
/// Panics if called while no element is being traversed.
|
|
|
|
pub fn is_initial_style(&self) -> bool {
|
|
|
|
self.current_element_info.as_ref().unwrap().is_initial_style
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<E: TElement> Drop for ThreadLocalStyleContext<E> {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
debug_assert!(self.current_element_info.is_none());
|
2017-04-13 16:56:03 +03:00
|
|
|
debug_assert!(thread_state::get() == thread_state::LAYOUT);
|
|
|
|
|
|
|
|
// Apply any slow selector flags that need to be set on parents.
|
|
|
|
self.selector_flags.apply_flags();
|
2017-02-09 06:33:27 +03:00
|
|
|
|
|
|
|
// Execute any enqueued sequential tasks.
|
|
|
|
for task in self.tasks.drain(..) {
|
|
|
|
task.execute();
|
|
|
|
}
|
2017-01-10 04:26:50 +03:00
|
|
|
}
|
2015-12-30 08:31:23 +03:00
|
|
|
}
|
|
|
|
|
2017-01-02 15:10:56 +03:00
|
|
|
/// A `StyleContext` is just a simple container for a immutable reference to a
|
|
|
|
/// shared style context, and a mutable reference to a local one.
|
2016-12-21 22:11:12 +03:00
|
|
|
pub struct StyleContext<'a, E: TElement + 'a> {
|
2017-01-02 15:10:56 +03:00
|
|
|
/// The shared style context reference.
|
servo: Merge #16014 - Per-process lock for CSSOM objects (from servo:style-ref); r=emilio
<!-- Please describe your changes on the following line: -->
Before this PR, every object reflected in CSSOM is in `Arc<RwLock<_>>` to enable safe (synchronized) mutable aliasing. Acquiring all these locks has significant cost during selector matching:
* https://bugzilla.mozilla.org/show_bug.cgi?id=1311469
* https://bugzilla.mozilla.org/show_bug.cgi?id=1335941
* https://bugzilla.mozilla.org/show_bug.cgi?id=1339703
This PR introduce a mechanism to protect many objects with the same `RwLock` that only needs to be acquired once.
In Stylo, there is one such lock per process (in a `lazy_static`), used for everything.
I non-Stylo Servo, I originally intended to have one such lock per document (for author-origin stylesheets, and one per process for user-agent and user sytlesheets since they’re shared across documents, and never mutated anyway). However I failed to have the same document-specific (or pipeline-specific) `Arc` reachable from both `Document` nodes and `LayoutThread`. Recursively following callers lead me to include this `Arc` in `UnprivilegedPipelineContent`, but that needs to be serializable. So there is a second process-wide lock.
This was previously #15998, closed accidentally.
---
<!-- 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 #__ (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Source-Repo: https://github.com/servo/servo
Source-Revision: bb54f0a429de0e8b8861f8071b6cf82f73622664
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 851230e57ac8775707df5f0f103be5feac81fc41
2017-03-20 00:31:19 +03:00
|
|
|
pub shared: &'a SharedStyleContext<'a>,
|
2017-01-02 15:10:56 +03:00
|
|
|
/// The thread-local style context (mutable) reference.
|
2016-12-21 22:11:12 +03:00
|
|
|
pub thread_local: &'a mut ThreadLocalStyleContext<E>,
|
2015-12-30 08:31:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Why we're doing reflow.
|
|
|
|
#[derive(PartialEq, Copy, Clone, Debug)]
|
|
|
|
pub enum ReflowGoal {
|
|
|
|
/// We're reflowing in order to send a display list to the screen.
|
|
|
|
ForDisplay,
|
|
|
|
/// We're reflowing in order to satisfy a script query. No display list will be created.
|
|
|
|
ForScriptQuery,
|
|
|
|
}
|