Skip to content

Commit

Permalink
Auto merge of #6583 - pcwalton:serializable-display-list, r=metajack
Browse files Browse the repository at this point in the history
gfx: Make display lists serializable using `serde`.

This commit introduces the `serde` dependency, which we will use to
serialize messages going between processes in multiprocess Servo.

This also adds a new debugging flag, `-Z print-display-list-json`,
allowing the output of display list serialization to be visualized.
This will be useful for our experiments with alternate rasterizers.

r? @metajack

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6583)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Jul 15, 2015
2 parents b6b9508 + 6eacb0c commit ef97152
Show file tree
Hide file tree
Showing 30 changed files with 320 additions and 124 deletions.
2 changes: 2 additions & 0 deletions components/gfx/Cargo.toml
Expand Up @@ -57,6 +57,8 @@ harfbuzz = "0.1"
smallvec = "0.1"
string_cache = "0.1"
euclid = "0.1"
serde = "*"
serde_macros = "*"

[target.x86_64-apple-darwin.dependencies]
core-foundation = "*"
Expand Down
134 changes: 69 additions & 65 deletions components/gfx/display_list/mod.rs
Expand Up @@ -25,28 +25,27 @@ use text::TextRun;

use azure::azure::AzFloat;
use azure::azure_hl::Color;

use std::collections::linked_list::{self, LinkedList};
use euclid::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D, Matrix4};
use euclid::approxeq::ApproxEq;
use euclid::num::Zero;
use euclid::{Point2D, Rect, SideOffsets2D, Size2D, Matrix2D, Matrix4};
use libc::uintptr_t;
use paint_task::PaintLayer;
use msg::compositor_msg::{LayerId, LayerKind};
use net_traits::image::base::Image;
use util::opts;
use util::cursor::Cursor;
use util::linked_list::prepend_from;
use util::geometry::{self, Au, MAX_RECT, ZERO_RECT};
use util::mem::HeapSizeOf;
use util::range::Range;
use paint_task::PaintLayer;
use smallvec::SmallVec8;
use std::collections::linked_list::{self, LinkedList};
use std::fmt;
use std::slice::Iter;
use std::sync::Arc;
use style::computed_values::{border_style, cursor, filter, image_rendering, mix_blend_mode};
use style::computed_values::{pointer_events};
use style::properties::ComputedValues;
use util::cursor::Cursor;
use util::geometry::{self, Au, MAX_RECT, ZERO_RECT};
use util::linked_list::{SerializableLinkedList, prepend_from};
use util::mem::HeapSizeOf;
use util::opts;
use util::range::Range;

// It seems cleaner to have layout code not mention Azure directly, so let's just reexport this for
// layout to use.
Expand All @@ -66,7 +65,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, HeapSizeOf)]
#[derive(Clone, PartialEq, Copy, Debug, HeapSizeOf, Deserialize, Serialize)]
pub struct OpaqueNode(pub uintptr_t);

impl OpaqueNode {
Expand All @@ -82,71 +81,71 @@ 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)]
#[derive(HeapSizeOf, Deserialize, Serialize)]
pub struct DisplayList {
/// 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: SerializableLinkedList<DisplayItem>,
/// Borders and backgrounds for block-level descendants: step 4.
pub block_backgrounds_and_borders: LinkedList<DisplayItem>,
pub block_backgrounds_and_borders: SerializableLinkedList<DisplayItem>,
/// Floats: step 5. These are treated as pseudo-stacking contexts.
pub floats: LinkedList<DisplayItem>,
pub floats: SerializableLinkedList<DisplayItem>,
/// All non-positioned content.
pub content: LinkedList<DisplayItem>,
pub content: SerializableLinkedList<DisplayItem>,
/// All positioned content that does not get a stacking context.
pub positioned_content: LinkedList<DisplayItem>,
pub positioned_content: SerializableLinkedList<DisplayItem>,
/// Outlines: step 10.
pub outlines: LinkedList<DisplayItem>,
pub outlines: SerializableLinkedList<DisplayItem>,
/// Child stacking contexts.
pub children: LinkedList<Arc<StackingContext>>,
pub children: SerializableLinkedList<Arc<StackingContext>>,
}

