servo: Merge #19931 - Use LayoutRects for bounds and overflow in display lists (from pyfisch:float-bounds); r=mrobinson
authorPyfisch <pyfisch@gmail.com>
Wed, 07 Feb 2018 07:11:41 -0500
changeset 402779 634e741ea109bdb4b8e37980962335662de32106
parent 402778 210eba4219fabcc3db899e09b4940fe01d3e3fb5
child 402780 fa845d221e7a5847067714ac5ecea11ba893e057
push id99659
push useraciure@mozilla.com
push dateWed, 07 Feb 2018 22:33:57 +0000
treeherdermozilla-inbound@5ceb1098fef3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrobinson
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #19931 - Use LayoutRects for bounds and overflow in display lists (from pyfisch:float-bounds); r=mrobinson Convert text runs to glyphs in display list builder. Remove ComplexClippingRegion and use the WebRender type. Source-Repo: https://github.com/servo/servo Source-Revision: 03a1a014ae3f7feeb91246343c487962d061d9fb
servo/components/gfx/display_list/mod.rs
servo/components/gfx/text/text_run.rs
servo/components/layout/display_list/builder.rs
servo/components/layout/display_list/webrender_helpers.rs
servo/components/layout_thread/lib.rs
servo/components/malloc_size_of/lib.rs
--- a/servo/components/gfx/display_list/mod.rs
+++ b/servo/components/gfx/display_list/mod.rs
@@ -9,38 +9,38 @@
 //! Finally, display lists allow tiles to be farmed out onto multiple CPUs and painted in parallel
 //! (although this benefit does not apply to GPU-based painting).
 //!
 //! Display items describe relatively high-level drawing operations (for example, entire borders
 //! and shadows instead of lines and blur operations), to reduce the amount of allocation required.
 //! They are therefore not exactly analogous to constructs like Skia pictures, which consist of
 //! low-level drawing primitives.
 
-use app_units::Au;
-use euclid::{Transform3D, Point2D, Vector2D, Rect, Size2D, TypedRect, SideOffsets2D};
+use euclid::{Transform3D, Vector2D, TypedRect, SideOffsets2D};
 use euclid::num::{One, Zero};
 use gfx_traits::{self, StackingContextId};
 use gfx_traits::print_tree::PrintTree;
 use ipc_channel::ipc::IpcSharedMemory;
 use msg::constellation_msg::PipelineId;
 use net_traits::image::base::{Image, PixelFormat};
 use range::Range;
 use servo_geometry::MaxRect;
-use std::cmp::{self, Ordering};
+use std::cmp::Ordering;
 use std::collections::HashMap;
 use std::f32;
 use std::fmt;
 use std::sync::Arc;
 use text::TextRun;
 use text::glyph::ByteIndex;
-use webrender_api::{BorderRadius, BorderWidths, BoxShadowClipMode, ColorF, ExtendMode};
-use webrender_api::{ExternalScrollId, FilterOp, GradientStop, ImageBorder, ImageKey};
-use webrender_api::{ImageRendering, LayoutPoint, LayoutRect, LayoutSize, LayoutVector2D};
-use webrender_api::{LineStyle, LocalClip, MixBlendMode, NormalBorder, ScrollPolicy};
-use webrender_api::{ScrollSensitivity, StickyOffsetBounds, TransformStyle};
+use webrender_api::{BorderRadius, BorderWidths, BoxShadowClipMode, ClipMode, ColorF};
+use webrender_api::{ComplexClipRegion, ExtendMode, ExternalScrollId, FilterOp, FontInstanceKey};
+use webrender_api::{GlyphInstance, GradientStop, ImageBorder, ImageKey, ImageRendering};
+use webrender_api::{LayoutPoint, LayoutRect, LayoutSize, LayoutVector2D, LineStyle, LocalClip};
+use webrender_api::{MixBlendMode, NormalBorder, ScrollPolicy, ScrollSensitivity};
+use webrender_api::{StickyOffsetBounds, TransformStyle};
 
 pub use style::dom::OpaqueNode;
 
 /// The factor that we multiply the blur radius by in order to inflate the boundaries of display
 /// items that involve a blur. This ensures that the display item boundaries include all the ink.
 pub static BLUR_INFLATION_FACTOR: i32 = 3;
 
 /// An index into the vector of ClipScrollNodes. During WebRender conversion these nodes
@@ -91,32 +91,32 @@ impl ClippingAndScrolling {
 pub struct DisplayList {
     pub list: Vec<DisplayItem>,
     pub clip_scroll_nodes: Vec<ClipScrollNode>,
 }
 
 impl DisplayList {
     /// Return the bounds of this display list based on the dimensions of the root
     /// stacking context.
-    pub fn bounds(&self) -> Rect<Au> {
+    pub fn bounds(&self) -> LayoutRect {
         match self.list.get(0) {
             Some(&DisplayItem::PushStackingContext(ref item)) => item.stacking_context.bounds,
             Some(_) => unreachable!("Root element of display list not stacking context."),
-            None => Rect::zero(),
+            None => LayoutRect::zero(),
         }
     }
 
     // Returns the text index within a node for the point of interest.
-    pub fn text_index(&self, node: OpaqueNode, point_in_item: &Point2D<Au>) -> Option<usize> {
+    pub fn text_index(&self, node: OpaqueNode, point_in_item: LayoutPoint) -> Option<usize> {
         for item in &self.list {
             match item {
                 &DisplayItem::Text(ref text) => {
                     let base = item.base();
                     if base.metadata.node == node {
-                        let point = *point_in_item + item.base().bounds.origin.to_vector();
+                        let point = point_in_item + item.base().bounds.origin.to_vector();
                         let offset = point - text.baseline_origin;
                         return Some(text.text_run.range_index_of_advance(&text.range, offset.x));
                     }
                 },
                 _ => {},
             }
         }
 
@@ -189,20 +189,20 @@ pub enum StackingContextType {
 pub struct StackingContext {
     /// The ID of this StackingContext for uniquely identifying it.
     pub id: StackingContextId,
 
     /// The type of this StackingContext. Used for collecting and sorting.
     pub context_type: StackingContextType,
 
     /// The position and size of this stacking context.
-    pub bounds: Rect<Au>,
+    pub bounds: LayoutRect,
 
     /// The overflow rect for this stacking context in its coordinate system.
-    pub overflow: Rect<Au>,
+    pub overflow: LayoutRect,
 
     /// The `z-index` for this stacking context.
     pub z_index: i32,
 
     /// CSS filters to be applied to this stacking context (including opacity).
     pub filters: Vec<FilterOp>,
 
     /// The blend mode with which this stacking context blends with its backdrop.
@@ -224,50 +224,50 @@ pub struct StackingContext {
     pub parent_clipping_and_scrolling: ClippingAndScrolling,
 }
 
 impl StackingContext {
     /// Creates a new stacking context.
     #[inline]
     pub fn new(id: StackingContextId,
                context_type: StackingContextType,
-               bounds: &Rect<Au>,
-               overflow: &Rect<Au>,
+               bounds: LayoutRect,
+               overflow: LayoutRect,
                z_index: i32,
                filters: Vec<FilterOp>,
                mix_blend_mode: MixBlendMode,
                transform: Option<Transform3D<f32>>,
                transform_style: TransformStyle,
                perspective: Option<Transform3D<f32>>,
                scroll_policy: ScrollPolicy,
                parent_clipping_and_scrolling: ClippingAndScrolling)
                -> StackingContext {
         StackingContext {
             id,
             context_type,
-            bounds: *bounds,
-            overflow: *overflow,
+            bounds,
+            overflow,
             z_index,
             filters,
             mix_blend_mode,
             transform,
             transform_style,
             perspective,
             scroll_policy,
             parent_clipping_and_scrolling,
         }
     }
 
     #[inline]
     pub fn root() -> StackingContext {
         StackingContext::new(
             StackingContextId::root(),
             StackingContextType::Real,
-            &Rect::zero(),
-            &Rect::zero(),
+            LayoutRect::zero(),
+            LayoutRect::zero(),
             0,
             vec![],
             MixBlendMode::Normal,
             None,
             TransformStyle::Flat,
             None,
             ScrollPolicy::Scrollable,
             ClippingAndScrolling::simple(ClipScrollNodeIndex(0))
@@ -389,17 +389,17 @@ pub enum DisplayItem {
     PopStackingContext(Box<PopStackingContextItem>),
     DefineClipScrollNode(Box<DefineClipScrollNodeItem>),
 }
 
 /// Information common to all display items.
 #[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
 pub struct BaseDisplayItem {
     /// The boundaries of the display item, in layer coordinates.
-    pub bounds: Rect<Au>,
+    pub bounds: LayoutRect,
 
     /// Metadata attached to this display item.
     pub metadata: DisplayItemMetadata,
 
     /// The local clip for this item.
     pub local_clip: LocalClip,
 
     /// The section of the display list that this item belongs to.
@@ -409,17 +409,17 @@ pub struct BaseDisplayItem {
     pub stacking_context_id: StackingContextId,
 
     /// The clip and scroll info for this item.
     pub clipping_and_scrolling: ClippingAndScrolling,
 }
 
 impl BaseDisplayItem {
     #[inline(always)]
-    pub fn new(bounds: Rect<Au>,
+    pub fn new(bounds: LayoutRect,
                metadata: DisplayItemMetadata,
                local_clip: LocalClip,
                section: DisplayListSection,
                stacking_context_id: StackingContextId,
                clipping_and_scrolling: ClippingAndScrolling)
                -> BaseDisplayItem {
         BaseDisplayItem {
             bounds,
@@ -449,120 +449,110 @@ impl BaseDisplayItem {
 }
 
 /// A clipping region for a display item. Currently, this can describe rectangles, rounded
 /// rectangles (for `border-radius`), or arbitrary intersections of the two. Arbitrary transforms
 /// are not supported because those are handled by the higher-level `StackingContext` abstraction.
 #[derive(Clone, Deserialize, MallocSizeOf, PartialEq, Serialize)]
 pub struct ClippingRegion {
     /// The main rectangular region. This does not include any corners.
-    pub main: Rect<Au>,
+    pub main: LayoutRect,
     /// Any complex regions.
     ///
     /// TODO(pcwalton): Atomically reference count these? Not sure if it's worth the trouble.
     /// Measure and follow up.
-    pub complex: Vec<ComplexClippingRegion>,
-}
-
-/// A complex clipping region. These don't as easily admit arbitrary intersection operations, so
-/// they're stored in a list over to the side. Currently a complex clipping region is just a
-/// rounded rectangle, but the CSS WGs will probably make us throw more stuff in here eventually.
-#[derive(Clone, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
-pub struct ComplexClippingRegion {
-    /// The boundaries of the rectangle.
-    pub rect: Rect<Au>,
-    /// Border radii of this rectangle.
-    pub radii: BorderRadii<Au>,
+    pub complex: Vec<ComplexClipRegion>,
 }
 
 impl ClippingRegion {
     /// Returns an empty clipping region that, if set, will result in no pixels being visible.
     #[inline]
     pub fn empty() -> ClippingRegion {
         ClippingRegion {
-            main: Rect::zero(),
+            main: LayoutRect::zero(),
             complex: Vec::new(),
         }
     }
 
     /// Returns an all-encompassing clipping region that clips no pixels out.
     #[inline]
     pub fn max() -> ClippingRegion {
         ClippingRegion {
-            main: Rect::max_rect(),
+            main: LayoutRect::max_rect(),
             complex: Vec::new(),
         }
     }
 
     /// Returns a clipping region that represents the given rectangle.
     #[inline]
-    pub fn from_rect(rect: &Rect<Au>) -> ClippingRegion {
+    pub fn from_rect(rect: LayoutRect) -> ClippingRegion {
         ClippingRegion {
-            main: *rect,
+            main: rect,
             complex: Vec::new(),
         }
     }
 
     /// Mutates this clipping region to intersect with the given rectangle.
     ///
     /// TODO(pcwalton): This could more eagerly eliminate complex clipping regions, at the cost of
     /// complexity.
     #[inline]
-    pub fn intersect_rect(&mut self, rect: &Rect<Au>) {
-        self.main = self.main.intersection(rect).unwrap_or(Rect::zero())
+    pub fn intersect_rect(&mut self, rect: &LayoutRect) {
+        self.main = self.main.intersection(rect).unwrap_or(LayoutRect::zero())
     }
 
     /// Returns true if this clipping region might be nonempty. This can return false positives,
     /// but never false negatives.
     #[inline]
     pub fn might_be_nonempty(&self) -> bool {
         !self.main.is_empty()
     }
 
     /// Returns true if this clipping region might contain the given point and false otherwise.
     /// This is a quick, not a precise, test; it can yield false positives.
     #[inline]
-    pub fn might_intersect_point(&self, point: &Point2D<Au>) -> bool {
+    pub fn might_intersect_point(&self, point: &LayoutPoint) -> bool {
         self.main.contains(point) &&
             self.complex.iter().all(|complex| complex.rect.contains(point))
     }
 
     /// Returns true if this clipping region might intersect the given rectangle and false
     /// otherwise. This is a quick, not a precise, test; it can yield false positives.
     #[inline]
-    pub fn might_intersect_rect(&self, rect: &Rect<Au>) -> bool {
+    pub fn might_intersect_rect(&self, rect: &LayoutRect) -> bool {
         self.main.intersects(rect) &&
             self.complex.iter().all(|complex| complex.rect.intersects(rect))
     }
 
     /// Returns true if this clipping region completely surrounds the given rect.
     #[inline]
-    pub fn does_not_clip_rect(&self, rect: &Rect<Au>) -> bool {
+    pub fn does_not_clip_rect(&self, rect: &LayoutRect) -> bool {
         self.main.contains(&rect.origin) && self.main.contains(&rect.bottom_right()) &&
             self.complex.iter().all(|complex| {
                 complex.rect.contains(&rect.origin) && complex.rect.contains(&rect.bottom_right())
             })
     }
 
     /// Returns a bounding rect that surrounds this entire clipping region.
     #[inline]
-    pub fn bounding_rect(&self) -> Rect<Au> {
+    pub fn bounding_rect(&self) -> LayoutRect {
         let mut rect = self.main;
         for complex in &*self.complex {
             rect = rect.union(&complex.rect)
         }
         rect
     }
 
     /// Intersects this clipping region with the given rounded rectangle.
     #[inline]
-    pub fn intersect_with_rounded_rect(&mut self, rect: &Rect<Au>, radii: &BorderRadii<Au>) {
-        let new_complex_region = ComplexClippingRegion {
-            rect: *rect,
-            radii: *radii,
+    pub fn intersect_with_rounded_rect(&mut self, rect: LayoutRect, radii: BorderRadius) {
+        let new_complex_region = ComplexClipRegion {
+            rect,
+            radii,
+            mode: ClipMode::Clip,
         };
 
         // FIXME(pcwalton): This is O(n²) worst case for disjoint clipping regions. Is that OK?
         // They're slow anyway…
         //
         // Possibly relevant if we want to do better:
         //
         //     http://www.inrg.csie.ntu.edu.tw/algorithm2014/presentation/D&C%20Lee-84.pdf
@@ -571,67 +561,69 @@ impl ClippingRegion {
                 *existing_complex_region = new_complex_region;
                 return
             }
             if new_complex_region.completely_encloses(existing_complex_region) {
                 return
             }
         }
 
-        self.complex.push(ComplexClippingRegion {
-            rect: *rect,
-            radii: *radii,
-        });
+        self.complex.push(new_complex_region);
     }
 
     /// Translates this clipping region by the given vector.
     #[inline]
-    pub fn translate(&self, delta: &Vector2D<Au>) -> ClippingRegion {
+    pub fn translate(&self, delta: &LayoutVector2D) -> ClippingRegion {
         ClippingRegion {
             main: self.main.translate(delta),
             complex: self.complex.iter().map(|complex| {
-                ComplexClippingRegion {
+                ComplexClipRegion {
                     rect: complex.rect.translate(delta),
                     radii: complex.radii,
+                    mode: complex.mode,
                 }
             }).collect(),
         }
     }
 
     #[inline]
     pub fn is_max(&self) -> bool {
-        self.main == Rect::max_rect() && self.complex.is_empty()
+        self.main == LayoutRect::max_rect() && self.complex.is_empty()
     }
 }
 
 impl fmt::Debug for ClippingRegion {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         if *self == ClippingRegion::max() {
             write!(f, "ClippingRegion::Max")
         } else if *self == ClippingRegion::empty() {
             write!(f, "ClippingRegion::Empty")
-        } else if self.main == Rect::max_rect() {
+        } else if self.main == LayoutRect::max_rect() {
             write!(f, "ClippingRegion(Complex={:?})", self.complex)
         } else {
             write!(f, "ClippingRegion(Rect={:?}, Complex={:?})", self.main, self.complex)
         }
     }
 }
 
-impl ComplexClippingRegion {
+pub trait CompletelyEncloses {
+    fn completely_encloses(&self, other: &Self) -> bool;
+}
+
+impl CompletelyEncloses for ComplexClipRegion {
     // TODO(pcwalton): This could be more aggressive by considering points that touch the inside of
     // the border radius ellipse.
-    fn completely_encloses(&self, other: &ComplexClippingRegion) -> bool {
-        let left = cmp::max(self.radii.top_left.width, self.radii.bottom_left.width);
-        let top = cmp::max(self.radii.top_left.height, self.radii.top_right.height);
-        let right = cmp::max(self.radii.top_right.width, self.radii.bottom_right.width);
-        let bottom = cmp::max(self.radii.bottom_left.height, self.radii.bottom_right.height);
-        let interior = Rect::new(Point2D::new(self.rect.origin.x + left, self.rect.origin.y + top),
-                                 Size2D::new(self.rect.size.width - left - right,
-                                             self.rect.size.height - top - bottom));
+    fn completely_encloses(&self, other: &Self) -> bool {
+        let left = self.radii.top_left.width.max(self.radii.bottom_left.width);
+        let top = self.radii.top_left.height.max(self.radii.top_right.height);
+        let right = self.radii.top_right.width.max(self.radii.bottom_right.width);
+        let bottom = self.radii.bottom_left.height.max(self.radii.bottom_right.height);
+        let interior = LayoutRect::new(LayoutPoint::new(self.rect.origin.x + left, self.rect.origin.y + top),
+                                       LayoutSize::new(self.rect.size.width - left - right,
+                                                       self.rect.size.height - top - bottom));
         interior.origin.x <= other.rect.origin.x && interior.origin.y <= other.rect.origin.y &&
             interior.max_x() >= other.rect.max_x() && interior.max_y() >= other.rect.max_y()
     }
 }
 
 /// Metadata attached to each display item. This is useful for performing auxiliary threads with
 /// the display list involving hit testing: finding the originating DOM node and determining the
 /// cursor to use when the element is hovered over.
@@ -662,24 +654,24 @@ pub struct TextDisplayItem {
 
     /// The text run.
     #[ignore_malloc_size_of = "Because it is non-owning"]
     pub text_run: Arc<TextRun>,
 
     /// The range of text within the text run.
     pub range: Range<ByteIndex>,
 
+    /// The position of the start of the baseline of this text.
+    pub baseline_origin: LayoutPoint,
+    /// A collection of (non-whitespace) glyphs to be displayed.
+    pub glyphs: Vec<GlyphInstance>,
+    /// Reference to the font to be used.
+    pub font_key: FontInstanceKey,
     /// The color of the text.
     pub text_color: ColorF,
-
-    /// The position of the start of the baseline of this text.
-    pub baseline_origin: Point2D<Au>,
-
-    /// The orientation of the text: upright or sideways left/right.
-    pub orientation: TextOrientation,
 }
 
 #[derive(Clone, Deserialize, Eq, MallocSizeOf, PartialEq, Serialize)]
 pub enum TextOrientation {
     Upright,
     SidewaysLeft,
     SidewaysRight,
 }
@@ -821,78 +813,16 @@ pub struct BorderDisplayItem {
 
     /// Border widths.
     pub border_widths: BorderWidths,
 
     /// Details for specific border type
     pub details: BorderDetails,
 }
 
-/// Information about the border radii.
-#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
-pub struct BorderRadii<T> {
-    pub top_left: Size2D<T>,
-    pub top_right: Size2D<T>,
-    pub bottom_right: Size2D<T>,
-    pub bottom_left: Size2D<T>,
-}
-
-impl<T> Default for BorderRadii<T> where T: Default, T: Clone {
-    fn default() -> Self {
-        let top_left = Size2D::new(Default::default(),
-                                   Default::default());
-        let top_right = Size2D::new(Default::default(),
-                                    Default::default());
-        let bottom_left = Size2D::new(Default::default(),
-                                      Default::default());
-        let bottom_right = Size2D::new(Default::default(),
-                                       Default::default());
-        BorderRadii { top_left: top_left,
-                      top_right: top_right,
-                      bottom_left: bottom_left,
-                      bottom_right: bottom_right }
-    }
-}
-
-impl BorderRadii<Au> {
-    // Scale the border radii by the specified factor
-    pub fn scale_by(&self, s: f32) -> BorderRadii<Au> {
-        BorderRadii { top_left: BorderRadii::scale_corner_by(self.top_left, s),
-                      top_right: BorderRadii::scale_corner_by(self.top_right, s),
-                      bottom_left: BorderRadii::scale_corner_by(self.bottom_left, s),
-                      bottom_right: BorderRadii::scale_corner_by(self.bottom_right, s) }
-    }
-
-    // Scale the border corner radius by the specified factor
-    pub fn scale_corner_by(corner: Size2D<Au>, s: f32) -> Size2D<Au> {
-        Size2D::new(corner.width.scale_by(s), corner.height.scale_by(s))
-    }
-}
-
-impl<T> BorderRadii<T> where T: PartialEq + Zero {
-    /// Returns true if all the radii are zero.
-    pub fn is_square(&self) -> bool {
-        let zero = Zero::zero();
-        self.top_left == zero && self.top_right == zero && self.bottom_right == zero &&
-            self.bottom_left == zero
-    }
-}
-
-impl<T> BorderRadii<T> where T: PartialEq + Zero + Clone {
-    /// Returns a set of border radii that all have the given value.
-    pub fn all_same(value: T) -> BorderRadii<T> {
-        BorderRadii {
-            top_left: Size2D::new(value.clone(), value.clone()),
-            top_right: Size2D::new(value.clone(), value.clone()),
-            bottom_right: Size2D::new(value.clone(), value.clone()),
-            bottom_left: Size2D::new(value.clone(), value.clone()),
-        }
-    }
-}
-
 /// Paints a line segment.
 #[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
 pub struct LineDisplayItem {
     pub base: BaseDisplayItem,
 
     /// The line segment color.
     pub color: ColorF,
 
@@ -1010,17 +940,17 @@ impl DisplayItem {
     pub fn stacking_context_id(&self) -> StackingContextId {
         self.base().stacking_context_id
     }
 
     pub fn section(&self) -> DisplayListSection {
         self.base().section
     }
 
-    pub fn bounds(&self) -> Rect<Au> {
+    pub fn bounds(&self) -> LayoutRect {
         self.base().bounds
     }
 
     pub fn debug_with_level(&self, level: u32) {
         let mut indent = String::new();
         for _ in 0..level {
             indent.push_str("| ")
         }
@@ -1045,21 +975,17 @@ impl fmt::Debug for DisplayItem {
         write!(f, "{} @ {:?} {:?}",
             match *self {
                 DisplayItem::SolidColor(ref solid_color) =>
                     format!("SolidColor rgba({}, {}, {}, {})",
                             solid_color.color.r,
                             solid_color.color.g,
                             solid_color.color.b,
                             solid_color.color.a),
-                DisplayItem::Text(ref text) => {
-                    format!("Text ({:?})",
-                            &text.text_run.text[
-                                text.range.begin().0 as usize..(text.range.begin().0 + text.range.length().0) as usize])
-                }
+                DisplayItem::Text(_) => "Text".to_owned(),
                 DisplayItem::Image(_) => "Image".to_owned(),
                 DisplayItem::Border(_) => "Border".to_owned(),
                 DisplayItem::Gradient(_) => "Gradient".to_owned(),
                 DisplayItem::RadialGradient(_) => "RadialGradient".to_owned(),
                 DisplayItem::Line(_) => "Line".to_owned(),
                 DisplayItem::BoxShadow(_) => "BoxShadow".to_owned(),
                 DisplayItem::PushTextShadow(_) => "PushTextShadow".to_owned(),
                 DisplayItem::PopAllTextShadows(_) => "PopTextShadow".to_owned(),
--- a/servo/components/gfx/text/text_run.rs
+++ b/servo/components/gfx/text/text_run.rs
@@ -328,20 +328,20 @@ impl<'a> TextRun {
         if let Some(glyph_index) = self.index_of_first_glyph_run_containing(index) {
             self.glyphs[glyph_index].range.begin() == index
         } else {
             true
         }
     }
 
     /// Returns the index in the range of the first glyph advancing over given advance
-    pub fn range_index_of_advance(&self, range: &Range<ByteIndex>, advance: Au) -> usize {
+    pub fn range_index_of_advance(&self, range: &Range<ByteIndex>, advance: f32) -> usize {
         // TODO(Issue #199): alter advance direction for RTL
         // TODO(Issue #98): using inter-char and inter-word spacing settings when measuring text
-        let mut remaining = advance;
+        let mut remaining = Au::from_f32_px(advance);
         self.natural_word_slices_in_range(range)
             .map(|slice| {
                 let (slice_index, slice_advance) =
                     slice.glyphs.range_index_of_advance(&slice.range, remaining, self.extra_word_spacing);
                 remaining -= slice_advance;
                 slice_index
             })
             .sum()
--- a/servo/components/layout/display_list/builder.rs
+++ b/servo/components/layout/display_list/builder.rs
@@ -12,48 +12,49 @@
 
 use app_units::{Au, AU_PER_PX};
 use block::{BlockFlow, BlockStackingContextType};
 use canvas_traits::canvas::{CanvasMsg, FromLayoutMsg};
 use context::LayoutContext;
 use display_list::ToLayout;
 use display_list::background::{compute_background_image_size, tile_image_axis};
 use display_list::background::{convert_linear_gradient, convert_radial_gradient};
-use display_list::webrender_helpers::ToBorderRadius;
-use euclid::{Point2D, Rect, SideOffsets2D, Size2D, Transform3D, TypedRect, TypedSize2D, Vector2D};
+use euclid::{Point2D, Rect, SideOffsets2D, Size2D, Transform3D, TypedSize2D, Vector2D, rect};
 use flex::FlexFlow;
 use flow::{BaseFlow, Flow, FlowFlags};
 use flow_ref::FlowRef;
 use fnv::FnvHashMap;
 use fragment::{CanvasFragmentSource, CoordinateSystem, Fragment, ScannedTextFragmentInfo};
 use fragment::SpecificFragmentInfo;
 use gfx::display_list;
 use gfx::display_list::{BaseDisplayItem, BorderDetails, BorderDisplayItem, BLUR_INFLATION_FACTOR};
-use gfx::display_list::{BorderRadii, BoxShadowDisplayItem, ClipScrollNode};
+use gfx::display_list::{BoxShadowDisplayItem, ClipScrollNode};
 use gfx::display_list::{ClipScrollNodeIndex, ClipScrollNodeType, ClippingAndScrolling};
 use gfx::display_list::{ClippingRegion, DisplayItem, DisplayItemMetadata, DisplayList};
 use gfx::display_list::{DisplayListSection, GradientDisplayItem, IframeDisplayItem};
 use gfx::display_list::{ImageDisplayItem, LineDisplayItem, OpaqueNode};
 use gfx::display_list::{PopAllTextShadowsDisplayItem, PushTextShadowDisplayItem};
 use gfx::display_list::{RadialGradientDisplayItem, SolidColorDisplayItem, StackingContext};
 use gfx::display_list::{StackingContextType, StickyFrameData, TextDisplayItem, TextOrientation};
 use gfx::display_list::WebRenderImageInfo;
+use gfx::text::TextRun;
+use gfx::text::glyph::ByteIndex;
 use gfx_traits::{combine_id_with_fragment_type, FragmentType, StackingContextId};
 use inline::{InlineFlow, InlineFragmentNodeFlags};
 use ipc_channel::ipc;
 use list_item::ListItemFlow;
 use model::{self, MaybeAuto};
 use msg::constellation_msg::{BrowsingContextId, PipelineId};
 use net_traits::image::base::PixelFormat;
 use net_traits::image_cache::UsePlaceholder;
 use range::Range;
 use servo_config::opts;
 use servo_geometry::MaxRect;
-use std::{cmp, f32};
 use std::default::Default;
+use std::f32;
 use std::mem;
 use std::sync::Arc;
 use style::computed_values::background_attachment::single_value::T as BackgroundAttachment;
 use style::computed_values::background_clip::single_value::T as BackgroundClip;
 use style::computed_values::background_origin::single_value::T as BackgroundOrigin;
 use style::computed_values::border_style::T as BorderStyle;
 use style::computed_values::overflow_x::T as StyleOverflow;
 use style::computed_values::pointer_events::T as PointerEvents;
@@ -68,20 +69,21 @@ use style::values::computed::{Gradient, 
 use style::values::computed::effects::SimpleShadow;
 use style::values::computed::pointing::Cursor;
 use style::values::generics::background::BackgroundSize;
 use style::values::generics::image::{GradientKind, Image, PaintWorklet};
 use style_traits::CSSPixel;
 use style_traits::ToCss;
 use style_traits::cursor::CursorKind;
 use table_cell::CollapsedBordersForCell;
-use webrender_api::{self, BorderSide, BoxShadowClipMode, ClipMode, ColorF, ComplexClipRegion};
-use webrender_api::{ExternalScrollId, FilterOp, ImageBorder, ImageRendering, LayoutRect};
-use webrender_api::{LayoutSize, LayoutVector2D, LineStyle, LocalClip, NinePatchDescriptor};
-use webrender_api::{NormalBorder, ScrollPolicy, ScrollSensitivity, StickyOffsetBounds};
+use webrender_api::{self, BorderRadius, BorderSide, BoxShadowClipMode, ClipMode, ColorF};
+use webrender_api::{ComplexClipRegion, ExternalScrollId, FilterOp, GlyphInstance, ImageBorder};
+use webrender_api::{ImageRendering, LayoutRect, LayoutSize, LayoutVector2D, LineStyle, LocalClip};
+use webrender_api::{NinePatchDescriptor, NormalBorder, ScrollPolicy, ScrollSensitivity};
+use webrender_api::StickyOffsetBounds;
 
 trait ResolvePercentage {
     fn resolve(&self, length: u32) -> u32;
 }
 
 impl ResolvePercentage for NumberOrPercentage {
     fn resolve(&self, length: u32) -> u32 {
         match *self {
@@ -239,17 +241,17 @@ pub struct StackingContextCollectionStat
 impl StackingContextCollectionState {
     pub fn new(pipeline_id: PipelineId) -> StackingContextCollectionState {
         let root_clip_indices = ClippingAndScrolling::simple(ClipScrollNodeIndex(0));
 
         // This is just a dummy node to take up a slot in the array. WebRender
         // takes care of adding this root node and it can be ignored during DL conversion.
         let root_node = ClipScrollNode {
             parent_index: ClipScrollNodeIndex(0),
-            clip: ClippingRegion::from_rect(&TypedRect::zero()),
+            clip: ClippingRegion::from_rect(LayoutRect::zero()),
             content_rect: LayoutRect::zero(),
             node_type: ClipScrollNodeType::ScrollFrame(
                 ScrollSensitivity::ScriptAndInputEvents,
                 pipeline_id.root_scroll_id(),
             ),
         };
 
         StackingContextCollectionState {
@@ -384,17 +386,17 @@ impl<'a> DisplayListBuildState<'a> {
             ClippingAndScrolling::simple(self.parent_clip_scroll_node_index(
                 self.current_clipping_and_scrolling.scrolling,
             ))
         } else {
             self.current_clipping_and_scrolling
         };
 
         BaseDisplayItem::new(
-            *bounds,
+            bounds.to_layout(),
             DisplayItemMetadata {
                 node,
                 // Store cursor id in display list.
                 pointing: cursor.map(|x| x as u16),
             },
             clip,
             section,
             self.current_stacking_context_id,
@@ -703,26 +705,35 @@ pub trait FragmentDisplayListBuilding {
         parent_clipping_and_scrolling: ClippingAndScrolling,
     ) -> StackingContext;
 
     fn unique_id(&self) -> u64;
 
     fn fragment_type(&self) -> FragmentType;
 }
 
-fn handle_overlapping_radii(size: &Size2D<Au>, radii: &BorderRadii<Au>) -> BorderRadii<Au> {
+fn scale_border_radii(radii: BorderRadius, factor: f32) -> BorderRadius {
+    BorderRadius {
+        top_left: radii.top_left * factor,
+        top_right: radii.top_right * factor,
+        bottom_left: radii.bottom_left * factor,
+        bottom_right: radii.bottom_right * factor,
+    }
+}
+
+fn handle_overlapping_radii(size: LayoutSize, radii: BorderRadius) -> BorderRadius {
     // No two corners' border radii may add up to more than the length of the edge
     // between them. To prevent that, all radii are scaled down uniformly.
-    fn scale_factor(radius_a: Au, radius_b: Au, edge_length: Au) -> f32 {
+    fn scale_factor(radius_a: f32, radius_b: f32, edge_length: f32) -> f32 {
         let required = radius_a + radius_b;
 
         if required <= edge_length {
             1.0
         } else {
-            edge_length.to_f32_px() / required.to_f32_px()
+            edge_length / required
         }
     }
 
     let top_factor = scale_factor(radii.top_left.width, radii.top_right.width, size.width);
     let bottom_factor = scale_factor(
         radii.bottom_left.width,
         radii.bottom_right.width,
         size.width,
@@ -733,61 +744,61 @@ fn handle_overlapping_radii(size: &Size2
         radii.bottom_right.height,
         size.height,
     );
     let min_factor = top_factor
         .min(bottom_factor)
         .min(left_factor)
         .min(right_factor);
     if min_factor < 1.0 {
-        radii.scale_by(min_factor)
+        scale_border_radii(radii, min_factor)
     } else {
-        *radii
+        radii
     }
 }
 
 fn build_border_radius(
     abs_bounds: &Rect<Au>,
     border_style: &style_structs::Border,
-) -> BorderRadii<Au> {
+) -> BorderRadius {
     // TODO(cgaebel): Support border radii even in the case of multiple border widths.
     // This is an extension of supporting elliptical radii. For now, all percentage
     // radii will be relative to the width.
 
     handle_overlapping_radii(
-        &abs_bounds.size,
-        &BorderRadii {
+        abs_bounds.size.to_layout(),
+        BorderRadius {
             top_left: model::specified_border_radius(
                 border_style.border_top_left_radius,
                 abs_bounds.size,
-            ),
+            ).to_layout(),
             top_right: model::specified_border_radius(
                 border_style.border_top_right_radius,
                 abs_bounds.size,
-            ),
+            ).to_layout(),
             bottom_right: model::specified_border_radius(
                 border_style.border_bottom_right_radius,
                 abs_bounds.size,
-            ),
+            ).to_layout(),
             bottom_left: model::specified_border_radius(
                 border_style.border_bottom_left_radius,
                 abs_bounds.size,
-            ),
+            ).to_layout(),
         },
     )
 }
 
 /// Get the border radius for the rectangle inside of a rounded border. This is useful
 /// for building the clip for the content inside the border.
 fn build_border_radius_for_inner_rect(
     outer_rect: &Rect<Au>,
     style: &ComputedValues,
-) -> BorderRadii<Au> {
+) -> BorderRadius {
     let radii = build_border_radius(&outer_rect, style.get_border());
-    if radii.is_square() {
+    if radii.is_zero() {
         return radii;
     }
 
     // Since we are going to using the inner rectangle (outer rectangle minus
     // border width), we need to adjust to border radius so that we are smaller
     // rectangle with the same border curve.
     let border_widths = style.logical_border_width().to_physical(style.writing_mode);
     calculate_inner_border_radii(radii, border_widths)
@@ -825,30 +836,33 @@ fn simple_normal_border(color: ColorF, s
         right: side,
         top: side,
         bottom: side,
         radius: webrender_api::BorderRadius::zero(),
     }
 }
 
 fn calculate_inner_border_radii(
-    mut radii: BorderRadii<Au>,
+    mut radii: BorderRadius,
     offsets: SideOffsets2D<Au>,
-) -> BorderRadii<Au> {
-    radii.top_left.width = cmp::max(Au(0), radii.top_left.width - offsets.left);
-    radii.bottom_left.width = cmp::max(Au(0), radii.bottom_left.width - offsets.left);
+) -> BorderRadius {
+    fn inner_length(x: f32, offset: Au) -> f32 {
+        0.0_f32.max(x - offset.to_f32_px())
+    }
+    radii.top_left.width = inner_length(radii.top_left.width, offsets.left);
+    radii.bottom_left.width = inner_length(radii.bottom_left.width, offsets.left);
 
-    radii.top_right.width = cmp::max(Au(0), radii.top_right.width - offsets.right);
-    radii.bottom_right.width = cmp::max(Au(0), radii.bottom_right.width - offsets.right);
+    radii.top_right.width = inner_length(radii.top_right.width, offsets.right);
+    radii.bottom_right.width = inner_length(radii.bottom_right.width, offsets.right);
 
-    radii.top_left.height = cmp::max(Au(0), radii.top_left.height - offsets.top);
-    radii.top_right.height = cmp::max(Au(0), radii.top_right.height - offsets.top);
+    radii.top_left.height = inner_length(radii.top_left.height, offsets.top);
+    radii.top_right.height = inner_length(radii.top_right.height, offsets.top);
 
-    radii.bottom_left.height = cmp::max(Au(0), radii.bottom_left.height - offsets.bottom);
-    radii.bottom_right.height = cmp::max(Au(0), radii.bottom_right.height - offsets.bottom);
+    radii.bottom_left.height = inner_length(radii.bottom_left.height, offsets.bottom);
+    radii.bottom_right.height = inner_length(radii.bottom_right.height, offsets.bottom);
     radii
 }
 
 fn build_image_border_details(
     webrender_image: WebRenderImageInfo,
     border_style_struct: &style_structs::Border,
 ) -> Option<BorderDetails> {
     let corners = &border_style_struct.border_image_slice.offsets;
@@ -872,16 +886,45 @@ fn build_image_border_details(
             repeat_horizontal: border_image_repeat.0.to_layout(),
             repeat_vertical: border_image_repeat.1.to_layout(),
         }))
     } else {
         None
     }
 }
 
+fn convert_text_run_to_glyphs(
+    text_run: Arc<TextRun>,
+    range: Range<ByteIndex>,
+    mut origin: Point2D<Au>,
+) -> Vec<GlyphInstance> {
+    let mut glyphs = vec![];
+
+    for slice in text_run.natural_word_slices_in_visual_order(&range) {
+        for glyph in slice.glyphs.iter_glyphs_for_byte_range(&slice.range) {
+            let glyph_advance = if glyph.char_is_space() {
+                glyph.advance() + text_run.extra_word_spacing
+            } else {
+                glyph.advance()
+            };
+            if !slice.glyphs.is_whitespace() {
+                let glyph_offset = glyph.offset().unwrap_or(Point2D::zero());
+                let point = origin + glyph_offset.to_vector();
+                let glyph = GlyphInstance {
+                    index: glyph.id(),
+                    point: point.to_layout(),
+                };
+                glyphs.push(glyph);
+            }
+            origin.x += glyph_advance;
+        }
+    }
+    return glyphs;
+}
+
 impl FragmentDisplayListBuilding for Fragment {
     fn collect_stacking_contexts_for_blocklike_fragment(
         &mut self,
         state: &mut StackingContextCollectionState,
     ) -> bool {
         match self.specific {
             SpecificFragmentInfo::InlineBlock(ref mut block_flow) => {
                 let block_flow = FlowRef::deref_mut(&mut block_flow.flow_ref);
@@ -941,24 +984,20 @@ impl FragmentDisplayListBuilding for Fra
             },
             BackgroundClip::ContentBox => {
                 let border_padding = self.border_padding.to_physical(style.writing_mode);
                 bounds = calculate_inner_bounds(bounds, border_padding);
                 border_radii = calculate_inner_border_radii(border_radii, border_padding);
             },
         }
 
-        let clip = if !border_radii.is_square() {
+        let clip = if !border_radii.is_zero() {
             LocalClip::RoundedRect(
                 bounds.to_layout(),
-                ComplexClipRegion::new(
-                    bounds.to_layout(),
-                    border_radii.to_border_radius(),
-                    ClipMode::Clip,
-                ),
+                ComplexClipRegion::new(bounds.to_layout(), border_radii, ClipMode::Clip),
             )
         } else {
             LocalClip::Rect(bounds.to_layout())
         };
 
         let base = state.create_base_display_item(
             &bounds,
             clip,
@@ -1320,17 +1359,17 @@ impl FragmentDisplayListBuilding for Fra
                     .unwrap_or(style.get_color().color)
                     .to_layout(),
                 offset: LayoutVector2D::new(
                     box_shadow.base.horizontal.px(),
                     box_shadow.base.vertical.px(),
                 ),
                 blur_radius: box_shadow.base.blur.px(),
                 spread_radius: box_shadow.spread.px(),
-                border_radius: border_radius.to_border_radius(),
+                border_radius: border_radius,
                 clip_mode: if box_shadow.inset {
                     BoxShadowClipMode::Inset
                 } else {
                     BoxShadowClipMode::Outset
                 },
             })));
         }
     }
@@ -1415,17 +1454,17 @@ impl FragmentDisplayListBuilding for Fra
                 top: BorderSide {
                     color: style.resolve_color(colors.top).to_layout(),
                     style: border_style.top.to_layout(),
                 },
                 bottom: BorderSide {
                     color: style.resolve_color(colors.bottom).to_layout(),
                     style: border_style.bottom.to_layout(),
                 },
-                radius: border_radius.to_border_radius(),
+                radius: border_radius,
             })),
             Either::Second(Image::Gradient(ref gradient)) => {
                 Some(match gradient.kind {
                     GradientKind::Linear(angle_or_corner) => {
                         BorderDetails::Gradient(display_list::GradientBorder {
                             gradient: convert_linear_gradient(
                                 bounds.size,
                                 &gradient.items[..],
@@ -1648,37 +1687,29 @@ impl FragmentDisplayListBuilding for Fra
             scanned_text_fragment_info.range.begin(),
             insertion_point_index - scanned_text_fragment_info.range.begin(),
         );
         let advance = scanned_text_fragment_info.run.advance_for_range(&range);
 
         let insertion_point_bounds;
         let cursor;
         if !self.style.writing_mode.is_vertical() {
-            insertion_point_bounds = Rect::new(
-                Point2D::new(
-                    stacking_relative_border_box.origin.x + advance,
-                    stacking_relative_border_box.origin.y,
-                ),
-                Size2D::new(
-                    INSERTION_POINT_LOGICAL_WIDTH,
-                    stacking_relative_border_box.size.height,
-                ),
+            insertion_point_bounds = rect(
+                stacking_relative_border_box.origin.x + advance,
+                stacking_relative_border_box.origin.y,
+                INSERTION_POINT_LOGICAL_WIDTH,
+                stacking_relative_border_box.size.height,
             );
             cursor = CursorKind::Text;
         } else {
-            insertion_point_bounds = Rect::new(
-                Point2D::new(
-                    stacking_relative_border_box.origin.x,
-                    stacking_relative_border_box.origin.y + advance,
-                ),
-                Size2D::new(
-                    stacking_relative_border_box.size.width,
-                    INSERTION_POINT_LOGICAL_WIDTH,
-                ),
+            insertion_point_bounds = rect(
+                stacking_relative_border_box.origin.x,
+                stacking_relative_border_box.origin.y + advance,
+                stacking_relative_border_box.size.width,
+                INSERTION_POINT_LOGICAL_WIDTH,
             );
             cursor = CursorKind::VerticalText;
         };
 
         let base = state.create_base_display_item(
             &insertion_point_bounds,
             LocalClip::from(clip.to_layout()),
             self.node,
@@ -1837,22 +1868,22 @@ impl FragmentDisplayListBuilding for Fra
     ) {
         // Compute the context box position relative to the parent stacking context.
         let stacking_relative_content_box =
             self.stacking_relative_content_box(stacking_relative_border_box);
 
         // Adjust the clipping region as necessary to account for `border-radius`.
         let build_local_clip = |style: &ComputedValues| {
             let radii = build_border_radius_for_inner_rect(&stacking_relative_border_box, style);
-            if !radii.is_square() {
+            if !radii.is_zero() {
                 LocalClip::RoundedRect(
                     stacking_relative_border_box.to_layout(),
                     ComplexClipRegion::new(
                         stacking_relative_content_box.to_layout(),
-                        radii.to_border_radius(),
+                        radii,
                         ClipMode::Clip,
                     ),
                 )
             } else {
                 LocalClip::Rect(stacking_relative_border_box.to_layout())
             }
         };
 
@@ -1941,20 +1972,17 @@ impl FragmentDisplayListBuilding for Fra
                         self.style.get_cursor(CursorKind::Default),
                         DisplayListSection::Content,
                     );
                     let item = DisplayItem::Iframe(Box::new(IframeDisplayItem {
                         base: base,
                         iframe: pipeline_id,
                     }));
 
-                    let size = Size2D::new(
-                        item.bounds().size.width.to_f32_px(),
-                        item.bounds().size.height.to_f32_px(),
-                    );
+                    let size = Size2D::new(item.bounds().size.width, item.bounds().size.height);
                     state
                         .iframe_sizes
                         .push((browsing_context_id, TypedSize2D::from_untyped(&size)));
 
                     state.add_display_item(item);
                 }
             },
             SpecificFragmentInfo::Image(ref mut image_fragment) => {
@@ -2062,18 +2090,18 @@ impl FragmentDisplayListBuilding for Fra
         let mut filters: Vec<FilterOp> = effects.filter.0.iter().map(ToLayout::to_layout).collect();
         if effects.opacity != 1.0 {
             filters.push(FilterOp::Opacity(effects.opacity.into(), effects.opacity));
         }
 
         StackingContext::new(
             id,
             context_type,
-            &border_box,
-            &overflow,
+            border_box.to_layout(),
+            overflow.to_layout(),
             self.effective_z_index(),
             filters,
             self.style().get_effects().mix_blend_mode.to_layout(),
             self.transform_matrix(&border_box),
             self.style().get_used_transform_style().to_layout(),
             self.perspective_matrix(&border_box),
             scroll_policy,
             parent_clipping_and_scrolling,
@@ -2095,17 +2123,17 @@ impl FragmentDisplayListBuilding for Fra
         // Paint the text with the color as described in its styling.
         let text_color = if text_fragment.selected() {
             self.selected_style().get_color().color
         } else {
             self.style().get_color().color
         };
 
         // Determine the orientation and cursor to use.
-        let (orientation, cursor) = if self.style.writing_mode.is_vertical() {
+        let (_orientation, cursor) = if self.style.writing_mode.is_vertical() {
             // TODO: Distinguish between 'sideways-lr' and 'sideways-rl' writing modes in CSS
             // Writing Modes Level 4.
             (TextOrientation::SidewaysRight, CursorKind::VerticalText)
         } else {
             (TextOrientation::Upright, CursorKind::Text)
         };
 
         // Compute location of the baseline.
@@ -2176,24 +2204,32 @@ impl FragmentDisplayListBuilding for Fra
                 state,
                 &text_color,
                 &stacking_relative_box,
                 clip,
             );
         }
 
         // Text
-        state.add_display_item(DisplayItem::Text(Box::new(TextDisplayItem {
-            base: base.clone(),
-            text_run: text_fragment.run.clone(),
-            range: text_fragment.range,
-            text_color: text_color.to_layout(),
-            orientation: orientation,
-            baseline_origin: baseline_origin,
-        })));
+        let glyphs = convert_text_run_to_glyphs(
+            text_fragment.run.clone(),
+            text_fragment.range,
+            baseline_origin,
+        );
+        if !glyphs.is_empty() {
+            state.add_display_item(DisplayItem::Text(Box::new(TextDisplayItem {
+                base: base.clone(),
+                text_run: text_fragment.run.clone(),
+                range: text_fragment.range,
+                baseline_origin: baseline_origin.to_layout(),
+                glyphs: glyphs,
+                font_key: text_fragment.run.font_key,
+                text_color: text_color.to_layout(),
+            })));
+        }
 
         // TODO(#17715): emit text-emphasis marks here.
         // (just push another TextDisplayItem?)
 
         // Line-Through
         if text_decorations.line_through {
             let mut stacking_relative_box = stacking_relative_content_box;
             stacking_relative_box.start.b =
@@ -2430,35 +2466,30 @@ impl BlockFlowDisplayListBuilding for Bl
                     // We cannot properly handle perspective transforms, because there may be a
                     // situation where an element is transformed from outside the clip into the
                     // clip region. Here we don't have enough information to detect when that is
                     // happening. For the moment we just punt on trying to optimize the display
                     // list for those cases.
                     Rect::max_rect()
                 },
                 Some(transform) => {
-                    let clip = Rect::new(
-                        Point2D::new(
-                            (clip.origin.x - origin.x).to_f32_px(),
-                            (clip.origin.y - origin.y).to_f32_px(),
-                        ),
-                        Size2D::new(clip.size.width.to_f32_px(), clip.size.height.to_f32_px()),
+                    let clip = rect(
+                        (clip.origin.x - origin.x).to_f32_px(),
+                        (clip.origin.y - origin.y).to_f32_px(),
+                        clip.size.width.to_f32_px(),
+                        clip.size.height.to_f32_px(),
                     );
 
                     let clip = transform.transform_rect(&clip);
 
-                    Rect::new(
-                        Point2D::new(
-                            Au::from_f32_px(clip.origin.x),
-                            Au::from_f32_px(clip.origin.y),
-                        ),
-                        Size2D::new(
-                            Au::from_f32_px(clip.size.width),
-                            Au::from_f32_px(clip.size.height),
-                        ),
+                    rect(
+                        Au::from_f32_px(clip.origin.x),
+                        Au::from_f32_px(clip.origin.y),
+                        Au::from_f32_px(clip.size.width),
+                        Au::from_f32_px(clip.size.height),
                     )
                 },
                 None => Rect::zero(),
             }
         };
 
         if let Some(clip) = state.clip_stack.last().cloned() {
             state.clip_stack.push(transform_clip(&clip));
@@ -2664,17 +2695,17 @@ impl BlockFlowDisplayListBuilding for Bl
                 sticky_position.left.to_option().map(|v| v.to_f32_px()),
             ),
             vertical_offset_bounds,
             horizontal_offset_bounds,
         };
 
         let new_clip_scroll_index = state.add_clip_scroll_node(ClipScrollNode {
             parent_index: self.clipping_and_scrolling().scrolling,
-            clip: ClippingRegion::from_rect(border_box),
+            clip: ClippingRegion::from_rect(border_box.to_layout()),
             content_rect: LayoutRect::zero(),
             node_type: ClipScrollNodeType::StickyFrame(sticky_frame_data),
         });
 
         let new_clipping_and_scrolling = ClippingAndScrolling::simple(new_clip_scroll_index);
         self.base.clipping_and_scrolling = Some(new_clipping_and_scrolling);
         state.current_clipping_and_scrolling = new_clipping_and_scrolling;
     }
@@ -2704,20 +2735,20 @@ impl BlockFlowDisplayListBuilding for Bl
             StyleOverflow::Hidden == self.fragment.style.get_box().overflow_y
         {
             ScrollSensitivity::Script
         } else {
             ScrollSensitivity::ScriptAndInputEvents
         };
 
         let clip_rect = build_inner_border_box_for_border_rect(&border_box, &self.fragment.style);
-        let mut clip = ClippingRegion::from_rect(&clip_rect);
+        let mut clip = ClippingRegion::from_rect(clip_rect.to_layout());
         let radii = build_border_radius_for_inner_rect(&border_box, &self.fragment.style);
-        if !radii.is_square() {
-            clip.intersect_with_rounded_rect(&clip_rect, &radii)
+        if !radii.is_zero() {
+            clip.intersect_with_rounded_rect(clip_rect.to_layout(), radii)
         }
 
         let content_size = self.base.overflow.scroll.origin + self.base.overflow.scroll.size;
         let content_size = Size2D::new(content_size.x, content_size.y);
 
         let external_id = ExternalScrollId(
             self.fragment.unique_id(),
             state.pipeline_id.to_webrender()
@@ -2771,17 +2802,17 @@ impl BlockFlowDisplayListBuilding for Bl
             .unwrap_or(stacking_relative_border_box.size.height);
         let clip_size = Size2D::new(right - clip_origin.x, bottom - clip_origin.y);
 
         let clip_rect = Rect::new(clip_origin, clip_size);
         preserved_state.push_clip(state, &clip_rect, self.positioning());
 
         let new_index = state.add_clip_scroll_node(ClipScrollNode {
             parent_index: self.clipping_and_scrolling().scrolling,
-            clip: ClippingRegion::from_rect(&clip_rect),
+            clip: ClippingRegion::from_rect(clip_rect.to_layout()),
             content_rect: LayoutRect::zero(), // content_rect isn't important for clips.
             node_type: ClipScrollNodeType::Clip,
         });
 
         let new_indices = ClippingAndScrolling::new(new_index, new_index);
         self.base.clipping_and_scrolling = Some(new_indices);
         state.current_clipping_and_scrolling = new_indices;
     }
--- a/servo/components/layout/display_list/webrender_helpers.rs
+++ b/servo/components/layout/display_list/webrender_helpers.rs
@@ -2,24 +2,21 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // TODO(gw): This contains helper traits and implementations for converting Servo display lists
 //           into WebRender display lists. In the future, this step should be completely removed.
 //           This might be achieved by sharing types between WR and Servo display lists, or
 //           completely converting layout to directly generate WebRender display lists, for example.
 
-use app_units::Au;
-use display_list::ToLayout;
-use euclid::Point2D;
-use gfx::display_list::{BorderDetails, BorderRadii, ClipScrollNode};
-use gfx::display_list::{ClipScrollNodeIndex, ClipScrollNodeType, ClippingRegion, DisplayItem};
+use gfx::display_list::{BorderDetails, ClipScrollNode};
+use gfx::display_list::{ClipScrollNodeIndex, ClipScrollNodeType, DisplayItem};
 use gfx::display_list::{DisplayList, StackingContextType};
 use msg::constellation_msg::PipelineId;
-use webrender_api::{self, ClipAndScrollInfo, ClipId, ClipMode, ComplexClipRegion};
+use webrender_api::{self, ClipAndScrollInfo, ClipId};
 use webrender_api::{DisplayListBuilder, LayoutTransform};
 
 pub trait WebRenderDisplayListConverter {
     fn convert_to_webrender(&self, pipeline_id: PipelineId) -> DisplayListBuilder;
 }
 
 trait WebRenderDisplayItemConverter {
     fn prim_info(&self) -> webrender_api::LayoutPrimitiveInfo;
@@ -27,36 +24,21 @@ trait WebRenderDisplayItemConverter {
         &self,
         builder: &mut DisplayListBuilder,
         clip_scroll_nodes: &[ClipScrollNode],
         clip_ids: &mut Vec<Option<ClipId>>,
         current_clip_and_scroll_info: &mut ClipAndScrollInfo,
     );
 }
 
-pub trait ToBorderRadius {
-    fn to_border_radius(&self) -> webrender_api::BorderRadius;
-}
-
-impl ToBorderRadius for BorderRadii<Au> {
-    fn to_border_radius(&self) -> webrender_api::BorderRadius {
-        webrender_api::BorderRadius {
-            top_left: self.top_left.to_layout(),
-            top_right: self.top_right.to_layout(),
-            bottom_left: self.bottom_left.to_layout(),
-            bottom_right: self.bottom_right.to_layout(),
-        }
-    }
-}
-
 impl WebRenderDisplayListConverter for DisplayList {
     fn convert_to_webrender(&self, pipeline_id: PipelineId) -> DisplayListBuilder {
         let mut builder = DisplayListBuilder::with_capacity(
             pipeline_id.to_webrender(),
-            self.bounds().size.to_layout(),
+            self.bounds().size,
             1024 * 1024,
         ); // 1 MB of space
 
         let mut current_clip_and_scroll_info = pipeline_id.root_clip_and_scroll_info();
         builder.push_clip_and_scroll_info(current_clip_and_scroll_info);
 
         let mut clip_ids = Vec::with_capacity(self.clip_scroll_nodes.len());
         clip_ids.resize(self.clip_scroll_nodes.len(), None);
@@ -76,17 +58,17 @@ impl WebRenderDisplayListConverter for D
 
 impl WebRenderDisplayItemConverter for DisplayItem {
     fn prim_info(&self) -> webrender_api::LayoutPrimitiveInfo {
         let tag = match self.base().metadata.pointing {
             Some(cursor) => Some((self.base().metadata.node.0 as u64, cursor)),
             None => None,
         };
         webrender_api::LayoutPrimitiveInfo {
-            rect: self.base().bounds.to_layout(),
+            rect: self.base().bounds,
             local_clip: self.base().local_clip,
             // TODO(gw): Make use of the WR backface visibility functionality.
             is_backface_visible: true,
             tag,
         }
     }
 
     fn convert_to_webrender(
@@ -116,52 +98,23 @@ impl WebRenderDisplayItemConverter for D
             *current_clip_and_scroll_info = clip_and_scroll_info;
         }
 
         match *self {
             DisplayItem::SolidColor(ref item) => {
                 builder.push_rect(&self.prim_info(), item.color);
             },
             DisplayItem::Text(ref item) => {
-                let mut origin = item.baseline_origin.clone();
-                let mut glyphs = vec![];
-
-                for slice in item.text_run
-                    .natural_word_slices_in_visual_order(&item.range)
-                {
-                    for glyph in slice.glyphs.iter_glyphs_for_byte_range(&slice.range) {
-                        let glyph_advance = if glyph.char_is_space() {
-                            glyph.advance() + item.text_run.extra_word_spacing
-                        } else {
-                            glyph.advance()
-                        };
-                        if !slice.glyphs.is_whitespace() {
-                            let glyph_offset = glyph.offset().unwrap_or(Point2D::zero());
-                            let x = (origin.x + glyph_offset.x).to_f32_px();
-                            let y = (origin.y + glyph_offset.y).to_f32_px();
-                            let point = webrender_api::LayoutPoint::new(x, y);
-                            let glyph = webrender_api::GlyphInstance {
-                                index: glyph.id(),
-                                point: point,
-                            };
-                            glyphs.push(glyph);
-                        }
-                        origin.x = origin.x + glyph_advance;
-                    }
-                }
-
-                if glyphs.len() > 0 {
-                    builder.push_text(
-                        &self.prim_info(),
-                        &glyphs,
-                        item.text_run.font_key,
-                        item.text_color,
-                        None,
-                    );
-                }
+                builder.push_text(
+                    &self.prim_info(),
+                    &item.glyphs,
+                    item.font_key,
+                    item.text_color,
+                    None,
+                );
             },
             DisplayItem::Image(ref item) => {
                 if let Some(id) = item.webrender_image.key {
                     if item.stretch_size.width > 0.0 && item.stretch_size.height > 0.0 {
                         builder.push_image(
                             &self.prim_info(),
                             item.stretch_size,
                             item.tile_spacing,
@@ -228,17 +181,17 @@ impl WebRenderDisplayItemConverter for D
                     item.tile,
                     item.tile_spacing,
                 );
             },
             DisplayItem::Line(ref item) => {
                 builder.push_line(
                     &self.prim_info(),
                     // TODO(gw): Use a better estimate for wavy line thickness.
-                    (0.33 * item.base.bounds.size.height.to_f32_px()).ceil(),
+                    (0.33 * item.base.bounds.size.height).ceil(),
                     webrender_api::LineOrientation::Horizontal,
                     &item.color,
                     item.style,
                 );
             },
             DisplayItem::BoxShadow(ref item) => {
                 builder.push_box_shadow(
                     &self.prim_info(),
@@ -274,45 +227,45 @@ impl WebRenderDisplayItemConverter for D
                 let transform = stacking_context
                     .transform
                     .map(|transform| LayoutTransform::from_untyped(&transform).into());
                 let perspective = stacking_context
                     .perspective
                     .map(|perspective| LayoutTransform::from_untyped(&perspective));
 
                 builder.push_stacking_context(
-                    &webrender_api::LayoutPrimitiveInfo::new(stacking_context.bounds.to_layout()),
+                    &webrender_api::LayoutPrimitiveInfo::new(stacking_context.bounds),
                     stacking_context.scroll_policy,
                     transform,
                     stacking_context.transform_style,
                     perspective,
                     stacking_context.mix_blend_mode,
                     stacking_context.filters.clone(),
                 );
             },
             DisplayItem::PopStackingContext(_) => builder.pop_stacking_context(),
             DisplayItem::DefineClipScrollNode(ref item) => {
                 let node = &clip_scroll_nodes[item.node_index.0];
                 let parent_id = get_id(clip_ids, node.parent_index);
-                let item_rect = node.clip.main.to_layout();
+                let item_rect = node.clip.main;
 
                 let webrender_id = match node.node_type {
                     ClipScrollNodeType::Clip => builder.define_clip_with_parent(
                         parent_id,
                         item_rect,
-                        node.clip.get_complex_clips(),
+                        node.clip.complex.clone(),
                         None,
                     ),
                     ClipScrollNodeType::ScrollFrame(scroll_sensitivity, external_id) => builder
                         .define_scroll_frame_with_parent(
                             parent_id,
                             Some(external_id),
                             node.content_rect,
-                            node.clip.main.to_layout(),
-                            node.clip.get_complex_clips(),
+                            node.clip.main,
+                            node.clip.complex.clone(),
                             None,
                             scroll_sensitivity,
                         ),
                     ClipScrollNodeType::StickyFrame(ref sticky_data) => {
                         // TODO: Add define_sticky_frame_with_parent to WebRender.
                         builder.push_clip_id(parent_id);
                         let id = builder.define_sticky_frame(
                             item_rect,
@@ -326,27 +279,8 @@ impl WebRenderDisplayItemConverter for D
                     },
                 };
 
                 clip_ids[item.node_index.0] = Some(webrender_id);
             },
         }
     }
 }
-
-trait ToWebRenderClip {
-    fn get_complex_clips(&self) -> Vec<ComplexClipRegion>;
-}
-
-impl ToWebRenderClip for ClippingRegion {
-    fn get_complex_clips(&self) -> Vec<ComplexClipRegion> {
-        self.complex
-            .iter()
-            .map(|complex_clipping_region| {
-                ComplexClipRegion::new(
-                    complex_clipping_region.rect.to_layout(),
-                    complex_clipping_region.radii.to_border_radius(),
-                    ClipMode::Clip,
-                )
-            })
-            .collect()
-    }
-}
--- a/servo/components/layout_thread/lib.rs
+++ b/servo/components/layout_thread/lib.rs
@@ -63,16 +63,17 @@ use gfx_traits::{Epoch, node_id_from_scr
 use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
 use ipc_channel::router::ROUTER;
 use layout::animation;
 use layout::construct::ConstructionResult;
 use layout::context::LayoutContext;
 use layout::context::RegisteredPainter;
 use layout::context::RegisteredPainters;
 use layout::context::malloc_size_of_persistent_local_context;
+use layout::display_list::ToLayout;
 use layout::display_list::WebRenderDisplayListConverter;
 use layout::flow::{Flow, GetBaseFlow, ImmutableFlowUtils, MutableOwnedFlowUtils};
 use layout::flow_ref::FlowRef;
 use layout::incremental::{LayoutDamageComputation, RelayoutMode, SpecialRestyleDamage};
 use layout::layout_debug;
 use layout::parallel;
 use layout::query::{LayoutRPCImpl, LayoutThreadData, process_content_box_request, process_content_boxes_request};
 use layout::query::{process_node_geometry_request, process_node_scroll_area_request};
@@ -981,17 +982,17 @@ impl LayoutThread {
                         let root_flow = layout_root.base();
                         if self.stylist.viewport_constraints().is_some() {
                             root_flow.position.size.to_physical(root_flow.writing_mode)
                         } else {
                             root_flow.overflow.scroll.size
                         }
                     };
 
-                    let origin = Rect::new(Point2D::new(Au(0), Au(0)), root_size);
+                    let origin = Rect::new(Point2D::new(Au(0), Au(0)), root_size).to_layout();
                     build_state.root_stacking_context.bounds = origin;
                     build_state.root_stacking_context.overflow = origin;
 
                     if !build_state.iframe_sizes.is_empty() {
                         // build_state.iframe_sizes is only used here, so its okay to replace
                         // it with an empty vector
                         let iframe_sizes = std::mem::replace(&mut build_state.iframe_sizes, vec![]);
                         let msg = ConstellationMsg::IFrameSizes(iframe_sizes);
@@ -1359,17 +1360,17 @@ impl LayoutThread {
                 let point_in_node = Point2D::new(
                     Au::from_f32_px(point_in_node.x),
                     Au::from_f32_px(point_in_node.y)
                 );
                 rw_data.text_index_response = TextIndexResponse(
                     rw_data.display_list
                     .as_ref()
                     .expect("Tried to hit test with no display list")
-                    .text_index(opaque_node, &point_in_node)
+                    .text_index(opaque_node, point_in_node.to_layout())
                 );
             },
             ReflowGoal::NodeGeometryQuery(node) => {
                 let node = unsafe { ServoLayoutNode::new(&node) };
                 rw_data.client_rect_response = process_node_geometry_request(node, root_flow);
             },
             ReflowGoal::NodeScrollGeometryQuery(node) => {
                 let node = unsafe { ServoLayoutNode::new(&node) };
--- a/servo/components/malloc_size_of/lib.rs
+++ b/servo/components/malloc_size_of/lib.rs
@@ -820,24 +820,30 @@ malloc_size_of_is_0!(webrender_api::Bord
 malloc_size_of_is_0!(webrender_api::BorderWidths);
 #[cfg(feature = "webrender_api")]
 malloc_size_of_is_0!(webrender_api::BoxShadowClipMode);
 #[cfg(feature = "webrender_api")]
 malloc_size_of_is_0!(webrender_api::ClipAndScrollInfo);
 #[cfg(feature = "webrender_api")]
 malloc_size_of_is_0!(webrender_api::ColorF);
 #[cfg(feature = "webrender_api")]
+malloc_size_of_is_0!(webrender_api::ComplexClipRegion);
+#[cfg(feature = "webrender_api")]
 malloc_size_of_is_0!(webrender_api::ExtendMode);
 #[cfg(feature = "webrender_api")]
 malloc_size_of_is_0!(webrender_api::FilterOp);
 #[cfg(feature = "webrender_api")]
 malloc_size_of_is_0!(webrender_api::ExternalScrollId);
 #[cfg(feature = "webrender_api")]
+malloc_size_of_is_0!(webrender_api::FontInstanceKey);
+#[cfg(feature = "webrender_api")]
 malloc_size_of_is_0!(webrender_api::GradientStop);
 #[cfg(feature = "webrender_api")]
+malloc_size_of_is_0!(webrender_api::GlyphInstance);
+#[cfg(feature = "webrender_api")]
 malloc_size_of_is_0!(webrender_api::ImageBorder);
 #[cfg(feature = "webrender_api")]
 malloc_size_of_is_0!(webrender_api::ImageKey);
 #[cfg(feature = "webrender_api")]
 malloc_size_of_is_0!(webrender_api::ImageRendering);
 #[cfg(feature = "webrender_api")]
 malloc_size_of_is_0!(webrender_api::LineStyle);
 #[cfg(feature = "webrender_api")]