introduce layout query timestamp

This commit is contained in:
csmoe 2018-03-17 00:40:13 +08:00
parent df6b64181b
commit 98fe118be4
9 changed files with 50 additions and 8 deletions

2
Cargo.lock generated
View file

@ -1455,6 +1455,7 @@ dependencies = [
"servo_url 0.0.1", "servo_url 0.0.1",
"style 0.0.1", "style 0.0.1",
"style_traits 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)", "webrender_api 0.57.0 (git+https://github.com/servo/webrender)",
] ]
@ -2527,6 +2528,7 @@ dependencies = [
"servo_atoms 0.0.1", "servo_atoms 0.0.1",
"servo_url 0.0.1", "servo_url 0.0.1",
"style 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)", "webrender_api 0.57.0 (git+https://github.com/servo/webrender)",
] ]

View file

@ -26,6 +26,7 @@ layout_traits = {path = "../layout_traits"}
lazy_static = "1" lazy_static = "1"
libc = "0.2" libc = "0.2"
log = "0.3.5" log = "0.3.5"
time = "0.1.17"
malloc_size_of = { path = "../malloc_size_of" } malloc_size_of = { path = "../malloc_size_of" }
metrics = {path = "../metrics"} metrics = {path = "../metrics"}
msg = {path = "../msg"} msg = {path = "../msg"}

View file

@ -46,6 +46,7 @@ extern crate servo_geometry;
extern crate servo_url; extern crate servo_url;
extern crate style; extern crate style;
extern crate style_traits; extern crate style_traits;
extern crate time as std_time;
extern crate webrender_api; extern crate webrender_api;
mod dom_wrapper; mod dom_wrapper;
@ -260,6 +261,9 @@ pub struct LayoutThread {
/// Paint time metrics. /// Paint time metrics.
paint_time_metrics: PaintTimeMetrics, paint_time_metrics: PaintTimeMetrics,
/// The time a layout query has waited before serviced by layout thread.
layout_query_timestamp: u64,
} }
impl LayoutThreadFactory for LayoutThread { 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 { impl ScriptReflowResult {
fn new(script_reflow: ScriptReflow) -> ScriptReflowResult { fn new(script_reflow: ScriptReflow) -> ScriptReflowResult {
ScriptReflowResult { ScriptReflowResult {
@ -541,6 +551,7 @@ impl LayoutThread {
}, },
layout_threads: layout_threads, layout_threads: layout_threads,
paint_time_metrics: paint_time_metrics, 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 // Drop the root flow explicitly to avoid holding style data, such as
// rule nodes. The `Stylist` checks when it is dropped that all rule // 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. // 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(); self.root_flow.borrow_mut().take();
// Drop the rayon threadpool if present. // Drop the rayon threadpool if present.
let _ = self.parallel_traversal.take(); let _ = self.parallel_traversal.take();
@ -1066,6 +1080,9 @@ impl LayoutThread {
fn handle_reflow<'a, 'b>(&mut self, fn handle_reflow<'a, 'b>(&mut self,
data: &mut ScriptReflowResult, data: &mut ScriptReflowResult,
possibly_locked_rw_data: &mut RwData<'a, 'b>) { 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 = unsafe { ServoLayoutNode::new(&data.document) };
let document = document.as_document().unwrap(); let document = document.as_document().unwrap();
@ -1080,10 +1097,11 @@ impl LayoutThread {
let element = match document.root_element() { let element = match document.root_element() {
None => { None => {
self.layout_query_timestamp = data.reflow_goal.timestamp().expect("Not a QueryMsg");
// Since we cannot compute anything, give spec-required placeholders. // Since we cannot compute anything, give spec-required placeholders.
debug!("layout: No root node: bailing"); debug!("layout: No root node: bailing");
match data.reflow_goal { match data.reflow_goal {
ReflowGoal::LayoutQuery(ref quermsg, _) => match quermsg { ReflowGoal::LayoutQuery(ref query_msg, _) => match query_msg {
&QueryMsg::ContentBoxQuery(_) => { &QueryMsg::ContentBoxQuery(_) => {
rw_data.content_box_response = None; rw_data.content_box_response = None;
}, },

View file

@ -1968,8 +1968,7 @@ impl Document {
client_point: &Point2D<f32>, client_point: &Point2D<f32>,
reflow_goal: NodesFromPointQueryType) reflow_goal: NodesFromPointQueryType)
-> Vec<UntrustedNodeAddress> { -> Vec<UntrustedNodeAddress> {
if !self.window.reflow(ReflowGoal::LayoutQuery(QueryMsg::NodesFromPointQuery(*client_point, reflow_goal), u64::default()), if !self.window.layout_reflow(QueryMsg::NodesFromPointQuery(*client_point, reflow_goal)) {
ReflowReason::Query) {
return vec!(); return vec!();
}; };

View file

@ -32,10 +32,9 @@ use dom::node::{document_from_node, window_from_node};
use dom::nodelist::NodeList; use dom::nodelist::NodeList;
use dom::text::Text; use dom::text::Text;
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use dom::window::ReflowReason;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix}; use html5ever::{LocalName, Prefix};
use script_layout_interface::message::{QueryMsg, ReflowGoal}; use script_layout_interface::message::QueryMsg;
use std::collections::HashSet; use std::collections::HashSet;
use std::default::Default; use std::default::Default;
use std::rc::Rc; use std::rc::Rc;
@ -419,7 +418,7 @@ impl HTMLElementMethods for HTMLElement {
return node.GetTextContent().unwrap(); 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()) DOMString::from(window.layout().element_inner_text())
} }

View file

@ -1374,8 +1374,8 @@ impl Window {
issued_reflow issued_reflow
} }
pub fn layout_reflow(&self, query_msg: QuerMsg) -> bool { pub fn layout_reflow(&self, query_msg: QueryMsg) -> bool {
self.reflow(ReflowGoal::LayoutQuery(query_msg, time::precise_time_ns()), ReflowReason::Query) self.reflow(ReflowGoal::LayoutQuery(query_msg, 0u64), ReflowReason::Query)
} }
pub fn layout(&self) -> &LayoutRPC { pub fn layout(&self) -> &LayoutRPC {

View file

@ -20,6 +20,7 @@ html5ever = "0.22"
ipc-channel = "0.9" ipc-channel = "0.9"
libc = "0.2" libc = "0.2"
log = "0.3.5" log = "0.3.5"
time = "0.1.17"
malloc_size_of = { path = "../malloc_size_of" } malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" } malloc_size_of_derive = { path = "../malloc_size_of_derive" }
metrics = {path = "../metrics"} metrics = {path = "../metrics"}

View file

@ -33,6 +33,7 @@ extern crate servo_arc;
extern crate servo_atoms; extern crate servo_atoms;
extern crate servo_url; extern crate servo_url;
extern crate style; extern crate style;
extern crate time;
extern crate webrender_api; extern crate webrender_api;
pub mod message; pub mod message;

View file

@ -24,6 +24,7 @@ use style::context::QuirksMode;
use style::properties::PropertyId; use style::properties::PropertyId;
use style::selector_parser::PseudoElement; use style::selector_parser::PseudoElement;
use style::stylesheets::Stylesheet; use style::stylesheets::Stylesheet;
use time;
/// Asynchronous messages that script can send to layout. /// Asynchronous messages that script can send to layout.
pub enum Msg { 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. /// Information needed for a reflow.