impl DisplayList {
/// Creates a new, empty display list.
#[inline]
pub fn new() -> DisplayList {
DisplayList {
background_and_borders: LinkedList::new(),
block_backgrounds_and_borders: LinkedList::new(),
floats: LinkedList::new(),
content: LinkedList::new(),
positioned_content: LinkedList::new(),
outlines: LinkedList::new(),
children: LinkedList::new(),
background_and_borders: SerializableLinkedList::new(LinkedList::new()),
block_backgrounds_and_borders: SerializableLinkedList::new(LinkedList::new()),
floats: SerializableLinkedList::new(LinkedList::new()),
content: SerializableLinkedList::new(LinkedList::new()),
positioned_content: SerializableLinkedList::new(LinkedList::new()),
outlines: SerializableLinkedList::new(LinkedList::new()),
children: SerializableLinkedList::new(LinkedList::new()),
}
}

/// Appends all display items from `other` into `self`, preserving stacking order and emptying
/// `other` in the process.
#[inline]
pub fn append_from(&mut self, other: &mut DisplayList) {
self.background_and_borders.append(&mut other.background_and_borders);
self.block_backgrounds_and_borders.append(&mut other.block_backgrounds_and_borders);
self.floats.append(&mut other.floats);
self.content.append(&mut other.content);
self.positioned_content.append(&mut other.positioned_content);
self.outlines.append(&mut other.outlines);
self.children.append(&mut other.children);
self.background_and_borders.append(&mut *other.background_and_borders);
self.block_backgrounds_and_borders.append(&mut *other.block_backgrounds_and_borders);
self.floats.append(&mut *other.floats);
self.content.append(&mut *other.content);
self.positioned_content.append(&mut *other.positioned_content);
self.outlines.append(&mut *other.outlines);
self.children.append(&mut *other.children);
}

/// Merges all display items from all non-float stacking levels to the `float` stacking level.
#[inline]
pub fn form_float_pseudo_stacking_context(&mut self) {
prepend_from(&mut self.floats, &mut self.outlines);
prepend_from(&mut self.floats, &mut self.positioned_content);
prepend_from(&mut self.floats, &mut self.content);
prepend_from(&mut self.floats, &mut self.block_backgrounds_and_borders);
prepend_from(&mut self.floats, &mut self.background_and_borders);
prepend_from(&mut *self.floats, &mut *self.outlines);
prepend_from(&mut *self.floats, &mut *self.positioned_content);
prepend_from(&mut *self.floats, &mut *self.content);
prepend_from(&mut *self.floats, &mut *self.block_backgrounds_and_borders);
prepend_from(&mut *self.floats, &mut *self.background_and_borders);
}

/// Merges all display items from all non-positioned-content stacking levels to the
/// positioned-content stacking level.
#[inline]
pub fn form_pseudo_stacking_context_for_positioned_content(&mut self) {
prepend_from(&mut self.positioned_content, &mut self.outlines);
prepend_from(&mut self.positioned_content, &mut self.content);
prepend_from(&mut self.positioned_content, &mut self.floats);
prepend_from(&mut self.positioned_content, &mut self.block_backgrounds_and_borders);
prepend_from(&mut self.positioned_content, &mut self.background_and_borders);
prepend_from(&mut *self.positioned_content, &mut *self.outlines);
prepend_from(&mut *self.positioned_content, &mut *self.content);
prepend_from(&mut *self.positioned_content, &mut *self.floats);
prepend_from(&mut *self.positioned_content, &mut *self.block_backgrounds_and_borders);
prepend_from(&mut *self.positioned_content, &mut *self.background_and_borders);
}

/// Returns a list of all items in this display list concatenated together. This is extremely
Expand Down Expand Up @@ -219,7 +218,7 @@ impl DisplayList {
}
}

