layout: Don't rebuild display lists at all unless restyling tells us

some object needs to be repainted.

Reduces CPU usage when mousing over simple documents. (More complex
documents tend to trigger unnecessary reflow bugs and so still have high
CPU.)

Part of #9999.
This commit is contained in:
Patrick Walton 2016-03-15 16:13:46 -07:00
parent 5dca005920
commit acfd8e448c
2 changed files with 40 additions and 32 deletions

View file

@ -869,6 +869,8 @@ impl LayoutThread {
flow::mut_base(flow_ref::deref_mut(layout_root)).clip =
ClippingRegion::from_rect(&data.page_clip_rect);
if flow::base(&**layout_root).restyle_damage.contains(REPAINT) ||
rw_data.display_list.is_none() {
let mut root_stacking_context =
StackingContext::new(StackingContextId::new(0),
StackingContextType::Real,
@ -888,7 +890,6 @@ impl LayoutThread {
&mut root_stacking_context,
shared_layout_context);
if data.goal == ReflowGoal::ForDisplay {
debug!("Done building display list.");
let root_background_color = get_root_flow_background_color(
@ -905,13 +906,20 @@ impl LayoutThread {
let origin = Rect::new(Point2D::new(Au(0), Au(0)), root_size);
root_stacking_context.bounds = origin;
root_stacking_context.overflow = origin;
root_stacking_context.layer_info = Some(LayerInfo::new(layout_root.layer_id(),
root_stacking_context.layer_info =
Some(LayerInfo::new(layout_root.layer_id(),
ScrollPolicy::Scrollable,
None,
root_background_color));
let display_list = DisplayList::new(root_stacking_context,
&mut Some(display_list_entries));
rw_data.display_list =
Some(Arc::new(DisplayList::new(root_stacking_context,
&mut Some(display_list_entries))))
}
if data.goal == ReflowGoal::ForDisplay {
let display_list = (*rw_data.display_list.as_ref().unwrap()).clone();
if opts::get().dump_display_list {
display_list.print();
}
@ -919,9 +927,6 @@ impl LayoutThread {
println!("{}", serde_json::to_string_pretty(&display_list).unwrap());
}
let display_list = Arc::new(display_list);
rw_data.display_list = Some(display_list.clone());
debug!("Layout done!");
self.epoch.next();
@ -942,7 +947,10 @@ impl LayoutThread {
epoch,
Some(root_scroll_layer_id),
&mut auxiliary_lists_builder);
let root_background_color = webrender_traits::ColorF::new(root_background_color.r,
let root_background_color = get_root_flow_background_color(
flow_ref::deref_mut(layout_root));
let root_background_color =
webrender_traits::ColorF::new(root_background_color.r,
root_background_color.g,
root_background_color.b,
root_background_color.a);

View file

@ -234,6 +234,6 @@ impl<'a> BuildDisplayList<'a> {
#[inline]
fn should_process(&self) -> bool {
self.state.layout_context.shared_context().goal == ReflowGoal::ForDisplay
true
}
}