use knownheapsize for geom stuff

This commit is contained in:
Manish Goregaokar 2015-05-27 22:11:01 +05:30
parent c1daf889af
commit a5975e8f33
2 changed files with 48 additions and 111 deletions

View file

@ -66,7 +66,7 @@ const MIN_INDENTATION_LENGTH: usize = 4;
/// Because the script task's GC does not trace layout, node data cannot be safely stored in layout /// Because the script task's GC does not trace layout, node data cannot be safely stored in layout
/// data structures. Also, layout code tends to be faster when the DOM is not being accessed, for /// data structures. Also, layout code tends to be faster when the DOM is not being accessed, for
/// locality reasons. Using `OpaqueNode` enforces this invariant. /// locality reasons. Using `OpaqueNode` enforces this invariant.
#[derive(Clone, PartialEq, Copy, Debug)] #[derive(Clone, PartialEq, Copy, Debug, HeapSizeOf)]
pub struct OpaqueNode(pub uintptr_t); pub struct OpaqueNode(pub uintptr_t);
impl OpaqueNode { impl OpaqueNode {
@ -82,6 +82,7 @@ impl OpaqueNode {
/// ///
/// TODO(pcwalton): We could reduce the size of this structure with a more "skip list"-like /// TODO(pcwalton): We could reduce the size of this structure with a more "skip list"-like
/// structure, omitting several pointers and lengths. /// structure, omitting several pointers and lengths.
#[derive(HeapSizeOf)]
pub struct DisplayList { pub struct DisplayList {
/// The border and backgrounds for the root of this stacking context: steps 1 and 2. /// The border and backgrounds for the root of this stacking context: steps 1 and 2.
pub background_and_borders: LinkedList<DisplayItem>, pub background_and_borders: LinkedList<DisplayItem>,
@ -218,24 +219,15 @@ impl DisplayList {
} }
} }
impl HeapSizeOf for DisplayList { // FIXME(njn): other fields may be measured later, esp. `layer`
fn heap_size_of_children(&self) -> usize { #[derive(HeapSizeOf)]
self.background_and_borders.heap_size_of_children() +
self.block_backgrounds_and_borders.heap_size_of_children() +
self.floats.heap_size_of_children() +
self.content.heap_size_of_children() +
self.positioned_content.heap_size_of_children() +
self.outlines.heap_size_of_children() +
self.children.heap_size_of_children()
}
}
/// Represents one CSS stacking context, which may or may not have a hardware layer. /// Represents one CSS stacking context, which may or may not have a hardware layer.
pub struct StackingContext { pub struct StackingContext {
/// The display items that make up this stacking context. /// The display items that make up this stacking context.
pub display_list: Box<DisplayList>, pub display_list: Box<DisplayList>,
/// The layer for this stacking context, if there is one. /// The layer for this stacking context, if there is one.
#[ignore_heap_size]
pub layer: Option<Arc<PaintLayer>>, pub layer: Option<Arc<PaintLayer>>,
/// The position and size of this stacking context. /// The position and size of this stacking context.
@ -248,13 +240,14 @@ pub struct StackingContext {
pub z_index: i32, pub z_index: i32,
/// CSS filters to be applied to this stacking context (including opacity). /// CSS filters to be applied to this stacking context (including opacity).
#[ignore_heap_size]
pub filters: filter::T, pub filters: filter::T,
/// The blend mode with which this stacking context blends with its backdrop. /// The blend mode with which this stacking context blends with its backdrop.
#[ignore_heap_size]
pub blend_mode: mix_blend_mode::T, pub blend_mode: mix_blend_mode::T,
/// A transform to be applied to this stacking context. /// A transform to be applied to this stacking context.
#[ignore_heap_size]
pub transform: Matrix2D<AzFloat>, pub transform: Matrix2D<AzFloat>,
} }
@ -584,14 +577,6 @@ impl StackingContext {
} }
} }
impl HeapSizeOf for StackingContext {
fn heap_size_of_children(&self) -> usize {
self.display_list.heap_size_of_children()
// FIXME(njn): other fields may be measured later, esp. `layer`
}
}
/// Returns the stacking context in the given tree of stacking contexts with a specific layer ID. /// Returns the stacking context in the given tree of stacking contexts with a specific layer ID.
pub fn find_stacking_context_with_layer_id(this: &Arc<StackingContext>, layer_id: LayerId) pub fn find_stacking_context_with_layer_id(this: &Arc<StackingContext>, layer_id: LayerId)
-> Option<Arc<StackingContext>> { -> Option<Arc<StackingContext>> {
@ -611,7 +596,7 @@ pub fn find_stacking_context_with_layer_id(this: &Arc<StackingContext>, layer_id
} }
/// One drawing command in the list. /// One drawing command in the list.
#[derive(Clone)] #[derive(Clone, HeapSizeOf)]
pub enum DisplayItem { pub enum DisplayItem {
SolidColorClass(Box<SolidColorDisplayItem>), SolidColorClass(Box<SolidColorDisplayItem>),
TextClass(Box<TextDisplayItem>), TextClass(Box<TextDisplayItem>),
@ -623,7 +608,7 @@ pub enum DisplayItem {
} }
/// Information common to all display items. /// Information common to all display items.
#[derive(Clone)] #[derive(Clone, HeapSizeOf)]
pub struct BaseDisplayItem { pub struct BaseDisplayItem {
/// The boundaries of the display item, in layer coordinates. /// The boundaries of the display item, in layer coordinates.
pub bounds: Rect<Au>, pub bounds: Rect<Au>,
@ -647,17 +632,11 @@ impl BaseDisplayItem {
} }
} }
impl HeapSizeOf for BaseDisplayItem {
fn heap_size_of_children(&self) -> usize {
self.metadata.heap_size_of_children() +
self.clip.heap_size_of_children()
}
}
/// A clipping region for a display item. Currently, this can describe rectangles, rounded /// 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 /// 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. /// are not supported because those are handled by the higher-level `StackingContext` abstraction.
#[derive(Clone, PartialEq, Debug)] #[derive(Clone, PartialEq, Debug, HeapSizeOf)]
pub struct ClippingRegion { pub struct ClippingRegion {
/// The main rectangular region. This does not include any corners. /// The main rectangular region. This does not include any corners.
pub main: Rect<Au>, pub main: Rect<Au>,
@ -671,7 +650,7 @@ pub struct ClippingRegion {
/// A complex clipping region. These don't as easily admit arbitrary intersection operations, so /// 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 /// 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. /// rounded rectangle, but the CSS WGs will probably make us throw more stuff in here eventually.
#[derive(Clone, PartialEq, Debug)] #[derive(Clone, PartialEq, Debug, HeapSizeOf)]
pub struct ComplexClippingRegion { pub struct ComplexClippingRegion {
/// The boundaries of the rectangle. /// The boundaries of the rectangle.
pub rect: Rect<Au>, pub rect: Rect<Au>,
@ -779,27 +758,17 @@ impl ClippingRegion {
} }
} }
impl HeapSizeOf for ClippingRegion {
fn heap_size_of_children(&self) -> usize {
self.complex.heap_size_of_children()
}
}
impl HeapSizeOf for ComplexClippingRegion {
fn heap_size_of_children(&self) -> usize {
0
}
}
/// Metadata attached to each display item. This is useful for performing auxiliary tasks with /// Metadata attached to each display item. This is useful for performing auxiliary tasks with
/// the display list involving hit testing: finding the originating DOM node and determining the /// the display list involving hit testing: finding the originating DOM node and determining the
/// cursor to use when the element is hovered over. /// cursor to use when the element is hovered over.
#[derive(Clone, Copy)] #[derive(Clone, Copy, HeapSizeOf)]
pub struct DisplayItemMetadata { pub struct DisplayItemMetadata {
/// The DOM node from which this display item originated. /// The DOM node from which this display item originated.
pub node: OpaqueNode, pub node: OpaqueNode,
/// The value of the `cursor` property when the mouse hovers over this display item. If `None`, /// The value of the `cursor` property when the mouse hovers over this display item. If `None`,
/// this display item is ineligible for pointer events (`pointer-events: none`). /// this display item is ineligible for pointer events (`pointer-events: none`).
#[ignore_heap_size]
pub pointing: Option<Cursor>, pub pointing: Option<Cursor>,
} }
@ -822,41 +791,33 @@ impl DisplayItemMetadata {
} }
} }
impl HeapSizeOf for DisplayItemMetadata {
fn heap_size_of_children(&self) -> usize {
0
}
}
/// Paints a solid color. /// Paints a solid color.
#[derive(Clone)] #[derive(Clone, HeapSizeOf)]
pub struct SolidColorDisplayItem { pub struct SolidColorDisplayItem {
/// Fields common to all display items. /// Fields common to all display items.
pub base: BaseDisplayItem, pub base: BaseDisplayItem,
/// The color. /// The color.
#[ignore_heap_size]
pub color: Color, pub color: Color,
} }
impl HeapSizeOf for SolidColorDisplayItem {
fn heap_size_of_children(&self) -> usize {
self.base.heap_size_of_children()
}
}
/// Paints text. /// Paints text.
#[derive(Clone)] #[derive(Clone, HeapSizeOf)]
pub struct TextDisplayItem { pub struct TextDisplayItem {
/// Fields common to all display items. /// Fields common to all display items.
pub base: BaseDisplayItem, pub base: BaseDisplayItem,
/// The text run. /// The text run.
#[ignore_heap_size] // We exclude `text_run` because it is non-owning.
pub text_run: Arc<Box<TextRun>>, pub text_run: Arc<Box<TextRun>>,
/// The range of text within the text run. /// The range of text within the text run.
#[ignore_heap_size]
pub range: Range<CharIndex>, pub range: Range<CharIndex>,
/// The color of the text. /// The color of the text.
#[ignore_heap_size]
pub text_color: Color, pub text_color: Color,
/// The position of the start of the baseline of this text. /// The position of the start of the baseline of this text.
@ -869,14 +830,7 @@ pub struct TextDisplayItem {
pub blur_radius: Au, pub blur_radius: Au,
} }
impl HeapSizeOf for TextDisplayItem { #[derive(Clone, Eq, PartialEq, HeapSizeOf)]
fn heap_size_of_children(&self) -> usize {
self.base.heap_size_of_children()
// We exclude `text_run` because it is non-owning.
}
}
#[derive(Clone, Eq, PartialEq)]
pub enum TextOrientation { pub enum TextOrientation {
Upright, Upright,
SidewaysLeft, SidewaysLeft,
@ -884,9 +838,10 @@ pub enum TextOrientation {
} }
/// Paints an image. /// Paints an image.
#[derive(Clone)] #[derive(Clone, HeapSizeOf)]
pub struct ImageDisplayItem { pub struct ImageDisplayItem {
pub base: BaseDisplayItem, pub base: BaseDisplayItem,
#[ignore_heap_size] // We exclude `image` here because it is non-owning.
pub image: Arc<Image>, pub image: Arc<Image>,
/// The dimensions to which the image display item should be stretched. If this is smaller than /// The dimensions to which the image display item should be stretched. If this is smaller than
@ -896,15 +851,10 @@ pub struct ImageDisplayItem {
/// The algorithm we should use to stretch the image. See `image_rendering` in CSS-IMAGES-3 § /// The algorithm we should use to stretch the image. See `image_rendering` in CSS-IMAGES-3 §
/// 5.3. /// 5.3.
#[ignore_heap_size]
pub image_rendering: image_rendering::T, pub image_rendering: image_rendering::T,
} }
impl HeapSizeOf for ImageDisplayItem {
fn heap_size_of_children(&self) -> usize {
self.base.heap_size_of_children()
// We exclude `image` here because it is non-owning.
}
}
/// Paints a gradient. /// Paints a gradient.
#[derive(Clone)] #[derive(Clone)]
@ -922,6 +872,7 @@ pub struct GradientDisplayItem {
pub stops: Vec<GradientStop>, pub stops: Vec<GradientStop>,
} }
impl HeapSizeOf for GradientDisplayItem { impl HeapSizeOf for GradientDisplayItem {
fn heap_size_of_children(&self) -> usize { fn heap_size_of_children(&self) -> usize {
use libc::c_void; use libc::c_void;
@ -937,7 +888,7 @@ impl HeapSizeOf for GradientDisplayItem {
/// Paints a border. /// Paints a border.
#[derive(Clone)] #[derive(Clone, HeapSizeOf)]
pub struct BorderDisplayItem { pub struct BorderDisplayItem {
/// Fields common to all display items. /// Fields common to all display items.
pub base: BaseDisplayItem, pub base: BaseDisplayItem,
@ -946,9 +897,11 @@ pub struct BorderDisplayItem {
pub border_widths: SideOffsets2D<Au>, pub border_widths: SideOffsets2D<Au>,
/// Border colors. /// Border colors.
#[ignore_heap_size]
pub color: SideOffsets2D<Color>, pub color: SideOffsets2D<Color>,
/// Border styles. /// Border styles.
#[ignore_heap_size]
pub style: SideOffsets2D<border_style::T>, pub style: SideOffsets2D<border_style::T>,
/// Border radii. /// Border radii.
@ -957,12 +910,6 @@ pub struct BorderDisplayItem {
pub radius: BorderRadii<Au>, pub radius: BorderRadii<Au>,
} }
impl HeapSizeOf for BorderDisplayItem {
fn heap_size_of_children(&self) -> usize {
self.base.heap_size_of_children()
}
}
/// Information about the border radii. /// Information about the border radii.
/// ///
/// TODO(pcwalton): Elliptical radii. /// TODO(pcwalton): Elliptical radii.
@ -996,25 +943,21 @@ impl<T> BorderRadii<T> where T: PartialEq + Zero + Clone {
} }
/// Paints a line segment. /// Paints a line segment.
#[derive(Clone)] #[derive(Clone, HeapSizeOf)]
pub struct LineDisplayItem { pub struct LineDisplayItem {
pub base: BaseDisplayItem, pub base: BaseDisplayItem,
/// The line segment color. /// The line segment color.
#[ignore_heap_size]
pub color: Color, pub color: Color,
/// The line segment style. /// The line segment style.
#[ignore_heap_size]
pub style: border_style::T pub style: border_style::T
} }
impl HeapSizeOf for LineDisplayItem {
fn heap_size_of_children(&self) -> usize {
self.base.heap_size_of_children()
}
}
/// Paints a box shadow per CSS-BACKGROUNDS. /// Paints a box shadow per CSS-BACKGROUNDS.
#[derive(Clone)] #[derive(Clone, HeapSizeOf)]
pub struct BoxShadowDisplayItem { pub struct BoxShadowDisplayItem {
/// Fields common to all display items. /// Fields common to all display items.
pub base: BaseDisplayItem, pub base: BaseDisplayItem,
@ -1026,6 +969,7 @@ pub struct BoxShadowDisplayItem {
pub offset: Point2D<Au>, pub offset: Point2D<Au>,
/// The color of this shadow. /// The color of this shadow.
#[ignore_heap_size]
pub color: Color, pub color: Color,
/// The blur radius for this shadow. /// The blur radius for this shadow.
@ -1038,14 +982,8 @@ pub struct BoxShadowDisplayItem {
pub clip_mode: BoxShadowClipMode, pub clip_mode: BoxShadowClipMode,
} }
impl HeapSizeOf for BoxShadowDisplayItem {
fn heap_size_of_children(&self) -> usize {
self.base.heap_size_of_children()
}
}
/// How a box shadow should be clipped. /// How a box shadow should be clipped.
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq, HeapSizeOf)]
pub enum BoxShadowClipMode { pub enum BoxShadowClipMode {
/// No special clipping should occur. This is used for (shadowed) text decorations. /// No special clipping should occur. This is used for (shadowed) text decorations.
None, None,
@ -1206,17 +1144,4 @@ impl fmt::Debug for DisplayItem {
} }
} }
impl HeapSizeOf for DisplayItem {
fn heap_size_of_children(&self) -> usize {
match *self {
SolidColorClass(ref item) => item.heap_size_of_children(),
TextClass(ref item) => item.heap_size_of_children(),
ImageClass(ref item) => item.heap_size_of_children(),
BorderClass(ref item) => item.heap_size_of_children(),
GradientClass(ref item) => item.heap_size_of_children(),
LineClass(ref item) => item.heap_size_of_children(),
BoxShadowClass(ref item) => item.heap_size_of_children(),
}
}
}

View file

@ -9,6 +9,11 @@ use std::collections::LinkedList;
use std::mem::transmute; use std::mem::transmute;
use std::sync::Arc; use std::sync::Arc;
use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D};
use geometry::Au;
use range::Range;
extern { extern {
// Get the size of a heap block. // Get the size of a heap block.
// //
@ -172,17 +177,24 @@ macro_rules! known_heap_size(
} }
)+ )+
); );
($size: expr, $ty:ident<$($gen:ident),+>) => ( ($size: expr, $($ty:ident<$($gen:ident),+>),+) => (
impl<$($gen),+> $crate::mem::HeapSizeOf for $ty<$($gen),+> { $(
impl<$($gen: $crate::mem::HeapSizeOf),+> $crate::mem::HeapSizeOf for $ty<$($gen),+> {
#[inline(always)] #[inline(always)]
fn heap_size_of_children(&self) -> usize { fn heap_size_of_children(&self) -> usize {
$size $size
} }
} }
)+
); );
); );
known_heap_size!(0, u8, u16, u32, u64, usize); known_heap_size!(0, u8, u16, u32, u64, usize);
known_heap_size!(0, i8, i16, i32, i64, isize); known_heap_size!(0, i8, i16, i32, i64, isize);
known_heap_size!(0, bool); known_heap_size!(0, bool, f32, f64);
known_heap_size!(0, Rect<T>, Point2D<T>, Size2D<T>, Matrix2D<T>, SideOffsets2D<T>);
known_heap_size!(0, Au);
known_heap_size!(0, Range<T>);