#[derive(HeapSizeOf)]
#[derive(HeapSizeOf, Deserialize, Serialize)]
/// 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.
Expand Down Expand Up @@ -443,7 +442,8 @@ impl StackingContext {

} else {
// Optimize the display list to throw out out-of-bounds display items and so forth.
let display_list = DisplayListOptimizer::new(tile_bounds).optimize(&*self.display_list);
let display_list =
DisplayListOptimizer::new(tile_bounds).optimize(&*self.display_list);

self.draw_into_context(&display_list,
paint_context,
Expand Down Expand Up @@ -515,12 +515,16 @@ impl StackingContext {
// If the point is inside the border, it didn't hit the border!
let interior_rect =
Rect::new(
Point2D::new(border.base.bounds.origin.x + border.border_widths.left,
border.base.bounds.origin.y + border.border_widths.top),
Point2D::new(border.base.bounds.origin.x +
border.border_widths.left,
border.base.bounds.origin.y +
border.border_widths.top),
Size2D::new(border.base.bounds.size.width -
(border.border_widths.left + border.border_widths.right),
(border.border_widths.left +
border.border_widths.right),
border.base.bounds.size.height -
(border.border_widths.top + border.border_widths.bottom)));
(border.border_widths.top +
border.border_widths.bottom)));
if geometry::rect_contains_point(interior_rect, point) {
continue
}
Expand All @@ -541,7 +545,7 @@ impl StackingContext {

debug_assert!(!topmost_only || result.is_empty());
let frac_point = self.transform.transform_point(&Point2D::new(point.x.to_f32_px(),
point.y.to_f32_px()));
point.y.to_f32_px()));
point = Point2D::new(Au::from_f32_px(frac_point.x), Au::from_f32_px(frac_point.y));

// Iterate through display items in reverse stacking order. Steps here refer to the
Expand Down Expand Up @@ -639,7 +643,7 @@ pub fn find_stacking_context_with_layer_id(this: &Arc<StackingContext>, layer_id
}

