mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
layout: Start using the new extensible RestyleDamage
type from Stylo (#37592)
This will allow Servo to add custom types of damage in the near future which correspond to minor phases layout. The damage exposed by Stylo only corresponds to the major layout phses. In the future, both phases will likely be managed by Servo itself and implementors will need to provide their own damage system entirely. Testing: This shouldn't change behavior and thus is covered by existing tests. Stylo PR: https://github.com/servo/stylo/pull/207 Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
a9dc2ac83a
commit
5286869b96
6 changed files with 56 additions and 35 deletions
36
Cargo.lock
generated
36
Cargo.lock
generated
|
@ -2384,7 +2384,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad"
|
checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3003,7 +3003,7 @@ dependencies = [
|
||||||
"gobject-sys",
|
"gobject-sys",
|
||||||
"libc",
|
"libc",
|
||||||
"system-deps",
|
"system-deps",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -4507,7 +4507,7 @@ checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hermit-abi 0.5.0",
|
"hermit-abi 0.5.0",
|
||||||
"libc",
|
"libc",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -6900,7 +6900,7 @@ dependencies = [
|
||||||
"errno",
|
"errno",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys 0.4.15",
|
"linux-raw-sys 0.4.15",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -6913,7 +6913,7 @@ dependencies = [
|
||||||
"errno",
|
"errno",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys 0.9.4",
|
"linux-raw-sys 0.9.4",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -7226,7 +7226,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "selectors"
|
name = "selectors"
|
||||||
version = "0.29.0"
|
version = "0.29.0"
|
||||||
source = "git+https://github.com/servo/stylo?branch=2025-06-03#2e1f66b06836428e4b29dd8144c72432c97ff316"
|
source = "git+https://github.com/servo/stylo?branch=2025-06-03#da53c540faa7dd5556c6718d4644a6e957947893"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.9.1",
|
"bitflags 2.9.1",
|
||||||
"cssparser",
|
"cssparser",
|
||||||
|
@ -7532,7 +7532,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "servo_arc"
|
name = "servo_arc"
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
source = "git+https://github.com/servo/stylo?branch=2025-06-03#2e1f66b06836428e4b29dd8144c72432c97ff316"
|
source = "git+https://github.com/servo/stylo?branch=2025-06-03#da53c540faa7dd5556c6718d4644a6e957947893"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"stable_deref_trait",
|
"stable_deref_trait",
|
||||||
|
@ -7994,7 +7994,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stylo"
|
name = "stylo"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/servo/stylo?branch=2025-06-03#2e1f66b06836428e4b29dd8144c72432c97ff316"
|
source = "git+https://github.com/servo/stylo?branch=2025-06-03#da53c540faa7dd5556c6718d4644a6e957947893"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"app_units",
|
"app_units",
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
|
@ -8051,7 +8051,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stylo_atoms"
|
name = "stylo_atoms"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/servo/stylo?branch=2025-06-03#2e1f66b06836428e4b29dd8144c72432c97ff316"
|
source = "git+https://github.com/servo/stylo?branch=2025-06-03#da53c540faa7dd5556c6718d4644a6e957947893"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"string_cache",
|
"string_cache",
|
||||||
"string_cache_codegen",
|
"string_cache_codegen",
|
||||||
|
@ -8060,12 +8060,12 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stylo_config"
|
name = "stylo_config"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/servo/stylo?branch=2025-06-03#2e1f66b06836428e4b29dd8144c72432c97ff316"
|
source = "git+https://github.com/servo/stylo?branch=2025-06-03#da53c540faa7dd5556c6718d4644a6e957947893"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stylo_derive"
|
name = "stylo_derive"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/servo/stylo?branch=2025-06-03#2e1f66b06836428e4b29dd8144c72432c97ff316"
|
source = "git+https://github.com/servo/stylo?branch=2025-06-03#da53c540faa7dd5556c6718d4644a6e957947893"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"darling",
|
"darling",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
|
@ -8077,7 +8077,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stylo_dom"
|
name = "stylo_dom"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/servo/stylo?branch=2025-06-03#2e1f66b06836428e4b29dd8144c72432c97ff316"
|
source = "git+https://github.com/servo/stylo?branch=2025-06-03#da53c540faa7dd5556c6718d4644a6e957947893"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.9.1",
|
"bitflags 2.9.1",
|
||||||
"stylo_malloc_size_of",
|
"stylo_malloc_size_of",
|
||||||
|
@ -8086,7 +8086,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stylo_malloc_size_of"
|
name = "stylo_malloc_size_of"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/servo/stylo?branch=2025-06-03#2e1f66b06836428e4b29dd8144c72432c97ff316"
|
source = "git+https://github.com/servo/stylo?branch=2025-06-03#da53c540faa7dd5556c6718d4644a6e957947893"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"app_units",
|
"app_units",
|
||||||
"cssparser",
|
"cssparser",
|
||||||
|
@ -8103,12 +8103,12 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stylo_static_prefs"
|
name = "stylo_static_prefs"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/servo/stylo?branch=2025-06-03#2e1f66b06836428e4b29dd8144c72432c97ff316"
|
source = "git+https://github.com/servo/stylo?branch=2025-06-03#da53c540faa7dd5556c6718d4644a6e957947893"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stylo_traits"
|
name = "stylo_traits"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
source = "git+https://github.com/servo/stylo?branch=2025-06-03#2e1f66b06836428e4b29dd8144c72432c97ff316"
|
source = "git+https://github.com/servo/stylo?branch=2025-06-03#da53c540faa7dd5556c6718d4644a6e957947893"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"app_units",
|
"app_units",
|
||||||
"bitflags 2.9.1",
|
"bitflags 2.9.1",
|
||||||
|
@ -8291,7 +8291,7 @@ dependencies = [
|
||||||
"getrandom 0.2.16",
|
"getrandom 0.2.16",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustix 0.38.44",
|
"rustix 0.38.44",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -8525,7 +8525,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "to_shmem"
|
name = "to_shmem"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
source = "git+https://github.com/servo/stylo?branch=2025-06-03#2e1f66b06836428e4b29dd8144c72432c97ff316"
|
source = "git+https://github.com/servo/stylo?branch=2025-06-03#da53c540faa7dd5556c6718d4644a6e957947893"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cssparser",
|
"cssparser",
|
||||||
"servo_arc",
|
"servo_arc",
|
||||||
|
@ -8538,7 +8538,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "to_shmem_derive"
|
name = "to_shmem_derive"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/servo/stylo?branch=2025-06-03#2e1f66b06836428e4b29dd8144c72432c97ff316"
|
source = "git+https://github.com/servo/stylo?branch=2025-06-03#da53c540faa7dd5556c6718d4644a6e957947893"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"darling",
|
"darling",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
|
|
|
@ -840,8 +840,8 @@ impl LayoutThread {
|
||||||
let mut damage =
|
let mut damage =
|
||||||
compute_damage_and_repair_style(layout_context.shared_context(), root_node);
|
compute_damage_and_repair_style(layout_context.shared_context(), root_node);
|
||||||
if viewport_changed {
|
if viewport_changed {
|
||||||
damage = RestyleDamage::REBUILD_BOX;
|
damage = RestyleDamage::RELAYOUT;
|
||||||
} else if !damage.contains(RestyleDamage::REBUILD_BOX) {
|
} else if !damage.contains(RestyleDamage::RELAYOUT) {
|
||||||
layout_context.style_context.stylist.rule_tree().maybe_gc();
|
layout_context.style_context.stylist.rule_tree().maybe_gc();
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,8 +104,7 @@ pub(crate) fn compute_damage_and_repair_style_inner(
|
||||||
node: ServoLayoutNode<'_>,
|
node: ServoLayoutNode<'_>,
|
||||||
parent_restyle_damage: RestyleDamage,
|
parent_restyle_damage: RestyleDamage,
|
||||||
) -> RestyleDamage {
|
) -> RestyleDamage {
|
||||||
let original_damage;
|
let element_damage;
|
||||||
let damage;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut element_data = node
|
let mut element_data = node
|
||||||
|
@ -114,28 +113,28 @@ pub(crate) fn compute_damage_and_repair_style_inner(
|
||||||
.element_data
|
.element_data
|
||||||
.borrow_mut();
|
.borrow_mut();
|
||||||
|
|
||||||
original_damage = std::mem::take(&mut element_data.damage);
|
element_damage = std::mem::take(&mut element_data.damage);
|
||||||
damage = original_damage | parent_restyle_damage;
|
|
||||||
|
|
||||||
if let Some(ref style) = element_data.styles.primary {
|
if let Some(ref style) = element_data.styles.primary {
|
||||||
if style.get_box().display == Display::None {
|
if style.get_box().display == Display::None {
|
||||||
return damage;
|
return element_damage | parent_restyle_damage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut propagated_damage = damage;
|
let element_and_parent_damage = element_damage | parent_restyle_damage;
|
||||||
|
let mut damage_from_children = RestyleDamage::empty();
|
||||||
for child in iter_child_nodes(node) {
|
for child in iter_child_nodes(node) {
|
||||||
if child.is_element() {
|
if child.is_element() {
|
||||||
propagated_damage |= compute_damage_and_repair_style_inner(context, child, damage);
|
damage_from_children |=
|
||||||
|
compute_damage_and_repair_style_inner(context, child, element_and_parent_damage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !propagated_damage.contains(RestyleDamage::REBUILD_BOX) &&
|
let damage_for_parent = damage_from_children | element_and_parent_damage;
|
||||||
!original_damage.contains(RestyleDamage::REBUILD_BOX)
|
if !damage_for_parent.contains(RestyleDamage::RELAYOUT) && !element_damage.is_empty() {
|
||||||
{
|
|
||||||
node.repair_style(context);
|
node.repair_style(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
propagated_damage
|
damage_for_parent
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use embedder_traits::UntrustedNodeAddress;
|
||||||
use html5ever::{LocalName, Namespace, local_name, ns};
|
use html5ever::{LocalName, Namespace, local_name, ns};
|
||||||
use js::jsapi::JSObject;
|
use js::jsapi::JSObject;
|
||||||
use layout_api::wrapper_traits::{LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode};
|
use layout_api::wrapper_traits::{LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode};
|
||||||
use layout_api::{LayoutNodeType, StyleData};
|
use layout_api::{LayoutDamage, LayoutNodeType, StyleData};
|
||||||
use selectors::Element as _;
|
use selectors::Element as _;
|
||||||
use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint};
|
use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint};
|
||||||
use selectors::bloom::{BLOOM_HASH_MASK, BloomFilter};
|
use selectors::bloom::{BLOOM_HASH_MASK, BloomFilter};
|
||||||
|
@ -26,10 +26,10 @@ use style::bloom::each_relevant_element_hash;
|
||||||
use style::context::SharedStyleContext;
|
use style::context::SharedStyleContext;
|
||||||
use style::data::ElementData;
|
use style::data::ElementData;
|
||||||
use style::dom::{DomChildren, LayoutIterator, TDocument, TElement, TNode, TShadowRoot};
|
use style::dom::{DomChildren, LayoutIterator, TDocument, TElement, TNode, TShadowRoot};
|
||||||
use style::properties::PropertyDeclarationBlock;
|
use style::properties::{ComputedValues, PropertyDeclarationBlock};
|
||||||
use style::selector_parser::{
|
use style::selector_parser::{
|
||||||
AttrValue as SelectorAttrValue, Lang, NonTSPseudoClass, PseudoElement, SelectorImpl,
|
AttrValue as SelectorAttrValue, Lang, NonTSPseudoClass, PseudoElement, RestyleDamage,
|
||||||
extended_filtering,
|
SelectorImpl, extended_filtering,
|
||||||
};
|
};
|
||||||
use style::shared_lock::Locked as StyleLocked;
|
use style::shared_lock::Locked as StyleLocked;
|
||||||
use style::stylesheets::scope_rule::ImplicitScopeRoot;
|
use style::stylesheets::scope_rule::ImplicitScopeRoot;
|
||||||
|
@ -554,6 +554,10 @@ impl<'dom> style::dom::TElement for ServoLayoutElement<'dom> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compute_layout_damage(_old: &ComputedValues, _new: &ComputedValues) -> RestyleDamage {
|
||||||
|
RestyleDamage::from_bits_retain(LayoutDamage::REBUILD_BOX.bits())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'dom> ::selectors::Element for ServoLayoutElement<'dom> {
|
impl<'dom> ::selectors::Element for ServoLayoutElement<'dom> {
|
||||||
|
|
16
components/shared/layout/layout_damage.rs
Normal file
16
components/shared/layout/layout_damage.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use bitflags::bitflags;
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
/// Individual layout actions that may be necessary after restyling. This is an extension
|
||||||
|
/// of `RestyleDamage` from stylo, which only uses the 4 lower bits.
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
|
pub struct LayoutDamage: u16 {
|
||||||
|
/// Rebuild the entire box for this element, which means that every part of layout
|
||||||
|
/// needs to happena again.
|
||||||
|
const REBUILD_BOX = 0b111111111111 << 4;
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
|
|
||||||
|
mod layout_damage;
|
||||||
pub mod wrapper_traits;
|
pub mod wrapper_traits;
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
@ -28,6 +29,7 @@ use fnv::FnvHashMap;
|
||||||
use fonts::{FontContext, SystemFontServiceProxy};
|
use fonts::{FontContext, SystemFontServiceProxy};
|
||||||
use fxhash::FxHashMap;
|
use fxhash::FxHashMap;
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
|
pub use layout_damage::LayoutDamage;
|
||||||
use libc::c_void;
|
use libc::c_void;
|
||||||
use malloc_size_of::{MallocSizeOf as MallocSizeOfTrait, MallocSizeOfOps, malloc_size_of_is_0};
|
use malloc_size_of::{MallocSizeOf as MallocSizeOfTrait, MallocSizeOfOps, malloc_size_of_is_0};
|
||||||
use malloc_size_of_derive::MallocSizeOf;
|
use malloc_size_of_derive::MallocSizeOf;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue