diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 393b909ed96..6e085ebb66c 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -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 /// data structures. Also, layout code tends to be faster when the DOM is not being accessed, for /// locality reasons. Using `OpaqueNode` enforces this invariant. -#[derive(Clone, PartialEq, Copy, Debug)] +#[derive(Clone, PartialEq, Copy, Debug, HeapSizeOf)] pub struct OpaqueNode(pub uintptr_t); impl OpaqueNode { @@ -82,6 +82,7 @@ impl OpaqueNode { /// /// TODO(pcwalton): We could reduce the size of this structure with a more "skip list"-like /// structure, omitting several pointers and lengths. +#[derive(HeapSizeOf)] pub struct DisplayList { /// The border and backgrounds for the root of this stacking context: steps 1 and 2. pub background_and_borders: LinkedList, @@ -218,24 +219,15 @@ impl DisplayList { } } -impl HeapSizeOf for DisplayList { - fn heap_size_of_children(&self) -> usize { - 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() - } -} - +// FIXME(njn): other fields may be measured later, esp. `layer` +#[derive(HeapSizeOf)] /// Represents one CSS stacking context, which may or may not have a hardware layer. pub struct StackingContext { /// The display items that make up this stacking context. pub display_list: Box, /// The layer for this stacking context, if there is one. + #[ignore_heap_size] pub layer: Option>, /// The position and size of this stacking context. @@ -248,13 +240,14 @@ pub struct StackingContext { pub z_index: i32, /// CSS filters to be applied to this stacking context (including opacity). + #[ignore_heap_size] pub filters: filter::T, /// The blend mode with which this stacking context blends with its backdrop. + #[ignore_heap_size] pub blend_mode: mix_blend_mode::T, /// A transform to be applied to this stacking context. - #[ignore_heap_size] pub transform: Matrix2D, } @@ -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. pub fn find_stacking_context_with_layer_id(this: &Arc, layer_id: LayerId) -> Option> { @@ -611,7 +596,7 @@ pub fn find_stacking_context_with_layer_id(this: &Arc, layer_id } /// One drawing command in the list. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub enum DisplayItem { SolidColorClass(Box), TextClass(Box), @@ -623,7 +608,7 @@ pub enum DisplayItem { } /// Information common to all display items. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct BaseDisplayItem { /// The boundaries of the display item, in layer coordinates. pub bounds: Rect, @@ -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 /// 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, PartialEq, Debug)] +#[derive(Clone, PartialEq, Debug, HeapSizeOf)] pub struct ClippingRegion { /// The main rectangular region. This does not include any corners. pub main: Rect, @@ -671,7 +650,7 @@ pub struct ClippingRegion { /// 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, PartialEq, Debug)] +#[derive(Clone, PartialEq, Debug, HeapSizeOf)] pub struct ComplexClippingRegion { /// The boundaries of the rectangle. pub rect: Rect, @@ -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 /// the display list involving hit testing: finding the originating DOM node and determining the /// cursor to use when the element is hovered over. -#[derive(Clone, Copy)] +#[derive(Clone, Copy, HeapSizeOf)] pub struct DisplayItemMetadata { /// The DOM node from which this display item originated. pub node: OpaqueNode, /// 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`). + #[ignore_heap_size] pub pointing: Option, } @@ -822,41 +791,33 @@ impl DisplayItemMetadata { } } -impl HeapSizeOf for DisplayItemMetadata { - fn heap_size_of_children(&self) -> usize { - 0 - } -} - /// Paints a solid color. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct SolidColorDisplayItem { /// Fields common to all display items. pub base: BaseDisplayItem, /// The color. + #[ignore_heap_size] pub color: Color, } -impl HeapSizeOf for SolidColorDisplayItem { - fn heap_size_of_children(&self) -> usize { - self.base.heap_size_of_children() - } -} - /// Paints text. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct TextDisplayItem { /// Fields common to all display items. pub base: BaseDisplayItem, /// The text run. + #[ignore_heap_size] // We exclude `text_run` because it is non-owning. pub text_run: Arc>, /// The range of text within the text run. + #[ignore_heap_size] pub range: Range, /// The color of the text. + #[ignore_heap_size] pub text_color: Color, /// The position of the start of the baseline of this text. @@ -869,14 +830,7 @@ pub struct TextDisplayItem { pub blur_radius: Au, } -impl HeapSizeOf for TextDisplayItem { - 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)] +#[derive(Clone, Eq, PartialEq, HeapSizeOf)] pub enum TextOrientation { Upright, SidewaysLeft, @@ -884,9 +838,10 @@ pub enum TextOrientation { } /// Paints an image. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct ImageDisplayItem { pub base: BaseDisplayItem, + #[ignore_heap_size] // We exclude `image` here because it is non-owning. pub image: Arc, /// 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 ยง /// 5.3. + #[ignore_heap_size] 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. #[derive(Clone)] @@ -922,6 +872,7 @@ pub struct GradientDisplayItem { pub stops: Vec, } + impl HeapSizeOf for GradientDisplayItem { fn heap_size_of_children(&self) -> usize { use libc::c_void; @@ -937,7 +888,7 @@ impl HeapSizeOf for GradientDisplayItem { /// Paints a border. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct BorderDisplayItem { /// Fields common to all display items. pub base: BaseDisplayItem, @@ -946,9 +897,11 @@ pub struct BorderDisplayItem { pub border_widths: SideOffsets2D, /// Border colors. + #[ignore_heap_size] pub color: SideOffsets2D, /// Border styles. + #[ignore_heap_size] pub style: SideOffsets2D, /// Border radii. @@ -957,12 +910,6 @@ pub struct BorderDisplayItem { pub radius: BorderRadii, } -impl HeapSizeOf for BorderDisplayItem { - fn heap_size_of_children(&self) -> usize { - self.base.heap_size_of_children() - } -} - /// Information about the border radii. /// /// TODO(pcwalton): Elliptical radii. @@ -996,25 +943,21 @@ impl BorderRadii where T: PartialEq + Zero + Clone { } /// Paints a line segment. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct LineDisplayItem { pub base: BaseDisplayItem, /// The line segment color. + #[ignore_heap_size] pub color: Color, /// The line segment style. + #[ignore_heap_size] 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. -#[derive(Clone)] +#[derive(Clone, HeapSizeOf)] pub struct BoxShadowDisplayItem { /// Fields common to all display items. pub base: BaseDisplayItem, @@ -1026,6 +969,7 @@ pub struct BoxShadowDisplayItem { pub offset: Point2D, /// The color of this shadow. + #[ignore_heap_size] pub color: Color, /// The blur radius for this shadow. @@ -1038,14 +982,8 @@ pub struct BoxShadowDisplayItem { 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. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, HeapSizeOf)] pub enum BoxShadowClipMode { /// No special clipping should occur. This is used for (shadowed) text decorations. 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(), - } - } -} diff --git a/components/util/mem.rs b/components/util/mem.rs index 8bbfb909199..6c9f04af984 100644 --- a/components/util/mem.rs +++ b/components/util/mem.rs @@ -9,6 +9,11 @@ use std::collections::LinkedList; use std::mem::transmute; use std::sync::Arc; +use geom::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D}; + +use geometry::Au; +use range::Range; + extern { // Get the size of a heap block. // @@ -172,17 +177,24 @@ macro_rules! known_heap_size( } )+ ); - ($size: expr, $ty:ident<$($gen:ident),+>) => ( - impl<$($gen),+> $crate::mem::HeapSizeOf for $ty<$($gen),+> { + ($size: expr, $($ty:ident<$($gen:ident),+>),+) => ( + $( + impl<$($gen: $crate::mem::HeapSizeOf),+> $crate::mem::HeapSizeOf for $ty<$($gen),+> { #[inline(always)] fn heap_size_of_children(&self) -> usize { $size } } + )+ ); ); known_heap_size!(0, u8, u16, u32, u64, usize); 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, Point2D, Size2D, Matrix2D, SideOffsets2D); + +known_heap_size!(0, Au); +known_heap_size!(0, Range); \ No newline at end of file