Auto merge of #20307 - csmoe:measure_query_time, r=jdm

Measure time required before a layout query is serviced by the layout thread

<!-- Please describe your changes on the following line: -->

- [X] extract QueryMsg from ReflowGoal
- [X] introduce QueryMsg timestamp

---
<!-- 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 #19795 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20307)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-03-26 15:42:03 -04:00 committed by GitHub
commit 4b8416fafb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 218 additions and 156 deletions

View file

@ -67,7 +67,7 @@ use profile_traits::ipc as ProfiledIpc;
use profile_traits::mem::ProfilerChan as MemProfilerChan;
use profile_traits::time::ProfilerChan as TimeProfilerChan;
use script_layout_interface::{TrustedNodeAddress, PendingImageState};
use script_layout_interface::message::{Msg, Reflow, ReflowGoal, ScriptReflow};
use script_layout_interface::message::{Msg, Reflow, QueryMsg, ReflowGoal, ScriptReflow};
use script_layout_interface::reporter::CSSErrorReporter;
use script_layout_interface::rpc::{ContentBoxResponse, ContentBoxesResponse, LayoutRPC};
use script_layout_interface::rpc::{NodeScrollIdResponse, ResolvedStyleResponse, TextIndexResponse};
@ -1385,12 +1385,16 @@ impl Window {
issued_reflow
}
pub fn layout_reflow(&self, query_msg: QueryMsg) -> bool {
self.reflow(ReflowGoal::LayoutQuery(query_msg, time::precise_time_ns()), ReflowReason::Query)
}
pub fn layout(&self) -> &LayoutRPC {
&*self.layout_rpc
}
pub fn content_box_query(&self, content_box_request: TrustedNodeAddress) -> Option<Rect<Au>> {
if !self.reflow(ReflowGoal::ContentBoxQuery(content_box_request), ReflowReason::Query) {
if !self.layout_reflow(QueryMsg::ContentBoxQuery(content_box_request)) {
return None;
}
let ContentBoxResponse(rect) = self.layout_rpc.content_box();
@ -1398,7 +1402,7 @@ impl Window {
}
pub fn content_boxes_query(&self, content_boxes_request: TrustedNodeAddress) -> Vec<Rect<Au>> {
if !self.reflow(ReflowGoal::ContentBoxesQuery(content_boxes_request), ReflowReason::Query) {
if !self.layout_reflow(QueryMsg::ContentBoxesQuery(content_boxes_request)) {
return vec![];
}
let ContentBoxesResponse(rects) = self.layout_rpc.content_boxes();
@ -1406,14 +1410,14 @@ impl Window {
}
pub fn client_rect_query(&self, node_geometry_request: TrustedNodeAddress) -> Rect<i32> {
if !self.reflow(ReflowGoal::NodeGeometryQuery(node_geometry_request), ReflowReason::Query) {
if !self.layout_reflow(QueryMsg::NodeGeometryQuery(node_geometry_request)) {
return Rect::zero();
}
self.layout_rpc.node_geometry().client_rect
}
pub fn scroll_area_query(&self, node: TrustedNodeAddress) -> Rect<i32> {
if !self.reflow(ReflowGoal::NodeScrollGeometryQuery(node), ReflowReason::Query) {
if !self.layout_reflow(QueryMsg::NodeScrollGeometryQuery(node)) {
return Rect::zero();
}
self.layout_rpc.node_scroll_area().client_rect
@ -1436,10 +1440,7 @@ impl Window {
y_: f64,
behavior: ScrollBehavior
) {
if !self.reflow(
ReflowGoal::NodeScrollIdQuery(node.to_trusted_node_address()),
ReflowReason::Query
) {
if !self.layout_reflow(QueryMsg::NodeScrollIdQuery(node.to_trusted_node_address())) {
return;
}
@ -1463,8 +1464,7 @@ impl Window {
element: TrustedNodeAddress,
pseudo: Option<PseudoElement>,
property: PropertyId) -> DOMString {
if !self.reflow(ReflowGoal::ResolvedStyleQuery(element, pseudo, property),
ReflowReason::Query) {
if !self.layout_reflow(QueryMsg::ResolvedStyleQuery(element, pseudo, property)) {
return DOMString::new();
}
let ResolvedStyleResponse(resolved) = self.layout_rpc.resolved_style();
@ -1473,7 +1473,7 @@ impl Window {
#[allow(unsafe_code)]
pub fn offset_parent_query(&self, node: TrustedNodeAddress) -> (Option<DomRoot<Element>>, Rect<Au>) {
if !self.reflow(ReflowGoal::OffsetParentQuery(node), ReflowReason::Query) {
if !self.layout_reflow(QueryMsg::OffsetParentQuery(node)) {
return (None, Rect::zero());
}
@ -1488,7 +1488,7 @@ impl Window {
}
pub fn style_query(&self, node: TrustedNodeAddress) -> Option<servo_arc::Arc<ComputedValues>> {
if !self.reflow(ReflowGoal::StyleQuery(node), ReflowReason::Query) {
if !self.layout_reflow(QueryMsg::StyleQuery(node)) {
return None
}
self.layout_rpc.style().0
@ -1499,7 +1499,7 @@ impl Window {
node: TrustedNodeAddress,
point_in_node: Point2D<f32>
) -> TextIndexResponse {
if !self.reflow(ReflowGoal::TextIndexQuery(node, point_in_node), ReflowReason::Query) {
if !self.layout_reflow(QueryMsg::TextIndexQuery(node, point_in_node)) {
return TextIndexResponse(None);
}
self.layout_rpc.text_index()
@ -1881,18 +1881,20 @@ fn debug_reflow_events(id: PipelineId, reflow_goal: &ReflowGoal, reason: &Reflow
let mut debug_msg = format!("**** pipeline={}", id);
debug_msg.push_str(match *reflow_goal {
ReflowGoal::Full => "\tFull",
ReflowGoal::ContentBoxQuery(_n) => "\tContentBoxQuery",
ReflowGoal::ContentBoxesQuery(_n) => "\tContentBoxesQuery",
ReflowGoal::NodesFromPointQuery(..) => "\tNodesFromPointQuery",
ReflowGoal::NodeGeometryQuery(_n) => "\tNodeGeometryQuery",
ReflowGoal::NodeScrollGeometryQuery(_n) => "\tNodeScrollGeometryQuery",
ReflowGoal::NodeScrollIdQuery(_n) => "\tNodeScrollIdQuery",
ReflowGoal::ResolvedStyleQuery(_, _, _) => "\tResolvedStyleQuery",
ReflowGoal::OffsetParentQuery(_n) => "\tOffsetParentQuery",
ReflowGoal::StyleQuery(_n) => "\tStyleQuery",
ReflowGoal::TextIndexQuery(..) => "\tTextIndexQuery",
ReflowGoal::TickAnimations => "\tTickAnimations",
ReflowGoal::ElementInnerTextQuery(_) => "\tElementInnerTextQuery",
ReflowGoal::LayoutQuery(ref query_msg, _) => match query_msg {
&QueryMsg::ContentBoxQuery(_n) => "\tContentBoxQuery",
&QueryMsg::ContentBoxesQuery(_n) => "\tContentBoxesQuery",
&QueryMsg::NodesFromPointQuery(..) => "\tNodesFromPointQuery",
&QueryMsg::NodeGeometryQuery(_n) => "\tNodeGeometryQuery",
&QueryMsg::NodeScrollGeometryQuery(_n) => "\tNodeScrollGeometryQuery",
&QueryMsg::NodeScrollIdQuery(_n) => "\tNodeScrollIdQuery",
&QueryMsg::ResolvedStyleQuery(_, _, _) => "\tResolvedStyleQuery",
&QueryMsg::OffsetParentQuery(_n) => "\tOffsetParentQuery",
&QueryMsg::StyleQuery(_n) => "\tStyleQuery",
&QueryMsg::TextIndexQuery(..) => "\tTextIndexQuery",
&QueryMsg::ElementInnerTextQuery(_) => "\tElementInnerTextQuery",
},
});
debug_msg.push_str(match *reason {