Skip to content

Commit

Permalink
Auto merge of #25957 - pcwalton:layout-2020-atomic-refcell, r=<try>
Browse files Browse the repository at this point in the history
Start using `AtomicRefCell` in layout 2020 as preparation for incremental layout

This makes `BlockLevelBox` and `InlineLevelBox` use `AtomicRefCell` for incremental layout, per @nox's suggestion in #25168.

As part of this, it reworks inline layout to use recursion, per #25950. LLVM should be able to optimize this into a loop (though I have not verified this).

r? @nox
  • Loading branch information
bors-servo committed Mar 17, 2020
2 parents 9fb83d8 + 791ec10 commit cd7e3cd
Show file tree
Hide file tree
Showing 12 changed files with 316 additions and 176 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion components/layout_2020/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ doctest = false

[dependencies]
app_units = "0.7"
atomic_refcell = "0.1"
atomic_refcell = "0.1.6"
canvas_traits = {path = "../canvas_traits"}
cssparser = "0.27"
embedder_traits = {path = "../embedder_traits"}
Expand Down
69 changes: 69 additions & 0 deletions components/layout_2020/cell.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* 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 serde::{Serialize, Serializer};
use servo_arc::Arc;
use std::fmt;
use std::ops::Deref;

pub(crate) struct ArcRefCell<T> {
value: Arc<AtomicRefCell<T>>,
}

impl<T> ArcRefCell<T> {
pub fn new(value: T) -> Self {
Self {
value: Arc::new(AtomicRefCell::new(value)),
}
}
}

impl<T> Clone for ArcRefCell<T> {
fn clone(&self) -> Self {
Self {
value: self.value.clone(),
}
}
}

impl<T> Default for ArcRefCell<T>
where
T: Default,
{
fn default() -> Self {
Self {
value: Arc::new(AtomicRefCell::new(Default::default())),
}
}
}

impl<T> Deref for ArcRefCell<T> {
type Target = AtomicRefCell<T>;

fn deref(&self) -> &Self::Target {
&self.value
}
}

impl<T> fmt::Debug for ArcRefCell<T>
where
T: fmt::Debug,
{
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
self.value.fmt(formatter)
}
}

impl<T> Serialize for ArcRefCell<T>
where
T: Serialize,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.borrow().serialize(serializer)
}
}
7 changes: 4 additions & 3 deletions components/layout_2020/dom_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
* 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 crate::cell::ArcRefCell;
use crate::context::LayoutContext;
use crate::element_data::{LayoutBox, LayoutDataForElement};
use crate::geom::PhysicalSize;
use crate::replaced::{CanvasInfo, CanvasSource, ReplacedContent};
use crate::style_ext::{Display, DisplayGeneratingBox, DisplayInside, DisplayOutside};
use crate::wrapper::GetRawData;
use atomic_refcell::{AtomicRefCell, AtomicRefMut};
use atomic_refcell::AtomicRefMut;
use html5ever::LocalName;
use net_traits::image::base::Image as NetImage;
use script_layout_interface::wrapper_traits::{
Expand Down Expand Up @@ -317,12 +318,12 @@ where
}

pub struct BoxSlot<'dom> {
slot: Option<ServoArc<AtomicRefCell<Option<LayoutBox>>>>,
slot: Option<ArcRefCell<Option<LayoutBox>>>,
marker: marker<&'dom ()>,
}

impl BoxSlot<'_> {
pub(crate) fn new(slot: ServoArc<AtomicRefCell<Option<LayoutBox>>>) -> Self {
pub(crate) fn new(slot: ArcRefCell<Option<LayoutBox>>) -> Self {
*slot.borrow_mut() = None;
let slot = Some(slot);
Self { slot, marker }
Expand Down
13 changes: 6 additions & 7 deletions components/layout_2020/element_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@
* 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 crate::cell::ArcRefCell;
use crate::flow::inline::InlineLevelBox;
use crate::flow::BlockLevelBox;
use atomic_refcell::AtomicRefCell;
use servo_arc::Arc;

#[derive(Default)]
pub struct LayoutDataForElement {
pub(super) self_box: Arc<AtomicRefCell<Option<LayoutBox>>>,
pub(super) self_box: ArcRefCell<Option<LayoutBox>>,
pub(super) pseudo_elements: Option<Box<PseudoElementBoxes>>,
}

#[derive(Default)]
pub(super) struct PseudoElementBoxes {
pub before: Arc<AtomicRefCell<Option<LayoutBox>>>,
pub after: Arc<AtomicRefCell<Option<LayoutBox>>>,
pub before: ArcRefCell<Option<LayoutBox>>,
pub after: ArcRefCell<Option<LayoutBox>>,
}

pub(super) enum LayoutBox {
DisplayContents,
BlockLevel(Arc<BlockLevelBox>),
InlineLevel(Arc<InlineLevelBox>),
BlockLevel(ArcRefCell<BlockLevelBox>),
InlineLevel(ArcRefCell<InlineLevelBox>),
}
Loading

0 comments on commit cd7e3cd

Please sign in to comment.