Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start using `AtomicRefCell` in layout 2020 as preparation for incremental layout #25957

Merged
merged 8 commits into from Mar 18, 2020

Some generated files are not rendered by default. Learn more.

@@ -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"}
@@ -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)
}
}
@@ -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::{
@@ -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 }
@@ -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>),
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.