aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/layout/construct.rs
diff options
context:
space:
mode:
authorGlenn Watson <gw@intuitionlibrary.com>2014-08-08 13:53:37 +1000
committerGlenn Watson <gw@intuitionlibrary.com>2014-08-11 12:10:28 +1000
commit4a0e01b4f033940b5d31ad1a47e322b2769ef1a5 (patch)
tree1e286508e0d54e3aad2e1155d39a252e783b8d77 /src/components/layout/construct.rs
parent4062af69ec562c8a3f781a2918bc4134a809b391 (diff)
downloadservo-4a0e01b4f033940b5d31ad1a47e322b2769ef1a5.tar.gz
servo-4a0e01b4f033940b5d31ad1a47e322b2769ef1a5.zip
Refactor how LayoutContext structure works (reduce TLS lookups + simplify fns used by seq/parallel code paths).
- LayoutContext is renamed to SharedLayoutContext. - SharedLayoutContext is immutable. - LayoutContext is a wrapper around SharedLayoutContext + access to local caches (font, style etc). - Creating a LayoutContext does a single local_data lookup to fetch the cache information. - Android shares same implementation of context.rs as other platforms. - LayoutContext can be used from both green thread (parallel layout) and native thread (sequential layout). - Removes the need for other types (such as FontContext, StyleSharingCandidateCache etc) to be passed around.
Diffstat (limited to 'src/components/layout/construct.rs')
-rw-r--r--src/components/layout/construct.rs52
1 files changed, 12 insertions, 40 deletions
diff --git a/src/components/layout/construct.rs b/src/components/layout/construct.rs
index a780c073f17..db6084a1c02 100644
--- a/src/components/layout/construct.rs
+++ b/src/components/layout/construct.rs
@@ -47,7 +47,6 @@ use wrapper::{PostorderNodeMutTraversal, TLayoutNode, ThreadSafeLayoutNode};
use wrapper::{Before, BeforeBlock, After, AfterBlock, Normal};
use gfx::display_list::OpaqueNode;
-use gfx::font_context::FontContext;
use script::dom::element::{HTMLIFrameElementTypeId, HTMLImageElementTypeId};
use script::dom::element::{HTMLObjectElementTypeId};
use script::dom::element::{HTMLTableColElementTypeId, HTMLTableDataCellElementTypeId};
@@ -184,47 +183,20 @@ enum WhitespaceStrippingMode {
}
/// An object that knows how to create flows.
-pub struct FlowConstructor<'a> {
+pub struct FlowConstructor<'a, 'b> {
/// The layout context.
- pub layout_context: &'a mut LayoutContext,
-
- /// An optional font context. If this is `None`, then we fetch the font context from the
- /// layout context.
- ///
- /// FIXME(pcwalton): This is pretty bogus and is basically just a workaround for libgreen
- /// having slow TLS.
- pub font_context: Option<Box<FontContext>>,
+ pub layout_context: &'b LayoutContext<'b>,
}
-impl<'a> FlowConstructor<'a> {
+impl<'a, 'b> FlowConstructor<'a, 'b> {
/// Creates a new flow constructor.
- pub fn new(layout_context: &'a mut LayoutContext, font_context: Option<Box<FontContext>>)
- -> FlowConstructor<'a> {
+ pub fn new<'b>(layout_context: &'b LayoutContext)
+ -> FlowConstructor<'a, 'b> {
FlowConstructor {
layout_context: layout_context,
- font_context: font_context,
}
}
- fn font_context<'a>(&'a mut self) -> &'a mut FontContext {
- match self.font_context {
- Some(ref mut font_context) => {
- let font_context: &mut FontContext = &mut **font_context;
- font_context
- }
- None => self.layout_context.font_context(),
- }
- }
-
- /// Destroys this flow constructor and retrieves the font context.
- pub fn unwrap_font_context(self) -> Option<Box<FontContext>> {
- let FlowConstructor {
- font_context,
- ..
- } = self;
- font_context
- }
-
/// Builds the `ImageFragmentInfo` for the given image. This is out of line to guide inlining.
fn build_fragment_info_for_image(&mut self, node: &ThreadSafeLayoutNode, url: Option<Url>)
-> SpecificFragmentInfo {
@@ -233,7 +205,7 @@ impl<'a> FlowConstructor<'a> {
Some(url) => {
// FIXME(pcwalton): The fact that image fragments store the cache within them makes
// little sense to me.
- ImageFragment(ImageFragmentInfo::new(node, url, self.layout_context.image_cache.clone()))
+ ImageFragment(ImageFragmentInfo::new(node, url, self.layout_context.shared.image_cache.clone()))
}
}
}
@@ -293,11 +265,11 @@ impl<'a> FlowConstructor<'a> {
}
let mut inline_flow = box InlineFlow::from_fragments((*node).clone(), fragments);
- let (ascent, descent) = inline_flow.compute_minimum_ascent_and_descent(self.font_context(), &**node.style());
+ let (ascent, descent) = inline_flow.compute_minimum_ascent_and_descent(self.layout_context.font_context(), &**node.style());
inline_flow.minimum_block_size_above_baseline = ascent;
inline_flow.minimum_depth_below_baseline = descent;
let mut inline_flow = inline_flow as Box<Flow>;
- TextRunScanner::new().scan_for_runs(self.font_context(), inline_flow);
+ TextRunScanner::new().scan_for_runs(self.layout_context.font_context(), inline_flow);
let mut inline_flow = FlowRef::new(inline_flow);
inline_flow.finish(self.layout_context);
@@ -797,7 +769,7 @@ impl<'a> FlowConstructor<'a> {
}
}
-impl<'a> PostorderNodeMutTraversal for FlowConstructor<'a> {
+impl<'a, 'b> PostorderNodeMutTraversal for FlowConstructor<'a, 'b> {
// Construct Flow based on 'display', 'position', and 'float' values.
//
// CSS 2.1 Section 9.7
@@ -1039,7 +1011,7 @@ pub trait FlowConstructionUtils {
///
/// All flows must be finished at some point, or they will not have their intrinsic inline-sizes
/// properly computed. (This is not, however, a memory safety problem.)
- fn finish(&mut self, context: &mut LayoutContext);
+ fn finish(&mut self, context: &LayoutContext);
}
impl FlowConstructionUtils for FlowRef {
@@ -1066,8 +1038,8 @@ impl FlowConstructionUtils for FlowRef {
/// properly computed. (This is not, however, a memory safety problem.)
///
/// This must not be public because only the layout constructor can do this.
- fn finish(&mut self, context: &mut LayoutContext) {
- if !context.opts.bubble_inline_sizes_separately {
+ fn finish(&mut self, context: &LayoutContext) {
+ if !context.shared.opts.bubble_inline_sizes_separately {
self.get_mut().bubble_inline_sizes(context)
}
}