layout: Cache content block size contributions (#33964)

This is the first part of caching intermediary layout during flexbox
layout. A later change will try to reuse these layouts, when possible,
for actual item layout and re-layout due to stretching.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2024-10-22 07:43:53 -07:00 committed by GitHub
parent 7015e0fb5f
commit 01c9ecfe01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 57 additions and 10 deletions

View file

@ -2,6 +2,7 @@
* 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 app_units::Au;
use geom::{FlexAxis, MainStartCrossStart};
use serde::Serialize;
use servo_arc::Arc as ServoArc;
@ -112,9 +113,17 @@ pub(crate) enum FlexLevelBox {
OutOfFlowAbsolutelyPositionedBox(ArcRefCell<AbsolutelyPositionedBox>),
}
#[derive(Debug, Serialize)]
#[derive(Serialize)]
pub(crate) struct FlexItemBox {
independent_formatting_context: IndependentFormattingContext,
#[serde(skip)]
cached_layout: ArcRefCell<Option<FlexItemLayoutCache>>,
}
impl std::fmt::Debug for FlexItemBox {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("FlexItemBox")
}
}
impl FlexItemBox {
@ -126,3 +135,20 @@ impl FlexItemBox {
self.independent_formatting_context.base_fragment_info()
}
}
#[derive(Debug)]
struct FlexItemLayoutCacheDescriptor {
containing_block_inline_size: Au,
content_block_size: Au,
}
impl FlexItemLayoutCacheDescriptor {
fn compatible_with_size(&self, inline: Au) -> bool {
inline == self.containing_block_inline_size
}
}
/// A cache to avoid multiple layouts during flexbox layout.
struct FlexItemLayoutCache {
descriptor: FlexItemLayoutCacheDescriptor,
}