mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
use knownheapsize for geom stuff
This commit is contained in:
parent
c1daf889af
commit
a5975e8f33
2 changed files with 48 additions and 111 deletions
|
@ -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<DisplayItem>,
|
||||
|
@ -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<DisplayList>,
|
||||
|
||||
/// The layer for this stacking context, if there is one.
|
||||
#[ignore_heap_size]
|
||||
pub layer: Option<Arc<PaintLayer>>,
|
||||
|
||||
/// 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<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.
|
||||
pub fn find_stacking_context_with_layer_id(this: &Arc<StackingContext>, layer_id: LayerId)
|
||||
-> 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.
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, HeapSizeOf)]
|
||||
pub enum DisplayItem {
|
||||
SolidColorClass(Box<SolidColorDisplayItem>),
|
||||
TextClass(Box<TextDisplayItem>),
|
||||
|
@ -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<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
|
||||
/// 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<Au>,
|
||||
|
@ -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<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
|
||||
/// 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<Cursor>,
|
||||
}
|
||||
|
||||
|
@ -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<Box<TextRun>>,
|
||||
|
||||
/// The range of text within the text run.
|
||||
#[ignore_heap_size]
|
||||
pub range: Range<CharIndex>,
|
||||
|
||||
/// 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<Image>,
|
||||
|
||||
/// 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<GradientStop>,
|
||||
}
|
||||
|
||||
|
||||
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<Au>,
|
||||
|
||||
/// Border colors.
|
||||
#[ignore_heap_size]
|
||||
pub color: SideOffsets2D<Color>,
|
||||
|
||||
/// Border styles.
|
||||
#[ignore_heap_size]
|
||||
pub style: SideOffsets2D<border_style::T>,
|
||||
|
||||
/// Border radii.
|
||||
|
@ -957,12 +910,6 @@ pub struct BorderDisplayItem {
|
|||
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.
|
||||
///
|
||||
/// TODO(pcwalton): Elliptical radii.
|
||||
|
@ -996,25 +943,21 @@ impl<T> BorderRadii<T> 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<Au>,
|
||||
|
||||
/// 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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<T>, Point2D<T>, Size2D<T>, Matrix2D<T>, SideOffsets2D<T>);
|
||||
|
||||
known_heap_size!(0, Au);
|
||||
known_heap_size!(0, Range<T>);
|
Loading…
Add table
Add a link
Reference in a new issue