diff options
Diffstat (limited to 'components/layout')
-rw-r--r-- | components/layout/display_list/border.rs | 4 | ||||
-rw-r--r-- | components/layout/display_list/builder.rs | 128 | ||||
-rw-r--r-- | components/layout/display_list/conversions.rs | 20 | ||||
-rw-r--r-- | components/layout/display_list/items.rs | 45 | ||||
-rw-r--r-- | components/layout/display_list/webrender_helpers.rs | 197 | ||||
-rw-r--r-- | components/layout/flow.rs | 2 | ||||
-rw-r--r-- | components/layout/fragment.rs | 3 | ||||
-rw-r--r-- | components/layout/query.rs | 2 | ||||
-rw-r--r-- | components/layout/sequential.rs | 26 |
9 files changed, 238 insertions, 189 deletions
diff --git a/components/layout/display_list/border.rs b/components/layout/display_list/border.rs index 848386cb630..fff18fcf6c0 100644 --- a/components/layout/display_list/border.rs +++ b/components/layout/display_list/border.rs @@ -12,8 +12,8 @@ use style::values::computed::{BorderCornerRadius, BorderImageWidth}; use style::values::computed::{BorderImageSideWidth, NonNegativeLengthOrNumber}; use style::values::generics::rect::Rect as StyleRect; use style::values::generics::NonNegative; -use webrender_api::{BorderRadius, BorderSide, BorderStyle, ColorF}; -use webrender_api::{LayoutSideOffsets, LayoutSize, NormalBorder}; +use webrender_api::units::{LayoutSideOffsets, LayoutSize}; +use webrender_api::{BorderRadius, BorderSide, BorderStyle, ColorF, NormalBorder}; /// Computes a border radius size against the containing size. /// diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index 8d32ec01520..e6ead2505ca 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -13,7 +13,7 @@ use crate::context::LayoutContext; use crate::display_list::background::{self, get_cyclic}; use crate::display_list::border; use crate::display_list::gradient; -use crate::display_list::items::{BaseDisplayItem, ClipScrollNode, BLUR_INFLATION_FACTOR}; +use crate::display_list::items::{self, BaseDisplayItem, ClipScrollNode}; use crate::display_list::items::{ClipScrollNodeIndex, ClipScrollNodeType, ClippingAndScrolling}; use crate::display_list::items::{ClippingRegion, DisplayItem, DisplayItemMetadata, DisplayList}; use crate::display_list::items::{CommonDisplayItem, DisplayListSection}; @@ -32,7 +32,7 @@ use crate::table_cell::CollapsedBordersForCell; use app_units::{Au, AU_PER_PX}; use canvas_traits::canvas::{CanvasMsg, FromLayoutMsg}; use embedder_traits::Cursor; -use euclid::{rect, Point2D, Rect, SideOffsets2D, Size2D, TypedRect, TypedSize2D, Vector2D}; +use euclid::{rect, Point2D, Rect, SideOffsets2D, Size2D, TypedRect, TypedSize2D}; use fnv::FnvHashMap; use gfx::text::glyph::ByteIndex; use gfx::text::TextRun; @@ -43,7 +43,7 @@ use net_traits::image_cache::UsePlaceholder; use range::Range; use script_traits::IFrameSize; use servo_config::opts; -use servo_geometry::MaxRect; +use servo_geometry::{self, MaxRect}; use std::default::Default; use std::f32; use std::mem; @@ -64,12 +64,11 @@ use style::values::generics::image::{GradientKind, PaintWorklet}; use style::values::specified::ui::CursorKind; use style::values::{Either, RGBA}; use style_traits::ToCss; -use webrender_api::{ - self, BorderDetails, BorderRadius, BorderSide, BoxShadowClipMode, ColorF, ColorU, - ExternalScrollId, FilterOp, GlyphInstance, ImageRendering, LayoutRect, LayoutSize, - LayoutTransform, LayoutVector2D, LineStyle, NinePatchBorder, NinePatchBorderSource, - NormalBorder, ScrollSensitivity, StickyOffsetBounds, -}; +use webrender_api::units::{LayoutRect, LayoutSize, LayoutTransform, LayoutVector2D}; +use webrender_api::{self, BorderDetails, BorderRadius, BorderSide, BoxShadowClipMode, ColorF}; +use webrender_api::{ColorU, ExternalScrollId, FilterOp, GlyphInstance, ImageRendering, LineStyle}; +use webrender_api::{NinePatchBorder, NinePatchBorderSource, NormalBorder}; +use webrender_api::{ScrollSensitivity, StickyOffsetBounds}; static THREAD_TINT_COLORS: [ColorF; 8] = [ ColorF { @@ -346,7 +345,7 @@ impl<'a> DisplayListBuildState<'a> { } } - fn add_display_item(&mut self, display_item: DisplayItem) { + pub fn add_display_item(&mut self, display_item: DisplayItem) { let items = self .items .entry(display_item.stacking_context_id()) @@ -375,9 +374,8 @@ impl<'a> DisplayListBuildState<'a> { self.processing_scrolling_overflow_element } - fn create_base_display_item( + pub fn create_base_display_item( &self, - bounds: Rect<Au>, clip_rect: Rect<Au>, node: OpaqueNode, cursor: Option<Cursor>, @@ -391,7 +389,6 @@ impl<'a> DisplayListBuildState<'a> { self.current_clipping_and_scrolling }; self.create_base_display_item_with_clipping_and_scrolling( - bounds, clip_rect, node, cursor, @@ -402,7 +399,6 @@ impl<'a> DisplayListBuildState<'a> { fn create_base_display_item_with_clipping_and_scrolling( &self, - bounds: Rect<Au>, clip_rect: Rect<Au>, node: OpaqueNode, cursor: Option<Cursor>, @@ -410,7 +406,6 @@ impl<'a> DisplayListBuildState<'a> { clipping_and_scrolling: ClippingAndScrolling, ) -> BaseDisplayItem { BaseDisplayItem::new( - bounds.to_layout(), DisplayItemMetadata { node, // Store cursor id in display list. @@ -708,7 +703,6 @@ impl Fragment { let base = state.create_base_display_item( bounds, - bounds, self.node, get_cursor(&style, Cursor::Default), display_list_section, @@ -717,6 +711,7 @@ impl Fragment { base, webrender_api::RectangleDisplayItem { color: background_color.to_layout(), + common: items::empty_common_item_properties(), }, ))); }); @@ -844,7 +839,6 @@ impl Fragment { // Create the image display item. let base = state.create_base_display_item( - placement.bounds, placement.clip_rect, self.node, get_cursor(&style, Cursor::Default), @@ -855,6 +849,8 @@ impl Fragment { state.add_image_item( base, webrender_api::ImageDisplayItem { + bounds: placement.bounds.to_f32_px(), + common: items::empty_common_item_properties(), image_key: webrender_image.key.unwrap(), stretch_size: placement.tile_size.to_layout(), tile_spacing: placement.tile_spacing.to_layout(), @@ -959,7 +955,6 @@ impl Fragment { } let base = state.create_base_display_item( - placement.bounds, placement.clip_rect, self.node, get_cursor(&style, Cursor::Default), @@ -977,6 +972,8 @@ impl Fragment { ); let item = webrender_api::GradientDisplayItem { gradient, + bounds: placement.bounds.to_f32_px(), + common: items::empty_common_item_properties(), tile_size: placement.tile_size.to_layout(), tile_spacing: placement.tile_spacing.to_layout(), }; @@ -993,6 +990,8 @@ impl Fragment { ); let item = webrender_api::RadialGradientDisplayItem { gradient, + bounds: placement.bounds.to_f32_px(), + common: items::empty_common_item_properties(), tile_size: placement.tile_size.to_layout(), tile_spacing: placement.tile_spacing.to_layout(), }; @@ -1015,17 +1014,7 @@ impl Fragment { ) { // NB: According to CSS-BACKGROUNDS, box shadows render in *reverse* order (front to back). for box_shadow in style.get_effects().box_shadow.0.iter().rev() { - let bounds = shadow_bounds( - absolute_bounds.translate(&Vector2D::new( - Au::from(box_shadow.base.horizontal), - Au::from(box_shadow.base.vertical), - )), - Au::from(box_shadow.base.blur), - Au::from(box_shadow.spread), - ); - let base = state.create_base_display_item( - bounds, clip, self.node, get_cursor(&style, Cursor::Default), @@ -1035,6 +1024,7 @@ impl Fragment { state.add_display_item(DisplayItem::BoxShadow(CommonDisplayItem::new( base, webrender_api::BoxShadowDisplayItem { + common: items::empty_common_item_properties(), box_bounds: absolute_bounds.to_layout(), color: style.resolve_color(box_shadow.base.color).to_layout(), offset: LayoutVector2D::new( @@ -1109,7 +1099,6 @@ impl Fragment { // Append the border to the display list. let base = state.create_base_display_item( - bounds, clip, self.node, get_cursor(&style, Cursor::Default), @@ -1161,6 +1150,8 @@ impl Fragment { state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data( base, webrender_api::BorderDisplayItem { + bounds: bounds.to_layout(), + common: items::empty_common_item_properties(), widths: border_widths.to_layout(), details, }, @@ -1265,6 +1256,8 @@ impl Fragment { state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data( base, webrender_api::BorderDisplayItem { + bounds: bounds.to_layout(), + common: items::empty_common_item_properties(), widths: border_image_width, details, }, @@ -1308,7 +1301,6 @@ impl Fragment { .resolve_color(style.get_outline().outline_color) .to_layout(); let base = state.create_base_display_item( - bounds, clip, self.node, get_cursor(&style, Cursor::Default), @@ -1317,6 +1309,8 @@ impl Fragment { state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data( base, webrender_api::BorderDisplayItem { + bounds: bounds.to_layout(), + common: items::empty_common_item_properties(), widths: SideOffsets2D::new_all_same(width).to_layout(), details: BorderDetails::Normal(border::simple(color, outline_style.to_layout())), }, @@ -1339,7 +1333,6 @@ impl Fragment { // Compute the text fragment bounds and draw a border surrounding them. let base = state.create_base_display_item( - stacking_relative_border_box, clip, self.node, get_cursor(&style, Cursor::Default), @@ -1348,6 +1341,8 @@ impl Fragment { state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data( base, webrender_api::BorderDisplayItem { + bounds: stacking_relative_border_box.to_layout(), + common: items::empty_common_item_properties(), widths: SideOffsets2D::new_all_same(Au::from_px(1)).to_layout(), details: BorderDetails::Normal(border::simple( ColorU::new(0, 0, 200, 1).into(), @@ -1368,17 +1363,19 @@ impl Fragment { let baseline = baseline.to_physical(self.style.writing_mode, container_size); let base = state.create_base_display_item( - baseline, clip, self.node, get_cursor(&style, Cursor::Default), DisplayListSection::Content, ); // TODO(gw): Use a better estimate for wavy line thickness. - let wavy_line_thickness = (0.33 * base.bounds.size.height).ceil(); + let area = baseline.to_layout(); + let wavy_line_thickness = (0.33 * area.size.height).ceil(); state.add_display_item(DisplayItem::Line(CommonDisplayItem::new( base, webrender_api::LineDisplayItem { + common: items::empty_common_item_properties(), + area, orientation: webrender_api::LineOrientation::Horizontal, wavy_line_thickness, color: ColorU::new(0, 200, 0, 1).into(), @@ -1396,7 +1393,6 @@ impl Fragment { ) { // This prints a debug border around the border of this fragment. let base = state.create_base_display_item( - stacking_relative_border_box, clip, self.node, get_cursor(&self.style, Cursor::Default), @@ -1405,6 +1401,8 @@ impl Fragment { state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data( base, webrender_api::BorderDisplayItem { + bounds: stacking_relative_border_box.to_layout(), + common: items::empty_common_item_properties(), widths: SideOffsets2D::new_all_same(Au::from_px(1)).to_layout(), details: BorderDetails::Normal(border::simple( ColorU::new(0, 0, 200, 1).into(), @@ -1422,7 +1420,6 @@ impl Fragment { state: &mut DisplayListBuildState, stacking_relative_border_box: Rect<Au>, display_list_section: DisplayListSection, - clip: Rect<Au>, ) { let scanned_text_fragment_info = match self.specific { SpecificFragmentInfo::ScannedText(ref scanned_text_fragment_info) => { @@ -1439,7 +1436,6 @@ impl Fragment { let background_color = style.resolve_color(style.get_background().background_color); let base = state.create_base_display_item( stacking_relative_border_box, - clip, self.node, get_cursor(&self.style, Cursor::Default), display_list_section, @@ -1447,6 +1443,7 @@ impl Fragment { state.add_display_item(DisplayItem::Rectangle(CommonDisplayItem::new( base, webrender_api::RectangleDisplayItem { + common: items::empty_common_item_properties(), color: background_color.to_layout(), }, ))); @@ -1485,7 +1482,6 @@ impl Fragment { let base = state.create_base_display_item( insertion_point_bounds, - clip, self.node, get_cursor(&self.style, cursor), display_list_section, @@ -1493,6 +1489,7 @@ impl Fragment { state.add_display_item(DisplayItem::Rectangle(CommonDisplayItem::new( base, webrender_api::RectangleDisplayItem { + common: items::empty_common_item_properties(), color: self.style().get_inherited_text().color.to_layout(), }, ))); @@ -1649,7 +1646,6 @@ impl Fragment { state, stacking_relative_border_box, display_list_section, - clip, ); } @@ -1667,7 +1663,6 @@ impl Fragment { let content_size = TypedRect::new(stacking_relative_border_box.origin, content_size); let base = state.create_base_display_item_with_clipping_and_scrolling( content_size, - content_size, self.node, // FIXME(emilio): Why does this ignore pointer-events? get_cursor(&self.style, Cursor::Default).or(Some(Cursor::Default)), @@ -1677,6 +1672,7 @@ impl Fragment { state.add_display_item(DisplayItem::Rectangle(CommonDisplayItem::new( base, webrender_api::RectangleDisplayItem { + common: items::empty_common_item_properties(), color: ColorF::TRANSPARENT, }, ))); @@ -1719,7 +1715,6 @@ impl Fragment { } state.create_base_display_item( - stacking_relative_content_box, stacking_relative_border_box, self.node, get_cursor(&self.style, Cursor::Default), @@ -1806,12 +1801,16 @@ impl Fragment { }; let base = create_base_display_item(state); + let bounds = stacking_relative_content_box.to_layout(); let item = DisplayItem::Iframe(Box::new(IframeDisplayItem { base, + bounds, iframe: pipeline_id, })); - let size = Size2D::new(item.bounds().size.width, item.bounds().size.height); + // XXXjdm: This sleight-of-hand to convert LayoutRect -> Size2D<CSSPixel> + // looks bogus. + let size = Size2D::new(bounds.size.width, bounds.size.height); state.iframe_sizes.push(IFrameSize { id: browsing_context_id, size: TypedSize2D::from_untyped(&size), @@ -1828,6 +1827,8 @@ impl Fragment { state.add_image_item( base, webrender_api::ImageDisplayItem { + bounds: stacking_relative_content_box.to_layout(), + common: items::empty_common_item_properties(), image_key: id, stretch_size: stacking_relative_content_box.size.to_layout(), tile_spacing: LayoutSize::zero(), @@ -1849,6 +1850,8 @@ impl Fragment { state.add_image_item( base, webrender_api::ImageDisplayItem { + bounds: stacking_relative_content_box.to_layout(), + common: items::empty_common_item_properties(), image_key: *image_key, stretch_size: stacking_relative_border_box.size.to_layout(), tile_spacing: LayoutSize::zero(), @@ -1880,6 +1883,8 @@ impl Fragment { let base = create_base_display_item(state); let display_item = webrender_api::ImageDisplayItem { + bounds: stacking_relative_border_box.to_layout(), + common: items::empty_common_item_properties(), image_key, stretch_size: stacking_relative_content_box.size.to_layout(), tile_spacing: LayoutSize::zero(), @@ -1997,7 +2002,6 @@ impl Fragment { // Base item for all text/shadows let base = state.create_base_display_item( - stacking_relative_content_box, clip, self.node, get_cursor(&self.style, cursor), @@ -2016,7 +2020,6 @@ impl Fragment { offset: LayoutVector2D::new(shadow.horizontal.px(), shadow.vertical.px()), color: self.style.resolve_color(shadow.color).to_layout(), blur_radius: shadow.blur.px(), - should_inflate: true, }, }, ))); @@ -2076,6 +2079,8 @@ impl Fragment { state.add_display_item(DisplayItem::Text(CommonDisplayItem::with_data( base.clone(), webrender_api::TextDisplayItem { + bounds: stacking_relative_content_box.to_layout(), + common: items::empty_common_item_properties(), font_key: text_fragment.run.font_key, color: text_color.to_layout(), glyph_options: None, @@ -2122,7 +2127,6 @@ impl Fragment { let stacking_relative_box = stacking_relative_box.to_physical(self.style.writing_mode, container_size); let base = state.create_base_display_item( - stacking_relative_box, clip, self.node, get_cursor(&self.style, Cursor::Default), @@ -2130,10 +2134,13 @@ impl Fragment { ); // TODO(gw): Use a better estimate for wavy line thickness. - let wavy_line_thickness = (0.33 * base.bounds.size.height).ceil(); + let area = stacking_relative_box.to_layout(); + let wavy_line_thickness = (0.33 * area.size.height).ceil(); state.add_display_item(DisplayItem::Line(CommonDisplayItem::new( base, webrender_api::LineDisplayItem { + common: items::empty_common_item_properties(), + area, orientation: webrender_api::LineOrientation::Horizontal, wavy_line_thickness, color: color.to_layout(), @@ -2837,16 +2844,14 @@ impl BaseFlow { let mut color = THREAD_TINT_COLORS[thread_id as usize % THREAD_TINT_COLORS.len()]; color.a = 1.0; - let base = state.create_base_display_item( - stacking_context_relative_bounds.inflate(Au::from_px(2), Au::from_px(2)), - self.clip, - node, - None, - DisplayListSection::Content, - ); + let base = + state.create_base_display_item(self.clip, node, None, DisplayListSection::Content); + let bounds = stacking_context_relative_bounds.inflate(Au::from_px(2), Au::from_px(2)); state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data( base, webrender_api::BorderDisplayItem { + bounds: bounds.to_layout(), + common: items::empty_common_item_properties(), widths: SideOffsets2D::new_all_same(Au::from_px(2)).to_layout(), details: BorderDetails::Normal(border::simple( color, @@ -2908,13 +2913,6 @@ fn get_cursor(values: &ComputedValues, default_cursor: Cursor) -> Option<Cursor> }) } -/// Adjusts `content_rect` as necessary for the given spread, and blur so that the resulting -/// bounding rect contains all of a shadow's ink. -fn shadow_bounds(content_rect: Rect<Au>, blur: Au, spread: Au) -> Rect<Au> { - let inflation = spread + blur * BLUR_INFLATION_FACTOR; - content_rect.inflate(inflation, inflation) -} - /// Adjusts borders as appropriate to account for a fragment's status as the /// first or last fragment within the range of an element. /// @@ -3012,3 +3010,15 @@ impl IndexableText { ) } } + +trait ToF32Px { + type Output; + fn to_f32_px(&self) -> Self::Output; +} + +impl ToF32Px for TypedRect<Au> { + type Output = LayoutRect; + fn to_f32_px(&self) -> LayoutRect { + LayoutRect::from_untyped(&servo_geometry::au_rect_to_f32_rect(*self)) + } +} diff --git a/components/layout/display_list/conversions.rs b/components/layout/display_list/conversions.rs index f541ef581ac..4624b5f8dd0 100644 --- a/components/layout/display_list/conversions.rs +++ b/components/layout/display_list/conversions.rs @@ -114,23 +114,23 @@ impl ToLayout for RGBA { } impl ToLayout for Point2D<Au> { - type Type = wr::LayoutPoint; + type Type = wr::units::LayoutPoint; fn to_layout(&self) -> Self::Type { - wr::LayoutPoint::new(self.x.to_f32_px(), self.y.to_f32_px()) + wr::units::LayoutPoint::new(self.x.to_f32_px(), self.y.to_f32_px()) } } impl ToLayout for Rect<Au> { - type Type = wr::LayoutRect; + type Type = wr::units::LayoutRect; fn to_layout(&self) -> Self::Type { - wr::LayoutRect::new(self.origin.to_layout(), self.size.to_layout()) + wr::units::LayoutRect::new(self.origin.to_layout(), self.size.to_layout()) } } impl ToLayout for SideOffsets2D<Au> { - type Type = wr::LayoutSideOffsets; + type Type = wr::units::LayoutSideOffsets; fn to_layout(&self) -> Self::Type { - wr::LayoutSideOffsets::new( + wr::units::LayoutSideOffsets::new( self.top.to_f32_px(), self.right.to_f32_px(), self.bottom.to_f32_px(), @@ -140,16 +140,16 @@ impl ToLayout for SideOffsets2D<Au> { } impl ToLayout for Size2D<Au> { - type Type = wr::LayoutSize; + type Type = wr::units::LayoutSize; fn to_layout(&self) -> Self::Type { - wr::LayoutSize::new(self.width.to_f32_px(), self.height.to_f32_px()) + wr::units::LayoutSize::new(self.width.to_f32_px(), self.height.to_f32_px()) } } impl ToLayout for Vector2D<Au> { - type Type = wr::LayoutVector2D; + type Type = wr::units::LayoutVector2D; fn to_layout(&self) -> Self::Type { - wr::LayoutVector2D::new(self.x.to_f32_px(), self.y.to_f32_px()) + wr::units::LayoutVector2D::new(self.x.to_f32_px(), self.y.to_f32_px()) } } diff --git a/components/layout/display_list/items.rs b/components/layout/display_list/items.rs index 10d3b81a8d8..b6674d972fe 100644 --- a/components/layout/display_list/items.rs +++ b/components/layout/display_list/items.rs @@ -12,7 +12,7 @@ //! They are therefore not exactly analogous to constructs like Skia pictures, which consist of //! low-level drawing primitives. -use euclid::{SideOffsets2D, TypedRect, Vector2D}; +use euclid::{SideOffsets2D, Vector2D}; use gfx_traits::print_tree::PrintTree; use gfx_traits::{self, StackingContextId}; use msg::constellation_msg::PipelineId; @@ -24,11 +24,10 @@ use std::f32; use std::fmt; use style::computed_values::_servo_top_layer::T as InTopLayer; use webrender_api as wr; -use webrender_api::{BorderRadius, ClipMode}; -use webrender_api::{ComplexClipRegion, ExternalScrollId, FilterOp}; -use webrender_api::{GlyphInstance, GradientStop, ImageKey, LayoutPoint}; -use webrender_api::{LayoutRect, LayoutSize, LayoutTransform}; -use webrender_api::{MixBlendMode, ScrollSensitivity, Shadow}; +use webrender_api::units::{LayoutPoint, LayoutRect, LayoutSize, LayoutTransform}; +use webrender_api::{BorderRadius, ClipId, ClipMode, CommonItemProperties, ComplexClipRegion}; +use webrender_api::{ExternalScrollId, FilterOp, GlyphInstance, GradientStop, ImageKey}; +use webrender_api::{MixBlendMode, ScrollSensitivity, Shadow, SpatialId}; use webrender_api::{StickyOffsetBounds, TransformStyle}; pub use style::dom::OpaqueNode; @@ -410,9 +409,6 @@ pub enum DisplayItem { /// Information common to all display items. #[derive(Clone, Serialize)] pub struct BaseDisplayItem { - /// The boundaries of the display item, in layer coordinates. - pub bounds: LayoutRect, - /// Metadata attached to this display item. pub metadata: DisplayItemMetadata, @@ -432,7 +428,6 @@ pub struct BaseDisplayItem { impl BaseDisplayItem { #[inline(always)] pub fn new( - bounds: LayoutRect, metadata: DisplayItemMetadata, clip_rect: LayoutRect, section: DisplayListSection, @@ -440,7 +435,6 @@ impl BaseDisplayItem { clipping_and_scrolling: ClippingAndScrolling, ) -> BaseDisplayItem { BaseDisplayItem { - bounds, metadata, clip_rect, section, @@ -452,7 +446,6 @@ impl BaseDisplayItem { #[inline(always)] pub fn empty() -> BaseDisplayItem { BaseDisplayItem { - bounds: TypedRect::zero(), metadata: DisplayItemMetadata { node: OpaqueNode(0), pointing: None, @@ -468,6 +461,16 @@ impl BaseDisplayItem { } } +pub fn empty_common_item_properties() -> CommonItemProperties { + CommonItemProperties { + clip_rect: LayoutRect::max_rect(), + clip_id: ClipId::root(wr::PipelineId::dummy()), + spatial_id: SpatialId::root_scroll_node(wr::PipelineId::dummy()), + hit_info: None, + is_backface_visible: false, + } +} + /// 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. @@ -609,6 +612,7 @@ pub enum TextOrientation { pub struct IframeDisplayItem { pub base: BaseDisplayItem, pub iframe: PipelineId, + pub bounds: LayoutRect, } #[derive(Clone, Serialize)] @@ -711,7 +715,22 @@ impl DisplayItem { } pub fn bounds(&self) -> LayoutRect { - self.base().bounds + match *self { + DisplayItem::Rectangle(ref item) => item.item.common.clip_rect, + DisplayItem::Text(ref item) => item.item.bounds, + DisplayItem::Image(ref item) => item.item.bounds, + DisplayItem::Border(ref item) => item.item.bounds, + DisplayItem::Gradient(ref item) => item.item.bounds, + DisplayItem::RadialGradient(ref item) => item.item.bounds, + DisplayItem::Line(ref item) => item.item.area, + DisplayItem::BoxShadow(ref item) => item.item.box_bounds, + DisplayItem::PushTextShadow(_) => LayoutRect::zero(), + DisplayItem::PopAllTextShadows(_) => LayoutRect::zero(), + DisplayItem::Iframe(ref item) => item.bounds, + DisplayItem::PushStackingContext(ref item) => item.stacking_context.bounds, + DisplayItem::PopStackingContext(_) => LayoutRect::zero(), + DisplayItem::DefineClipScrollNode(_) => LayoutRect::zero(), + } } } diff --git a/components/layout/display_list/webrender_helpers.rs b/components/layout/display_list/webrender_helpers.rs index 099a1d1807a..6bdb1bfcfdc 100644 --- a/components/layout/display_list/webrender_helpers.rs +++ b/components/layout/display_list/webrender_helpers.rs @@ -7,16 +7,18 @@ // 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 crate::display_list::items::{ClipScrollNode, ClipScrollNodeType}; +use crate::display_list::items::{BaseDisplayItem, ClipScrollNode, ClipScrollNodeType}; use crate::display_list::items::{DisplayItem, DisplayList, StackingContextType}; use msg::constellation_msg::PipelineId; +use webrender_api::units::LayoutPoint; +use webrender_api::{self, ClipId, CommonItemProperties, DisplayItem as WrDisplayItem}; +use webrender_api::{DisplayListBuilder, PropertyBinding, PushStackingContextDisplayItem}; use webrender_api::{ - self, ClipId, DisplayListBuilder, RasterSpace, ReferenceFrameKind, SpaceAndClipInfo, SpatialId, + RasterSpace, ReferenceFrameKind, SpaceAndClipInfo, SpatialId, StackingContext, }; -use webrender_api::{LayoutPoint, PropertyBinding, SpecificDisplayItem}; pub trait WebRenderDisplayListConverter { - fn convert_to_webrender(&self, pipeline_id: PipelineId) -> DisplayListBuilder; + fn convert_to_webrender(&mut self, pipeline_id: PipelineId) -> DisplayListBuilder; } struct ClipScrollState { @@ -27,9 +29,8 @@ struct ClipScrollState { } trait WebRenderDisplayItemConverter { - fn prim_info(&self) -> webrender_api::LayoutPrimitiveInfo; fn convert_to_webrender( - &self, + &mut self, clip_scroll_nodes: &[ClipScrollNode], state: &mut ClipScrollState, builder: &mut DisplayListBuilder, @@ -37,7 +38,7 @@ trait WebRenderDisplayItemConverter { } impl WebRenderDisplayListConverter for DisplayList { - fn convert_to_webrender(&self, pipeline_id: PipelineId) -> DisplayListBuilder { + fn convert_to_webrender(&mut self, pipeline_id: PipelineId) -> DisplayListBuilder { let mut clip_ids = vec![None; self.clip_scroll_nodes.len()]; let mut spatial_ids = vec![None; self.clip_scroll_nodes.len()]; @@ -66,7 +67,7 @@ impl WebRenderDisplayListConverter for DisplayList { 1024 * 1024, // 1 MB of space ); - for item in &self.list { + for item in &mut self.list { item.convert_to_webrender(&self.clip_scroll_nodes, &mut state, &mut builder); } @@ -75,22 +76,8 @@ impl WebRenderDisplayListConverter for DisplayList { } 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, - clip_rect: self.base().clip_rect, - // TODO(gw): Make use of the WR backface visibility functionality. - is_backface_visible: true, - tag, - } - } - fn convert_to_webrender( - &self, + &mut self, clip_scroll_nodes: &[ClipScrollNode], state: &mut ClipScrollState, builder: &mut DisplayListBuilder, @@ -118,92 +105,78 @@ impl WebRenderDisplayItemConverter for DisplayItem { state.active_clip_id = cur_clip_id; } - let space_clip_info = SpaceAndClipInfo { - spatial_id: state.active_spatial_id, - clip_id: state.active_clip_id, - }; match *self { - DisplayItem::Rectangle(ref item) => { - builder.push_item( - &SpecificDisplayItem::Rectangle(item.item), - &self.prim_info(), - &space_clip_info, - ); + DisplayItem::Rectangle(ref mut item) => { + item.item.common = build_common_item_properties(&item.base, state); + builder.push_item(&WrDisplayItem::Rectangle(item.item)); }, - DisplayItem::Text(ref item) => { - builder.push_item( - &SpecificDisplayItem::Text(item.item), - &self.prim_info(), - &space_clip_info, - ); + DisplayItem::Text(ref mut item) => { + item.item.common = build_common_item_properties(&item.base, state); + builder.push_item(&WrDisplayItem::Text(item.item)); builder.push_iter(item.data.iter()); }, - DisplayItem::Image(ref item) => { - builder.push_item( - &SpecificDisplayItem::Image(item.item), - &self.prim_info(), - &space_clip_info, - ); + DisplayItem::Image(ref mut item) => { + item.item.common = build_common_item_properties(&item.base, state); + builder.push_item(&WrDisplayItem::Image(item.item)); }, - DisplayItem::Border(ref item) => { + DisplayItem::Border(ref mut item) => { + item.item.common = build_common_item_properties(&item.base, state); if !item.data.is_empty() { builder.push_stops(item.data.as_ref()); } - builder.push_item( - &SpecificDisplayItem::Border(item.item), - &self.prim_info(), - &space_clip_info, - ); + builder.push_item(&WrDisplayItem::Border(item.item)); }, - DisplayItem::Gradient(ref item) => { + DisplayItem::Gradient(ref mut item) => { + item.item.common = build_common_item_properties(&item.base, state); builder.push_stops(item.data.as_ref()); - builder.push_item( - &SpecificDisplayItem::Gradient(item.item), - &self.prim_info(), - &space_clip_info, - ); + builder.push_item(&WrDisplayItem::Gradient(item.item)); }, - DisplayItem::RadialGradient(ref item) => { + DisplayItem::RadialGradient(ref mut item) => { + item.item.common = build_common_item_properties(&item.base, state); builder.push_stops(item.data.as_ref()); - builder.push_item( - &SpecificDisplayItem::RadialGradient(item.item), - &self.prim_info(), - &space_clip_info, - ); + builder.push_item(&WrDisplayItem::RadialGradient(item.item)); }, - DisplayItem::Line(ref item) => { - builder.push_item( - &SpecificDisplayItem::Line(item.item), - &self.prim_info(), - &space_clip_info, - ); + DisplayItem::Line(ref mut item) => { + item.item.common = build_common_item_properties(&item.base, state); + builder.push_item(&WrDisplayItem::Line(item.item)); }, - DisplayItem::BoxShadow(ref item) => { - builder.push_item( - &SpecificDisplayItem::BoxShadow(item.item), - &self.prim_info(), - &space_clip_info, - ); + DisplayItem::BoxShadow(ref mut item) => { + item.item.common = build_common_item_properties(&item.base, state); + builder.push_item(&WrDisplayItem::BoxShadow(item.item)); }, - DisplayItem::PushTextShadow(ref item) => { - builder.push_shadow(&self.prim_info(), &space_clip_info, item.shadow); + DisplayItem::PushTextShadow(ref mut item) => { + let common = build_common_item_properties(&item.base, state); + builder.push_shadow( + &SpaceAndClipInfo { + spatial_id: common.spatial_id, + clip_id: common.clip_id, + }, + item.shadow, + true, + ); }, DisplayItem::PopAllTextShadows(_) => { - builder.pop_all_shadows(); + builder.push_item(&WrDisplayItem::PopAllShadows); }, - DisplayItem::Iframe(ref item) => { + DisplayItem::Iframe(ref mut item) => { + let common = build_common_item_properties(&item.base, state); builder.push_iframe( - &self.prim_info(), - &space_clip_info, + item.bounds, + common.clip_rect, + &SpaceAndClipInfo { + spatial_id: common.spatial_id, + clip_id: common.clip_id, + }, item.iframe.to_webrender(), true, ); }, - DisplayItem::PushStackingContext(ref item) => { + DisplayItem::PushStackingContext(ref mut item) => { let stacking_context = &item.stacking_context; debug_assert_eq!(stacking_context.context_type, StackingContextType::Real); - let mut info = webrender_api::LayoutPrimitiveInfo::new(stacking_context.bounds); + //let mut info = webrender_api::LayoutPrimitiveInfo::new(stacking_context.bounds); + let mut bounds = stacking_context.bounds; let spatial_id = if let Some(frame_index) = stacking_context.established_reference_frame { let (transform, ref_frame) = @@ -225,7 +198,7 @@ impl WebRenderDisplayItemConverter for DisplayItem { }; let spatial_id = builder.push_reference_frame( - &stacking_context.bounds, + stacking_context.bounds.origin, state.active_spatial_id, stacking_context.transform_style, PropertyBinding::Value(transform), @@ -235,27 +208,35 @@ impl WebRenderDisplayItemConverter for DisplayItem { state.spatial_ids[frame_index.to_index()] = Some(spatial_id); state.clip_ids[frame_index.to_index()] = Some(cur_clip_id); - info.rect.origin = LayoutPoint::zero(); - info.clip_rect.origin = LayoutPoint::zero(); + bounds.origin = LayoutPoint::zero(); spatial_id } else { state.active_spatial_id }; - builder.push_stacking_context( - &info, + if !stacking_context.filters.is_empty() { + builder.push_item(&WrDisplayItem::SetFilterOps); + builder.push_iter(&stacking_context.filters); + } + + let wr_item = PushStackingContextDisplayItem { + origin: bounds.origin, spatial_id, - None, - stacking_context.transform_style, - stacking_context.mix_blend_mode, - &stacking_context.filters, - &[], - RasterSpace::Screen, - /* cache_tiles = */ false, - ); + is_backface_visible: true, + stacking_context: StackingContext { + transform_style: stacking_context.transform_style, + mix_blend_mode: stacking_context.mix_blend_mode, + clip_id: None, + raster_space: RasterSpace::Screen, + // TODO(pcwalton): Enable picture caching? + cache_tiles: false, + }, + }; + + builder.push_item(&WrDisplayItem::PushStackingContext(wr_item)); }, DisplayItem::PopStackingContext(_) => builder.pop_stacking_context(), - DisplayItem::DefineClipScrollNode(ref item) => { + DisplayItem::DefineClipScrollNode(ref mut item) => { let node = &clip_scroll_nodes[item.node_index.to_index()]; let item_rect = node.clip.main; @@ -291,7 +272,7 @@ impl WebRenderDisplayItemConverter for DisplayItem { node.clip.complex.clone(), None, scroll_sensitivity, - webrender_api::LayoutVector2D::zero(), + webrender_api::units::LayoutVector2D::zero(), ); state.clip_ids[item.node_index.to_index()] = Some(space_clip_info.clip_id); @@ -306,7 +287,7 @@ impl WebRenderDisplayItemConverter for DisplayItem { sticky_data.margins, sticky_data.vertical_offset_bounds, sticky_data.horizontal_offset_bounds, - webrender_api::LayoutVector2D::zero(), + webrender_api::units::LayoutVector2D::zero(), ); state.spatial_ids[item.node_index.to_index()] = Some(id); @@ -320,3 +301,21 @@ impl WebRenderDisplayItemConverter for DisplayItem { } } } + +fn build_common_item_properties( + base: &BaseDisplayItem, + state: &ClipScrollState, +) -> CommonItemProperties { + let tag = match base.metadata.pointing { + Some(cursor) => Some((base.metadata.node.0 as u64, cursor)), + None => None, + }; + CommonItemProperties { + clip_rect: base.clip_rect, + spatial_id: state.active_spatial_id, + clip_id: state.active_clip_id, + // TODO(gw): Make use of the WR backface visibility functionality. + is_backface_visible: true, + hit_info: tag, + } +} diff --git a/components/layout/flow.rs b/components/layout/flow.rs index bcc38252b9b..d7ab73cd8d3 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -65,7 +65,7 @@ use style::properties::ComputedValues; use style::selector_parser::RestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage; use style::values::computed::LengthPercentageOrAuto; -use webrender_api::LayoutTransform; +use webrender_api::units::LayoutTransform; /// This marker trait indicates that a type is a struct with `#[repr(C)]` whose first field /// is of type `BaseFlow` or some type that also implements this trait. diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 72029fb2484..879e2af2f64 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -65,7 +65,8 @@ use style::values::computed::{LengthPercentage, LengthPercentageOrAuto, Size, Ve use style::values::generics::box_::{Perspective, VerticalAlignKeyword}; use style::values::generics::transform; use style::Zero; -use webrender_api::{self, LayoutTransform}; +use webrender_api; +use webrender_api::units::LayoutTransform; // From gfxFontConstants.h in Firefox. static FONT_SUBSCRIPT_OFFSET_RATIO: f32 = 0.20; diff --git a/components/layout/query.rs b/components/layout/query.rs index a74eda165e2..789056753d5 100644 --- a/components/layout/query.rs +++ b/components/layout/query.rs @@ -51,7 +51,7 @@ pub struct LayoutThreadData { pub constellation_chan: IpcSender<ConstellationMsg>, /// The root stacking context. - pub display_list: Option<Arc<DisplayList>>, + pub display_list: Option<DisplayList>, pub indexable_text: IndexableText, diff --git a/components/layout/sequential.rs b/components/layout/sequential.rs index a1fe086d79f..16dd3b8d4da 100644 --- a/components/layout/sequential.rs +++ b/components/layout/sequential.rs @@ -5,6 +5,7 @@ //! Implements sequential traversals over the DOM and flow trees. use crate::context::LayoutContext; +use crate::display_list::items::{self, CommonDisplayItem, DisplayItem, DisplayListSection}; use crate::display_list::{DisplayListBuildState, StackingContextCollectionState}; use crate::floats::SpeculatedFloatPlacement; use crate::flow::{Flow, FlowFlags, GetBaseFlow, ImmutableFlowUtils}; @@ -14,10 +15,10 @@ use crate::incremental::RelayoutMode; use crate::traversal::{AssignBSizes, AssignISizes, BubbleISizes, BuildDisplayList}; use crate::traversal::{InorderFlowTraversal, PostorderFlowTraversal, PreorderFlowTraversal}; use app_units::Au; -use euclid::{Point2D, Vector2D}; +use euclid::{Point2D, Rect, Size2D, Vector2D}; use servo_config::opts; use style::servo::restyle_damage::ServoRestyleDamage; -use webrender_api::LayoutPoint; +use webrender_api::units::LayoutPoint; pub fn resolve_generated_content(root: &mut dyn Flow, layout_context: &LayoutContext) { ResolveGeneratedContent::new(&layout_context).traverse(root, 0); @@ -72,11 +73,30 @@ pub fn reflow(root: &mut dyn Flow, layout_context: &LayoutContext, relayout_mode pub fn build_display_list_for_subtree<'a>( flow_root: &mut dyn Flow, layout_context: &'a LayoutContext, + background_color: webrender_api::ColorF, + client_size: Size2D<Au>, ) -> DisplayListBuildState<'a> { let mut state = StackingContextCollectionState::new(layout_context.id); flow_root.collect_stacking_contexts(&mut state); - let state = DisplayListBuildState::new(layout_context, state); + let mut state = DisplayListBuildState::new(layout_context, state); + + // Create a base rectangle for the page background based on the root + // background color. + let base = state.create_base_display_item( + Rect::new(Point2D::new(Au::new(0), Au::new(0)), client_size), + flow_root.as_block().fragment.node, + None, + DisplayListSection::BackgroundAndBorders, + ); + state.add_display_item(DisplayItem::Rectangle(CommonDisplayItem::new( + base, + webrender_api::RectangleDisplayItem { + color: background_color, + common: items::empty_common_item_properties(), + }, + ))); + let mut build_display_list = BuildDisplayList { state: state }; build_display_list.traverse(flow_root); build_display_list.state |