/// One drawing command in the list.
#[derive(Clone, HeapSizeOf)]
#[derive(Clone, Deserialize, HeapSizeOf, Serialize)]
pub enum DisplayItem {
SolidColorClass(Box<SolidColorDisplayItem>),
TextClass(Box<TextDisplayItem>),
Expand All @@ -651,7 +655,7 @@ pub enum DisplayItem {
}

/// Information common to all display items.
#[derive(Clone, HeapSizeOf)]
#[derive(Clone, Deserialize, HeapSizeOf, Serialize)]
pub struct BaseDisplayItem {
/// The boundaries of the display item, in layer coordinates.
pub bounds: Rect<Au>,
Expand Down Expand Up @@ -679,7 +683,7 @@ 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, PartialEq, Debug, HeapSizeOf)]
#[derive(Clone, PartialEq, Debug, HeapSizeOf, Deserialize, Serialize)]
pub struct ClippingRegion {
/// The main rectangular region. This does not include any corners.
pub main: Rect<Au>,
Expand All @@ -693,7 +697,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, HeapSizeOf)]
#[derive(Clone, PartialEq, Debug, HeapSizeOf, Deserialize, Serialize)]
pub struct ComplexClippingRegion {
/// The boundaries of the rectangle.
pub rect: Rect<Au>,
Expand Down Expand Up @@ -805,7 +809,7 @@ impl ClippingRegion {
/// 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, HeapSizeOf)]
#[derive(Clone, Copy, HeapSizeOf, Deserialize, Serialize)]
pub struct DisplayItemMetadata {
/// The DOM node from which this display item originated.
pub node: OpaqueNode,
Expand Down Expand Up @@ -834,7 +838,7 @@ impl DisplayItemMetadata {
}

/// Paints a solid color.
#[derive(Clone, HeapSizeOf)]
#[derive(Clone, HeapSizeOf, Deserialize, Serialize)]
pub struct SolidColorDisplayItem {
/// Fields common to all display items.
pub base: BaseDisplayItem,
Expand All @@ -844,7 +848,7 @@ pub struct SolidColorDisplayItem {
}

/// Paints text.
#[derive(Clone, HeapSizeOf)]
#[derive(Clone, HeapSizeOf, Deserialize, Serialize)]
pub struct TextDisplayItem {
/// Fields common to all display items.
pub base: BaseDisplayItem,
Expand All @@ -869,15 +873,15 @@ pub struct TextDisplayItem {
pub blur_radius: Au,
}

#[derive(Clone, Eq, PartialEq, HeapSizeOf)]
#[derive(Clone, Eq, PartialEq, HeapSizeOf, Deserialize, Serialize)]
pub enum TextOrientation {
Upright,
SidewaysLeft,
SidewaysRight,
}

/// Paints an image.
#[derive(Clone, HeapSizeOf)]
#[derive(Clone, HeapSizeOf, Deserialize, Serialize)]
pub struct ImageDisplayItem {
pub base: BaseDisplayItem,
#[ignore_heap_size_of = "Because it is non-owning"]
Expand All @@ -895,7 +899,7 @@ pub struct ImageDisplayItem {


/// Paints a gradient.
#[derive(Clone)]
#[derive(Clone, Deserialize, Serialize)]
pub struct GradientDisplayItem {
/// Fields common to all display items.
pub base: BaseDisplayItem,
Expand Down Expand Up @@ -926,7 +930,7 @@ impl HeapSizeOf for GradientDisplayItem {


/// Paints a border.
#[derive(Clone, HeapSizeOf)]
#[derive(Clone, HeapSizeOf, Deserialize, Serialize)]
pub struct BorderDisplayItem {
/// Fields common to all display items.
pub base: BaseDisplayItem,
Expand All @@ -949,7 +953,7 @@ pub struct BorderDisplayItem {
/// Information about the border radii.
///
/// TODO(pcwalton): Elliptical radii.
#[derive(Clone, Default, PartialEq, Debug, Copy, HeapSizeOf)]
#[derive(Clone, Default, PartialEq, Debug, Copy, HeapSizeOf, Deserialize, Serialize)]
pub struct BorderRadii<T> {
pub top_left: T,
pub top_right: T,
Expand Down Expand Up @@ -979,7 +983,7 @@ impl<T> BorderRadii<T> where T: PartialEq + Zero + Clone {
}

/// Paints a line segment.
#[derive(Clone, HeapSizeOf)]
#[derive(Clone, HeapSizeOf, Deserialize, Serialize)]
pub struct LineDisplayItem {
pub base: BaseDisplayItem,

Expand All @@ -991,7 +995,7 @@ pub struct LineDisplayItem {
}

/// Paints a box shadow per CSS-BACKGROUNDS.
#[derive(Clone, HeapSizeOf)]
#[derive(Clone, HeapSizeOf, Deserialize, Serialize)]
pub struct BoxShadowDisplayItem {
/// Fields common to all display items.
pub base: BaseDisplayItem,
Expand All @@ -1016,7 +1020,7 @@ pub struct BoxShadowDisplayItem {
}

/// How a box shadow should be clipped.
#[derive(Clone, Copy, Debug, PartialEq, HeapSizeOf)]
#[derive(Clone, Copy, Debug, PartialEq, HeapSizeOf, Deserialize, Serialize)]
pub enum BoxShadowClipMode {
/// No special clipping should occur. This is used for (shadowed) text decorations.
None,
Expand Down
3 changes: 2 additions & 1 deletion components/gfx/display_list/optimizer.rs
Expand Up @@ -37,7 +37,8 @@ impl DisplayListOptimizer {
self.add_in_bounds_display_items(&mut result.content, display_list.content.iter());
self.add_in_bounds_display_items(&mut result.positioned_content,
display_list.positioned_content.iter());
self.add_in_bounds_display_items(&mut result.outlines, display_list.outlines.iter());
self.add_in_bounds_display_items(&mut result.outlines,
display_list.outlines.iter());
self.add_in_bounds_stacking_contexts(&mut result.children, display_list.children.iter());
result
}
Expand Down
2 changes: 1 addition & 1 deletion components/gfx/font.rs
Expand Up @@ -69,7 +69,7 @@ pub trait FontTableMethods {
fn with_buffer<F>(&self, F) where F: FnOnce(*const u8, usize);
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct FontMetrics {
pub underline_size: Au,
pub underline_offset: Au,
Expand Down
2 changes: 2 additions & 0 deletions components/gfx/lib.rs
Expand Up @@ -14,9 +14,11 @@
#![feature(vec_push_all)]

#![plugin(plugins)]
#![plugin(serde_macros)]

#[macro_use]
extern crate log;
extern crate serde;

extern crate azure;
#[macro_use] extern crate bitflags;
Expand Down

0 comments on commit ef97152

Please sign in to comment.