summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/constraints.rs8
-rw-r--r--src/layout/incremental.rs14
-rw-r--r--src/layout/mod.rs41
3 files changed, 30 insertions, 33 deletions
diff --git a/src/layout/constraints.rs b/src/layout/constraints.rs
index 0d772cea..3bdbc4bc 100644
--- a/src/layout/constraints.rs
+++ b/src/layout/constraints.rs
@@ -1,4 +1,4 @@
-use std::rc::Rc;
+use std::sync::Arc;
use super::Regions;
use crate::frame::Frame;
@@ -7,12 +7,12 @@ use crate::geom::{Length, Size, Spec};
/// Constrain a frame with constraints.
pub trait Constrain {
/// Reference-count the frame and wrap it with constraints.
- fn constrain(self, cts: Constraints) -> Constrained<Rc<Frame>>;
+ fn constrain(self, cts: Constraints) -> Constrained<Arc<Frame>>;
}
impl Constrain for Frame {
- fn constrain(self, cts: Constraints) -> Constrained<Rc<Frame>> {
- Constrained::new(Rc::new(self), cts)
+ fn constrain(self, cts: Constraints) -> Constrained<Arc<Frame>> {
+ Constrained::new(Arc::new(self), cts)
}
}
diff --git a/src/layout/incremental.rs b/src/layout/incremental.rs
index 63915b53..2112fef1 100644
--- a/src/layout/incremental.rs
+++ b/src/layout/incremental.rs
@@ -1,6 +1,6 @@
use std::cmp::Reverse;
use std::collections::HashMap;
-use std::rc::Rc;
+use std::sync::Arc;
use itertools::Itertools;
@@ -65,7 +65,7 @@ impl LayoutCache {
&mut self,
hash: u64,
regions: &Regions,
- ) -> Option<Vec<Constrained<Rc<Frame>>>> {
+ ) -> Option<Vec<Constrained<Arc<Frame>>>> {
self.frames
.get_mut(&hash)?
.iter_mut()
@@ -193,7 +193,7 @@ impl LayoutCache {
#[derive(Debug, Clone)]
pub struct FramesEntry {
/// The cached frames for a node.
- frames: Vec<Constrained<Rc<Frame>>>,
+ frames: Vec<Constrained<Arc<Frame>>>,
/// How nested the frame was in the context is was originally appearing in.
level: usize,
/// For how long the element already exists.
@@ -209,7 +209,7 @@ pub struct FramesEntry {
impl FramesEntry {
/// Construct a new instance.
- pub fn new(frames: Vec<Constrained<Rc<Frame>>>, level: usize) -> Self {
+ pub fn new(frames: Vec<Constrained<Arc<Frame>>>, level: usize) -> Self {
Self {
frames,
level,
@@ -222,7 +222,7 @@ impl FramesEntry {
/// Checks if the cached frames are valid in the given regions and returns
/// them if so.
- pub fn lookup(&mut self, regions: &Regions) -> Option<Vec<Constrained<Rc<Frame>>>> {
+ pub fn lookup(&mut self, regions: &Regions) -> Option<Vec<Constrained<Arc<Frame>>>> {
self.check(regions).then(|| {
self.temperature[0] = self.temperature[0].saturating_add(1);
self.frames.clone()
@@ -396,9 +396,9 @@ mod tests {
use crate::geom::{Size, Spec};
use crate::layout::Constraints;
- fn empty_frames() -> Vec<Constrained<Rc<Frame>>> {
+ fn empty_frames() -> Vec<Constrained<Arc<Frame>>> {
vec![Constrained {
- item: Rc::new(Frame::default()),
+ item: Arc::new(Frame::default()),
cts: Constraints::new(Spec::splat(false)),
}]
}
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index e4c29f9b..147e8c9d 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -13,7 +13,7 @@ pub use regions::*;
use std::any::Any;
use std::fmt::{self, Debug, Formatter};
use std::hash::{Hash, Hasher};
-use std::rc::Rc;
+use std::sync::Arc;
use crate::eval::{StyleChain, Styled};
use crate::font::FontStore;
@@ -29,7 +29,7 @@ pub struct RootNode(pub Vec<Styled<PageNode>>);
impl RootNode {
/// Layout the document into a sequence of frames, one per page.
- pub fn layout(&self, ctx: &mut Context) -> Vec<Rc<Frame>> {
+ pub fn layout(&self, ctx: &mut Context) -> Vec<Arc<Frame>> {
let (mut ctx, styles) = LayoutContext::new(ctx);
self.0
.iter()
@@ -56,17 +56,17 @@ pub trait Layout {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>>;
+ ) -> Vec<Constrained<Arc<Frame>>>;
/// Convert to a packed node.
fn pack(self) -> PackedNode
where
- Self: Debug + Hash + Sized + 'static,
+ Self: Debug + Hash + Sized + Sync + Send + 'static,
{
PackedNode {
#[cfg(feature = "layout-cache")]
hash: self.hash64(),
- node: Rc::new(self),
+ node: Arc::new(self),
}
}
}
@@ -112,7 +112,7 @@ impl Layout for EmptyNode {
_: &mut LayoutContext,
regions: &Regions,
_: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let size = regions.expand.select(regions.current, Size::zero());
let mut cts = Constraints::new(regions.expand);
cts.exact = regions.current.filter(regions.expand);
@@ -124,7 +124,7 @@ impl Layout for EmptyNode {
#[derive(Clone)]
pub struct PackedNode {
/// The type-erased node.
- node: Rc<dyn Bounds>,
+ node: Arc<dyn Bounds>,
/// A precomputed hash for the node.
#[cfg(feature = "layout-cache")]
hash: u64,
@@ -205,7 +205,7 @@ impl Layout for PackedNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let styles = styles.barred(self.node.as_any().type_id());
#[cfg(not(feature = "layout-cache"))]
@@ -243,10 +243,7 @@ impl Layout for PackedNode {
})
}
- fn pack(self) -> PackedNode
- where
- Self: Sized + Hash + 'static,
- {
+ fn pack(self) -> PackedNode {
self
}
}
@@ -266,8 +263,8 @@ impl Debug for PackedNode {
impl PartialEq for PackedNode {
fn eq(&self, other: &Self) -> bool {
std::ptr::eq(
- Rc::as_ptr(&self.node) as *const (),
- Rc::as_ptr(&other.node) as *const (),
+ Arc::as_ptr(&self.node) as *const (),
+ Arc::as_ptr(&other.node) as *const (),
)
}
}
@@ -282,14 +279,14 @@ impl Hash for PackedNode {
}
}
-trait Bounds: Layout + Debug + 'static {
+trait Bounds: Layout + Debug + Sync + Send + 'static {
fn as_any(&self) -> &dyn Any;
fn hash64(&self) -> u64;
}
impl<T> Bounds for T
where
- T: Layout + Hash + Debug + 'static,
+ T: Layout + Hash + Debug + Sync + Send + 'static,
{
fn as_any(&self) -> &dyn Any {
self
@@ -320,7 +317,7 @@ impl Layout for SizedNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let is_auto = self.sizing.map_is_none();
let is_rel = self.sizing.map(|s| s.map_or(false, Linear::is_relative));
@@ -346,7 +343,7 @@ impl Layout for SizedNode {
// Ensure frame size matches regions size if expansion is on.
let target = regions.expand.select(regions.current, frame.size);
- Rc::make_mut(frame).resize(target, Align::LEFT_TOP);
+ Arc::make_mut(frame).resize(target, Align::LEFT_TOP);
// Set base & exact constraints if the child is automatically sized
// since we don't know what the child might have done. Also set base if
@@ -374,11 +371,11 @@ impl Layout for FillNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let mut frames = self.child.layout(ctx, regions, styles);
for Constrained { item: frame, .. } in &mut frames {
let shape = Shape::filled(Geometry::Rect(frame.size), self.fill);
- Rc::make_mut(frame).prepend(Point::zero(), Element::Shape(shape));
+ Arc::make_mut(frame).prepend(Point::zero(), Element::Shape(shape));
}
frames
}
@@ -399,11 +396,11 @@ impl Layout for StrokeNode {
ctx: &mut LayoutContext,
regions: &Regions,
styles: StyleChain,
- ) -> Vec<Constrained<Rc<Frame>>> {
+ ) -> Vec<Constrained<Arc<Frame>>> {
let mut frames = self.child.layout(ctx, regions, styles);
for Constrained { item: frame, .. } in &mut frames {
let shape = Shape::stroked(Geometry::Rect(frame.size), self.stroke);
- Rc::make_mut(frame).prepend(Point::zero(), Element::Shape(shape));
+ Arc::make_mut(frame).prepend(Point::zero(), Element::Shape(shape));
}
frames
}