aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcsmoe <35686186+csmoe@users.noreply.github.com>2018-03-17 00:40:13 +0800
committercsmoe <35686186+csmoe@users.noreply.github.com>2018-03-18 11:45:15 +0800
commit98fe118be44e829ec6f236ff8f527a7b518f755e (patch)
treef3d6fa04a444b9ecc242894e5cafac1c2eeaced7
parentdf6b64181b276482c4082b2064d3b9c4ed86b970 (diff)
downloadservo-98fe118be44e829ec6f236ff8f527a7b518f755e.tar.gz
servo-98fe118be44e829ec6f236ff8f527a7b518f755e.zip
introduce layout query timestamp
-rw-r--r--Cargo.lock2
-rw-r--r--components/layout_thread/Cargo.toml1
-rw-r--r--components/layout_thread/lib.rs20
-rw-r--r--components/script/dom/document.rs3
-rw-r--r--components/script/dom/htmlelement.rs5
-rw-r--r--components/script/dom/window.rs4
-rw-r--r--components/script_layout_interface/Cargo.toml1
-rw-r--r--components/script_layout_interface/lib.rs1
-rw-r--r--components/script_layout_interface/message.rs21
9 files changed, 50 insertions, 8 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 63096eaceb0..8f6d1bf36a0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1455,6 +1455,7 @@ dependencies = [
"servo_url 0.0.1",
"style 0.0.1",
"style_traits 0.0.1",
+ "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"webrender_api 0.57.0 (git+https://github.com/servo/webrender)",
]
@@ -2527,6 +2528,7 @@ dependencies = [
"servo_atoms 0.0.1",
"servo_url 0.0.1",
"style 0.0.1",
+ "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"webrender_api 0.57.0 (git+https://github.com/servo/webrender)",
]
diff --git a/components/layout_thread/Cargo.toml b/components/layout_thread/Cargo.toml
index 1c43b48e409..d07746c54c9 100644
--- a/components/layout_thread/Cargo.toml
+++ b/components/layout_thread/Cargo.toml
@@ -26,6 +26,7 @@ layout_traits = {path = "../layout_traits"}
lazy_static = "1"
libc = "0.2"
log = "0.3.5"
+time = "0.1.17"
malloc_size_of = { path = "../malloc_size_of" }
metrics = {path = "../metrics"}
msg = {path = "../msg"}
diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs
index 0bb38326865..d3798d6e05b 100644
--- a/components/layout_thread/lib.rs
+++ b/components/layout_thread/lib.rs
@@ -46,6 +46,7 @@ extern crate servo_geometry;
extern crate servo_url;
extern crate style;
extern crate style_traits;
+extern crate time as std_time;
extern crate webrender_api;
mod dom_wrapper;
@@ -260,6 +261,9 @@ pub struct LayoutThread {
/// Paint time metrics.
paint_time_metrics: PaintTimeMetrics,
+
+ /// The time a layout query has waited before serviced by layout thread.
+ layout_query_timestamp: u64,
}
impl LayoutThreadFactory for LayoutThread {
@@ -332,6 +336,12 @@ impl Deref for ScriptReflowResult {
}
}
+impl DerefMut for ScriptReflowResult {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.script_reflow
+ }
+}
+
impl ScriptReflowResult {
fn new(script_reflow: ScriptReflow) -> ScriptReflowResult {
ScriptReflowResult {
@@ -541,6 +551,7 @@ impl LayoutThread {
},
layout_threads: layout_threads,
paint_time_metrics: paint_time_metrics,
+ layout_query_timestamp: 0u64,
}
}
@@ -858,6 +869,9 @@ impl LayoutThread {
// 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.
+ let now = std_time::precise_time_ns();
+ let waiting_time = now - self.layout_query_timestamp;
+ debug!("layout: query has been waited: {}", waiting_time);
self.root_flow.borrow_mut().take();
// Drop the rayon threadpool if present.
let _ = self.parallel_traversal.take();
@@ -1066,6 +1080,9 @@ impl LayoutThread {
fn handle_reflow<'a, 'b>(&mut self,
data: &mut ScriptReflowResult,
possibly_locked_rw_data: &mut RwData<'a, 'b>) {
+ // Set layout query timestamp
+ data.reflow_goal.set_timestamp();
+
let document = unsafe { ServoLayoutNode::new(&data.document) };
let document = document.as_document().unwrap();
@@ -1080,10 +1097,11 @@ impl LayoutThread {
let element = match document.root_element() {
None => {
+ self.layout_query_timestamp = data.reflow_goal.timestamp().expect("Not a QueryMsg");
// Since we cannot compute anything, give spec-required placeholders.
debug!("layout: No root node: bailing");
match data.reflow_goal {
- ReflowGoal::LayoutQuery(ref quermsg, _) => match quermsg {
+ ReflowGoal::LayoutQuery(ref query_msg, _) => match query_msg {
&QueryMsg::ContentBoxQuery(_) => {
rw_data.content_box_response = None;
},
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 1f202dcc55c..68a24e9dcbc 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -1968,8 +1968,7 @@ impl Document {
client_point: &Point2D<f32>,
reflow_goal: NodesFromPointQueryType)
-> Vec<UntrustedNodeAddress> {
- if !self.window.reflow(ReflowGoal::LayoutQuery(QueryMsg::NodesFromPointQuery(*client_point, reflow_goal), u64::default()),
- ReflowReason::Query) {
+ if !self.window.layout_reflow(QueryMsg::NodesFromPointQuery(*client_point, reflow_goal)) {
return vec!();
};
diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs
index e1eb260d285..e28ff1053a2 100644
--- a/components/script/dom/htmlelement.rs
+++ b/components/script/dom/htmlelement.rs
@@ -32,10 +32,9 @@ use dom::node::{document_from_node, window_from_node};
use dom::nodelist::NodeList;
use dom::text::Text;
use dom::virtualmethods::VirtualMethods;
-use dom::window::ReflowReason;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
-use script_layout_interface::message::{QueryMsg, ReflowGoal};
+use script_layout_interface::message::QueryMsg;
use std::collections::HashSet;
use std::default::Default;
use std::rc::Rc;
@@ -419,7 +418,7 @@ impl HTMLElementMethods for HTMLElement {
return node.GetTextContent().unwrap();
}
- window.reflow(ReflowGoal::LayoutQuery(QueryMsg::ElementInnerTextQuery(node.to_trusted_node_address()), u64::default()), ReflowReason::Query);
+ window.layout_reflow(QueryMsg::ElementInnerTextQuery(node.to_trusted_node_address()));
DOMString::from(window.layout().element_inner_text())
}
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 5d4e3c3a72e..bbaee9ea7c8 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -1374,8 +1374,8 @@ impl Window {
issued_reflow
}
- pub fn layout_reflow(&self, query_msg: QuerMsg) -> bool {
- self.reflow(ReflowGoal::LayoutQuery(query_msg, time::precise_time_ns()), ReflowReason::Query)
+ pub fn layout_reflow(&self, query_msg: QueryMsg) -> bool {
+ self.reflow(ReflowGoal::LayoutQuery(query_msg, 0u64), ReflowReason::Query)
}
pub fn layout(&self) -> &LayoutRPC {
diff --git a/components/script_layout_interface/Cargo.toml b/components/script_layout_interface/Cargo.toml
index caddb62a1de..18fb45385b8 100644
--- a/components/script_layout_interface/Cargo.toml
+++ b/components/script_layout_interface/Cargo.toml
@@ -20,6 +20,7 @@ html5ever = "0.22"
ipc-channel = "0.9"
libc = "0.2"
log = "0.3.5"
+time = "0.1.17"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
metrics = {path = "../metrics"}
diff --git a/components/script_layout_interface/lib.rs b/components/script_layout_interface/lib.rs
index dc2c6f515a7..289dd7c0c8b 100644
--- a/components/script_layout_interface/lib.rs
+++ b/components/script_layout_interface/lib.rs
@@ -33,6 +33,7 @@ extern crate servo_arc;
extern crate servo_atoms;
extern crate servo_url;
extern crate style;
+extern crate time;
extern crate webrender_api;
pub mod message;
diff --git a/components/script_layout_interface/message.rs b/components/script_layout_interface/message.rs
index ac52d9373ce..8a8b1f8b0d0 100644
--- a/components/script_layout_interface/message.rs
+++ b/components/script_layout_interface/message.rs
@@ -24,6 +24,7 @@ use style::context::QuirksMode;
use style::properties::PropertyId;
use style::selector_parser::PseudoElement;
use style::stylesheets::Stylesheet;
+use time;
/// Asynchronous messages that script can send to layout.
pub enum Msg {
@@ -171,6 +172,26 @@ impl ReflowGoal {
},
}
}
+
+ /// Set the timestamp of query message.
+ pub fn set_timestamp(&mut self) {
+ match *self {
+ ReflowGoal::LayoutQuery(_, ref mut timestamp) => {
+ *timestamp = time::precise_time_ns();
+ },
+ _ => (),
+ }
+ }
+
+ /// Get the query timestamp.
+ pub fn timestamp(&self) -> Option<u64> {
+ match *self {
+ ReflowGoal::LayoutQuery(_, ref timestamp) => {
+ Some(*timestamp)
+ },
+ _ => None,
+ }
+ }
}
/// Information needed for a reflow.