mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
layout: Add a repaint-only incremental layout mode (#36978)
This change adds the simplest kind of incremental layout. When Servo detects that all style changes only require a repaint, only run stacking context tree and WebRender display list generation. This means that these kind of restyles do not need a re-layout. Instead, the existing box and fragment trees will be used and the styles of damaged nodes will be updated in their box and fragment tree nodes. This requires a new style repair DOM traversal for nodes that have had their style damaged. In addition, careful accounting of all the places where we store style must happen in order ot update those styles. Testing: This is covered by existing WPT tests as it should not change observable behavior. We have created a test case which shows a 50% speedup when run in Servo, even though there still a long way to go to match the speed of other browsers: https://gist.github.com/mrobinson/44ec87d028c0198917a7715a06dd98a0 Co-authored-by: Oriol Brufau <obrufau@igalia.com> Signed-off-by: Martin Robinson <mrobinson@igalia.com> Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
51fa6cdcb6
commit
8808f9a468
20 changed files with 467 additions and 72 deletions
|
@ -19,11 +19,11 @@ use script_layout_interface::{
|
|||
GenericLayoutDataTrait, LayoutElementType, LayoutNodeType as ScriptLayoutNodeType,
|
||||
};
|
||||
use servo_arc::Arc as ServoArc;
|
||||
use style::context::SharedStyleContext;
|
||||
use style::properties::ComputedValues;
|
||||
use style::selector_parser::PseudoElement;
|
||||
|
||||
use crate::cell::ArcRefCell;
|
||||
use crate::context::LayoutContext;
|
||||
use crate::flexbox::FlexLevelBox;
|
||||
use crate::flow::BlockLevelBox;
|
||||
use crate::flow::inline::{InlineItem, SharedInlineStyles};
|
||||
|
@ -102,6 +102,41 @@ impl LayoutBox {
|
|||
LayoutBox::TableLevelBox(table_box) => table_box.fragments(),
|
||||
}
|
||||
}
|
||||
|
||||
fn repair_style(
|
||||
&self,
|
||||
context: &SharedStyleContext,
|
||||
node: &ServoLayoutNode,
|
||||
new_style: &ServoArc<ComputedValues>,
|
||||
) {
|
||||
match self {
|
||||
LayoutBox::DisplayContents(inline_shared_styles) => {
|
||||
*inline_shared_styles.style.borrow_mut() = new_style.clone();
|
||||
*inline_shared_styles.selected.borrow_mut() = node.to_threadsafe().selected_style();
|
||||
},
|
||||
LayoutBox::BlockLevel(block_level_box) => {
|
||||
block_level_box
|
||||
.borrow_mut()
|
||||
.repair_style(context, node, new_style);
|
||||
},
|
||||
LayoutBox::InlineLevel(inline_items) => {
|
||||
for inline_item in inline_items {
|
||||
inline_item
|
||||
.borrow_mut()
|
||||
.repair_style(context, node, new_style);
|
||||
}
|
||||
},
|
||||
LayoutBox::FlexLevel(flex_level_box) => {
|
||||
flex_level_box.borrow_mut().repair_style(context, new_style)
|
||||
},
|
||||
LayoutBox::TableLevelBox(table_level_box) => {
|
||||
table_level_box.repair_style(context, new_style)
|
||||
},
|
||||
LayoutBox::TaffyItemBox(taffy_item_box) => {
|
||||
taffy_item_box.borrow_mut().repair_style(context, new_style)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper for [`InnerDOMLayoutData`]. This is necessary to give the entire data
|
||||
|
@ -167,7 +202,7 @@ pub(crate) trait NodeExt<'dom> {
|
|||
fn as_iframe(&self) -> Option<(PipelineId, BrowsingContextId)>;
|
||||
fn as_video(&self) -> Option<(Option<webrender_api::ImageKey>, Option<PhysicalSize<f64>>)>;
|
||||
fn as_typeless_object_with_data_attribute(&self) -> Option<String>;
|
||||
fn style(&self, context: &LayoutContext) -> ServoArc<ComputedValues>;
|
||||
fn style(&self, context: &SharedStyleContext) -> ServoArc<ComputedValues>;
|
||||
|
||||
fn layout_data_mut(&self) -> AtomicRefMut<'dom, InnerDOMLayoutData>;
|
||||
fn layout_data(&self) -> Option<AtomicRef<'dom, InnerDOMLayoutData>>;
|
||||
|
@ -180,6 +215,8 @@ pub(crate) trait NodeExt<'dom> {
|
|||
|
||||
fn fragments_for_pseudo(&self, pseudo_element: Option<PseudoElement>) -> Vec<Fragment>;
|
||||
fn invalidate_cached_fragment(&self);
|
||||
|
||||
fn repair_style(&self, context: &SharedStyleContext);
|
||||
}
|
||||
|
||||
impl<'dom> NodeExt<'dom> for ServoLayoutNode<'dom> {
|
||||
|
@ -253,8 +290,8 @@ impl<'dom> NodeExt<'dom> for ServoLayoutNode<'dom> {
|
|||
.map(|string| string.to_owned())
|
||||
}
|
||||
|
||||
fn style(&self, context: &LayoutContext) -> ServoArc<ComputedValues> {
|
||||
self.to_threadsafe().style(context.shared_context())
|
||||
fn style(&self, context: &SharedStyleContext) -> ServoArc<ComputedValues> {
|
||||
self.to_threadsafe().style(context)
|
||||
}
|
||||
|
||||
fn layout_data_mut(&self) -> AtomicRefMut<'dom, InnerDOMLayoutData> {
|
||||
|
@ -339,4 +376,30 @@ impl<'dom> NodeExt<'dom> for ServoLayoutNode<'dom> {
|
|||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn repair_style(&self, context: &SharedStyleContext) {
|
||||
let data = self.layout_data_mut();
|
||||
if let Some(layout_object) = &*data.self_box.borrow() {
|
||||
let style = self.to_threadsafe().style(context);
|
||||
layout_object.repair_style(context, self, &style);
|
||||
}
|
||||
|
||||
if let Some(layout_object) = &*data.pseudo_before_box.borrow() {
|
||||
if let Some(node) = self.to_threadsafe().with_pseudo(PseudoElement::Before) {
|
||||
layout_object.repair_style(context, self, &node.style(context));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(layout_object) = &*data.pseudo_after_box.borrow() {
|
||||
if let Some(node) = self.to_threadsafe().with_pseudo(PseudoElement::After) {
|
||||
layout_object.repair_style(context, self, &node.style(context));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(layout_object) = &*data.pseudo_marker_box.borrow() {
|
||||
if let Some(node) = self.to_threadsafe().with_pseudo(PseudoElement::Marker) {
|
||||
layout_object.repair_style(context, self, &node.style(context));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue