Skip to content

Commit

Permalink
Auto merge of #29716 - mrobinson:generic-dom-wrapper, r=<try>
Browse files Browse the repository at this point in the history
Eliminate duplicate Layout DOM wrappers

There are duplicate sets of Layout DOM wrappers: one for Layout 2013 and one for Layout 2020. As part of cleaning up and simplifying the wrappers, this change parameterizes them on the specific layout data they contain. This allows them to be shared again. In addition, various small cleanups are included.

Fixes #29691.

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

---
<!-- 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 #29691
- [x] There are tests for these changes

<!-- 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. -->
  • Loading branch information
bors-servo committed May 5, 2023
2 parents 0e1d1e3 + f68549b commit 232d1aa
Show file tree
Hide file tree
Showing 14 changed files with 1,016 additions and 2,343 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions components/layout/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use crate::construct::ConstructionResult;
use atomic_refcell::AtomicRefCell;
use script_layout_interface::wrapper_traits::LayoutDataTrait;
use script_layout_interface::StyleData;

pub struct StyleAndLayoutData<'dom> {
Expand All @@ -14,6 +15,7 @@ pub struct StyleAndLayoutData<'dom> {
}

/// Data that layout associates with a node.
#[derive(Clone)]
pub struct LayoutData {
/// The current results of flow construction for this node. This is either a
/// flow or a `ConstructionItem`. See comments in `construct.rs` for more
Expand All @@ -32,9 +34,11 @@ pub struct LayoutData {
pub flags: LayoutDataFlags,
}

impl LayoutData {
impl LayoutDataTrait for LayoutData {}

impl Default for LayoutData {
/// Creates new layout data.
pub fn new() -> LayoutData {
fn default() -> LayoutData {
Self {
flow_construction_result: ConstructionResult::None,
before_flow_construction_result: ConstructionResult::None,
Expand Down
3 changes: 3 additions & 0 deletions components/layout_2020/element_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::cell::ArcRefCell;
use crate::flexbox::FlexLevelBox;
use crate::flow::inline::InlineLevelBox;
use crate::flow::BlockLevelBox;
use script_layout_interface::wrapper_traits::LayoutDataTrait;

#[derive(Default)]
pub struct LayoutDataForElement {
Expand All @@ -20,3 +21,5 @@ pub(super) enum LayoutBox {
InlineLevel(ArcRefCell<InlineLevelBox>),
FlexLevel(ArcRefCell<FlexLevelBox>),
}

impl LayoutDataTrait for LayoutDataForElement {}
40 changes: 20 additions & 20 deletions components/layout_thread/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#[macro_use]
extern crate crossbeam_channel;
#[macro_use]
extern crate html5ever;
#[macro_use]
extern crate layout;
#[macro_use]
extern crate lazy_static;
Expand All @@ -21,9 +19,6 @@ extern crate log;
#[macro_use]
extern crate profile_traits;

mod dom_wrapper;

use crate::dom_wrapper::{ServoLayoutDocument, ServoLayoutElement, ServoLayoutNode};
use app_units::Au;
use crossbeam_channel::{Receiver, Sender};
use embedder_traits::resources::{self, Resource};
Expand All @@ -47,7 +42,6 @@ use layout::display_list::{IndexableText, ToLayout};
use layout::flow::{Flow, FlowFlags, GetBaseFlow, ImmutableFlowUtils, MutableOwnedFlowUtils};
use layout::flow_ref::FlowRef;
use layout::incremental::{RelayoutMode, SpecialRestyleDamage};
use layout::layout_debug;
use layout::parallel;
use layout::query::{
process_client_rect_query, process_content_box_request, process_content_boxes_request,
Expand All @@ -62,6 +56,7 @@ use layout::traversal::{
RecalcStyleAndConstructFlows,
};
use layout::wrapper::LayoutNodeLayoutData;
use layout::{layout_debug, LayoutData};
use layout_traits::LayoutThreadFactory;
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory, ProgressiveWebMetric};
Expand All @@ -75,6 +70,7 @@ use parking_lot::RwLock;
use profile_traits::mem::{self as profile_mem, Report, ReportKind, ReportsChan};
use profile_traits::time::{self as profile_time, profile, TimerMetadata};
use profile_traits::time::{TimerMetadataFrameType, TimerMetadataReflowType};
use script::layout_dom::{ServoLayoutDocument, ServoLayoutElement, ServoLayoutNode};
use script_layout_interface::message::{LayoutThreadInit, Msg, NodesFromPointQueryType, Reflow};
use script_layout_interface::message::{QueryMsg, ReflowComplete, ReflowGoal, ScriptReflow};
use script_layout_interface::rpc::TextIndexResponse;
Expand Down Expand Up @@ -976,7 +972,7 @@ impl LayoutThread {
&self,
data: &Reflow,
reflow_goal: &ReflowGoal,
document: Option<&ServoLayoutDocument>,
document: Option<&ServoLayoutDocument<LayoutData>>,
layout_root: &mut dyn Flow,
layout_context: &mut LayoutContext,
rw_data: &mut LayoutThreadData,
Expand Down Expand Up @@ -1302,11 +1298,16 @@ impl LayoutThread {
let elements_with_snapshot: Vec<_> = restyles
.iter()
.filter(|r| r.1.snapshot.is_some())
.map(|r| unsafe { ServoLayoutNode::new(&r.0).as_element().unwrap() })
.map(|r| unsafe {
ServoLayoutNode::<LayoutData>::new(&r.0)
.as_element()
.unwrap()
})
.collect();

for (el, restyle) in restyles {
let el = unsafe { ServoLayoutNode::new(&el).as_element().unwrap() };
let el: ServoLayoutElement<LayoutData> =
unsafe { ServoLayoutNode::new(&el).as_element().unwrap() };

// If we haven't styled this node yet, we don't need to track a
// restyle.
Expand Down Expand Up @@ -1357,10 +1358,9 @@ impl LayoutThread {

let traversal = RecalcStyleAndConstructFlows::new(layout_context);
let token = {
let shared =
<RecalcStyleAndConstructFlows as DomTraversal<ServoLayoutElement>>::shared_context(
&traversal,
);
let shared = <RecalcStyleAndConstructFlows as DomTraversal<
ServoLayoutElement<LayoutData>,
>>::shared_context(&traversal);
RecalcStyleAndConstructFlows::pre_traverse(dirty_root, shared)
};

Expand All @@ -1373,7 +1373,7 @@ impl LayoutThread {
|| {
// Perform CSS selector matching and flow construction.
let root = driver::traverse_dom::<
ServoLayoutElement,
ServoLayoutElement<LayoutData>,
RecalcStyleAndConstructFlows,
>(&traversal, token, thread_pool);
unsafe {
Expand Down Expand Up @@ -1482,17 +1482,17 @@ impl LayoutThread {
process_node_scroll_area_request(node, root_flow);
},
&QueryMsg::NodeScrollIdQuery(node) => {
let node = unsafe { ServoLayoutNode::new(&node) };
let node: ServoLayoutNode<LayoutData> = unsafe { ServoLayoutNode::new(&node) };
rw_data.scroll_id_response =
Some(process_node_scroll_id_request(self.id, node));
},
&QueryMsg::ResolvedStyleQuery(node, ref pseudo, ref property) => {
let node = unsafe { ServoLayoutNode::new(&node) };
let node: ServoLayoutNode<LayoutData> = unsafe { ServoLayoutNode::new(&node) };
rw_data.resolved_style_response =
process_resolved_style_request(context, node, pseudo, property, root_flow);
},
&QueryMsg::ResolvedFontStyleQuery(node, ref property, ref value) => {
let node = unsafe { ServoLayoutNode::new(&node) };
let node: ServoLayoutNode<LayoutData> = unsafe { ServoLayoutNode::new(&node) };
let url = self.url.clone();
rw_data.resolved_font_style_response = process_resolved_font_style_request(
context,
Expand Down Expand Up @@ -1528,7 +1528,7 @@ impl LayoutThread {
results.iter().map(|result| result.node).collect()
},
&QueryMsg::ElementInnerTextQuery(node) => {
let node = unsafe { ServoLayoutNode::new(&node) };
let node: ServoLayoutNode<LayoutData> = unsafe { ServoLayoutNode::new(&node) };
rw_data.element_inner_text_response =
process_element_inner_text_query(node, &rw_data.indexable_text);
},
Expand Down Expand Up @@ -1633,7 +1633,7 @@ impl LayoutThread {
root_flow: &mut FlowRef,
data: &Reflow,
reflow_goal: &ReflowGoal,
document: Option<&ServoLayoutDocument>,
document: Option<&ServoLayoutDocument<LayoutData>>,
rw_data: &mut LayoutThreadData,
context: &mut LayoutContext,
) {
Expand Down Expand Up @@ -1742,7 +1742,7 @@ impl LayoutThread {
data: &Reflow,
mut root_flow: &mut FlowRef,
reflow_goal: &ReflowGoal,
document: Option<&ServoLayoutDocument>,
document: Option<&ServoLayoutDocument<LayoutData>>,
rw_data: &mut LayoutThreadData,
layout_context: &mut LayoutContext,
) {
Expand Down

0 comments on commit 232d1aa

Please sign in to comment.