2013-04-06 03:31:01 +04: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-01-10 13:19:04 +03:00
|
|
|
//! The layout thread. Performs layout on the DOM, builds display lists and sends them to be
|
2014-12-08 20:28:10 +03:00
|
|
|
//! painted.
|
2012-05-04 04:14:39 +04:00
|
|
|
|
2016-06-21 01:00:13 +03:00
|
|
|
#![feature(box_syntax)]
|
|
|
|
#![feature(mpsc_select)]
|
2017-07-15 17:44:08 +03:00
|
|
|
#![feature(nonzero)]
|
2016-06-21 01:00:13 +03:00
|
|
|
|
|
|
|
extern crate app_units;
|
2017-07-15 17:44:08 +03:00
|
|
|
extern crate atomic_refcell;
|
|
|
|
extern crate core;
|
2016-06-21 01:00:13 +03:00
|
|
|
extern crate euclid;
|
|
|
|
extern crate fnv;
|
|
|
|
extern crate gfx;
|
|
|
|
extern crate gfx_traits;
|
|
|
|
extern crate heapsize;
|
2017-07-15 17:44:08 +03:00
|
|
|
#[macro_use]
|
|
|
|
extern crate html5ever;
|
2016-06-21 01:00:13 +03:00
|
|
|
extern crate ipc_channel;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate layout;
|
|
|
|
extern crate layout_traits;
|
2016-08-23 16:34:04 +03:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
2016-06-21 01:00:13 +03:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2017-07-20 21:34:35 +03:00
|
|
|
extern crate metrics;
|
2016-06-21 01:00:13 +03:00
|
|
|
extern crate msg;
|
|
|
|
extern crate net_traits;
|
2016-11-02 02:26:20 +03:00
|
|
|
extern crate parking_lot;
|
2016-06-21 01:00:13 +03:00
|
|
|
#[macro_use]
|
|
|
|
extern crate profile_traits;
|
2017-07-15 17:44:08 +03:00
|
|
|
extern crate range;
|
2016-11-14 23:47:21 +03:00
|
|
|
extern crate rayon;
|
2016-06-21 01:00:13 +03:00
|
|
|
extern crate script;
|
|
|
|
extern crate script_layout_interface;
|
|
|
|
extern crate script_traits;
|
2016-10-30 01:14:10 +03:00
|
|
|
extern crate selectors;
|
2016-06-21 01:00:13 +03:00
|
|
|
extern crate serde_json;
|
2017-07-19 16:03:17 +03:00
|
|
|
extern crate servo_arc;
|
2017-07-12 02:24:18 +03:00
|
|
|
extern crate servo_atoms;
|
2016-12-15 03:48:42 +03:00
|
|
|
extern crate servo_config;
|
|
|
|
extern crate servo_geometry;
|
2016-11-18 00:34:47 +03:00
|
|
|
extern crate servo_url;
|
2016-06-21 01:00:13 +03:00
|
|
|
extern crate style;
|
2017-07-31 21:13:26 +03:00
|
|
|
extern crate style_traits;
|
2017-07-13 07:52:27 +03:00
|
|
|
extern crate webrender_api;
|
2015-02-09 07:00:43 +03:00
|
|
|
|
2017-07-15 17:44:08 +03:00
|
|
|
mod dom_wrapper;
|
|
|
|
|
2015-10-01 00:19:33 +03:00
|
|
|
use app_units::Au;
|
2017-07-15 17:44:08 +03:00
|
|
|
use dom_wrapper::{ServoLayoutElement, ServoLayoutDocument, ServoLayoutNode};
|
|
|
|
use dom_wrapper::drop_style_and_layout_data;
|
2017-07-31 21:13:26 +03:00
|
|
|
use euclid::{Point2D, Rect, Size2D, ScaleFactor, TypedSize2D};
|
2017-05-30 15:28:06 +03:00
|
|
|
use fnv::FnvHashMap;
|
2017-04-18 00:08:00 +03:00
|
|
|
use gfx::display_list::{OpaqueNode, WebRenderImageInfo};
|
2015-12-17 08:27:29 +03:00
|
|
|
use gfx::font;
|
2016-01-10 13:19:04 +03:00
|
|
|
use gfx::font_cache_thread::FontCacheThread;
|
2015-09-28 21:11:50 +03:00
|
|
|
use gfx::font_context;
|
2017-04-20 09:55:33 +03:00
|
|
|
use gfx_traits::{Epoch, node_id_from_clip_id};
|
2016-02-05 01:10:36 +03:00
|
|
|
use heapsize::HeapSizeOf;
|
2015-07-25 10:50:31 +03:00
|
|
|
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
2015-07-25 03:55:05 +03:00
|
|
|
use ipc_channel::router::ROUTER;
|
2016-06-21 01:00:13 +03:00
|
|
|
use layout::animation;
|
|
|
|
use layout::construct::ConstructionResult;
|
2017-02-08 04:16:05 +03:00
|
|
|
use layout::context::LayoutContext;
|
2017-07-12 02:24:18 +03:00
|
|
|
use layout::context::RegisteredPainter;
|
2017-07-31 21:13:26 +03:00
|
|
|
use layout::context::RegisteredPainters;
|
2016-12-21 22:11:12 +03:00
|
|
|
use layout::context::heap_size_of_persistent_local_context;
|
2016-06-21 01:00:13 +03:00
|
|
|
use layout::display_list_builder::ToGfxColor;
|
2017-08-08 22:04:23 +03:00
|
|
|
use layout::flow::{self, Flow, ImmutableFlowUtils, MutableOwnedFlowUtils};
|
2016-11-05 00:53:38 +03:00
|
|
|
use layout::flow_ref::FlowRef;
|
2017-04-23 07:55:22 +03:00
|
|
|
use layout::incremental::{LayoutDamageComputation, REFLOW_ENTIRE_DOCUMENT, RelayoutMode};
|
2016-06-21 01:00:13 +03:00
|
|
|
use layout::layout_debug;
|
2017-03-02 22:43:17 +03:00
|
|
|
use layout::opaque_node::OpaqueNodeMethods;
|
2016-06-21 01:00:13 +03:00
|
|
|
use layout::parallel;
|
|
|
|
use layout::query::{LayoutRPCImpl, LayoutThreadData, process_content_box_request, process_content_boxes_request};
|
2016-09-09 06:19:19 +03:00
|
|
|
use layout::query::{process_margin_style_query, process_node_overflow_request, process_resolved_style_request};
|
2016-10-21 09:43:25 +03:00
|
|
|
use layout::query::{process_node_geometry_request, process_node_scroll_area_request};
|
2016-12-07 01:42:00 +03:00
|
|
|
use layout::query::{process_node_scroll_root_id_request, process_offset_parent_query};
|
2016-06-21 01:00:13 +03:00
|
|
|
use layout::sequential;
|
2017-08-08 22:04:23 +03:00
|
|
|
use layout::traversal::{ComputeStackingRelativePositions, PreorderFlowTraversal, RecalcStyleAndConstructFlows};
|
2016-11-29 13:36:05 +03:00
|
|
|
use layout::webrender_helpers::WebRenderDisplayListConverter;
|
2016-11-01 21:05:46 +03:00
|
|
|
use layout::wrapper::LayoutNodeLayoutData;
|
2016-05-28 17:49:44 +03:00
|
|
|
use layout_traits::LayoutThreadFactory;
|
2017-07-20 21:34:35 +03:00
|
|
|
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory};
|
2017-05-22 23:13:42 +03:00
|
|
|
use msg::constellation_msg::PipelineId;
|
|
|
|
use msg::constellation_msg::TopLevelBrowsingContextId;
|
2017-03-27 23:50:46 +03:00
|
|
|
use net_traits::image_cache::{ImageCache, UsePlaceholder};
|
2016-11-02 02:26:20 +03:00
|
|
|
use parking_lot::RwLock;
|
2015-08-07 02:43:09 +03:00
|
|
|
use profile_traits::mem::{self, Report, ReportKind, ReportsChan};
|
2015-11-10 05:17:45 +03:00
|
|
|
use profile_traits::time::{self, TimerMetadata, profile};
|
2016-09-09 06:19:19 +03:00
|
|
|
use profile_traits::time::{TimerMetadataFrameType, TimerMetadataReflowType};
|
2017-05-15 23:00:19 +03:00
|
|
|
use script_layout_interface::message::{Msg, NewLayoutThreadInfo, Reflow, ReflowQueryType};
|
|
|
|
use script_layout_interface::message::{ScriptReflow, ReflowComplete};
|
2016-06-20 20:54:20 +03:00
|
|
|
use script_layout_interface::rpc::{LayoutRPC, MarginStyleResponse, NodeOverflowResponse, OffsetParentResponse};
|
2017-01-12 01:19:10 +03:00
|
|
|
use script_layout_interface::rpc::TextIndexResponse;
|
2016-06-20 20:54:20 +03:00
|
|
|
use script_layout_interface::wrapper_traits::LayoutNode;
|
2016-06-01 04:54:29 +03:00
|
|
|
use script_traits::{ConstellationControlMsg, LayoutControlMsg, LayoutMsg as ConstellationMsg};
|
2017-05-16 16:33:22 +03:00
|
|
|
use script_traits::{ScrollState, UntrustedNodeAddress};
|
2017-07-31 21:13:26 +03:00
|
|
|
use script_traits::DrawAPaintImageResult;
|
|
|
|
use script_traits::Painter;
|
2016-10-30 01:14:10 +03:00
|
|
|
use selectors::Element;
|
2017-07-19 16:03:17 +03:00
|
|
|
use servo_arc::Arc as ServoArc;
|
2017-07-12 02:24:18 +03:00
|
|
|
use servo_atoms::Atom;
|
2016-12-15 03:48:42 +03:00
|
|
|
use servo_config::opts;
|
|
|
|
use servo_config::prefs::PREFS;
|
|
|
|
use servo_config::resource_files::read_resource_file;
|
|
|
|
use servo_geometry::max_rect;
|
2016-11-18 00:34:47 +03:00
|
|
|
use servo_url::ServoUrl;
|
2015-03-17 22:39:51 +03:00
|
|
|
use std::borrow::ToOwned;
|
2017-05-12 16:56:47 +03:00
|
|
|
use std::cell::{Cell, RefCell};
|
2015-05-20 03:40:36 +03:00
|
|
|
use std::collections::HashMap;
|
2017-02-23 04:50:48 +03:00
|
|
|
use std::mem as std_mem;
|
2015-11-16 22:48:45 +03:00
|
|
|
use std::ops::{Deref, DerefMut};
|
2016-08-23 16:34:04 +03:00
|
|
|
use std::process;
|
2016-11-02 02:26:20 +03:00
|
|
|
use std::sync::{Arc, Mutex, MutexGuard};
|
2016-09-09 06:19:19 +03:00
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
|
|
use std::sync::mpsc::{Receiver, Sender, channel};
|
2016-12-15 03:48:42 +03:00
|
|
|
use std::thread;
|
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
|
|
|
use style::animation::Animation;
|
2017-04-12 10:27:02 +03:00
|
|
|
use style::context::{QuirksMode, ReflowGoal, SharedStyleContext};
|
|
|
|
use style::context::{StyleSystemOptions, ThreadLocalStyleContextCreationInfo};
|
2017-07-31 21:13:26 +03:00
|
|
|
use style::context::RegisteredSpeculativePainter;
|
|
|
|
use style::context::RegisteredSpeculativePainters;
|
2016-12-13 06:13:03 +03:00
|
|
|
use style::dom::{ShowSubtree, ShowSubtreeDataAndPrimaryValues, TElement, TNode};
|
2017-08-25 20:23:41 +03:00
|
|
|
use style::driver;
|
2017-04-24 13:05:51 +03:00
|
|
|
use style::error_reporting::{NullReporter, RustLogReporter};
|
2017-06-14 14:16:24 +03:00
|
|
|
use style::invalidation::element::restyle_hints::RestyleHint;
|
2016-02-18 12:21:29 +03:00
|
|
|
use style::logical_geometry::LogicalPoint;
|
2017-04-12 18:00:26 +03:00
|
|
|
use style::media_queries::{Device, MediaList, MediaType};
|
2017-07-12 02:24:18 +03:00
|
|
|
use style::properties::PropertyId;
|
2017-05-10 23:08:59 +03:00
|
|
|
use style::selector_parser::SnapshotMap;
|
2016-11-08 01:31:10 +03:00
|
|
|
use style::servo::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, REPOSITION, STORE_OVERFLOW};
|
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 style::shared_lock::{SharedRwLock, SharedRwLockReadGuard, StylesheetGuards};
|
2017-09-14 23:55:21 +03:00
|
|
|
use style::stylesheets::{Origin, Stylesheet, DocumentStyleSheet, StylesheetInDocument, UserAgentStylesheets};
|
2017-08-13 14:39:40 +03:00
|
|
|
use style::stylist::Stylist;
|
2016-08-22 18:39:51 +03:00
|
|
|
use style::thread_state;
|
2016-07-20 21:38:31 +03:00
|
|
|
use style::timer::Timer;
|
2017-08-25 20:23:41 +03:00
|
|
|
use style::traversal::DomTraversal;
|
2017-07-28 02:29:29 +03:00
|
|
|
use style::traversal_flags::TraversalFlags;
|
2017-07-31 21:13:26 +03:00
|
|
|
use style_traits::CSSPixel;
|
|
|
|
use style_traits::DevicePixel;
|
|
|
|
use style_traits::SpeculativePainter;
|
2015-05-20 03:40:36 +03:00
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
/// Information needed by the layout thread.
|
|
|
|
pub struct LayoutThread {
|
2013-11-18 23:54:00 +04:00
|
|
|
/// The ID of the pipeline that we belong to.
|
2015-11-12 23:56:12 +03:00
|
|
|
id: PipelineId,
|
2013-11-18 23:54:00 +04:00
|
|
|
|
2017-05-22 23:13:42 +03:00
|
|
|
/// The ID of the top-level browsing context that we belong to.
|
|
|
|
top_level_browsing_context_id: TopLevelBrowsingContextId,
|
|
|
|
|
2015-03-17 06:33:50 +03:00
|
|
|
/// The URL of the pipeline that we belong to.
|
2016-11-18 00:34:47 +03:00
|
|
|
url: ServoUrl,
|
2015-03-17 06:33:50 +03:00
|
|
|
|
2017-05-12 16:56:47 +03:00
|
|
|
/// Performs CSS selector matching and style resolution.
|
|
|
|
stylist: Stylist,
|
|
|
|
|
2015-04-02 23:18:42 +03:00
|
|
|
/// Is the current reflow of an iframe, as opposed to a root window?
|
2015-11-12 23:56:12 +03:00
|
|
|
is_iframe: bool,
|
2015-04-02 23:18:42 +03:00
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
/// The port on which we receive messages from the script thread.
|
2015-11-12 23:56:12 +03:00
|
|
|
port: Receiver<Msg>,
|
2013-11-18 23:54:00 +04:00
|
|
|
|
2015-07-14 17:46:07 +03:00
|
|
|
/// The port on which we receive messages from the constellation.
|
2015-11-12 23:56:12 +03:00
|
|
|
pipeline_port: Receiver<LayoutControlMsg>,
|
2014-08-09 00:17:40 +04:00
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
/// The port on which we receive messages from the font cache thread.
|
2015-09-28 21:11:50 +03:00
|
|
|
font_cache_receiver: Receiver<()>,
|
|
|
|
|
|
|
|
/// The channel on which the font cache can send messages to us.
|
2015-11-20 01:29:48 +03:00
|
|
|
font_cache_sender: IpcSender<()>,
|
2015-09-28 21:11:50 +03:00
|
|
|
|
2015-03-04 01:12:45 +03:00
|
|
|
/// The channel on which messages can be sent to the constellation.
|
2016-05-19 22:38:26 +03:00
|
|
|
constellation_chan: IpcSender<ConstellationMsg>,
|
2015-03-04 01:12:45 +03:00
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
/// The channel on which messages can be sent to the script thread.
|
2015-11-20 01:29:48 +03:00
|
|
|
script_chan: IpcSender<ConstellationControlMsg>,
|
2013-11-18 23:54:00 +04:00
|
|
|
|
2014-09-05 06:14:18 +04:00
|
|
|
/// The channel on which messages can be sent to the time profiler.
|
2015-11-12 23:56:12 +03:00
|
|
|
time_profiler_chan: time::ProfilerChan,
|
2014-09-05 06:14:18 +04:00
|
|
|
|
2015-03-17 06:33:50 +03:00
|
|
|
/// The channel on which messages can be sent to the memory profiler.
|
2015-11-12 23:56:12 +03:00
|
|
|
mem_profiler_chan: mem::ProfilerChan,
|
2015-03-17 06:33:50 +03:00
|
|
|
|
2017-03-27 23:50:46 +03:00
|
|
|
/// Reference to the script thread image cache.
|
|
|
|
image_cache: Arc<ImageCache>,
|
2014-09-16 19:16:29 +04:00
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
/// Public interface to the font cache thread.
|
|
|
|
font_cache_thread: FontCacheThread,
|
2014-07-09 03:31:07 +04:00
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
/// Is this the first reflow in this LayoutThread?
|
2017-05-12 16:56:47 +03:00
|
|
|
first_reflow: Cell<bool>,
|
2014-09-18 20:12:34 +04:00
|
|
|
|
2015-11-10 05:17:45 +03:00
|
|
|
/// The workers that we use for parallel operation.
|
2016-11-14 23:47:21 +03:00
|
|
|
parallel_traversal: Option<rayon::ThreadPool>,
|
2015-11-10 05:17:45 +03:00
|
|
|
|
2016-12-08 01:32:20 +03:00
|
|
|
/// Flag to indicate whether to use parallel operations
|
|
|
|
parallel_flag: bool,
|
|
|
|
|
2015-11-10 05:17:45 +03:00
|
|
|
/// Starts at zero, and increased by one every time a layout completes.
|
|
|
|
/// This can be used to easily check for invalid stale data.
|
2017-05-12 16:56:47 +03:00
|
|
|
generation: Cell<u32>,
|
2015-11-10 05:17:45 +03:00
|
|
|
|
|
|
|
/// A channel on which new animations that have been triggered by style recalculation can be
|
|
|
|
/// sent.
|
|
|
|
new_animations_sender: Sender<Animation>,
|
|
|
|
|
|
|
|
/// Receives newly-discovered animations.
|
|
|
|
new_animations_receiver: Receiver<Animation>,
|
|
|
|
|
|
|
|
/// The number of Web fonts that have been requested but not yet loaded.
|
|
|
|
outstanding_web_fonts: Arc<AtomicUsize>,
|
|
|
|
|
|
|
|
/// The root of the flow tree.
|
2017-05-12 16:56:47 +03:00
|
|
|
root_flow: RefCell<Option<FlowRef>>,
|
2015-11-10 05:17:45 +03:00
|
|
|
|
2017-03-20 04:22:23 +03:00
|
|
|
/// The document-specific shared lock used for author-origin stylesheets
|
|
|
|
document_shared_lock: Option<SharedRwLock>,
|
|
|
|
|
2015-11-10 05:17:45 +03:00
|
|
|
/// The list of currently-running animations.
|
2017-07-19 16:03:17 +03:00
|
|
|
running_animations: ServoArc<RwLock<FnvHashMap<OpaqueNode, Vec<Animation>>>>,
|
2015-11-25 05:30:14 +03:00
|
|
|
|
|
|
|
/// The list of animations that have expired since the last style recalculation.
|
2017-07-19 16:03:17 +03:00
|
|
|
expired_animations: ServoArc<RwLock<FnvHashMap<OpaqueNode, Vec<Animation>>>>,
|
2015-11-10 05:17:45 +03:00
|
|
|
|
|
|
|
/// A counter for epoch messages
|
2017-05-12 16:56:47 +03:00
|
|
|
epoch: Cell<Epoch>,
|
2015-11-10 05:17:45 +03:00
|
|
|
|
|
|
|
/// The size of the viewport. This may be different from the size of the screen due to viewport
|
|
|
|
/// constraints.
|
|
|
|
viewport_size: Size2D<Au>,
|
|
|
|
|
2014-09-05 06:14:18 +04:00
|
|
|
/// A mutex to allow for fast, read-only RPC of layout's internal data
|
2016-01-10 13:19:04 +03:00
|
|
|
/// structures, while still letting the LayoutThread modify them.
|
2014-09-05 06:14:18 +04:00
|
|
|
///
|
|
|
|
/// All the other elements of this struct are read-only.
|
2016-01-10 13:19:04 +03:00
|
|
|
rw_data: Arc<Mutex<LayoutThreadData>>,
|
2015-11-27 01:26:08 +03:00
|
|
|
|
2017-05-30 15:28:06 +03:00
|
|
|
webrender_image_cache: Arc<RwLock<FnvHashMap<(ServoUrl, UsePlaceholder),
|
|
|
|
WebRenderImageInfo>>>,
|
2017-07-31 21:13:26 +03:00
|
|
|
|
|
|
|
/// The executors for paint worklets.
|
|
|
|
registered_painters: RegisteredPaintersImpl,
|
2016-03-23 05:36:31 +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
|
|
|
/// Webrender interface.
|
2017-07-13 07:52:27 +03:00
|
|
|
webrender_api: webrender_api::RenderApi,
|
2016-07-20 21:38:31 +03:00
|
|
|
|
2017-07-29 15:38:23 +03:00
|
|
|
/// Webrender document.
|
|
|
|
webrender_document: webrender_api::DocumentId,
|
|
|
|
|
2016-07-20 21:38:31 +03:00
|
|
|
/// The timer object to control the timing of the animations. This should
|
|
|
|
/// only be a test-mode timer during testing for animations.
|
|
|
|
timer: Timer,
|
2016-07-24 22:53:34 +03:00
|
|
|
|
2016-12-15 03:48:42 +03:00
|
|
|
// Number of layout threads. This is copied from `servo_config::opts`, but we'd
|
2016-07-24 22:53:34 +03:00
|
|
|
// rather limit the dependency on that module here.
|
|
|
|
layout_threads: usize,
|
2016-12-18 00:25:06 +03:00
|
|
|
|
2017-07-20 21:34:35 +03:00
|
|
|
/// Paint time metrics.
|
|
|
|
paint_time_metrics: PaintTimeMetrics,
|
2012-09-26 03:07:38 +04:00
|
|
|
}
|
2012-08-04 02:16:08 +04:00
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
impl LayoutThreadFactory for LayoutThread {
|
2016-05-25 12:25:50 +03:00
|
|
|
type Message = Msg;
|
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
/// Spawns a new layout thread.
|
2016-05-20 13:03:54 +03:00
|
|
|
fn create(id: PipelineId,
|
2017-05-22 23:13:42 +03:00
|
|
|
top_level_browsing_context_id: TopLevelBrowsingContextId,
|
2016-11-18 00:34:47 +03:00
|
|
|
url: ServoUrl,
|
2015-04-02 23:18:42 +03:00
|
|
|
is_iframe: bool,
|
2016-05-25 12:25:50 +03:00
|
|
|
chan: (Sender<Msg>, Receiver<Msg>),
|
2015-07-14 17:46:07 +03:00
|
|
|
pipeline_port: IpcReceiver<LayoutControlMsg>,
|
2016-05-19 22:38:26 +03:00
|
|
|
constellation_chan: IpcSender<ConstellationMsg>,
|
2015-11-20 01:29:48 +03:00
|
|
|
script_chan: IpcSender<ConstellationControlMsg>,
|
2017-03-27 23:50:46 +03:00
|
|
|
image_cache: Arc<ImageCache>,
|
2016-01-10 13:19:04 +03:00
|
|
|
font_cache_thread: FontCacheThread,
|
2015-03-31 19:39:56 +03:00
|
|
|
time_profiler_chan: time::ProfilerChan,
|
2015-07-21 06:43:09 +03:00
|
|
|
mem_profiler_chan: mem::ProfilerChan,
|
2016-12-01 11:35:12 +03:00
|
|
|
content_process_shutdown_chan: Option<IpcSender<()>>,
|
2017-07-13 07:52:27 +03:00
|
|
|
webrender_api_sender: webrender_api::RenderApiSender,
|
2017-07-29 15:38:23 +03:00
|
|
|
webrender_document: webrender_api::DocumentId,
|
2017-07-20 21:34:35 +03:00
|
|
|
layout_threads: usize,
|
|
|
|
paint_time_metrics: PaintTimeMetrics) {
|
2016-12-15 03:48:42 +03:00
|
|
|
thread::Builder::new().name(format!("LayoutThread {:?}", id)).spawn(move || {
|
2016-07-21 19:20:37 +03:00
|
|
|
thread_state::initialize(thread_state::LAYOUT);
|
2016-11-22 00:51:59 +03:00
|
|
|
|
2017-05-22 23:13:42 +03:00
|
|
|
// In order to get accurate crash reports, we install the top-level bc id.
|
|
|
|
TopLevelBrowsingContextId::install(top_level_browsing_context_id);
|
2016-11-22 00:51:59 +03:00
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
{ // Ensures layout thread is destroyed before we send shutdown message
|
2016-05-25 12:25:50 +03:00
|
|
|
let sender = chan.0;
|
2016-01-10 13:19:04 +03:00
|
|
|
let layout = LayoutThread::new(id,
|
2017-05-22 23:13:42 +03:00
|
|
|
top_level_browsing_context_id,
|
2016-11-18 00:34:47 +03:00
|
|
|
url,
|
|
|
|
is_iframe,
|
|
|
|
chan.1,
|
|
|
|
pipeline_port,
|
|
|
|
constellation_chan,
|
|
|
|
script_chan,
|
2017-03-27 23:50:46 +03:00
|
|
|
image_cache.clone(),
|
2016-11-18 00:34:47 +03:00
|
|
|
font_cache_thread,
|
|
|
|
time_profiler_chan,
|
|
|
|
mem_profiler_chan.clone(),
|
|
|
|
webrender_api_sender,
|
2017-07-29 15:38:23 +03:00
|
|
|
webrender_document,
|
2017-07-20 21:34:35 +03:00
|
|
|
layout_threads,
|
|
|
|
paint_time_metrics);
|
2015-07-21 06:43:09 +03:00
|
|
|
|
2015-10-06 10:08:32 +03:00
|
|
|
let reporter_name = format!("layout-reporter-{}", id);
|
2015-08-07 02:43:09 +03:00
|
|
|
mem_profiler_chan.run_with_memory_reporting(|| {
|
|
|
|
layout.start();
|
2015-11-12 23:56:12 +03:00
|
|
|
}, reporter_name, sender, Msg::CollectReports);
|
2013-12-16 03:28:17 +04:00
|
|
|
}
|
2016-12-01 11:35:12 +03:00
|
|
|
if let Some(content_process_shutdown_chan) = content_process_shutdown_chan {
|
|
|
|
let _ = content_process_shutdown_chan.send(());
|
|
|
|
}
|
2016-12-15 03:48:42 +03:00
|
|
|
}).expect("Thread spawning failed");
|
2013-07-03 20:42:47 +04:00
|
|
|
}
|
2014-07-21 23:15:10 +04:00
|
|
|
}
|
2013-07-03 20:42:47 +04:00
|
|
|
|
2017-05-15 23:00:19 +03:00
|
|
|
struct ScriptReflowResult {
|
|
|
|
script_reflow: ScriptReflow,
|
|
|
|
result: RefCell<Option<ReflowComplete>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Deref for ScriptReflowResult {
|
|
|
|
type Target = ScriptReflow;
|
|
|
|
fn deref(&self) -> &ScriptReflow {
|
|
|
|
&self.script_reflow
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ScriptReflowResult {
|
|
|
|
fn new(script_reflow: ScriptReflow) -> ScriptReflowResult {
|
|
|
|
ScriptReflowResult {
|
|
|
|
script_reflow: script_reflow,
|
|
|
|
result: RefCell::new(Some(Default::default())),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for ScriptReflowResult {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
self.script_reflow.script_join_chan.send(
|
|
|
|
self.result
|
|
|
|
.borrow_mut()
|
|
|
|
.take()
|
|
|
|
.unwrap()).unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
/// The `LayoutThread` `rw_data` lock must remain locked until the first reflow,
|
2014-09-12 02:00:13 +04:00
|
|
|
/// as RPC calls don't make sense until then. Use this in combination with
|
2016-01-10 13:19:04 +03:00
|
|
|
/// `LayoutThread::lock_rw_data` and `LayoutThread::return_rw_data`.
|
2015-08-06 12:29:16 +03:00
|
|
|
pub enum RWGuard<'a> {
|
2016-01-10 13:19:04 +03:00
|
|
|
/// If the lock was previously held, from when the thread started.
|
|
|
|
Held(MutexGuard<'a, LayoutThreadData>),
|
2014-09-12 02:00:13 +04:00
|
|
|
/// If the lock was just used, and has been returned since there has been
|
|
|
|
/// a reflow already.
|
2016-01-10 13:19:04 +03:00
|
|
|
Used(MutexGuard<'a, LayoutThreadData>),
|
2014-09-12 02:00:13 +04:00
|
|
|
}
|
|
|
|
|
2015-01-28 04:15:50 +03:00
|
|
|
impl<'a> Deref for RWGuard<'a> {
|
2016-01-10 13:19:04 +03:00
|
|
|
type Target = LayoutThreadData;
|
|
|
|
fn deref(&self) -> &LayoutThreadData {
|
2014-09-12 02:00:13 +04:00
|
|
|
match *self {
|
2015-01-22 18:06:50 +03:00
|
|
|
RWGuard::Held(ref x) => &**x,
|
|
|
|
RWGuard::Used(ref x) => &**x,
|
2014-09-12 02:00:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 04:15:50 +03:00
|
|
|
impl<'a> DerefMut for RWGuard<'a> {
|
2016-01-10 13:19:04 +03:00
|
|
|
fn deref_mut(&mut self) -> &mut LayoutThreadData {
|
2014-09-12 02:00:13 +04:00
|
|
|
match *self {
|
2015-01-22 18:06:50 +03:00
|
|
|
RWGuard::Held(ref mut x) => &mut **x,
|
|
|
|
RWGuard::Used(ref mut x) => &mut **x,
|
2014-09-12 02:00:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-10 05:17:45 +03:00
|
|
|
struct RwData<'a, 'b: 'a> {
|
2016-01-10 13:19:04 +03:00
|
|
|
rw_data: &'b Arc<Mutex<LayoutThreadData>>,
|
|
|
|
possibly_locked_rw_data: &'a mut Option<MutexGuard<'b, LayoutThreadData>>,
|
2015-11-10 05:17:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'b: 'a> RwData<'a, 'b> {
|
|
|
|
/// If no reflow has happened yet, this will just return the lock in
|
|
|
|
/// `possibly_locked_rw_data`. Otherwise, it will acquire the `rw_data` lock.
|
|
|
|
///
|
|
|
|
/// If you do not wish RPCs to remain blocked, just drop the `RWGuard`
|
|
|
|
/// returned from this function. If you _do_ wish for them to remain blocked,
|
|
|
|
/// use `block`.
|
|
|
|
fn lock(&mut self) -> RWGuard<'b> {
|
|
|
|
match self.possibly_locked_rw_data.take() {
|
2017-08-21 18:59:10 +03:00
|
|
|
None => RWGuard::Used(self.rw_data.lock().unwrap()),
|
2015-11-10 05:17:45 +03:00
|
|
|
Some(x) => RWGuard::Held(x),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-28 21:11:50 +03:00
|
|
|
fn add_font_face_rules(stylesheet: &Stylesheet,
|
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
|
|
|
guard: &SharedRwLockReadGuard,
|
2015-09-28 21:11:50 +03:00
|
|
|
device: &Device,
|
2016-01-10 13:19:04 +03:00
|
|
|
font_cache_thread: &FontCacheThread,
|
2015-11-20 01:29:48 +03:00
|
|
|
font_cache_sender: &IpcSender<()>,
|
2015-09-28 21:11:50 +03:00
|
|
|
outstanding_web_fonts_counter: &Arc<AtomicUsize>) {
|
2016-06-07 11:50:18 +03:00
|
|
|
if opts::get().load_webfonts_synchronously {
|
|
|
|
let (sender, receiver) = ipc::channel().unwrap();
|
2017-04-03 11:53:09 +03:00
|
|
|
stylesheet.effective_font_face_rules(&device, guard, |rule| {
|
|
|
|
if let Some(font_face) = rule.font_face() {
|
|
|
|
let effective_sources = font_face.effective_sources();
|
|
|
|
font_cache_thread.add_web_font(font_face.family().clone(),
|
|
|
|
effective_sources,
|
|
|
|
sender.clone());
|
|
|
|
receiver.recv().unwrap();
|
|
|
|
}
|
2016-10-20 19:29:27 +03:00
|
|
|
})
|
2016-06-07 11:50:18 +03:00
|
|
|
} else {
|
2017-04-03 11:53:09 +03:00
|
|
|
stylesheet.effective_font_face_rules(&device, guard, |rule| {
|
|
|
|
if let Some(font_face) = rule.font_face() {
|
|
|
|
let effective_sources = font_face.effective_sources();
|
|
|
|
outstanding_web_fonts_counter.fetch_add(1, Ordering::SeqCst);
|
|
|
|
font_cache_thread.add_web_font(font_face.family().clone(),
|
|
|
|
effective_sources,
|
|
|
|
(*font_cache_sender).clone());
|
|
|
|
}
|
2016-10-20 19:29:27 +03:00
|
|
|
})
|
2015-08-07 23:05:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
impl LayoutThread {
|
|
|
|
/// Creates a new `LayoutThread` structure.
|
2013-07-30 08:21:19 +04:00
|
|
|
fn new(id: PipelineId,
|
2017-05-22 23:13:42 +03:00
|
|
|
top_level_browsing_context_id: TopLevelBrowsingContextId,
|
2016-11-18 00:34:47 +03:00
|
|
|
url: ServoUrl,
|
2015-04-02 23:18:42 +03:00
|
|
|
is_iframe: bool,
|
2014-04-05 02:52:50 +04:00
|
|
|
port: Receiver<Msg>,
|
2015-07-14 17:46:07 +03:00
|
|
|
pipeline_port: IpcReceiver<LayoutControlMsg>,
|
2016-05-19 22:38:26 +03:00
|
|
|
constellation_chan: IpcSender<ConstellationMsg>,
|
2015-11-20 01:29:48 +03:00
|
|
|
script_chan: IpcSender<ConstellationControlMsg>,
|
2017-03-27 23:50:46 +03:00
|
|
|
image_cache: Arc<ImageCache>,
|
2016-01-10 13:19:04 +03:00
|
|
|
font_cache_thread: FontCacheThread,
|
2015-03-26 06:18:48 +03:00
|
|
|
time_profiler_chan: time::ProfilerChan,
|
2016-02-18 22:24:06 +03:00
|
|
|
mem_profiler_chan: mem::ProfilerChan,
|
2017-07-13 07:52:27 +03:00
|
|
|
webrender_api_sender: webrender_api::RenderApiSender,
|
2017-07-29 15:38:23 +03:00
|
|
|
webrender_document: webrender_api::DocumentId,
|
2017-07-20 21:34:35 +03:00
|
|
|
layout_threads: usize,
|
|
|
|
paint_time_metrics: PaintTimeMetrics)
|
2016-01-10 13:19:04 +03:00
|
|
|
-> LayoutThread {
|
2017-07-21 03:09:06 +03:00
|
|
|
// The device pixel ratio is incorrect (it does not have the hidpi value),
|
|
|
|
// but it will be set correctly when the initial reflow takes place.
|
2015-03-18 20:25:00 +03:00
|
|
|
let device = Device::new(
|
2017-08-10 02:24:48 +03:00
|
|
|
MediaType::screen(),
|
2017-07-21 03:09:06 +03:00
|
|
|
opts::get().initial_window_size.to_f32() * ScaleFactor::new(1.0),
|
|
|
|
ScaleFactor::new(opts::get().device_pixels_per_px.unwrap_or(1.0)));
|
2016-12-08 01:32:20 +03:00
|
|
|
|
|
|
|
let configuration =
|
2017-09-19 23:05:54 +03:00
|
|
|
rayon::Configuration::new().num_threads(layout_threads)
|
|
|
|
.start_handler(|_| thread_state::initialize_layout_worker_thread());
|
2017-06-08 05:57:57 +03:00
|
|
|
let parallel_traversal = if layout_threads > 1 {
|
|
|
|
Some(rayon::ThreadPool::new(configuration).expect("ThreadPool creation failed"))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2016-12-08 01:32:20 +03:00
|
|
|
debug!("Possible layout Threads: {}", layout_threads);
|
2013-05-30 11:06:42 +04:00
|
|
|
|
2015-03-31 19:39:56 +03:00
|
|
|
// Create the channel on which new animations can be sent.
|
|
|
|
let (new_animations_sender, new_animations_receiver) = channel();
|
|
|
|
|
2015-07-27 09:08:15 +03:00
|
|
|
// Proxy IPC messages from the pipeline to the layout thread.
|
|
|
|
let pipeline_receiver = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(pipeline_port);
|
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
// Ask the router to proxy IPC messages from the font cache thread to the layout thread.
|
2015-11-20 01:29:48 +03:00
|
|
|
let (ipc_font_cache_sender, ipc_font_cache_receiver) = ipc::channel().unwrap();
|
|
|
|
let font_cache_receiver =
|
|
|
|
ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_font_cache_receiver);
|
2015-09-28 21:11:50 +03:00
|
|
|
|
2015-08-07 23:05:19 +03:00
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
LayoutThread {
|
2013-07-30 08:21:19 +04:00
|
|
|
id: id,
|
2017-05-22 23:13:42 +03:00
|
|
|
top_level_browsing_context_id: top_level_browsing_context_id,
|
2016-05-27 06:37:23 +03:00
|
|
|
url: url,
|
2015-04-02 23:18:42 +03:00
|
|
|
is_iframe: is_iframe,
|
2013-06-18 00:21:34 +04:00
|
|
|
port: port,
|
2015-07-14 17:46:07 +03:00
|
|
|
pipeline_port: pipeline_receiver,
|
2016-02-11 23:15:58 +03:00
|
|
|
script_chan: script_chan.clone(),
|
2015-03-04 01:12:45 +03:00
|
|
|
constellation_chan: constellation_chan.clone(),
|
2014-09-05 06:14:18 +04:00
|
|
|
time_profiler_chan: time_profiler_chan,
|
2015-03-26 06:18:48 +03:00
|
|
|
mem_profiler_chan: mem_profiler_chan,
|
2017-07-31 21:13:26 +03:00
|
|
|
registered_painters: RegisteredPaintersImpl(FnvHashMap::default()),
|
2017-03-27 23:50:46 +03:00
|
|
|
image_cache: image_cache.clone(),
|
2016-01-10 13:19:04 +03:00
|
|
|
font_cache_thread: font_cache_thread,
|
2017-05-12 16:56:47 +03:00
|
|
|
first_reflow: Cell::new(true),
|
2015-09-28 21:11:50 +03:00
|
|
|
font_cache_receiver: font_cache_receiver,
|
2015-11-20 01:29:48 +03:00
|
|
|
font_cache_sender: ipc_font_cache_sender,
|
2015-11-10 05:17:45 +03:00
|
|
|
parallel_traversal: parallel_traversal,
|
2016-12-08 01:32:20 +03:00
|
|
|
parallel_flag: true,
|
2017-05-12 16:56:47 +03:00
|
|
|
generation: Cell::new(0),
|
2015-11-10 05:17:45 +03:00
|
|
|
new_animations_sender: new_animations_sender,
|
|
|
|
new_animations_receiver: new_animations_receiver,
|
2017-08-21 18:59:10 +03:00
|
|
|
outstanding_web_fonts: Arc::new(AtomicUsize::new(0)),
|
2017-05-12 16:56:47 +03:00
|
|
|
root_flow: RefCell::new(None),
|
2017-03-20 04:22:23 +03:00
|
|
|
document_shared_lock: None,
|
2017-07-19 16:03:17 +03:00
|
|
|
running_animations: ServoArc::new(RwLock::new(FnvHashMap::default())),
|
|
|
|
expired_animations: ServoArc::new(RwLock::new(FnvHashMap::default())),
|
2017-05-12 16:56:47 +03:00
|
|
|
epoch: Cell::new(Epoch(0)),
|
2015-11-10 05:17:45 +03:00
|
|
|
viewport_size: Size2D::new(Au(0), Au(0)),
|
2016-10-18 03:22:20 +03:00
|
|
|
webrender_api: webrender_api_sender.create_api(),
|
2017-07-29 15:38:23 +03:00
|
|
|
webrender_document,
|
2017-08-21 18:59:10 +03:00
|
|
|
stylist: Stylist::new(device, QuirksMode::NoQuirks),
|
2014-09-05 06:14:18 +04:00
|
|
|
rw_data: Arc::new(Mutex::new(
|
2016-01-10 13:19:04 +03:00
|
|
|
LayoutThreadData {
|
2014-12-18 10:24:49 +03:00
|
|
|
constellation_chan: constellation_chan,
|
2016-03-02 03:51:08 +03:00
|
|
|
display_list: None,
|
2017-01-18 19:43:19 +03:00
|
|
|
content_box_response: None,
|
2014-11-03 22:03:37 +03:00
|
|
|
content_boxes_response: Vec::new(),
|
2015-07-28 05:45:05 +03:00
|
|
|
client_rect_response: Rect::zero(),
|
2016-03-04 01:30:30 +03:00
|
|
|
hit_test_response: (None, false),
|
2016-12-07 01:42:00 +03:00
|
|
|
scroll_root_id_response: None,
|
2016-03-11 21:49:24 +03:00
|
|
|
scroll_area_response: Rect::zero(),
|
2016-04-20 16:10:26 +03:00
|
|
|
overflow_response: NodeOverflowResponse(None),
|
2016-12-10 12:16:26 +03:00
|
|
|
resolved_style_response: String::new(),
|
2015-08-04 03:39:43 +03:00
|
|
|
offset_parent_response: OffsetParentResponse::empty(),
|
2016-02-24 21:52:43 +03:00
|
|
|
margin_style_response: MarginStyleResponse::empty(),
|
2017-05-16 16:33:22 +03:00
|
|
|
scroll_offsets: HashMap::new(),
|
2017-01-12 01:19:10 +03:00
|
|
|
text_index_response: TextIndexResponse(None),
|
2017-03-02 22:43:17 +03:00
|
|
|
nodes_from_point_response: vec![],
|
2016-07-20 21:38:31 +03:00
|
|
|
})),
|
|
|
|
webrender_image_cache:
|
2017-05-30 15:28:06 +03:00
|
|
|
Arc::new(RwLock::new(FnvHashMap::default())),
|
2016-07-20 21:38:31 +03:00
|
|
|
timer:
|
|
|
|
if PREFS.get("layout.animations.test.enabled")
|
|
|
|
.as_boolean().unwrap_or(false) {
|
|
|
|
Timer::test_mode()
|
|
|
|
} else {
|
|
|
|
Timer::new()
|
|
|
|
},
|
2016-07-24 22:53:34 +03:00
|
|
|
layout_threads: layout_threads,
|
2017-07-20 21:34:35 +03:00
|
|
|
paint_time_metrics: paint_time_metrics,
|
2013-05-30 11:06:42 +04:00
|
|
|
}
|
|
|
|
}
|
2012-09-18 04:24:10 +04:00
|
|
|
|
2013-11-18 23:54:00 +04:00
|
|
|
/// Starts listening on the port.
|
2015-11-10 05:17:45 +03:00
|
|
|
fn start(mut self) {
|
|
|
|
let rw_data = self.rw_data.clone();
|
|
|
|
let mut possibly_locked_rw_data = Some(rw_data.lock().unwrap());
|
|
|
|
let mut rw_data = RwData {
|
|
|
|
rw_data: &rw_data,
|
|
|
|
possibly_locked_rw_data: &mut possibly_locked_rw_data,
|
|
|
|
};
|
|
|
|
while self.handle_request(&mut rw_data) {
|
2013-05-30 11:06:42 +04:00
|
|
|
// Loop indefinitely.
|
2012-10-14 11:42:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-12 02:27:33 +04:00
|
|
|
// Create a layout context for use in building display lists, hit testing, &c.
|
2017-05-12 16:56:47 +03:00
|
|
|
fn build_layout_context<'a>(&'a self,
|
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: StylesheetGuards<'a>,
|
2017-05-15 23:00:19 +03:00
|
|
|
script_initiated_layout: bool,
|
2017-05-10 23:08:59 +03:00
|
|
|
snapshot_map: &'a SnapshotMap)
|
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
|
|
|
-> LayoutContext<'a> {
|
2016-12-16 22:38:27 +03:00
|
|
|
let thread_local_style_context_creation_data =
|
|
|
|
ThreadLocalStyleContextCreationInfo::new(self.new_animations_sender.clone());
|
2016-07-02 00:12:54 +03:00
|
|
|
|
2017-02-08 04:16:05 +03:00
|
|
|
LayoutContext {
|
2017-04-20 09:55:33 +03:00
|
|
|
id: self.id,
|
2015-12-30 08:31:23 +03:00
|
|
|
style_context: SharedStyleContext {
|
2017-05-12 16:56:47 +03:00
|
|
|
stylist: &self.stylist,
|
2017-04-12 10:27:02 +03:00
|
|
|
options: StyleSystemOptions::default(),
|
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: guards,
|
2017-07-23 23:46:43 +03:00
|
|
|
visited_styles_enabled: false,
|
2015-12-30 08:31:23 +03:00
|
|
|
running_animations: self.running_animations.clone(),
|
|
|
|
expired_animations: self.expired_animations.clone(),
|
2017-07-31 21:13:26 +03:00
|
|
|
registered_speculative_painters: &self.registered_painters,
|
2016-12-16 22:38:27 +03:00
|
|
|
local_context_creation_data: Mutex::new(thread_local_style_context_creation_data),
|
2016-07-20 21:38:31 +03:00
|
|
|
timer: self.timer.clone(),
|
2017-04-09 09:04:57 +03:00
|
|
|
traversal_flags: TraversalFlags::empty(),
|
2017-05-10 23:08:59 +03:00
|
|
|
snapshot_map: snapshot_map,
|
2015-12-30 08:31:23 +03:00
|
|
|
},
|
2017-03-27 23:50:46 +03:00
|
|
|
image_cache: self.image_cache.clone(),
|
2016-01-10 13:19:04 +03:00
|
|
|
font_cache_thread: Mutex::new(self.font_cache_thread.clone()),
|
2016-03-23 05:36:31 +03:00
|
|
|
webrender_image_cache: self.webrender_image_cache.clone(),
|
2017-05-15 23:00:19 +03:00
|
|
|
pending_images: if script_initiated_layout { Some(Mutex::new(vec![])) } else { None },
|
|
|
|
newly_transitioning_nodes: if script_initiated_layout { Some(Mutex::new(vec![])) } else { None },
|
2017-07-31 21:13:26 +03:00
|
|
|
registered_painters: &self.registered_painters,
|
2013-06-12 02:27:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
/// Receives and dispatches messages from the script and constellation threads
|
2015-11-10 05:17:45 +03:00
|
|
|
fn handle_request<'a, 'b>(&mut self, possibly_locked_rw_data: &mut RwData<'a, 'b>) -> bool {
|
|
|
|
enum Request {
|
|
|
|
FromPipeline(LayoutControlMsg),
|
|
|
|
FromScript(Msg),
|
|
|
|
FromFontCache,
|
|
|
|
}
|
|
|
|
|
|
|
|
let request = {
|
|
|
|
let port_from_script = &self.port;
|
|
|
|
let port_from_pipeline = &self.pipeline_port;
|
|
|
|
let port_from_font_cache = &self.font_cache_receiver;
|
|
|
|
select! {
|
|
|
|
msg = port_from_pipeline.recv() => {
|
|
|
|
Request::FromPipeline(msg.unwrap())
|
|
|
|
},
|
|
|
|
msg = port_from_script.recv() => {
|
|
|
|
Request::FromScript(msg.unwrap())
|
|
|
|
},
|
|
|
|
msg = port_from_font_cache.recv() => {
|
|
|
|
msg.unwrap();
|
|
|
|
Request::FromFontCache
|
2014-10-29 02:21:48 +03:00
|
|
|
}
|
2015-11-10 05:17:45 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
match request {
|
2017-05-16 16:33:22 +03:00
|
|
|
Request::FromPipeline(LayoutControlMsg::SetScrollStates(new_scroll_states)) => {
|
|
|
|
self.handle_request_helper(Msg::SetScrollStates(new_scroll_states),
|
2016-06-01 04:54:29 +03:00
|
|
|
possibly_locked_rw_data)
|
|
|
|
},
|
2015-11-10 05:17:45 +03:00
|
|
|
Request::FromPipeline(LayoutControlMsg::TickAnimations) => {
|
|
|
|
self.handle_request_helper(Msg::TickAnimations, possibly_locked_rw_data)
|
|
|
|
},
|
|
|
|
Request::FromPipeline(LayoutControlMsg::GetCurrentEpoch(sender)) => {
|
|
|
|
self.handle_request_helper(Msg::GetCurrentEpoch(sender), possibly_locked_rw_data)
|
|
|
|
},
|
|
|
|
Request::FromPipeline(LayoutControlMsg::GetWebFontLoadState(sender)) => {
|
|
|
|
self.handle_request_helper(Msg::GetWebFontLoadState(sender),
|
|
|
|
possibly_locked_rw_data)
|
2015-10-22 20:14:52 +03:00
|
|
|
},
|
2015-11-10 05:17:45 +03:00
|
|
|
Request::FromPipeline(LayoutControlMsg::ExitNow) => {
|
|
|
|
self.handle_request_helper(Msg::ExitNow, possibly_locked_rw_data)
|
2015-10-22 20:14:52 +03:00
|
|
|
},
|
2017-08-22 18:06:30 +03:00
|
|
|
Request::FromPipeline(LayoutControlMsg::PaintMetric(epoch, paint_time)) => {
|
|
|
|
self.paint_time_metrics.maybe_set_metric(epoch, paint_time);
|
|
|
|
true
|
|
|
|
},
|
2015-11-10 05:17:45 +03:00
|
|
|
Request::FromScript(msg) => {
|
|
|
|
self.handle_request_helper(msg, possibly_locked_rw_data)
|
|
|
|
},
|
|
|
|
Request::FromFontCache => {
|
|
|
|
let _rw_data = possibly_locked_rw_data.lock();
|
|
|
|
self.outstanding_web_fonts.fetch_sub(1, Ordering::SeqCst);
|
2015-09-28 21:11:50 +03:00
|
|
|
font_context::invalidate_font_caches();
|
|
|
|
self.script_chan.send(ConstellationControlMsg::WebFontLoaded(self.id)).unwrap();
|
|
|
|
true
|
2015-11-10 05:17:45 +03:00
|
|
|
},
|
2014-09-12 02:00:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
/// Receives and dispatches messages from other threads.
|
2017-08-18 16:33:35 +03:00
|
|
|
fn handle_request_helper<'a, 'b>(
|
|
|
|
&mut self,
|
|
|
|
request: Msg,
|
|
|
|
possibly_locked_rw_data: &mut RwData<'a, 'b>,
|
|
|
|
) -> bool {
|
2014-08-09 00:17:40 +04:00
|
|
|
match request {
|
2017-08-18 16:33:35 +03:00
|
|
|
Msg::AddStylesheet(stylesheet, before_stylesheet) => {
|
|
|
|
let guard = stylesheet.shared_lock.read();
|
2017-08-21 18:59:10 +03:00
|
|
|
self.handle_add_stylesheet(&stylesheet, &guard);
|
2017-08-18 16:33:35 +03:00
|
|
|
|
|
|
|
match before_stylesheet {
|
|
|
|
Some(insertion_point) => {
|
2017-08-22 19:45:42 +03:00
|
|
|
self.stylist.insert_stylesheet_before(
|
2017-08-18 16:33:35 +03:00
|
|
|
DocumentStyleSheet(stylesheet.clone()),
|
|
|
|
DocumentStyleSheet(insertion_point),
|
|
|
|
&guard,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
None => {
|
2017-08-22 19:45:42 +03:00
|
|
|
self.stylist.append_stylesheet(
|
2017-08-18 16:33:35 +03:00
|
|
|
DocumentStyleSheet(stylesheet.clone()),
|
|
|
|
&guard,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Msg::RemoveStylesheet(stylesheet) => {
|
|
|
|
let guard = stylesheet.shared_lock.read();
|
2017-08-22 19:45:42 +03:00
|
|
|
self.stylist.remove_stylesheet(
|
2017-08-18 16:33:35 +03:00
|
|
|
DocumentStyleSheet(stylesheet.clone()),
|
|
|
|
&guard,
|
|
|
|
);
|
2015-03-31 19:39:56 +03:00
|
|
|
}
|
2017-05-12 16:56:47 +03:00
|
|
|
Msg::SetQuirksMode(mode) => self.handle_set_quirks_mode(mode),
|
2014-12-19 01:57:48 +03:00
|
|
|
Msg::GetRPC(response_chan) => {
|
2014-10-29 02:21:48 +03:00
|
|
|
response_chan.send(box LayoutRPCImpl(self.rw_data.clone()) as
|
2015-02-03 21:24:53 +03:00
|
|
|
Box<LayoutRPC + Send>).unwrap();
|
2014-09-05 06:14:18 +04:00
|
|
|
},
|
2014-12-19 01:57:48 +03:00
|
|
|
Msg::Reflow(data) => {
|
2017-05-15 23:00:19 +03:00
|
|
|
let mut data = ScriptReflowResult::new(data);
|
2015-03-26 06:18:48 +03:00
|
|
|
profile(time::ProfilerCategory::LayoutPerform,
|
2015-04-02 23:18:42 +03:00
|
|
|
self.profiler_metadata(),
|
2014-10-29 02:21:48 +03:00
|
|
|
self.time_profiler_chan.clone(),
|
2017-05-15 23:00:19 +03:00
|
|
|
|| self.handle_reflow(&mut data, possibly_locked_rw_data));
|
2014-09-05 06:14:18 +04:00
|
|
|
},
|
2015-03-31 19:39:56 +03:00
|
|
|
Msg::TickAnimations => self.tick_all_animations(possibly_locked_rw_data),
|
2017-05-16 16:33:22 +03:00
|
|
|
Msg::SetScrollStates(new_scroll_states) => {
|
|
|
|
self.set_scroll_states(new_scroll_states, possibly_locked_rw_data);
|
|
|
|
}
|
|
|
|
Msg::UpdateScrollStateFromScript(state) => {
|
|
|
|
let mut rw_data = possibly_locked_rw_data.lock();
|
|
|
|
rw_data.scroll_offsets.insert(state.scroll_root_id, state.scroll_offset);
|
2016-06-01 04:54:29 +03:00
|
|
|
}
|
2015-12-30 07:34:14 +03:00
|
|
|
Msg::ReapStyleAndLayoutData(dead_data) => {
|
2013-11-18 23:54:00 +04:00
|
|
|
unsafe {
|
2016-11-01 21:05:46 +03:00
|
|
|
drop_style_and_layout_data(dead_data)
|
2013-11-18 23:54:00 +04:00
|
|
|
}
|
2015-09-30 04:26:49 +03:00
|
|
|
}
|
2015-03-26 06:18:48 +03:00
|
|
|
Msg::CollectReports(reports_chan) => {
|
|
|
|
self.collect_reports(reports_chan, possibly_locked_rw_data);
|
2015-03-17 06:33:50 +03:00
|
|
|
},
|
2015-05-14 02:37:54 +03:00
|
|
|
Msg::GetCurrentEpoch(sender) => {
|
2015-11-10 05:17:45 +03:00
|
|
|
let _rw_data = possibly_locked_rw_data.lock();
|
2017-05-12 16:56:47 +03:00
|
|
|
sender.send(self.epoch.get()).unwrap();
|
2015-05-14 02:37:54 +03:00
|
|
|
},
|
2016-08-08 06:52:32 +03:00
|
|
|
Msg::AdvanceClockMs(how_many, do_tick) => {
|
|
|
|
self.handle_advance_clock_ms(how_many, possibly_locked_rw_data, do_tick);
|
2016-07-20 21:38:31 +03:00
|
|
|
}
|
2015-09-28 21:11:50 +03:00
|
|
|
Msg::GetWebFontLoadState(sender) => {
|
2015-11-10 05:17:45 +03:00
|
|
|
let _rw_data = possibly_locked_rw_data.lock();
|
|
|
|
let outstanding_web_fonts = self.outstanding_web_fonts.load(Ordering::SeqCst);
|
2015-09-28 21:11:50 +03:00
|
|
|
sender.send(outstanding_web_fonts != 0).unwrap();
|
|
|
|
},
|
2016-01-10 13:19:04 +03:00
|
|
|
Msg::CreateLayoutThread(info) => {
|
|
|
|
self.create_layout_thread(info)
|
2015-07-14 21:11:09 +03:00
|
|
|
}
|
2015-12-16 20:48:30 +03:00
|
|
|
Msg::SetFinalUrl(final_url) => {
|
2016-05-27 06:37:23 +03:00
|
|
|
self.url = final_url;
|
2015-12-16 20:48:30 +03:00
|
|
|
},
|
2017-07-12 02:24:18 +03:00
|
|
|
Msg::RegisterPaint(name, mut properties, painter) => {
|
|
|
|
debug!("Registering the painter");
|
|
|
|
let properties = properties.drain(..)
|
2017-08-16 23:45:49 +03:00
|
|
|
.filter_map(|name| PropertyId::parse(&*name, None)
|
|
|
|
.ok().map(|id| (name.clone(), id)))
|
2017-07-12 02:24:18 +03:00
|
|
|
.filter(|&(_, ref id)| id.as_shorthand().is_err())
|
|
|
|
.collect();
|
2017-07-31 21:13:26 +03:00
|
|
|
let registered_painter = RegisteredPainterImpl {
|
2017-07-12 02:24:18 +03:00
|
|
|
name: name.clone(),
|
|
|
|
properties: properties,
|
|
|
|
painter: painter,
|
|
|
|
};
|
2017-07-31 21:13:26 +03:00
|
|
|
self.registered_painters.0.insert(name, registered_painter);
|
2017-06-07 21:57:07 +03:00
|
|
|
},
|
2014-12-19 01:57:48 +03:00
|
|
|
Msg::PrepareToExit(response_chan) => {
|
2015-11-10 05:17:45 +03:00
|
|
|
self.prepare_to_exit(response_chan);
|
2013-12-13 23:28:10 +04:00
|
|
|
return false
|
2014-09-05 06:14:18 +04:00
|
|
|
},
|
2015-11-07 20:04:45 +03:00
|
|
|
Msg::ExitNow => {
|
2015-04-29 23:51:39 +03:00
|
|
|
debug!("layout: ExitNow received");
|
2015-11-10 05:17:45 +03:00
|
|
|
self.exit_now();
|
2012-10-14 11:42:25 +04:00
|
|
|
return false
|
2017-07-20 21:34:35 +03:00
|
|
|
},
|
|
|
|
Msg::SetNavigationStart(time) => {
|
|
|
|
self.paint_time_metrics.set_navigation_start(time);
|
|
|
|
},
|
2012-10-14 11:42:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2015-11-10 05:17:45 +03:00
|
|
|
fn collect_reports<'a, 'b>(&self,
|
|
|
|
reports_chan: ReportsChan,
|
|
|
|
possibly_locked_rw_data: &mut RwData<'a, 'b>) {
|
2015-03-17 06:33:50 +03:00
|
|
|
let mut reports = vec![];
|
|
|
|
|
|
|
|
// FIXME(njn): Just measuring the display tree for now.
|
2015-11-10 05:17:45 +03:00
|
|
|
let rw_data = possibly_locked_rw_data.lock();
|
2016-03-02 03:51:08 +03:00
|
|
|
let display_list = rw_data.display_list.as_ref();
|
2016-05-27 06:37:23 +03:00
|
|
|
let formatted_url = &format!("url({})", self.url);
|
2015-03-26 06:18:48 +03:00
|
|
|
reports.push(Report {
|
2016-01-10 13:19:04 +03:00
|
|
|
path: path![formatted_url, "layout-thread", "display-list"],
|
2015-07-30 04:42:00 +03:00
|
|
|
kind: ReportKind::ExplicitJemallocHeapSize,
|
2016-03-02 03:51:08 +03:00
|
|
|
size: display_list.map_or(0, |sc| sc.heap_size_of_children()),
|
2015-03-17 06:33:50 +03:00
|
|
|
});
|
|
|
|
|
2016-03-22 04:24:11 +03:00
|
|
|
reports.push(Report {
|
|
|
|
path: path![formatted_url, "layout-thread", "stylist"],
|
|
|
|
kind: ReportKind::ExplicitJemallocHeapSize,
|
2017-05-12 16:56:47 +03:00
|
|
|
size: self.stylist.heap_size_of_children(),
|
2016-03-22 04:24:11 +03:00
|
|
|
});
|
|
|
|
|
2016-12-21 22:11:12 +03:00
|
|
|
// The LayoutThread has data in Persistent TLS...
|
2015-06-13 03:42:32 +03:00
|
|
|
reports.push(Report {
|
2016-01-10 13:19:04 +03:00
|
|
|
path: path![formatted_url, "layout-thread", "local-context"],
|
2015-07-30 04:42:00 +03:00
|
|
|
kind: ReportKind::ExplicitJemallocHeapSize,
|
2016-12-21 22:11:12 +03:00
|
|
|
size: heap_size_of_persistent_local_context(),
|
2015-06-13 03:42:32 +03:00
|
|
|
});
|
|
|
|
|
2015-03-17 06:33:50 +03:00
|
|
|
reports_chan.send(reports);
|
|
|
|
}
|
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
fn create_layout_thread(&self, info: NewLayoutThreadInfo) {
|
2016-05-20 13:03:54 +03:00
|
|
|
LayoutThread::create(info.id,
|
2017-05-22 23:13:42 +03:00
|
|
|
self.top_level_browsing_context_id,
|
2016-05-20 13:03:54 +03:00
|
|
|
info.url.clone(),
|
|
|
|
info.is_parent,
|
|
|
|
info.layout_pair,
|
|
|
|
info.pipeline_port,
|
|
|
|
info.constellation_chan,
|
|
|
|
info.script_chan.clone(),
|
2017-03-27 23:50:46 +03:00
|
|
|
info.image_cache.clone(),
|
2016-05-20 13:03:54 +03:00
|
|
|
self.font_cache_thread.clone(),
|
|
|
|
self.time_profiler_chan.clone(),
|
|
|
|
self.mem_profiler_chan.clone(),
|
|
|
|
info.content_process_shutdown_chan,
|
2016-10-18 03:22:20 +03:00
|
|
|
self.webrender_api.clone_sender(),
|
2017-07-29 15:38:23 +03:00
|
|
|
self.webrender_document,
|
2017-07-20 21:34:35 +03:00
|
|
|
info.layout_threads,
|
|
|
|
info.paint_time_metrics);
|
2015-07-14 21:11:09 +03:00
|
|
|
}
|
|
|
|
|
2015-09-30 04:26:49 +03:00
|
|
|
/// Enters a quiescent state in which no new messages will be processed until an `ExitNow` is
|
2015-03-31 19:39:56 +03:00
|
|
|
/// received. A pong is immediately sent on the given response channel.
|
2015-11-10 05:17:45 +03:00
|
|
|
fn prepare_to_exit(&mut self, response_chan: Sender<()>) {
|
2015-02-03 21:24:53 +03:00
|
|
|
response_chan.send(()).unwrap();
|
2013-12-13 23:28:10 +04:00
|
|
|
loop {
|
2015-01-28 04:15:50 +03:00
|
|
|
match self.port.recv().unwrap() {
|
2015-12-30 07:34:14 +03:00
|
|
|
Msg::ReapStyleAndLayoutData(dead_data) => {
|
2013-12-13 23:28:10 +04:00
|
|
|
unsafe {
|
2016-11-01 21:05:46 +03:00
|
|
|
drop_style_and_layout_data(dead_data)
|
2013-12-13 23:28:10 +04:00
|
|
|
}
|
|
|
|
}
|
2015-11-07 20:04:45 +03:00
|
|
|
Msg::ExitNow => {
|
2016-01-10 13:19:04 +03:00
|
|
|
debug!("layout thread is exiting...");
|
2015-11-10 05:17:45 +03:00
|
|
|
self.exit_now();
|
2013-12-13 23:28:10 +04:00
|
|
|
break
|
|
|
|
}
|
2015-06-11 09:58:41 +03:00
|
|
|
Msg::CollectReports(_) => {
|
|
|
|
// Just ignore these messages at this point.
|
|
|
|
}
|
2013-12-13 23:28:10 +04:00
|
|
|
_ => {
|
2015-06-11 09:58:41 +03:00
|
|
|
panic!("layout: unexpected message received after `PrepareToExitMsg`")
|
2013-11-18 23:54:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
/// Shuts down the layout thread now. If there are any DOM nodes left, layout will now (safely)
|
2013-11-18 23:54:00 +04:00
|
|
|
/// crash.
|
2016-01-03 06:46:34 +03:00
|
|
|
fn exit_now(&mut self) {
|
2017-06-23 03:46:55 +03:00
|
|
|
// Drop the root flow explicitly to avoid holding style data, such as
|
|
|
|
// rule nodes. The `Stylist` checks when it is dropped that all rule
|
|
|
|
// nodes have been GCed, so we want drop anyone who holds them first.
|
|
|
|
self.root_flow.borrow_mut().take();
|
2016-11-14 23:47:21 +03:00
|
|
|
// Drop the rayon threadpool if present.
|
|
|
|
let _ = self.parallel_traversal.take();
|
2013-11-18 23:54:00 +04:00
|
|
|
}
|
|
|
|
|
2017-08-21 18:59:10 +03:00
|
|
|
fn handle_add_stylesheet(
|
2017-08-18 16:33:35 +03:00
|
|
|
&self,
|
2017-08-21 18:59:10 +03:00
|
|
|
stylesheet: &Stylesheet,
|
2017-08-18 16:33:35 +03:00
|
|
|
guard: &SharedRwLockReadGuard,
|
|
|
|
) {
|
2014-08-06 03:12:41 +04:00
|
|
|
// Find all font-face rules and notify the font cache of them.
|
servo: Merge #8039 - Move Stylesheet loading and ownership from the layout task into HTML elements (from tschneidereit:script-owns-stylesheets); r=jdm
Stylesheets for `HTMLLinkElement`s are now loaded by the resource task, triggered by the element in question. Stylesheets are owned by the elements they're associated with, which can be `HTMLStyleElement`, `HTMLLinkElement`, and `HTMLMetaElement` (for `<meta name="viewport">).
Additionally, the quirks mode stylesheet (just as the user and user agent stylesheets a couple of commits ago), is implemented as a lazy static, loaded once per process and shared between all documents.
This all has various nice consequences:
- Stylesheet loading becomes a non-blocking operation.
- Stylesheets are removed when the element they're associated with is removed from the document.
- It'll be possible to implement the CSSOM APIs that require direct access to the stylesheets (i.e., ~ all of them).
- Various subtle correctness issues are fixed.
One piece of interesting follow-up work would be to move parsing of external stylesheets to the resource task, too. Right now, it happens in the link element once loading is complete, so blocks the script task. Moving it to the resource task would probably be fairly straight-forward as it doesn't require access to any external state.
Depends on #7979 because without that loading stylesheets asynchronously breaks lots of content.
Source-Repo: https://github.com/servo/servo
Source-Revision: 7ff3a17524e0e703e3ac279441729c185444be24
2015-11-07 22:41:54 +03:00
|
|
|
// GWTODO: Need to handle unloading web fonts.
|
2017-05-23 04:12:46 +03:00
|
|
|
if stylesheet.is_effective_for_device(self.stylist.device(), &guard) {
|
servo: Merge #8039 - Move Stylesheet loading and ownership from the layout task into HTML elements (from tschneidereit:script-owns-stylesheets); r=jdm
Stylesheets for `HTMLLinkElement`s are now loaded by the resource task, triggered by the element in question. Stylesheets are owned by the elements they're associated with, which can be `HTMLStyleElement`, `HTMLLinkElement`, and `HTMLMetaElement` (for `<meta name="viewport">).
Additionally, the quirks mode stylesheet (just as the user and user agent stylesheets a couple of commits ago), is implemented as a lazy static, loaded once per process and shared between all documents.
This all has various nice consequences:
- Stylesheet loading becomes a non-blocking operation.
- Stylesheets are removed when the element they're associated with is removed from the document.
- It'll be possible to implement the CSSOM APIs that require direct access to the stylesheets (i.e., ~ all of them).
- Various subtle correctness issues are fixed.
One piece of interesting follow-up work would be to move parsing of external stylesheets to the resource task, too. Right now, it happens in the link element once loading is complete, so blocks the script task. Moving it to the resource task would probably be fairly straight-forward as it doesn't require access to any external state.
Depends on #7979 because without that loading stylesheets asynchronously breaks lots of content.
Source-Repo: https://github.com/servo/servo
Source-Revision: 7ff3a17524e0e703e3ac279441729c185444be24
2015-11-07 22:41:54 +03:00
|
|
|
add_font_face_rules(&*stylesheet,
|
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
|
|
|
&guard,
|
2017-05-23 04:12:46 +03:00
|
|
|
self.stylist.device(),
|
2016-01-10 13:19:04 +03:00
|
|
|
&self.font_cache_thread,
|
2015-09-28 21:11:50 +03:00
|
|
|
&self.font_cache_sender,
|
2015-11-10 05:17:45 +03:00
|
|
|
&self.outstanding_web_fonts);
|
2015-03-16 18:54:56 +03:00
|
|
|
}
|
2012-10-31 06:01:55 +04:00
|
|
|
}
|
|
|
|
|
2016-07-20 21:38:31 +03:00
|
|
|
/// Advances the animation clock of the document.
|
|
|
|
fn handle_advance_clock_ms<'a, 'b>(&mut self,
|
|
|
|
how_many_ms: i32,
|
2016-08-08 06:52:32 +03:00
|
|
|
possibly_locked_rw_data: &mut RwData<'a, 'b>,
|
|
|
|
tick_animations: bool) {
|
2016-07-20 21:38:31 +03:00
|
|
|
self.timer.increment(how_many_ms as f64 / 1000.0);
|
2016-08-08 06:52:32 +03:00
|
|
|
if tick_animations {
|
|
|
|
self.tick_all_animations(possibly_locked_rw_data);
|
|
|
|
}
|
2016-07-20 21:38:31 +03:00
|
|
|
}
|
|
|
|
|
servo: Merge #8039 - Move Stylesheet loading and ownership from the layout task into HTML elements (from tschneidereit:script-owns-stylesheets); r=jdm
Stylesheets for `HTMLLinkElement`s are now loaded by the resource task, triggered by the element in question. Stylesheets are owned by the elements they're associated with, which can be `HTMLStyleElement`, `HTMLLinkElement`, and `HTMLMetaElement` (for `<meta name="viewport">).
Additionally, the quirks mode stylesheet (just as the user and user agent stylesheets a couple of commits ago), is implemented as a lazy static, loaded once per process and shared between all documents.
This all has various nice consequences:
- Stylesheet loading becomes a non-blocking operation.
- Stylesheets are removed when the element they're associated with is removed from the document.
- It'll be possible to implement the CSSOM APIs that require direct access to the stylesheets (i.e., ~ all of them).
- Various subtle correctness issues are fixed.
One piece of interesting follow-up work would be to move parsing of external stylesheets to the resource task, too. Right now, it happens in the link element once loading is complete, so blocks the script task. Moving it to the resource task would probably be fairly straight-forward as it doesn't require access to any external state.
Depends on #7979 because without that loading stylesheets asynchronously breaks lots of content.
Source-Repo: https://github.com/servo/servo
Source-Revision: 7ff3a17524e0e703e3ac279441729c185444be24
2015-11-07 22:41:54 +03:00
|
|
|
/// Sets quirks mode for the document, causing the quirks mode stylesheet to be used.
|
2017-05-12 16:56:47 +03:00
|
|
|
fn handle_set_quirks_mode<'a, 'b>(&mut self, quirks_mode: QuirksMode) {
|
|
|
|
self.stylist.set_quirks_mode(quirks_mode);
|
2014-12-16 05:33:46 +03:00
|
|
|
}
|
|
|
|
|
servo: Merge #9976 - Remove lifetimes from Style/Layout traits (from bholley:remove_trait_lifetimes); r=SimonSapin
Right now, there's a huge amount of complexity in T{Node,Element,Document} and friends because of the lifetime parameter.
Before I started generalizing this code for use by Gecko, these wrappers were plain structs. They had (and still have) a phantom lifetime associated with them to prevent references to DOM nodes from leaking past the end of restyle, when they might be invalidated by a GC.
When I generalized them, I decided to put the lifetime on the trait as well, since there are some situations where the lifetime is, in fact, necessary. Specifically, they are necessary for the compiler to understand that all the things borrowed from all the nodes and elements and so on have the same lifetime (the lifetime of the restyle), rather than the lifetime of whichever particular element or node pointer the value was borrowed from. This come up in situations where we do |let el = node.as_element()| or |let n = el.as_node()| and then borrow something from the result. The compiler thinks the borrow lifetime is that of |el| or |n|, when it's actually longer.
In practice though, I think the style and layout algorithms we use don't run into this issue much, and we can hack around it where it comes up. So I think we should remove the lifetimes from the traits, which will let us aggregate the embedding-provided traits together onto a single meta-trait and significantly simplify the code.
Source-Repo: https://github.com/servo/servo
Source-Revision: aea8d8959dcb157a8cc381f1403246ce8ca1ca00
2016-03-15 00:33:53 +03:00
|
|
|
fn try_get_layout_root<N: LayoutNode>(&self, node: N) -> Option<FlowRef> {
|
2015-12-30 07:34:14 +03:00
|
|
|
let mut data = match node.mutate_layout_data() {
|
|
|
|
Some(x) => x,
|
|
|
|
None => return None,
|
|
|
|
};
|
2017-03-05 16:14:45 +03:00
|
|
|
let result = data.flow_construction_result.get();
|
2014-10-15 02:51:30 +04:00
|
|
|
|
2013-11-18 23:54:00 +04:00
|
|
|
let mut flow = match result {
|
2014-12-18 04:45:49 +03:00
|
|
|
ConstructionResult::Flow(mut flow, abs_descendants) => {
|
2014-03-03 22:37:33 +04:00
|
|
|
// Note: Assuming that the root has display 'static' (as per
|
|
|
|
// CSS Section 9.3.1). Otherwise, if it were absolutely
|
|
|
|
// positioned, it would return a reference to itself in
|
|
|
|
// `abs_descendants` and would lead to a circular reference.
|
|
|
|
// Set Root as CB for any remaining absolute descendants.
|
2014-09-19 18:51:02 +04:00
|
|
|
flow.set_absolute_descendants(abs_descendants);
|
2014-03-03 22:37:33 +04:00
|
|
|
flow
|
|
|
|
}
|
2014-10-28 21:00:51 +03:00
|
|
|
_ => return None,
|
2013-11-18 23:54:00 +04:00
|
|
|
};
|
2014-10-15 02:51:30 +04:00
|
|
|
|
2016-11-05 00:53:38 +03:00
|
|
|
FlowRef::deref_mut(&mut flow).mark_as_root();
|
2014-10-28 21:00:51 +03:00
|
|
|
|
|
|
|
Some(flow)
|
|
|
|
}
|
|
|
|
|
2013-10-31 23:10:32 +04:00
|
|
|
/// Performs layout constraint solving.
|
|
|
|
///
|
|
|
|
/// This corresponds to `Reflow()` in Gecko and `layout()` in WebKit/Blink and should be
|
|
|
|
/// benchmarked against those two. It is marked `#[inline(never)]` to aid profiling.
|
|
|
|
#[inline(never)]
|
2016-08-25 12:52:24 +03:00
|
|
|
fn solve_constraints(layout_root: &mut Flow,
|
2017-02-08 04:16:05 +03:00
|
|
|
layout_context: &LayoutContext) {
|
2014-09-08 10:33:09 +04:00
|
|
|
let _scope = layout_debug_scope!("solve_constraints");
|
2017-08-08 22:04:23 +03:00
|
|
|
sequential::reflow(layout_root, layout_context, RelayoutMode::Incremental);
|
2014-01-23 04:04:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Performs layout constraint solving in parallel.
|
|
|
|
///
|
|
|
|
/// This corresponds to `Reflow()` in Gecko and `layout()` in WebKit/Blink and should be
|
|
|
|
/// benchmarked against those two. It is marked `#[inline(never)]` to aid profiling.
|
|
|
|
#[inline(never)]
|
2016-11-14 23:47:21 +03:00
|
|
|
fn solve_constraints_parallel(traversal: &rayon::ThreadPool,
|
2016-08-25 12:52:24 +03:00
|
|
|
layout_root: &mut Flow,
|
2015-11-10 05:17:45 +03:00
|
|
|
profiler_metadata: Option<TimerMetadata>,
|
|
|
|
time_profiler_chan: time::ProfilerChan,
|
2017-02-08 04:16:05 +03:00
|
|
|
layout_context: &LayoutContext) {
|
2014-10-15 05:33:28 +04:00
|
|
|
let _scope = layout_debug_scope!("solve_constraints_parallel");
|
2014-02-25 09:04:32 +04:00
|
|
|
|
2015-07-12 11:44:04 +03:00
|
|
|
// NOTE: this currently computes borders, so any pruning should separate that
|
|
|
|
// operation out.
|
2017-08-08 22:04:23 +03:00
|
|
|
parallel::reflow(layout_root,
|
|
|
|
profiler_metadata,
|
|
|
|
time_profiler_chan,
|
|
|
|
layout_context,
|
|
|
|
traversal);
|
2013-10-31 23:10:32 +04:00
|
|
|
}
|
|
|
|
|
2016-09-27 04:57:59 +03:00
|
|
|
/// Computes the stacking-relative positions of all flows and, if the painting is dirty and the
|
|
|
|
/// reflow goal and query type need it, builds the display list.
|
2017-05-12 16:56:47 +03:00
|
|
|
fn compute_abs_pos_and_build_display_list(&self,
|
2015-11-14 23:02:35 +03:00
|
|
|
data: &Reflow,
|
2016-09-27 04:57:59 +03:00
|
|
|
query_type: Option<&ReflowQueryType>,
|
2016-08-31 05:05:56 +03:00
|
|
|
document: Option<&ServoLayoutDocument>,
|
2016-08-25 12:52:24 +03:00
|
|
|
layout_root: &mut Flow,
|
2017-02-08 04:16:05 +03:00
|
|
|
layout_context: &mut LayoutContext,
|
2016-01-10 13:19:04 +03:00
|
|
|
rw_data: &mut LayoutThreadData) {
|
2016-08-25 12:52:24 +03:00
|
|
|
let writing_mode = flow::base(layout_root).writing_mode;
|
2015-11-10 05:17:45 +03:00
|
|
|
let (metadata, sender) = (self.profiler_metadata(), self.time_profiler_chan.clone());
|
2015-03-26 06:18:48 +03:00
|
|
|
profile(time::ProfilerCategory::LayoutDispListBuild,
|
2015-11-10 05:17:45 +03:00
|
|
|
metadata.clone(),
|
|
|
|
sender.clone(),
|
2014-12-18 10:24:49 +03:00
|
|
|
|| {
|
2016-08-25 12:52:24 +03:00
|
|
|
flow::mut_base(layout_root).stacking_relative_position =
|
2014-11-03 22:03:37 +03:00
|
|
|
LogicalPoint::zero(writing_mode).to_physical(writing_mode,
|
2017-06-14 17:25:05 +03:00
|
|
|
self.viewport_size).to_vector();
|
2014-11-03 22:03:37 +03:00
|
|
|
|
2017-04-18 00:08:00 +03:00
|
|
|
flow::mut_base(layout_root).clip = data.page_clip_rect;
|
2014-11-13 03:36:32 +03:00
|
|
|
|
2017-08-08 22:04:23 +03:00
|
|
|
let traversal = ComputeStackingRelativePositions { layout_context: layout_context };
|
|
|
|
traversal.traverse(layout_root);
|
2016-09-27 04:57:59 +03:00
|
|
|
|
2016-08-25 12:52:24 +03:00
|
|
|
if flow::base(layout_root).restyle_damage.contains(REPAINT) ||
|
2016-03-22 01:07:49 +03:00
|
|
|
rw_data.display_list.is_none() {
|
2016-09-27 04:57:59 +03:00
|
|
|
let display_list_needed = query_type.map(reflow_query_type_needs_display_list)
|
|
|
|
.unwrap_or(false);
|
|
|
|
match (data.goal, display_list_needed) {
|
|
|
|
(ReflowGoal::ForDisplay, _) | (ReflowGoal::ForScriptQuery, true) => {
|
2016-11-02 21:55:07 +03:00
|
|
|
let mut build_state =
|
2016-11-08 03:49:53 +03:00
|
|
|
sequential::build_display_list_for_subtree(layout_root,
|
2017-02-08 04:16:05 +03:00
|
|
|
layout_context);
|
2016-09-27 04:57:59 +03:00
|
|
|
|
|
|
|
debug!("Done building display list.");
|
|
|
|
|
|
|
|
let root_size = {
|
|
|
|
let root_flow = flow::base(layout_root);
|
2017-05-12 16:56:47 +03:00
|
|
|
if self.stylist.viewport_constraints().is_some() {
|
2016-09-27 04:57:59 +03:00
|
|
|
root_flow.position.size.to_physical(root_flow.writing_mode)
|
|
|
|
} else {
|
|
|
|
root_flow.overflow.scroll.size
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let origin = Rect::new(Point2D::new(Au(0), Au(0)), root_size);
|
2016-11-02 21:55:07 +03:00
|
|
|
build_state.root_stacking_context.bounds = origin;
|
|
|
|
build_state.root_stacking_context.overflow = origin;
|
2017-01-25 13:36:15 +03:00
|
|
|
|
|
|
|
if !build_state.iframe_sizes.is_empty() {
|
|
|
|
// build_state.iframe_sizes is only used here, so its okay to replace
|
|
|
|
// it with an empty vector
|
|
|
|
let iframe_sizes = std::mem::replace(&mut build_state.iframe_sizes, vec![]);
|
2017-05-17 07:10:45 +03:00
|
|
|
let msg = ConstellationMsg::IFrameSizes(iframe_sizes);
|
2017-01-25 13:36:15 +03:00
|
|
|
if let Err(e) = self.constellation_chan.send(msg) {
|
|
|
|
warn!("Layout resize to constellation failed ({}).", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 21:55:07 +03:00
|
|
|
rw_data.display_list = Some(Arc::new(build_state.to_display_list()));
|
2015-09-11 20:20:13 +03:00
|
|
|
}
|
2016-09-27 04:57:59 +03:00
|
|
|
(ReflowGoal::ForScriptQuery, false) => {}
|
|
|
|
}
|
2016-03-22 01:07:49 +03:00
|
|
|
}
|
|
|
|
|
2016-08-31 05:05:56 +03:00
|
|
|
if data.goal != ReflowGoal::ForDisplay {
|
|
|
|
// Defer the paint step until the next ForDisplay.
|
|
|
|
//
|
|
|
|
// We need to tell the document about this so it doesn't
|
|
|
|
// incorrectly suppress reflows. See #13131.
|
|
|
|
document.expect("No document in a non-display reflow?")
|
|
|
|
.needs_paint_from_layout();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if let Some(document) = document {
|
|
|
|
document.will_paint();
|
|
|
|
}
|
|
|
|
let display_list = (*rw_data.display_list.as_ref().unwrap()).clone();
|
2016-03-02 03:51:08 +03:00
|
|
|
|
2016-08-31 05:05:56 +03:00
|
|
|
if opts::get().dump_display_list {
|
|
|
|
display_list.print();
|
|
|
|
}
|
|
|
|
if opts::get().dump_display_list_json {
|
|
|
|
println!("{}", serde_json::to_string_pretty(&display_list).unwrap());
|
|
|
|
}
|
2015-05-13 22:27:21 +03:00
|
|
|
|
2016-08-31 05:05:56 +03:00
|
|
|
debug!("Layout done!");
|
|
|
|
|
2016-10-18 03:22:20 +03:00
|
|
|
// TODO: Avoid the temporary conversion and build webrender sc/dl directly!
|
2016-11-29 13:36:05 +03:00
|
|
|
let builder = rw_data.display_list.as_ref().unwrap().convert_to_webrender(self.id);
|
2016-10-18 03:22:20 +03:00
|
|
|
|
|
|
|
let viewport_size = Size2D::new(self.viewport_size.width.to_f32_px(),
|
|
|
|
self.viewport_size.height.to_f32_px());
|
|
|
|
|
2017-05-12 16:56:47 +03:00
|
|
|
let mut epoch = self.epoch.get();
|
|
|
|
epoch.next();
|
|
|
|
self.epoch.set(epoch);
|
2016-11-16 13:47:34 +03:00
|
|
|
|
2017-07-13 07:52:27 +03:00
|
|
|
let viewport_size = webrender_api::LayoutSize::from_untyped(&viewport_size);
|
2017-07-20 21:34:35 +03:00
|
|
|
|
2017-08-22 18:06:30 +03:00
|
|
|
// Observe notifications about rendered frames if needed right before
|
|
|
|
// sending the display list to WebRender in order to set time related
|
|
|
|
// Progressive Web Metrics.
|
|
|
|
self.paint_time_metrics.maybe_observe_paint_time(self, epoch, &display_list);
|
2017-07-20 21:34:35 +03:00
|
|
|
|
2017-04-04 22:41:41 +03:00
|
|
|
self.webrender_api.set_display_list(
|
2017-07-29 15:38:23 +03:00
|
|
|
self.webrender_document,
|
2017-07-29 02:20:27 +03:00
|
|
|
webrender_api::Epoch(epoch.0),
|
2017-07-29 15:38:23 +03:00
|
|
|
Some(get_root_flow_background_color(layout_root)),
|
2016-11-16 13:47:34 +03:00
|
|
|
viewport_size,
|
2017-02-27 02:22:25 +03:00
|
|
|
builder.finalize(),
|
2017-08-09 00:05:54 +03:00
|
|
|
true,
|
|
|
|
webrender_api::ResourceUpdates::new());
|
2017-07-29 15:38:23 +03:00
|
|
|
self.webrender_api.generate_frame(self.webrender_document, None);
|
2014-11-03 22:03:37 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-10 13:19:04 +03:00
|
|
|
/// The high-level routine that performs layout threads.
|
2015-11-10 05:17:45 +03:00
|
|
|
fn handle_reflow<'a, 'b>(&mut self,
|
2017-05-15 23:00:19 +03:00
|
|
|
data: &mut ScriptReflowResult,
|
2015-11-10 05:17:45 +03:00
|
|
|
possibly_locked_rw_data: &mut RwData<'a, 'b>) {
|
2015-11-19 04:42:40 +03:00
|
|
|
let document = unsafe { ServoLayoutNode::new(&data.document) };
|
2015-10-30 11:13:17 +03:00
|
|
|
let document = document.as_document().unwrap();
|
2015-11-11 02:19:49 +03:00
|
|
|
|
2016-09-27 04:57:59 +03:00
|
|
|
// FIXME(pcwalton): Combine `ReflowGoal` and `ReflowQueryType`. Then remove this assert.
|
|
|
|
debug_assert!((data.reflow_info.goal == ReflowGoal::ForDisplay &&
|
|
|
|
data.query_type == ReflowQueryType::NoQuery) ||
|
|
|
|
(data.reflow_info.goal == ReflowGoal::ForScriptQuery &&
|
|
|
|
data.query_type != ReflowQueryType::NoQuery));
|
|
|
|
|
2016-12-08 01:32:20 +03:00
|
|
|
// Parallelize if there's more than 750 objects based on rzambre's suggestion
|
|
|
|
// https://github.com/servo/servo/issues/10110
|
|
|
|
self.parallel_flag = self.layout_threads > 1 && data.dom_count > 750;
|
|
|
|
debug!("layout: received layout request for: {}", self.url);
|
|
|
|
debug!("Number of objects in DOM: {}", data.dom_count);
|
|
|
|
debug!("layout: parallel? {}", self.parallel_flag);
|
|
|
|
|
2015-11-11 02:19:49 +03:00
|
|
|
let mut rw_data = possibly_locked_rw_data.lock();
|
|
|
|
|
2016-11-25 20:00:44 +03:00
|
|
|
let element: ServoLayoutElement = match document.root_node() {
|
2015-11-11 02:19:49 +03:00
|
|
|
None => {
|
|
|
|
// Since we cannot compute anything, give spec-required placeholders.
|
|
|
|
debug!("layout: No root node: bailing");
|
|
|
|
match data.query_type {
|
|
|
|
ReflowQueryType::ContentBoxQuery(_) => {
|
2017-01-18 19:43:19 +03:00
|
|
|
rw_data.content_box_response = None;
|
2015-11-11 02:19:49 +03:00
|
|
|
},
|
|
|
|
ReflowQueryType::ContentBoxesQuery(_) => {
|
|
|
|
rw_data.content_boxes_response = Vec::new();
|
|
|
|
},
|
2016-08-11 02:50:33 +03:00
|
|
|
ReflowQueryType::HitTestQuery(..) => {
|
2016-03-04 01:30:30 +03:00
|
|
|
rw_data.hit_test_response = (None, false);
|
|
|
|
},
|
2017-03-02 22:43:17 +03:00
|
|
|
ReflowQueryType::NodesFromPoint(..) => {
|
|
|
|
rw_data.nodes_from_point_response = Vec::new();
|
|
|
|
},
|
2015-11-11 02:19:49 +03:00
|
|
|
ReflowQueryType::NodeGeometryQuery(_) => {
|
|
|
|
rw_data.client_rect_response = Rect::zero();
|
|
|
|
},
|
2016-03-11 21:49:24 +03:00
|
|
|
ReflowQueryType::NodeScrollGeometryQuery(_) => {
|
|
|
|
rw_data.scroll_area_response = Rect::zero();
|
|
|
|
},
|
2016-04-20 16:10:26 +03:00
|
|
|
ReflowQueryType::NodeOverflowQuery(_) => {
|
|
|
|
rw_data.overflow_response = NodeOverflowResponse(None);
|
|
|
|
},
|
2016-12-07 01:42:00 +03:00
|
|
|
ReflowQueryType::NodeScrollRootIdQuery(_) => {
|
|
|
|
rw_data.scroll_root_id_response = None;
|
|
|
|
},
|
2015-11-11 02:19:49 +03:00
|
|
|
ReflowQueryType::ResolvedStyleQuery(_, _, _) => {
|
2016-12-10 12:16:26 +03:00
|
|
|
rw_data.resolved_style_response = String::new();
|
2015-11-11 02:19:49 +03:00
|
|
|
},
|
|
|
|
ReflowQueryType::OffsetParentQuery(_) => {
|
|
|
|
rw_data.offset_parent_response = OffsetParentResponse::empty();
|
|
|
|
},
|
2016-02-24 21:52:43 +03:00
|
|
|
ReflowQueryType::MarginStyleQuery(_) => {
|
|
|
|
rw_data.margin_style_response = MarginStyleResponse::empty();
|
|
|
|
},
|
2017-01-12 01:19:10 +03:00
|
|
|
ReflowQueryType::TextIndexQuery(..) => {
|
|
|
|
rw_data.text_index_response = TextIndexResponse(None);
|
|
|
|
}
|
2015-11-11 02:19:49 +03:00
|
|
|
ReflowQueryType::NoQuery => {}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
},
|
2016-11-25 20:00:44 +03:00
|
|
|
Some(x) => x.as_element().unwrap(),
|
2013-05-30 06:30:47 +04:00
|
|
|
};
|
|
|
|
|
2016-11-25 20:00:44 +03:00
|
|
|
debug!("layout: processing reflow request for: {:?} ({}) (query={:?})",
|
|
|
|
element, self.url, data.query_type);
|
2017-06-08 05:57:57 +03:00
|
|
|
trace!("{:?}", ShowSubtree(element.as_node()));
|
2013-11-18 23:54:00 +04:00
|
|
|
|
2015-05-06 20:41:09 +03:00
|
|
|
let initial_viewport = data.window_size.initial_viewport;
|
2017-07-21 03:09:06 +03:00
|
|
|
let device_pixel_ratio = data.window_size.device_pixel_ratio;
|
2015-11-10 05:17:45 +03:00
|
|
|
let old_viewport_size = self.viewport_size;
|
2016-08-12 04:12:29 +03:00
|
|
|
let current_screen_size = Size2D::new(Au::from_f32_px(initial_viewport.width),
|
|
|
|
Au::from_f32_px(initial_viewport.height));
|
2012-10-14 11:42:25 +04:00
|
|
|
|
2015-11-04 03:58:46 +03:00
|
|
|
// Calculate the actual viewport as per DEVICE-ADAPT § 6
|
2017-09-14 23:55:21 +03:00
|
|
|
// If the entire flow tree is invalid, then it will be reflowed anyhow.
|
2017-03-20 04:22:23 +03:00
|
|
|
let document_shared_lock = document.style_shared_lock();
|
|
|
|
self.document_shared_lock = Some(document_shared_lock.clone());
|
|
|
|
let author_guard = document_shared_lock.read();
|
2017-09-14 23:55:21 +03:00
|
|
|
|
|
|
|
let ua_stylesheets = &*UA_STYLESHEETS;
|
|
|
|
let ua_or_user_guard = ua_stylesheets.shared_lock.read();
|
|
|
|
let guards = StylesheetGuards {
|
|
|
|
author: &author_guard,
|
|
|
|
ua_or_user: &ua_or_user_guard,
|
|
|
|
};
|
|
|
|
|
2017-08-28 16:48:47 +03:00
|
|
|
let had_used_viewport_units = self.stylist.device().used_viewport_units();
|
2017-08-10 02:24:48 +03:00
|
|
|
let device = Device::new(MediaType::screen(), initial_viewport, device_pixel_ratio);
|
2017-08-21 18:59:10 +03:00
|
|
|
let sheet_origins_affected_by_device_change =
|
2017-09-14 23:55:21 +03:00
|
|
|
self.stylist.set_device(device, &guards);
|
2015-05-06 20:41:09 +03:00
|
|
|
|
2017-08-22 19:45:42 +03:00
|
|
|
self.stylist.force_stylesheet_origins_dirty(sheet_origins_affected_by_device_change);
|
2017-01-02 15:10:56 +03:00
|
|
|
self.viewport_size =
|
2017-05-12 16:56:47 +03:00
|
|
|
self.stylist.viewport_constraints().map_or(current_screen_size, |constraints| {
|
2015-05-06 20:41:09 +03:00
|
|
|
debug!("Viewport constraints: {:?}", constraints);
|
|
|
|
|
|
|
|
// other rules are evaluated against the actual viewport
|
2016-08-12 04:12:29 +03:00
|
|
|
Size2D::new(Au::from_f32_px(constraints.size.width),
|
|
|
|
Au::from_f32_px(constraints.size.height))
|
2017-01-02 15:10:56 +03:00
|
|
|
});
|
2015-11-04 03:58:46 +03:00
|
|
|
|
2015-11-10 05:17:45 +03:00
|
|
|
let viewport_size_changed = self.viewport_size != old_viewport_size;
|
2015-11-04 03:58:46 +03:00
|
|
|
if viewport_size_changed {
|
2017-05-12 16:56:47 +03:00
|
|
|
if let Some(constraints) = self.stylist.viewport_constraints() {
|
2015-05-06 20:41:09 +03:00
|
|
|
// let the constellation know about the viewport constraints
|
2016-05-19 22:38:26 +03:00
|
|
|
rw_data.constellation_chan
|
2017-01-02 15:10:56 +03:00
|
|
|
.send(ConstellationMsg::ViewportConstrained(self.id, constraints.clone()))
|
2016-05-19 22:38:26 +03:00
|
|
|
.unwrap();
|
2015-05-06 20:41:09 +03:00
|
|
|
}
|
2017-08-28 16:48:47 +03:00
|
|
|
if had_used_viewport_units {
|
2017-08-29 22:18:58 +03:00
|
|
|
if let Some(mut data) = element.mutate_data() {
|
2017-09-12 21:16:26 +03:00
|
|
|
data.hint.insert(RestyleHint::recascade_subtree());
|
2016-07-18 06:46:24 +03:00
|
|
|
}
|
2016-03-22 16:28:47 +03:00
|
|
|
}
|
2014-11-07 03:24:28 +03:00
|
|
|
}
|
|
|
|
|
2017-08-22 19:45:42 +03:00
|
|
|
{
|
2017-08-21 18:59:10 +03:00
|
|
|
if self.first_reflow.get() {
|
|
|
|
debug!("First reflow, rebuilding user and UA rules");
|
|
|
|
for stylesheet in &ua_stylesheets.user_or_user_agent_stylesheets {
|
2017-09-14 23:55:21 +03:00
|
|
|
self.stylist.append_stylesheet(stylesheet.clone(), &ua_or_user_guard);
|
|
|
|
self.handle_add_stylesheet(&stylesheet.0, &ua_or_user_guard);
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.stylist.quirks_mode() != QuirksMode::NoQuirks {
|
|
|
|
self.stylist.append_stylesheet(
|
|
|
|
ua_stylesheets.quirks_mode_stylesheet.clone(),
|
|
|
|
&ua_or_user_guard,
|
|
|
|
);
|
|
|
|
self.handle_add_stylesheet(
|
|
|
|
&ua_stylesheets.quirks_mode_stylesheet.0,
|
|
|
|
&ua_or_user_guard,
|
|
|
|
);
|
2017-08-21 18:59:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-18 16:33:35 +03:00
|
|
|
if data.stylesheets_changed {
|
2017-08-21 18:59:10 +03:00
|
|
|
debug!("Doc sheets changed, flushing author sheets too");
|
2017-08-22 19:45:42 +03:00
|
|
|
self.stylist.force_stylesheet_origins_dirty(Origin::Author.into());
|
2017-08-18 16:33:35 +03:00
|
|
|
}
|
2017-08-21 18:59:10 +03:00
|
|
|
|
2017-09-14 23:55:21 +03:00
|
|
|
self.stylist.flush(&guards, Some(element));
|
2014-10-09 21:21:32 +04:00
|
|
|
}
|
2017-08-22 19:45:42 +03:00
|
|
|
|
|
|
|
if viewport_size_changed {
|
2016-11-25 20:00:44 +03:00
|
|
|
if let Some(mut flow) = self.try_get_layout_root(element.as_node()) {
|
2016-11-05 00:53:38 +03:00
|
|
|
LayoutThread::reflow_all_nodes(FlowRef::deref_mut(&mut flow));
|
2015-03-16 22:16:03 +03:00
|
|
|
}
|
2014-10-28 21:00:51 +03:00
|
|
|
}
|
|
|
|
|
2016-11-17 21:25:52 +03:00
|
|
|
let restyles = document.drain_pending_restyles();
|
2017-08-22 19:45:42 +03:00
|
|
|
debug!("Draining restyles: {}", restyles.len());
|
|
|
|
|
2017-05-10 23:08:59 +03:00
|
|
|
let mut map = SnapshotMap::new();
|
|
|
|
let elements_with_snapshot: Vec<_> =
|
|
|
|
restyles
|
|
|
|
.iter()
|
|
|
|
.filter(|r| r.1.snapshot.is_some())
|
|
|
|
.map(|r| r.0)
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
for (el, restyle) in restyles {
|
|
|
|
// Propagate the descendant bit up the ancestors. Do this before
|
|
|
|
// the restyle calculation so that we can also do it for new
|
|
|
|
// unstyled nodes, which the descendants bit helps us find.
|
|
|
|
if let Some(parent) = el.parent_element() {
|
|
|
|
unsafe { parent.note_dirty_descendant() };
|
|
|
|
}
|
2016-11-17 21:25:52 +03:00
|
|
|
|
2017-05-10 23:08:59 +03:00
|
|
|
// If we haven't styled this node yet, we don't need to track a
|
|
|
|
// restyle.
|
2017-05-26 03:58:47 +03:00
|
|
|
let style_data = match el.get_data() {
|
2017-05-10 23:08:59 +03:00
|
|
|
Some(d) => d,
|
|
|
|
None => {
|
|
|
|
unsafe { el.unset_snapshot_flags() };
|
|
|
|
continue;
|
2016-12-10 04:01:05 +03:00
|
|
|
}
|
2017-05-10 23:08:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if let Some(s) = restyle.snapshot {
|
|
|
|
unsafe { el.set_has_snapshot() };
|
|
|
|
map.insert(el.as_node().opaque(), s);
|
2015-10-28 21:54:53 +03:00
|
|
|
}
|
2017-05-10 23:08:59 +03:00
|
|
|
|
2017-05-26 03:58:47 +03:00
|
|
|
let mut style_data = style_data.borrow_mut();
|
2017-05-10 23:08:59 +03:00
|
|
|
|
|
|
|
// Stash the data on the element for processing by the style system.
|
2017-09-12 21:16:26 +03:00
|
|
|
style_data.hint.insert(restyle.hint.into());
|
|
|
|
style_data.damage = restyle.damage;
|
|
|
|
debug!("Noting restyle for {:?}: {:?}", el, style_data);
|
2015-10-28 21:54:53 +03:00
|
|
|
}
|
|
|
|
|
2015-03-13 18:36:50 +03:00
|
|
|
// Create a layout context for use throughout the following passes.
|
2017-05-10 23:08:59 +03:00
|
|
|
let mut layout_context =
|
2017-05-12 16:56:47 +03:00
|
|
|
self.build_layout_context(guards.clone(), true, &map);
|
2015-03-13 18:36:50 +03:00
|
|
|
|
2017-08-25 20:23:41 +03:00
|
|
|
let thread_pool = if self.parallel_flag {
|
|
|
|
self.parallel_traversal.as_ref()
|
2017-01-25 04:02:41 +03:00
|
|
|
} else {
|
2017-08-25 20:23:41 +03:00
|
|
|
None
|
2017-01-25 04:02:41 +03:00
|
|
|
};
|
|
|
|
|
2017-08-25 20:23:41 +03:00
|
|
|
// NB: Type inference falls apart here for some reason, so we need to be very verbose. :-(
|
|
|
|
let traversal = RecalcStyleAndConstructFlows::new(layout_context);
|
2016-12-16 22:38:27 +03:00
|
|
|
let token = {
|
2017-05-10 23:08:59 +03:00
|
|
|
let context = <RecalcStyleAndConstructFlows as
|
|
|
|
DomTraversal<ServoLayoutElement>>::shared_context(&traversal);
|
2016-12-16 22:38:27 +03:00
|
|
|
<RecalcStyleAndConstructFlows as
|
2017-05-10 23:08:59 +03:00
|
|
|
DomTraversal<ServoLayoutElement>>::pre_traverse(element,
|
|
|
|
context,
|
|
|
|
TraversalFlags::empty())
|
2016-12-16 22:38:27 +03:00
|
|
|
};
|
|
|
|
|
2016-12-10 04:01:05 +03:00
|
|
|
if token.should_traverse() {
|
2015-05-08 02:13:29 +03:00
|
|
|
// Recalculate CSS styles and rebuild flows and fragments.
|
|
|
|
profile(time::ProfilerCategory::LayoutStyleRecalc,
|
|
|
|
self.profiler_metadata(),
|
|
|
|
self.time_profiler_chan.clone(),
|
|
|
|
|| {
|
|
|
|
// Perform CSS selector matching and flow construction.
|
2017-08-25 20:23:41 +03:00
|
|
|
driver::traverse_dom::<ServoLayoutElement, RecalcStyleAndConstructFlows>(
|
|
|
|
&traversal, element, token, thread_pool);
|
2015-05-08 02:13:29 +03:00
|
|
|
});
|
2015-12-17 08:27:29 +03:00
|
|
|
// TODO(pcwalton): Measure energy usage of text shaping, perhaps?
|
|
|
|
let text_shaping_time =
|
|
|
|
(font::get_and_reset_text_shaping_performance_counter() as u64) /
|
2016-07-24 22:53:34 +03:00
|
|
|
(self.layout_threads as u64);
|
2015-12-17 08:27:29 +03:00
|
|
|
time::send_profile_data(time::ProfilerCategory::LayoutTextShaping,
|
|
|
|
self.profiler_metadata(),
|
servo: Merge #17383 - #17363 : Passing ProfilerChan by reference to the send_profile_data method (from o0Ignition0o:profiler_chan_by_reference); r=jdm
<!-- Please describe your changes on the following line: -->
Passed the ProfilerChan by reference to the send_profile_data method.
I wonder if I should also refactor the
`pub fn profile<T, F>(category: ProfilerCategory, meta: Option<TimerMetadata>, profiler_chan: ProfilerChan, callback: F) -> T where F: FnOnce() -> T method ` , but I don't feel confident enough to make the call, since I don't really understand what it would imply.
---
<!-- 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 #17363 (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because the project would not compile if there were missing by reference calls.
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- 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: d8ae4638397a3834203267ceae075509e9cb9931
--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 79e9240a4279e5bf6fa0ac2c835572493926183c
2017-06-25 19:06:28 +03:00
|
|
|
&self.time_profiler_chan,
|
2015-12-17 08:27:29 +03:00
|
|
|
0,
|
|
|
|
text_shaping_time,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
|
2015-05-08 02:13:29 +03:00
|
|
|
// Retrieve the (possibly rebuilt) root flow.
|
2017-05-12 16:56:47 +03:00
|
|
|
*self.root_flow.borrow_mut() = self.try_get_layout_root(element.as_node());
|
2015-05-08 02:13:29 +03:00
|
|
|
}
|
2015-03-31 19:39:56 +03:00
|
|
|
|
2017-05-10 23:08:59 +03:00
|
|
|
for element in elements_with_snapshot {
|
|
|
|
unsafe { element.unset_snapshot_flags() }
|
|
|
|
}
|
|
|
|
|
2017-02-08 04:16:05 +03:00
|
|
|
layout_context = traversal.destroy();
|
2016-12-16 22:38:27 +03:00
|
|
|
|
2016-08-13 04:55:27 +03:00
|
|
|
if opts::get().dump_style_tree {
|
2016-12-13 06:13:03 +03:00
|
|
|
println!("{:?}", ShowSubtreeDataAndPrimaryValues(element.as_node()));
|
2016-08-13 04:55:27 +03:00
|
|
|
}
|
|
|
|
|
2016-11-06 01:11:24 +03:00
|
|
|
if opts::get().dump_rule_tree {
|
2017-05-23 04:12:46 +03:00
|
|
|
layout_context.style_context.stylist.rule_tree().dump_stdout(&guards);
|
2016-11-06 01:11:24 +03:00
|
|
|
}
|
|
|
|
|
2016-11-20 07:01:12 +03:00
|
|
|
// GC the rule tree if some heuristics are met.
|
2017-05-23 04:12:46 +03:00
|
|
|
unsafe { layout_context.style_context.stylist.rule_tree().maybe_gc(); }
|
2016-11-06 01:11:24 +03:00
|
|
|
|
2015-03-31 19:39:56 +03:00
|
|
|
// Perform post-style recalculation layout passes.
|
2017-05-12 16:56:47 +03:00
|
|
|
if let Some(mut root_flow) = self.root_flow.borrow().clone() {
|
2017-03-20 04:22:23 +03:00
|
|
|
self.perform_post_style_recalc_layout_passes(&mut root_flow,
|
|
|
|
&data.reflow_info,
|
|
|
|
Some(&data.query_type),
|
|
|
|
Some(&document),
|
|
|
|
&mut rw_data,
|
|
|
|
&mut layout_context);
|
|
|
|
}
|
2015-03-31 19:39:56 +03:00
|
|
|
|
2016-09-27 04:57:59 +03:00
|
|
|
self.respond_to_query_if_necessary(&data.query_type,
|
|
|
|
&mut *rw_data,
|
2017-05-15 23:00:19 +03:00
|
|
|
&mut layout_context,
|
|
|
|
data.result.borrow_mut().as_mut().unwrap());
|
2016-09-27 04:57:59 +03:00
|
|
|
}
|
|
|
|
|
2017-05-12 16:56:47 +03:00
|
|
|
fn respond_to_query_if_necessary(&self,
|
2016-09-27 04:57:59 +03:00
|
|
|
query_type: &ReflowQueryType,
|
|
|
|
rw_data: &mut LayoutThreadData,
|
2017-05-15 23:00:19 +03:00
|
|
|
context: &mut LayoutContext,
|
|
|
|
reflow_result: &mut ReflowComplete) {
|
2017-02-23 04:50:48 +03:00
|
|
|
let pending_images = match context.pending_images {
|
|
|
|
Some(ref pending) => std_mem::replace(&mut *pending.lock().unwrap(), vec![]),
|
|
|
|
None => vec![],
|
|
|
|
};
|
2017-05-15 23:00:19 +03:00
|
|
|
reflow_result.pending_images = pending_images;
|
|
|
|
|
|
|
|
let newly_transitioning_nodes = match context.newly_transitioning_nodes {
|
|
|
|
Some(ref nodes) => std_mem::replace(&mut *nodes.lock().unwrap(), vec![]),
|
|
|
|
None => vec![],
|
|
|
|
};
|
|
|
|
reflow_result.newly_transitioning_nodes = newly_transitioning_nodes;
|
2017-02-23 04:50:48 +03:00
|
|
|
|
2017-05-12 16:56:47 +03:00
|
|
|
let mut root_flow = match self.root_flow.borrow().clone() {
|
2016-09-27 04:57:59 +03:00
|
|
|
Some(root_flow) => root_flow,
|
|
|
|
None => return,
|
|
|
|
};
|
2016-11-05 00:53:38 +03:00
|
|
|
let root_flow = FlowRef::deref_mut(&mut root_flow);
|
2016-09-27 04:57:59 +03:00
|
|
|
match *query_type {
|
|
|
|
ReflowQueryType::ContentBoxQuery(node) => {
|
|
|
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
|
|
|
rw_data.content_box_response = process_content_box_request(node, root_flow);
|
|
|
|
},
|
|
|
|
ReflowQueryType::ContentBoxesQuery(node) => {
|
|
|
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
|
|
|
rw_data.content_boxes_response = process_content_boxes_request(node, root_flow);
|
|
|
|
},
|
2017-05-16 16:33:22 +03:00
|
|
|
ReflowQueryType::HitTestQuery(client_point, update_cursor) => {
|
|
|
|
let point = Point2D::new(Au::from_f32_px(client_point.x),
|
|
|
|
Au::from_f32_px(client_point.y));
|
2016-09-27 04:57:59 +03:00
|
|
|
let result = rw_data.display_list
|
|
|
|
.as_ref()
|
|
|
|
.expect("Tried to hit test with no display list")
|
2017-05-16 16:33:22 +03:00
|
|
|
.hit_test(&point, &rw_data.scroll_offsets);
|
2016-09-27 04:57:59 +03:00
|
|
|
rw_data.hit_test_response = (result.last().cloned(), update_cursor);
|
|
|
|
},
|
2017-01-12 01:19:10 +03:00
|
|
|
ReflowQueryType::TextIndexQuery(node, mouse_x, mouse_y) => {
|
|
|
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
|
|
|
let opaque_node = node.opaque();
|
|
|
|
let client_point = Point2D::new(Au::from_px(mouse_x),
|
|
|
|
Au::from_px(mouse_y));
|
|
|
|
rw_data.text_index_response =
|
|
|
|
TextIndexResponse(rw_data.display_list
|
|
|
|
.as_ref()
|
|
|
|
.expect("Tried to hit test with no display list")
|
|
|
|
.text_index(opaque_node,
|
|
|
|
&client_point,
|
2017-05-16 16:33:22 +03:00
|
|
|
&rw_data.scroll_offsets));
|
2017-01-12 01:19:10 +03:00
|
|
|
},
|
2016-09-27 04:57:59 +03:00
|
|
|
ReflowQueryType::NodeGeometryQuery(node) => {
|
|
|
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
|
|
|
rw_data.client_rect_response = process_node_geometry_request(node, root_flow);
|
|
|
|
},
|
|
|
|
ReflowQueryType::NodeScrollGeometryQuery(node) => {
|
|
|
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
|
|
|
rw_data.scroll_area_response = process_node_scroll_area_request(node, root_flow);
|
|
|
|
},
|
|
|
|
ReflowQueryType::NodeOverflowQuery(node) => {
|
|
|
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
|
|
|
rw_data.overflow_response = process_node_overflow_request(node);
|
|
|
|
},
|
2016-12-07 01:42:00 +03:00
|
|
|
ReflowQueryType::NodeScrollRootIdQuery(node) => {
|
|
|
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
2017-04-20 09:55:33 +03:00
|
|
|
rw_data.scroll_root_id_response = Some(process_node_scroll_root_id_request(self.id,
|
|
|
|
node));
|
2016-12-07 01:42:00 +03:00
|
|
|
},
|
2016-09-27 04:57:59 +03:00
|
|
|
ReflowQueryType::ResolvedStyleQuery(node, ref pseudo, ref property) => {
|
|
|
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
|
|
|
rw_data.resolved_style_response =
|
2017-02-08 04:16:05 +03:00
|
|
|
process_resolved_style_request(context,
|
2016-12-16 22:38:27 +03:00
|
|
|
node,
|
2016-09-27 04:57:59 +03:00
|
|
|
pseudo,
|
|
|
|
property,
|
|
|
|
root_flow);
|
|
|
|
},
|
|
|
|
ReflowQueryType::OffsetParentQuery(node) => {
|
|
|
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
|
|
|
rw_data.offset_parent_response = process_offset_parent_query(node, root_flow);
|
|
|
|
},
|
|
|
|
ReflowQueryType::MarginStyleQuery(node) => {
|
|
|
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
|
|
|
rw_data.margin_style_response = process_margin_style_query(node);
|
|
|
|
},
|
2017-05-16 16:33:22 +03:00
|
|
|
ReflowQueryType::NodesFromPoint(client_point) => {
|
2017-03-02 22:43:17 +03:00
|
|
|
let client_point = Point2D::new(Au::from_f32_px(client_point.x),
|
|
|
|
Au::from_f32_px(client_point.y));
|
|
|
|
let nodes_from_point_list = {
|
|
|
|
let result = match rw_data.display_list {
|
|
|
|
None => panic!("Tried to hit test without a DisplayList"),
|
|
|
|
Some(ref display_list) => {
|
2017-05-16 16:33:22 +03:00
|
|
|
display_list.hit_test(&client_point, &rw_data.scroll_offsets)
|
2017-03-02 22:43:17 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
result
|
|
|
|
};
|
|
|
|
|
|
|
|
rw_data.nodes_from_point_response = nodes_from_point_list.iter()
|
|
|
|
.rev()
|
|
|
|
.map(|metadata| metadata.node.to_untrusted_node_address())
|
|
|
|
.collect()
|
|
|
|
},
|
2016-09-27 04:57:59 +03:00
|
|
|
ReflowQueryType::NoQuery => {}
|
2015-03-31 19:39:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-16 16:33:22 +03:00
|
|
|
fn set_scroll_states<'a, 'b>(&mut self,
|
|
|
|
new_scroll_states: Vec<ScrollState>,
|
|
|
|
possibly_locked_rw_data: &mut RwData<'a, 'b>) {
|
2016-06-11 19:01:36 +03:00
|
|
|
let mut rw_data = possibly_locked_rw_data.lock();
|
|
|
|
let mut script_scroll_states = vec![];
|
|
|
|
let mut layout_scroll_states = HashMap::new();
|
2016-06-01 04:54:29 +03:00
|
|
|
for new_scroll_state in &new_scroll_states {
|
2016-06-11 19:01:36 +03:00
|
|
|
let offset = new_scroll_state.scroll_offset;
|
2016-10-30 23:27:56 +03:00
|
|
|
layout_scroll_states.insert(new_scroll_state.scroll_root_id, offset);
|
2016-06-11 19:01:36 +03:00
|
|
|
|
2017-04-20 09:55:33 +03:00
|
|
|
if new_scroll_state.scroll_root_id.is_root_scroll_node() {
|
2016-06-11 19:01:36 +03:00
|
|
|
script_scroll_states.push((UntrustedNodeAddress::from_id(0), offset))
|
2017-04-20 09:55:33 +03:00
|
|
|
} else if let Some(id) = new_scroll_state.scroll_root_id.external_id() {
|
|
|
|
if let Some(node_id) = node_id_from_clip_id(id as usize) {
|
|
|
|
script_scroll_states.push((UntrustedNodeAddress::from_id(node_id), offset))
|
|
|
|
}
|
2016-06-01 04:54:29 +03:00
|
|
|
}
|
|
|
|
}
|
2016-06-11 19:01:36 +03:00
|
|
|
let _ = self.script_chan
|
|
|
|
.send(ConstellationControlMsg::SetScrollState(self.id, script_scroll_states));
|
2017-05-16 16:33:22 +03:00
|
|
|
rw_data.scroll_offsets = layout_scroll_states
|
2016-06-01 04:54:29 +03:00
|
|
|
}
|
|
|
|
|
2015-11-10 05:17:45 +03:00
|
|
|
fn tick_all_animations<'a, 'b>(&mut self, possibly_locked_rw_data: &mut RwData<'a, 'b>) {
|
|
|
|
let mut rw_data = possibly_locked_rw_data.lock();
|
2015-11-12 23:56:12 +03:00
|
|
|
self.tick_animations(&mut rw_data);
|
2015-03-31 19:39:56 +03:00
|
|
|
}
|
|
|
|
|
servo: Merge #11766 - Add `@keyframes` and `animation-*` support (from emilio:keyframes-parsing); r=SimonSapin,pcwalton
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
<!-- Either: -->
- [x] There are tests for these changes
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This adds support for parsing `@keyframes` rules, and animation properties. Stylo will need it sometime soonish, plus I want to make animations work in Servo.
The remaining part is doin the math and trigger the animations correctly from servo. I don't expect it to be *that* hard, but probaby I'll need to learn a bit more about the current animation infra (e.g. why the heck is the `new_animations_sender` guarded by a `Mutex`?).
I'd expect to land this, since this is already a bunch of work, this is the part exclusively required by stylo (at least if we don't use Servo's machinery), the media query parsing is tested, and the properties land after a flag, but if you prefer to wait until I finish this up it's fine for me too.
r? @SimonSapin
cc @pcwalton @bholley
Source-Repo: https://github.com/servo/servo
Source-Revision: d3a81373e44634c30d31da0457e1c1e86c0911ed
2016-06-29 01:31:01 +03:00
|
|
|
fn tick_animations(&mut self, rw_data: &mut LayoutThreadData) {
|
2016-12-01 21:16:38 +03:00
|
|
|
if opts::get().relayout_event {
|
|
|
|
println!("**** pipeline={}\tForDisplay\tSpecial\tAnimationTick", self.id);
|
|
|
|
}
|
|
|
|
|
2017-05-12 16:56:47 +03:00
|
|
|
if let Some(mut root_flow) = self.root_flow.borrow().clone() {
|
2017-03-20 04:22:23 +03:00
|
|
|
let reflow_info = Reflow {
|
|
|
|
goal: ReflowGoal::ForDisplay,
|
|
|
|
page_clip_rect: max_rect(),
|
|
|
|
};
|
|
|
|
|
|
|
|
// Unwrap here should not panic since self.root_flow is only ever set to Some(_)
|
|
|
|
// in handle_reflow() where self.document_shared_lock is as well.
|
|
|
|
let author_shared_lock = self.document_shared_lock.clone().unwrap();
|
|
|
|
let author_guard = author_shared_lock.read();
|
|
|
|
let ua_or_user_guard = UA_STYLESHEETS.shared_lock.read();
|
|
|
|
let guards = StylesheetGuards {
|
|
|
|
author: &author_guard,
|
|
|
|
ua_or_user: &ua_or_user_guard,
|
|
|
|
};
|
2017-05-10 23:08:59 +03:00
|
|
|
let snapshots = SnapshotMap::new();
|
|
|
|
let mut layout_context = self.build_layout_context(guards,
|
|
|
|
false,
|
|
|
|
&snapshots);
|
2017-03-20 04:22:23 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
// Perform an abbreviated style recalc that operates without access to the DOM.
|
|
|
|
let animations = self.running_animations.read();
|
|
|
|
profile(time::ProfilerCategory::LayoutStyleRecalc,
|
|
|
|
self.profiler_metadata(),
|
|
|
|
self.time_profiler_chan.clone(),
|
|
|
|
|| {
|
|
|
|
animation::recalc_style_for_animations(
|
|
|
|
&layout_context, FlowRef::deref_mut(&mut root_flow), &animations)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
self.perform_post_style_recalc_layout_passes(&mut root_flow,
|
|
|
|
&reflow_info,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
&mut *rw_data,
|
|
|
|
&mut layout_context);
|
|
|
|
assert!(layout_context.pending_images.is_none());
|
2017-05-15 23:00:19 +03:00
|
|
|
assert!(layout_context.newly_transitioning_nodes.is_none());
|
2015-08-03 00:04:54 +03:00
|
|
|
}
|
2015-03-31 19:39:56 +03:00
|
|
|
}
|
|
|
|
|
2017-05-12 16:56:47 +03:00
|
|
|
fn perform_post_style_recalc_layout_passes(&self,
|
2017-03-20 04:22:23 +03:00
|
|
|
root_flow: &mut FlowRef,
|
2015-11-14 23:02:35 +03:00
|
|
|
data: &Reflow,
|
2016-09-27 04:57:59 +03:00
|
|
|
query_type: Option<&ReflowQueryType>,
|
2016-08-31 05:05:56 +03:00
|
|
|
document: Option<&ServoLayoutDocument>,
|
2016-01-10 13:19:04 +03:00
|
|
|
rw_data: &mut LayoutThreadData,
|
2017-02-08 04:16:05 +03:00
|
|
|
context: &mut LayoutContext) {
|
2017-05-15 23:00:19 +03:00
|
|
|
{
|
|
|
|
let mut newly_transitioning_nodes = context
|
|
|
|
.newly_transitioning_nodes
|
|
|
|
.as_ref()
|
|
|
|
.map(|nodes| nodes.lock().unwrap());
|
|
|
|
let newly_transitioning_nodes = newly_transitioning_nodes
|
|
|
|
.as_mut()
|
|
|
|
.map(|nodes| &mut **nodes);
|
|
|
|
// Kick off animations if any were triggered, expire completed ones.
|
|
|
|
animation::update_animation_state(&self.constellation_chan,
|
|
|
|
&self.script_chan,
|
|
|
|
&mut *self.running_animations.write(),
|
|
|
|
&mut *self.expired_animations.write(),
|
|
|
|
newly_transitioning_nodes,
|
|
|
|
&self.new_animations_receiver,
|
|
|
|
self.id,
|
|
|
|
&self.timer);
|
|
|
|
}
|
2017-03-20 04:22:23 +03:00
|
|
|
|
|
|
|
profile(time::ProfilerCategory::LayoutRestyleDamagePropagation,
|
|
|
|
self.profiler_metadata(),
|
|
|
|
self.time_profiler_chan.clone(),
|
|
|
|
|| {
|
|
|
|
// Call `compute_layout_damage` even in non-incremental mode, because it sets flags
|
|
|
|
// that are needed in both incremental and non-incremental traversals.
|
|
|
|
let damage = FlowRef::deref_mut(root_flow).compute_layout_damage();
|
2014-10-15 02:51:30 +04:00
|
|
|
|
2017-03-20 04:22:23 +03:00
|
|
|
if opts::get().nonincremental_layout || damage.contains(REFLOW_ENTIRE_DOCUMENT) {
|
|
|
|
FlowRef::deref_mut(root_flow).reflow_entire_document()
|
2015-09-09 05:39:09 +03:00
|
|
|
}
|
2017-03-20 04:22:23 +03:00
|
|
|
});
|
2014-09-08 10:33:09 +04:00
|
|
|
|
2017-03-20 04:22:23 +03:00
|
|
|
if opts::get().trace_layout {
|
|
|
|
layout_debug::begin_trace(root_flow.clone());
|
|
|
|
}
|
2012-10-14 11:42:25 +04:00
|
|
|
|
2017-03-20 04:22:23 +03:00
|
|
|
// Resolve generated content.
|
|
|
|
profile(time::ProfilerCategory::LayoutGeneratedContent,
|
|
|
|
self.profiler_metadata(),
|
|
|
|
self.time_profiler_chan.clone(),
|
|
|
|
|| sequential::resolve_generated_content(FlowRef::deref_mut(root_flow), &context));
|
|
|
|
|
|
|
|
// Guess float placement.
|
|
|
|
profile(time::ProfilerCategory::LayoutFloatPlacementSpeculation,
|
|
|
|
self.profiler_metadata(),
|
|
|
|
self.time_profiler_chan.clone(),
|
|
|
|
|| sequential::guess_float_placement(FlowRef::deref_mut(root_flow)));
|
|
|
|
|
|
|
|
// Perform the primary layout passes over the flow tree to compute the locations of all
|
|
|
|
// the boxes.
|
|
|
|
if flow::base(&**root_flow).restyle_damage.intersects(REFLOW | REFLOW_OUT_OF_FLOW) {
|
|
|
|
profile(time::ProfilerCategory::LayoutMain,
|
2016-03-19 22:23:27 +03:00
|
|
|
self.profiler_metadata(),
|
|
|
|
self.time_profiler_chan.clone(),
|
|
|
|
|| {
|
2017-03-20 04:22:23 +03:00
|
|
|
let profiler_metadata = self.profiler_metadata();
|
|
|
|
|
2017-05-12 16:56:47 +03:00
|
|
|
if let (true, Some(traversal)) = (self.parallel_flag, self.parallel_traversal.as_ref()) {
|
2017-03-20 04:22:23 +03:00
|
|
|
// Parallel mode.
|
|
|
|
LayoutThread::solve_constraints_parallel(traversal,
|
|
|
|
FlowRef::deref_mut(root_flow),
|
|
|
|
profiler_metadata,
|
|
|
|
self.time_profiler_chan.clone(),
|
|
|
|
&*context);
|
|
|
|
} else {
|
|
|
|
//Sequential mode
|
|
|
|
LayoutThread::solve_constraints(FlowRef::deref_mut(root_flow), &context)
|
|
|
|
}
|
2016-03-19 22:23:27 +03:00
|
|
|
});
|
2015-09-09 05:39:09 +03:00
|
|
|
}
|
2017-03-20 04:22:23 +03:00
|
|
|
|
|
|
|
profile(time::ProfilerCategory::LayoutStoreOverflow,
|
|
|
|
self.profiler_metadata(),
|
|
|
|
self.time_profiler_chan.clone(),
|
|
|
|
|| {
|
|
|
|
sequential::store_overflow(context,
|
|
|
|
FlowRef::deref_mut(root_flow) as &mut Flow);
|
|
|
|
});
|
|
|
|
|
|
|
|
self.perform_post_main_layout_passes(data,
|
|
|
|
query_type,
|
|
|
|
document,
|
|
|
|
rw_data,
|
|
|
|
context);
|
2015-05-20 03:40:36 +03:00
|
|
|
}
|
|
|
|
|
2017-05-12 16:56:47 +03:00
|
|
|
fn perform_post_main_layout_passes(&self,
|
2015-11-14 23:02:35 +03:00
|
|
|
data: &Reflow,
|
2016-09-27 04:57:59 +03:00
|
|
|
query_type: Option<&ReflowQueryType>,
|
2016-08-31 05:05:56 +03:00
|
|
|
document: Option<&ServoLayoutDocument>,
|
2016-01-10 13:19:04 +03:00
|
|
|
rw_data: &mut LayoutThreadData,
|
2017-02-08 04:16:05 +03:00
|
|
|
layout_context: &mut LayoutContext) {
|
2014-12-08 20:28:10 +03:00
|
|
|
// Build the display list if necessary, and send it to the painter.
|
2017-05-12 16:56:47 +03:00
|
|
|
if let Some(mut root_flow) = self.root_flow.borrow().clone() {
|
2015-09-09 05:39:09 +03:00
|
|
|
self.compute_abs_pos_and_build_display_list(data,
|
2016-09-27 04:57:59 +03:00
|
|
|
query_type,
|
2016-08-31 05:05:56 +03:00
|
|
|
document,
|
2016-11-05 00:53:38 +03:00
|
|
|
FlowRef::deref_mut(&mut root_flow),
|
2015-09-09 05:39:09 +03:00
|
|
|
&mut *layout_context,
|
|
|
|
rw_data);
|
2017-05-12 16:56:47 +03:00
|
|
|
self.first_reflow.set(false);
|
2015-09-09 05:39:09 +03:00
|
|
|
|
|
|
|
if opts::get().trace_layout {
|
2017-05-12 16:56:47 +03:00
|
|
|
layout_debug::end_trace(self.generation.get());
|
2015-09-09 05:39:09 +03:00
|
|
|
}
|
2014-09-08 10:33:09 +04:00
|
|
|
|
2015-09-09 05:39:09 +03:00
|
|
|
if opts::get().dump_flow_tree {
|
2015-11-24 05:19:07 +03:00
|
|
|
root_flow.print("Post layout flow tree".to_owned());
|
2015-09-09 05:39:09 +03:00
|
|
|
}
|
2014-10-18 05:51:24 +04:00
|
|
|
|
2017-05-12 16:56:47 +03:00
|
|
|
self.generation.set(self.generation.get() + 1);
|
2015-09-09 05:39:09 +03:00
|
|
|
}
|
2012-10-14 11:42:25 +04:00
|
|
|
}
|
|
|
|
|
2014-10-28 21:00:51 +03:00
|
|
|
fn reflow_all_nodes(flow: &mut Flow) {
|
2015-05-19 21:51:30 +03:00
|
|
|
debug!("reflowing all nodes!");
|
2017-03-03 05:46:40 +03:00
|
|
|
flow::mut_base(flow)
|
|
|
|
.restyle_damage
|
|
|
|
.insert(REPAINT | STORE_OVERFLOW | REFLOW | REPOSITION);
|
2014-10-28 21:00:51 +03:00
|
|
|
|
2016-04-09 01:24:40 +03:00
|
|
|
for child in flow::child_iter_mut(flow) {
|
2016-01-10 13:19:04 +03:00
|
|
|
LayoutThread::reflow_all_nodes(child);
|
2014-10-09 21:21:32 +04:00
|
|
|
}
|
|
|
|
}
|
2014-09-05 06:14:18 +04:00
|
|
|
|
2014-12-18 10:24:49 +03:00
|
|
|
/// Returns profiling information which is passed to the time profiler.
|
2015-11-10 05:17:45 +03:00
|
|
|
fn profiler_metadata(&self) -> Option<TimerMetadata> {
|
|
|
|
Some(TimerMetadata {
|
2016-05-27 06:37:23 +03:00
|
|
|
url: self.url.to_string(),
|
2015-11-10 05:17:45 +03:00
|
|
|
iframe: if self.is_iframe {
|
2014-12-18 10:24:49 +03:00
|
|
|
TimerMetadataFrameType::IFrame
|
2015-11-10 05:17:45 +03:00
|
|
|
} else {
|
2014-12-18 10:24:49 +03:00
|
|
|
TimerMetadataFrameType::RootWindow
|
2015-11-10 05:17:45 +03:00
|
|
|
},
|
2017-05-12 16:56:47 +03:00
|
|
|
incremental: if self.first_reflow.get() {
|
2014-12-18 10:24:49 +03:00
|
|
|
TimerMetadataReflowType::FirstReflow
|
2015-11-10 05:17:45 +03:00
|
|
|
} else {
|
2014-12-18 10:24:49 +03:00
|
|
|
TimerMetadataReflowType::Incremental
|
2015-11-10 05:17:45 +03:00
|
|
|
},
|
|
|
|
})
|
2014-12-18 10:24:49 +03:00
|
|
|
}
|
2014-09-05 06:14:18 +04:00
|
|
|
}
|
|
|
|
|
2017-07-20 21:34:35 +03:00
|
|
|
impl ProfilerMetadataFactory for LayoutThread {
|
|
|
|
fn new_metadata(&self) -> Option<TimerMetadata> {
|
|
|
|
self.profiler_metadata()
|
|
|
|
}
|
|
|
|
}
|
2015-08-04 03:39:43 +03:00
|
|
|
|
2015-03-30 20:40:14 +03:00
|
|
|
// The default computed value for background-color is transparent (see
|
|
|
|
// http://dev.w3.org/csswg/css-backgrounds/#background-color). However, we
|
|
|
|
// need to propagate the background color from the root HTML/Body
|
|
|
|
// element (http://dev.w3.org/csswg/css-backgrounds/#special-backgrounds) if
|
|
|
|
// it is non-transparent. The phrase in the spec "If the canvas background
|
|
|
|
// is not opaque, what shows through is UA-dependent." is handled by rust-layers
|
|
|
|
// clearing the frame buffer to white. This ensures that setting a background
|
|
|
|
// color on an iframe element, while the iframe content itself has a default
|
|
|
|
// transparent background color is handled correctly.
|
2017-07-13 07:52:27 +03:00
|
|
|
fn get_root_flow_background_color(flow: &mut Flow) -> webrender_api::ColorF {
|
|
|
|
let transparent = webrender_api::ColorF { r: 0.0, g: 0.0, b: 0.0, a: 0.0 };
|
2015-03-30 20:40:14 +03:00
|
|
|
if !flow.is_block_like() {
|
2016-11-05 15:26:30 +03:00
|
|
|
return transparent;
|
2015-03-30 20:40:14 +03:00
|
|
|
}
|
|
|
|
|
2015-08-18 16:31:57 +03:00
|
|
|
let block_flow = flow.as_mut_block();
|
2015-03-30 20:40:14 +03:00
|
|
|
let kid = match block_flow.base.children.iter_mut().next() {
|
2016-11-05 15:26:30 +03:00
|
|
|
None => return transparent,
|
2015-03-30 20:40:14 +03:00
|
|
|
Some(kid) => kid,
|
|
|
|
};
|
|
|
|
if !kid.is_block_like() {
|
2016-11-05 15:26:30 +03:00
|
|
|
return transparent;
|
2015-03-30 20:40:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let kid_block_flow = kid.as_block();
|
|
|
|
kid_block_flow.fragment
|
|
|
|
.style
|
|
|
|
.resolve_color(kid_block_flow.fragment.style.get_background().background_color)
|
|
|
|
.to_gfx_color()
|
|
|
|
}
|
2016-08-23 16:34:04 +03:00
|
|
|
|
|
|
|
fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
|
2017-09-14 23:55:21 +03:00
|
|
|
fn parse_ua_stylesheet(
|
|
|
|
shared_lock: &SharedRwLock,
|
|
|
|
filename: &'static str,
|
|
|
|
) -> Result<DocumentStyleSheet, &'static str> {
|
2017-06-18 15:55:11 +03:00
|
|
|
let res = read_resource_file(filename).map_err(|_| filename)?;
|
2017-09-14 23:55:21 +03:00
|
|
|
Ok(DocumentStyleSheet(ServoArc::new(Stylesheet::from_bytes(
|
2016-08-23 16:34:04 +03:00
|
|
|
&res,
|
2016-11-18 00:34:47 +03:00
|
|
|
ServoUrl::parse(&format!("chrome://resources/{:?}", filename)).unwrap(),
|
2016-08-23 16:34:04 +03:00
|
|
|
None,
|
|
|
|
None,
|
|
|
|
Origin::UserAgent,
|
2017-04-12 18:00:26 +03:00
|
|
|
MediaList::empty(),
|
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
|
|
|
shared_lock.clone(),
|
2016-12-16 20:43:19 +03:00
|
|
|
None,
|
2017-04-28 06:32:24 +03:00
|
|
|
&NullReporter,
|
2017-09-14 23:55:21 +03:00
|
|
|
QuirksMode::NoQuirks,
|
|
|
|
))))
|
2016-08-23 16:34:04 +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
|
|
|
let shared_lock = SharedRwLock::new();
|
2016-08-23 16:34:04 +03:00
|
|
|
let mut user_or_user_agent_stylesheets = vec!();
|
|
|
|
// FIXME: presentational-hints.css should be at author origin with zero specificity.
|
|
|
|
// (Does it make a difference?)
|
|
|
|
for &filename in &["user-agent.css", "servo.css", "presentational-hints.css"] {
|
2017-06-18 15:55:11 +03:00
|
|
|
user_or_user_agent_stylesheets.push(parse_ua_stylesheet(&shared_lock, filename)?);
|
2016-08-23 16:34:04 +03:00
|
|
|
}
|
|
|
|
for &(ref contents, ref url) in &opts::get().user_stylesheets {
|
2017-09-14 23:55:21 +03:00
|
|
|
user_or_user_agent_stylesheets.push(
|
|
|
|
DocumentStyleSheet(ServoArc::new(Stylesheet::from_bytes(
|
|
|
|
&contents,
|
|
|
|
url.clone(),
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
Origin::User,
|
|
|
|
MediaList::empty(),
|
|
|
|
shared_lock.clone(),
|
|
|
|
None,
|
|
|
|
&RustLogReporter,
|
|
|
|
QuirksMode::NoQuirks,
|
|
|
|
)))
|
|
|
|
);
|
2016-08-23 16:34:04 +03:00
|
|
|
}
|
|
|
|
|
2017-06-18 15:55:11 +03:00
|
|
|
let quirks_mode_stylesheet = parse_ua_stylesheet(&shared_lock, "quirks-mode.css")?;
|
2016-08-23 16:34:04 +03:00
|
|
|
|
|
|
|
Ok(UserAgentStylesheets {
|
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
|
|
|
shared_lock: shared_lock,
|
2016-08-23 16:34:04 +03:00
|
|
|
user_or_user_agent_stylesheets: user_or_user_agent_stylesheets,
|
|
|
|
quirks_mode_stylesheet: quirks_mode_stylesheet,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-09-27 04:57:59 +03:00
|
|
|
/// Returns true if the given reflow query type needs a full, up-to-date display list to be present
|
|
|
|
/// or false if it only needs stacking-relative positions.
|
|
|
|
fn reflow_query_type_needs_display_list(query_type: &ReflowQueryType) -> bool {
|
|
|
|
match *query_type {
|
2017-03-02 22:43:17 +03:00
|
|
|
ReflowQueryType::HitTestQuery(..) | ReflowQueryType::TextIndexQuery(..) |
|
|
|
|
ReflowQueryType::NodesFromPoint(..) => true,
|
2016-09-27 04:57:59 +03:00
|
|
|
ReflowQueryType::ContentBoxQuery(_) | ReflowQueryType::ContentBoxesQuery(_) |
|
|
|
|
ReflowQueryType::NodeGeometryQuery(_) | ReflowQueryType::NodeScrollGeometryQuery(_) |
|
2016-12-07 01:42:00 +03:00
|
|
|
ReflowQueryType::NodeOverflowQuery(_) | ReflowQueryType::NodeScrollRootIdQuery(_) |
|
|
|
|
ReflowQueryType::ResolvedStyleQuery(..) | ReflowQueryType::OffsetParentQuery(_) |
|
|
|
|
ReflowQueryType::MarginStyleQuery(_) | ReflowQueryType::NoQuery => false,
|
2016-09-27 04:57:59 +03:00
|
|
|
}
|
|
|
|
}
|
2016-08-23 16:34:04 +03:00
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
static ref UA_STYLESHEETS: UserAgentStylesheets = {
|
|
|
|
match get_ua_stylesheets() {
|
|
|
|
Ok(stylesheets) => stylesheets,
|
|
|
|
Err(filename) => {
|
|
|
|
error!("Failed to load UA stylesheet {}!", filename);
|
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2017-07-31 21:13:26 +03:00
|
|
|
|
|
|
|
struct RegisteredPainterImpl {
|
|
|
|
painter: Box<Painter>,
|
|
|
|
name: Atom,
|
|
|
|
properties: FnvHashMap<Atom, PropertyId>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SpeculativePainter for RegisteredPainterImpl {
|
|
|
|
fn speculatively_draw_a_paint_image(&self, properties: Vec<(Atom, String)>, arguments: Vec<String>) {
|
|
|
|
self.painter.speculatively_draw_a_paint_image(properties, arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RegisteredSpeculativePainter for RegisteredPainterImpl {
|
|
|
|
fn properties(&self) -> &FnvHashMap<Atom, PropertyId> {
|
|
|
|
&self.properties
|
|
|
|
}
|
|
|
|
fn name(&self) -> Atom {
|
|
|
|
self.name.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Painter for RegisteredPainterImpl {
|
|
|
|
fn draw_a_paint_image(&self,
|
|
|
|
size: TypedSize2D<f32, CSSPixel>,
|
|
|
|
device_pixel_ratio: ScaleFactor<f32, CSSPixel, DevicePixel>,
|
|
|
|
properties: Vec<(Atom, String)>,
|
|
|
|
arguments: Vec<String>)
|
|
|
|
-> DrawAPaintImageResult
|
|
|
|
{
|
|
|
|
self.painter.draw_a_paint_image(size, device_pixel_ratio, properties, arguments)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RegisteredPainter for RegisteredPainterImpl {}
|
|
|
|
|
|
|
|
struct RegisteredPaintersImpl(FnvHashMap<Atom, RegisteredPainterImpl>);
|
|
|
|
|
|
|
|
impl RegisteredSpeculativePainters for RegisteredPaintersImpl {
|
|
|
|
fn get(&self, name: &Atom) -> Option<&RegisteredSpeculativePainter> {
|
|
|
|
self.0.get(&name).map(|painter| painter as &RegisteredSpeculativePainter)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RegisteredPainters for RegisteredPaintersImpl {
|
|
|
|
fn get(&self, name: &Atom) -> Option<&RegisteredPainter> {
|
|
|
|
self.0.get(&name).map(|painter| painter as &RegisteredPainter)
|
|
|
|
}
|
|
|
|
}
|