mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
There were two kinds of layout tracing controlled by the same debugging option: - modern layout: Functionality that dumped a JSON serialization of the layout tree before and after layout. - legacy layout: A scope based tracing that reported the process of layout in a structured way. I don't think anyone working on layout is using either of these two features. For modern layout requiring data structure to implement `serde` serialization is incredibly inconvenient and also generates a lot of extra code. We also have a more modern tracing functionality based on perfetto that we have started to use for layout and IMO it's actually being used and more robust. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
60 lines
2.3 KiB
Rust
60 lines
2.3 KiB
Rust
/* 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 atomic_refcell::AtomicRefCell;
|
|
use servo_arc::Arc;
|
|
use style::properties::ComputedValues;
|
|
|
|
use crate::context::LayoutContext;
|
|
use crate::fragment_tree::BaseFragmentInfo;
|
|
use crate::geom::SizeConstraint;
|
|
use crate::sizing::{ComputeInlineContentSizes, InlineContentSizesResult};
|
|
use crate::ConstraintSpace;
|
|
|
|
/// A box tree node that handles containing information about style and the original DOM
|
|
/// node or pseudo-element that it is based on. This also handles caching of layout values
|
|
/// such as the inline content sizes to avoid recalculating these values during layout
|
|
/// passes.
|
|
///
|
|
/// In the future, this will hold layout results to support incremental layout.
|
|
#[derive(Debug)]
|
|
pub(crate) struct LayoutBoxBase {
|
|
pub base_fragment_info: BaseFragmentInfo,
|
|
pub style: Arc<ComputedValues>,
|
|
pub cached_inline_content_size:
|
|
AtomicRefCell<Option<(SizeConstraint, InlineContentSizesResult)>>,
|
|
}
|
|
|
|
impl LayoutBoxBase {
|
|
pub(crate) fn new(base_fragment_info: BaseFragmentInfo, style: Arc<ComputedValues>) -> Self {
|
|
Self {
|
|
base_fragment_info,
|
|
style,
|
|
cached_inline_content_size: AtomicRefCell::default(),
|
|
}
|
|
}
|
|
|
|
/// Get the inline content sizes of a box tree node that extends this [`LayoutBoxBase`], fetch
|
|
/// the result from a cache when possible.
|
|
pub(crate) fn inline_content_sizes(
|
|
&self,
|
|
layout_context: &LayoutContext,
|
|
constraint_space: &ConstraintSpace,
|
|
layout_box: &impl ComputeInlineContentSizes,
|
|
) -> InlineContentSizesResult {
|
|
let mut cache = self.cached_inline_content_size.borrow_mut();
|
|
if let Some((previous_cb_block_size, result)) = *cache {
|
|
if !result.depends_on_block_constraints ||
|
|
previous_cb_block_size == constraint_space.block_size
|
|
{
|
|
return result;
|
|
}
|
|
// TODO: Should we keep multiple caches for various block sizes?
|
|
}
|
|
|
|
let result = layout_box.compute_inline_content_sizes(layout_context, constraint_space);
|
|
*cache = Some((constraint_space.block_size, result));
|
|
result
|
|
}
|
|
}
|