diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 6c3df102817..c4c73e50dc7 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -33,8 +33,8 @@ use style::values::computed::Filter; use style_traits::cursor::Cursor; use text::TextRun; use text::glyph::ByteIndex; -use webrender_api::{self, ClipId, ColorF, GradientStop, LocalClip, MixBlendMode, ScrollPolicy}; -use webrender_api::{ScrollSensitivity, StickyOffsetBounds, TransformStyle}; +use webrender_api::{self, BoxShadowClipMode, ClipId, ColorF, GradientStop, LocalClip, MixBlendMode}; +use webrender_api::{ScrollPolicy, ScrollSensitivity, StickyOffsetBounds, TransformStyle}; pub use style::dom::OpaqueNode; @@ -944,6 +944,7 @@ pub struct BoxShadowDisplayItem { pub border_radius: BorderRadii, /// How we should clip the result. + #[ignore_malloc_size_of = "enum type in webrender"] pub clip_mode: BoxShadowClipMode, } @@ -998,17 +999,6 @@ pub struct DefineClipScrollNodeItem { pub node_index: ClipScrollNodeIndex, } -/// How a box shadow should be clipped. -#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)] -pub enum BoxShadowClipMode { - /// The area inside `box_bounds` should be clipped out. Corresponds to the normal CSS - /// `box-shadow`. - Outset, - /// The area outside `box_bounds` should be clipped out. Corresponds to the `inset` flag on CSS - /// `box-shadow`. - Inset, -} - impl DisplayItem { pub fn base(&self) -> &BaseDisplayItem { match *self { diff --git a/components/layout/display_list/background.rs b/components/layout/display_list/background.rs index 57e79625633..7db8744a3df 100644 --- a/components/layout/display_list/background.rs +++ b/components/layout/display_list/background.rs @@ -9,7 +9,7 @@ // FIXME(rust-lang/rust#26264): Remove GenericEndingShape and GenericGradientItem. use app_units::Au; -use display_list::ToGfxColor; +use display_list::ToLayout; use euclid::{Point2D, Size2D, Vector2D}; use gfx::display_list; use model::MaybeAuto; @@ -364,7 +364,7 @@ fn convert_gradient_stops(gradient_items: &[GradientItem], total_length: Au) -> assert!(offset.is_finite()); stops.push(GradientStop { offset: offset, - color: stop.color.to_gfx_color(), + color: stop.color.to_layout(), }) } stops diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index 5eac20ccbd3..780ca9e9607 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -14,9 +14,10 @@ use app_units::{Au, AU_PER_PX}; use block::{BlockFlow, BlockStackingContextType}; use canvas_traits::canvas::{CanvasMsg, FromLayoutMsg}; use context::LayoutContext; +use display_list::ToLayout; use display_list::background::{compute_background_image_size, tile_image_axis}; use display_list::background::{convert_linear_gradient, convert_radial_gradient}; -use display_list::webrender_helpers::{ToBorderRadius, ToMixBlendMode, ToRectF, ToTransformStyle}; +use display_list::webrender_helpers::ToBorderRadius; use euclid::{Point2D, Rect, SideOffsets2D, Size2D, Transform3D, TypedRect, TypedSize2D, Vector2D}; use flex::FlexFlow; use flow::{BaseFlow, Flow, FlowFlags}; @@ -26,7 +27,7 @@ use fragment::{CanvasFragmentSource, CoordinateSystem, Fragment, ScannedTextFrag use fragment::SpecificFragmentInfo; use gfx::display_list; use gfx::display_list::{BaseDisplayItem, BorderDetails, BorderDisplayItem, BLUR_INFLATION_FACTOR}; -use gfx::display_list::{BorderRadii, BoxShadowClipMode, BoxShadowDisplayItem, ClipScrollNode}; +use gfx::display_list::{BorderRadii, BoxShadowDisplayItem, ClipScrollNode}; use gfx::display_list::{ClipScrollNodeIndex, ClipScrollNodeType, ClippingAndScrolling}; use gfx::display_list::{ClippingRegion, DisplayItem, DisplayItemMetadata, DisplayList}; use gfx::display_list::{DisplayListSection, GradientDisplayItem, IframeDisplayItem, ImageBorder}; @@ -76,7 +77,7 @@ use style_traits::CSSPixel; use style_traits::ToCss; use style_traits::cursor::Cursor; use table_cell::CollapsedBordersForCell; -use webrender_api::{ClipId, ClipMode, ColorF, ComplexClipRegion, LineStyle}; +use webrender_api::{BoxShadowClipMode, ClipId, ClipMode, ColorF, ComplexClipRegion, LineStyle}; use webrender_api::{LocalClip, RepeatMode, ScrollPolicy, ScrollSensitivity, StickyOffsetBounds}; trait ResolvePercentage { @@ -914,15 +915,15 @@ impl FragmentDisplayListBuilding for Fragment { let clip = if !border_radii.is_square() { LocalClip::RoundedRect( - bounds.to_rectf(), + bounds.to_layout(), ComplexClipRegion::new( - bounds.to_rectf(), + bounds.to_layout(), border_radii.to_border_radius(), ClipMode::Clip, ), ) } else { - LocalClip::Rect(bounds.to_rectf()) + LocalClip::Rect(bounds.to_layout()) }; let base = state.create_base_display_item( @@ -934,7 +935,7 @@ impl FragmentDisplayListBuilding for Fragment { ); state.add_display_item(DisplayItem::SolidColor(Box::new(SolidColorDisplayItem { base: base, - color: background_color.to_gfx_color(), + color: background_color.to_layout(), }))); // The background image is painted on top of the background color. @@ -1118,7 +1119,7 @@ impl FragmentDisplayListBuilding for Fragment { // Create the image display item. let base = state.create_base_display_item( &placement.bounds, - LocalClip::Rect(placement.css_clip.to_rectf()), + LocalClip::Rect(placement.css_clip.to_layout()), self.node, style.get_cursor(Cursor::Default), display_list_section, @@ -1210,7 +1211,7 @@ impl FragmentDisplayListBuilding for Fragment { let base = state.create_base_display_item( &placement.bounds, - LocalClip::Rect(placement.css_clip.to_rectf()), + LocalClip::Rect(placement.css_clip.to_layout()), self.node, style.get_cursor(Cursor::Default), display_list_section, @@ -1271,7 +1272,7 @@ impl FragmentDisplayListBuilding for Fragment { let base = state.create_base_display_item( &bounds, - LocalClip::from(clip.to_rectf()), + LocalClip::from(clip.to_layout()), self.node, style.get_cursor(Cursor::Default), display_list_section, @@ -1284,7 +1285,7 @@ impl FragmentDisplayListBuilding for Fragment { .base .color .unwrap_or(style.get_color().color) - .to_gfx_color(), + .to_layout(), offset: Vector2D::new( Au::from(box_shadow.base.horizontal), Au::from(box_shadow.base.vertical), @@ -1367,7 +1368,7 @@ impl FragmentDisplayListBuilding for Fragment { // Append the border to the display list. let base = state.create_base_display_item( &bounds, - LocalClip::from(clip.to_rectf()), + LocalClip::from(clip.to_layout()), self.node, style.get_cursor(Cursor::Default), display_list_section, @@ -1380,10 +1381,10 @@ impl FragmentDisplayListBuilding for Fragment { border_widths: border.to_physical(style.writing_mode), details: BorderDetails::Normal(NormalBorder { color: SideOffsets2D::new( - colors.top.to_gfx_color(), - colors.right.to_gfx_color(), - colors.bottom.to_gfx_color(), - colors.left.to_gfx_color(), + colors.top.to_layout(), + colors.right.to_layout(), + colors.bottom.to_layout(), + colors.left.to_layout(), ), style: border_style, radius: build_border_radius(&bounds, border_style_struct), @@ -1533,10 +1534,10 @@ impl FragmentDisplayListBuilding for Fragment { // Append the outline to the display list. let color = style .resolve_color(style.get_outline().outline_color) - .to_gfx_color(); + .to_layout(); let base = state.create_base_display_item( &bounds, - LocalClip::from(clip.to_rectf()), + LocalClip::from(clip.to_layout()), self.node, style.get_cursor(Cursor::Default), DisplayListSection::Outlines, @@ -1567,7 +1568,7 @@ impl FragmentDisplayListBuilding for Fragment { // Compute the text fragment bounds and draw a border surrounding them. let base = state.create_base_display_item( stacking_relative_border_box, - LocalClip::from(clip.to_rectf()), + LocalClip::from(clip.to_layout()), self.node, style.get_cursor(Cursor::Default), DisplayListSection::Content, @@ -1594,7 +1595,7 @@ impl FragmentDisplayListBuilding for Fragment { let base = state.create_base_display_item( &baseline, - LocalClip::from(clip.to_rectf()), + LocalClip::from(clip.to_layout()), self.node, style.get_cursor(Cursor::Default), DisplayListSection::Content, @@ -1615,7 +1616,7 @@ impl FragmentDisplayListBuilding for Fragment { // This prints a debug border around the border of this fragment. let base = state.create_base_display_item( stacking_relative_border_box, - LocalClip::from(clip.to_rectf()), + LocalClip::from(clip.to_layout()), self.node, self.style.get_cursor(Cursor::Default), DisplayListSection::Content, @@ -1653,14 +1654,14 @@ impl FragmentDisplayListBuilding for Fragment { let background_color = style.resolve_color(style.get_background().background_color); let base = state.create_base_display_item( stacking_relative_border_box, - LocalClip::from(clip.to_rectf()), + LocalClip::from(clip.to_layout()), self.node, self.style.get_cursor(Cursor::Default), display_list_section, ); state.add_display_item(DisplayItem::SolidColor(Box::new(SolidColorDisplayItem { base: base, - color: background_color.to_gfx_color(), + color: background_color.to_layout(), }))); } @@ -1705,14 +1706,14 @@ impl FragmentDisplayListBuilding for Fragment { let base = state.create_base_display_item( &insertion_point_bounds, - LocalClip::from(clip.to_rectf()), + LocalClip::from(clip.to_layout()), self.node, self.style.get_cursor(cursor), display_list_section, ); state.add_display_item(DisplayItem::SolidColor(Box::new(SolidColorDisplayItem { base: base, - color: self.style().get_color().color.to_gfx_color(), + color: self.style().get_color().color.to_layout(), }))); } @@ -1869,15 +1870,15 @@ impl FragmentDisplayListBuilding for Fragment { let radii = build_border_radius_for_inner_rect(&stacking_relative_border_box, style); if !radii.is_square() { LocalClip::RoundedRect( - stacking_relative_border_box.to_rectf(), + stacking_relative_border_box.to_layout(), ComplexClipRegion::new( - stacking_relative_content_box.to_rectf(), + stacking_relative_content_box.to_layout(), radii.to_border_radius(), ClipMode::Clip, ), ) } else { - LocalClip::Rect(stacking_relative_border_box.to_rectf()) + LocalClip::Rect(stacking_relative_border_box.to_layout()) } }; @@ -2096,12 +2097,9 @@ impl FragmentDisplayListBuilding for Fragment { &overflow, self.effective_z_index(), filters.into(), - self.style() - .get_effects() - .mix_blend_mode - .to_mix_blend_mode(), + self.style().get_effects().mix_blend_mode.to_layout(), self.transform_matrix(&border_box), - self.style().get_used_transform_style().to_transform_style(), + self.style().get_used_transform_style().to_layout(), self.perspective_matrix(&border_box), scroll_policy, parent_clipping_and_scrolling, @@ -2149,7 +2147,7 @@ impl FragmentDisplayListBuilding for Fragment { // Base item for all text/shadows let base = state.create_base_display_item( &stacking_relative_content_box, - LocalClip::from(clip.to_rectf()), + LocalClip::from(clip.to_layout()), self.node, self.style().get_cursor(cursor), DisplayListSection::Content, @@ -2168,7 +2166,7 @@ impl FragmentDisplayListBuilding for Fragment { color: shadow .color .unwrap_or(self.style().get_color().color) - .to_gfx_color(), + .to_layout(), }, ))); } @@ -2215,7 +2213,7 @@ impl FragmentDisplayListBuilding for Fragment { base: base.clone(), text_run: text_fragment.run.clone(), range: text_fragment.range, - text_color: text_color.to_gfx_color(), + text_color: text_color.to_layout(), orientation: orientation, baseline_origin: baseline_origin, }))); @@ -2258,7 +2256,7 @@ impl FragmentDisplayListBuilding for Fragment { stacking_relative_box.to_physical(self.style.writing_mode, container_size); let base = state.create_base_display_item( &stacking_relative_box, - LocalClip::from(clip.to_rectf()), + LocalClip::from(clip.to_layout()), self.node, self.style.get_cursor(Cursor::Default), DisplayListSection::Content, @@ -2266,7 +2264,7 @@ impl FragmentDisplayListBuilding for Fragment { state.add_display_item(DisplayItem::Line(Box::new(LineDisplayItem { base: base, - color: color.to_gfx_color(), + color: color.to_layout(), style: LineStyle::Solid, }))); } @@ -2736,10 +2734,8 @@ impl BlockFlowDisplayListBuilding for BlockFlow { // If we already have a scroll root for this flow, just return. This can happen // when fragments map to more than one flow, such as in the case of table // wrappers. We just accept the first scroll root in that case. - let new_clip_scroll_node_id = ClipId::new( - self.fragment.unique_id(), - state.pipeline_id.to_webrender(), - ); + let new_clip_scroll_node_id = + ClipId::new(self.fragment.unique_id(), state.pipeline_id.to_webrender()); let sensitivity = if StyleOverflow::Hidden == self.fragment.style.get_box().overflow_x && StyleOverflow::Hidden == self.fragment.style.get_box().overflow_y @@ -3145,7 +3141,7 @@ impl BaseFlowDisplayListBuilding for BaseFlow { color.a = 1.0; let base = state.create_base_display_item( &stacking_context_relative_bounds.inflate(Au::from_px(2), Au::from_px(2)), - LocalClip::from(self.clip.to_rectf()), + LocalClip::from(self.clip.to_layout()), node, None, DisplayListSection::Content, @@ -3208,23 +3204,6 @@ fn modify_border_width_for_inline_sides( } } -/// Allows a CSS color to be converted into a graphics color. -pub trait ToGfxColor { - /// Converts a CSS color to a graphics color. - fn to_gfx_color(&self) -> ColorF; -} - -impl ToGfxColor for RGBA { - fn to_gfx_color(&self) -> ColorF { - ColorF::new( - self.red_f32(), - self.green_f32(), - self.blue_f32(), - self.alpha_f32(), - ) - } -} - /// Describes how to paint the borders. #[derive(Clone, Copy)] pub enum BorderPaintingMode<'a> { diff --git a/components/layout/display_list/conversions.rs b/components/layout/display_list/conversions.rs new file mode 100644 index 00000000000..113b83ce42b --- /dev/null +++ b/components/layout/display_list/conversions.rs @@ -0,0 +1,152 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use app_units::Au; +use euclid::{Point2D, Rect, SideOffsets2D, Size2D, Vector2D}; +use style::computed_values::image_rendering::T as ImageRendering; +use style::computed_values::mix_blend_mode::T as MixBlendMode; +use style::computed_values::transform_style::T as TransformStyle; +use style::values::RGBA; +use style::values::computed::{BorderStyle, Filter}; +use style::values::generics::effects::Filter as GenericFilter; +use webrender_api as wr; + +pub trait ToLayout { + type Type; + fn to_layout(&self) -> Self::Type; +} + +impl ToLayout for BorderStyle { + type Type = wr::BorderStyle; + fn to_layout(&self) -> Self::Type { + match *self { + BorderStyle::None => wr::BorderStyle::None, + BorderStyle::Solid => wr::BorderStyle::Solid, + BorderStyle::Double => wr::BorderStyle::Double, + BorderStyle::Dotted => wr::BorderStyle::Dotted, + BorderStyle::Dashed => wr::BorderStyle::Dashed, + BorderStyle::Hidden => wr::BorderStyle::Hidden, + BorderStyle::Groove => wr::BorderStyle::Groove, + BorderStyle::Ridge => wr::BorderStyle::Ridge, + BorderStyle::Inset => wr::BorderStyle::Inset, + BorderStyle::Outset => wr::BorderStyle::Outset, + } + } +} + +impl ToLayout for Filter { + type Type = wr::FilterOp; + fn to_layout(&self) -> Self::Type { + match *self { + GenericFilter::Blur(radius) => wr::FilterOp::Blur(radius.px()), + GenericFilter::Brightness(amount) => wr::FilterOp::Brightness(amount.0), + GenericFilter::Contrast(amount) => wr::FilterOp::Contrast(amount.0), + GenericFilter::Grayscale(amount) => wr::FilterOp::Grayscale(amount.0), + GenericFilter::HueRotate(angle) => wr::FilterOp::HueRotate(angle.radians()), + GenericFilter::Invert(amount) => wr::FilterOp::Invert(amount.0), + GenericFilter::Opacity(amount) => wr::FilterOp::Opacity(amount.0.into(), amount.0), + GenericFilter::Saturate(amount) => wr::FilterOp::Saturate(amount.0), + GenericFilter::Sepia(amount) => wr::FilterOp::Sepia(amount.0), + // Statically check that DropShadow is impossible. + GenericFilter::DropShadow(ref shadow) => match *shadow {}, + } + } +} + +impl ToLayout for ImageRendering { + type Type = wr::ImageRendering; + fn to_layout(&self) -> Self::Type { + match *self { + ImageRendering::Auto => wr::ImageRendering::Auto, + ImageRendering::CrispEdges => wr::ImageRendering::CrispEdges, + ImageRendering::Pixelated => wr::ImageRendering::Pixelated, + } + } +} + +impl ToLayout for MixBlendMode { + type Type = wr::MixBlendMode; + fn to_layout(&self) -> Self::Type { + match *self { + MixBlendMode::Normal => wr::MixBlendMode::Normal, + MixBlendMode::Multiply => wr::MixBlendMode::Multiply, + MixBlendMode::Screen => wr::MixBlendMode::Screen, + MixBlendMode::Overlay => wr::MixBlendMode::Overlay, + MixBlendMode::Darken => wr::MixBlendMode::Darken, + MixBlendMode::Lighten => wr::MixBlendMode::Lighten, + MixBlendMode::ColorDodge => wr::MixBlendMode::ColorDodge, + MixBlendMode::ColorBurn => wr::MixBlendMode::ColorBurn, + MixBlendMode::HardLight => wr::MixBlendMode::HardLight, + MixBlendMode::SoftLight => wr::MixBlendMode::SoftLight, + MixBlendMode::Difference => wr::MixBlendMode::Difference, + MixBlendMode::Exclusion => wr::MixBlendMode::Exclusion, + MixBlendMode::Hue => wr::MixBlendMode::Hue, + MixBlendMode::Saturation => wr::MixBlendMode::Saturation, + MixBlendMode::Color => wr::MixBlendMode::Color, + MixBlendMode::Luminosity => wr::MixBlendMode::Luminosity, + } + } +} + +impl ToLayout for TransformStyle { + type Type = wr::TransformStyle; + fn to_layout(&self) -> Self::Type { + match *self { + TransformStyle::Auto | TransformStyle::Flat => wr::TransformStyle::Flat, + TransformStyle::Preserve3d => wr::TransformStyle::Preserve3D, + } + } +} + +impl ToLayout for RGBA { + type Type = wr::ColorF; + fn to_layout(&self) -> Self::Type { + wr::ColorF::new( + self.red_f32(), + self.green_f32(), + self.blue_f32(), + self.alpha_f32(), + ) + } +} + +impl ToLayout for Point2D { + type Type = wr::LayoutPoint; + fn to_layout(&self) -> Self::Type { + wr::LayoutPoint::new(self.x.to_f32_px(), self.y.to_f32_px()) + } +} + +impl ToLayout for Rect { + type Type = wr::LayoutRect; + fn to_layout(&self) -> Self::Type { + wr::LayoutRect::new(self.origin.to_layout(), self.size.to_layout()) + } +} + +impl ToLayout for SideOffsets2D { + type Type = wr::BorderWidths; + fn to_layout(&self) -> Self::Type { + wr::BorderWidths { + left: self.left.to_f32_px(), + top: self.top.to_f32_px(), + right: self.right.to_f32_px(), + bottom: self.bottom.to_f32_px(), + } + } +} + +impl ToLayout for Size2D { + type Type = wr::LayoutSize; + fn to_layout(&self) -> Self::Type { + wr::LayoutSize::new(self.width.to_f32_px(), self.height.to_f32_px()) + } +} + +impl ToLayout for Vector2D { + type Type = wr::LayoutVector2D; + fn to_layout(&self) -> Self::Type { + wr::LayoutVector2D::new(self.x.to_f32_px(), self.y.to_f32_px()) + } +} diff --git a/components/layout/display_list/mod.rs b/components/layout/display_list/mod.rs index 3f733f783a6..c5f1aa2aa71 100644 --- a/components/layout/display_list/mod.rs +++ b/components/layout/display_list/mod.rs @@ -10,9 +10,10 @@ pub use self::builder::InlineFlowDisplayListBuilding; pub use self::builder::ListItemFlowDisplayListBuilding; pub use self::builder::StackingContextCollectionFlags; pub use self::builder::StackingContextCollectionState; -pub use self::builder::ToGfxColor; +pub use self::conversions::ToLayout; pub use self::webrender_helpers::WebRenderDisplayListConverter; mod background; mod builder; +mod conversions; mod webrender_helpers; diff --git a/components/layout/display_list/webrender_helpers.rs b/components/layout/display_list/webrender_helpers.rs index 7cc0f4023db..4bd6d21c1a8 100644 --- a/components/layout/display_list/webrender_helpers.rs +++ b/components/layout/display_list/webrender_helpers.rs @@ -8,16 +8,12 @@ // completely converting layout to directly generate WebRender display lists, for example. use app_units::Au; -use euclid::{Point2D, Rect, SideOffsets2D, Size2D, Vector2D}; -use gfx::display_list::{BorderDetails, BorderRadii, BoxShadowClipMode, ClipScrollNode}; +use display_list::ToLayout; +use euclid::Point2D; +use gfx::display_list::{BorderDetails, BorderRadii, ClipScrollNode}; use gfx::display_list::{ClipScrollNodeIndex, ClipScrollNodeType, ClippingRegion, DisplayItem}; use gfx::display_list::{DisplayList, StackingContextType}; use msg::constellation_msg::PipelineId; -use style::computed_values::image_rendering::T as ImageRendering; -use style::computed_values::mix_blend_mode::T as MixBlendMode; -use style::computed_values::transform_style::T as TransformStyle; -use style::values::computed::{BorderStyle, Filter}; -use style::values::generics::effects::Filter as GenericFilter; use webrender_api::{self, ClipAndScrollInfo, ClipId, ClipMode, ComplexClipRegion}; use webrender_api::{DisplayListBuilder, ExtendMode, LayoutTransform}; @@ -36,101 +32,6 @@ trait WebRenderDisplayItemConverter { ); } -trait ToBorderStyle { - fn to_border_style(&self) -> webrender_api::BorderStyle; -} - -impl ToBorderStyle for BorderStyle { - fn to_border_style(&self) -> webrender_api::BorderStyle { - match *self { - BorderStyle::None => webrender_api::BorderStyle::None, - BorderStyle::Solid => webrender_api::BorderStyle::Solid, - BorderStyle::Double => webrender_api::BorderStyle::Double, - BorderStyle::Dotted => webrender_api::BorderStyle::Dotted, - BorderStyle::Dashed => webrender_api::BorderStyle::Dashed, - BorderStyle::Hidden => webrender_api::BorderStyle::Hidden, - BorderStyle::Groove => webrender_api::BorderStyle::Groove, - BorderStyle::Ridge => webrender_api::BorderStyle::Ridge, - BorderStyle::Inset => webrender_api::BorderStyle::Inset, - BorderStyle::Outset => webrender_api::BorderStyle::Outset, - } - } -} - -trait ToBorderWidths { - fn to_border_widths(&self) -> webrender_api::BorderWidths; -} - -impl ToBorderWidths for SideOffsets2D { - fn to_border_widths(&self) -> webrender_api::BorderWidths { - webrender_api::BorderWidths { - left: self.left.to_f32_px(), - top: self.top.to_f32_px(), - right: self.right.to_f32_px(), - bottom: self.bottom.to_f32_px(), - } - } -} - -trait ToBoxShadowClipMode { - fn to_clip_mode(&self) -> webrender_api::BoxShadowClipMode; -} - -impl ToBoxShadowClipMode for BoxShadowClipMode { - fn to_clip_mode(&self) -> webrender_api::BoxShadowClipMode { - match *self { - BoxShadowClipMode::Inset => webrender_api::BoxShadowClipMode::Inset, - BoxShadowClipMode::Outset => webrender_api::BoxShadowClipMode::Outset, - } - } -} - -trait ToSizeF { - fn to_sizef(&self) -> webrender_api::LayoutSize; -} - -trait ToPointF { - fn to_pointf(&self) -> webrender_api::LayoutPoint; -} - -trait ToVectorF { - fn to_vectorf(&self) -> webrender_api::LayoutVector2D; -} - -impl ToPointF for Point2D { - fn to_pointf(&self) -> webrender_api::LayoutPoint { - webrender_api::LayoutPoint::new(self.x.to_f32_px(), self.y.to_f32_px()) - } -} - -impl ToVectorF for Vector2D { - fn to_vectorf(&self) -> webrender_api::LayoutVector2D { - webrender_api::LayoutVector2D::new(self.x.to_f32_px(), self.y.to_f32_px()) - } -} - -impl ToSizeF for Size2D { - fn to_sizef(&self) -> webrender_api::LayoutSize { - webrender_api::LayoutSize::new(self.width.to_f32_px(), self.height.to_f32_px()) - } -} - -pub trait ToRectF { - fn to_rectf(&self) -> webrender_api::LayoutRect; -} - -impl ToRectF for Rect { - fn to_rectf(&self) -> webrender_api::LayoutRect { - let x = self.origin.x.to_f32_px(); - let y = self.origin.y.to_f32_px(); - let w = self.size.width.to_f32_px(); - let h = self.size.height.to_f32_px(); - let point = webrender_api::LayoutPoint::new(x, y); - let size = webrender_api::LayoutSize::new(w, h); - webrender_api::LayoutRect::new(point, size) - } -} - pub trait ToBorderRadius { fn to_border_radius(&self) -> webrender_api::BorderRadius; } @@ -138,107 +39,10 @@ pub trait ToBorderRadius { impl ToBorderRadius for BorderRadii { fn to_border_radius(&self) -> webrender_api::BorderRadius { webrender_api::BorderRadius { - top_left: self.top_left.to_sizef(), - top_right: self.top_right.to_sizef(), - bottom_left: self.bottom_left.to_sizef(), - bottom_right: self.bottom_right.to_sizef(), - } - } -} - -pub trait ToMixBlendMode { - fn to_mix_blend_mode(&self) -> webrender_api::MixBlendMode; -} - -impl ToMixBlendMode for MixBlendMode { - fn to_mix_blend_mode(&self) -> webrender_api::MixBlendMode { - match *self { - MixBlendMode::Normal => webrender_api::MixBlendMode::Normal, - MixBlendMode::Multiply => webrender_api::MixBlendMode::Multiply, - MixBlendMode::Screen => webrender_api::MixBlendMode::Screen, - MixBlendMode::Overlay => webrender_api::MixBlendMode::Overlay, - MixBlendMode::Darken => webrender_api::MixBlendMode::Darken, - MixBlendMode::Lighten => webrender_api::MixBlendMode::Lighten, - MixBlendMode::ColorDodge => webrender_api::MixBlendMode::ColorDodge, - MixBlendMode::ColorBurn => webrender_api::MixBlendMode::ColorBurn, - MixBlendMode::HardLight => webrender_api::MixBlendMode::HardLight, - MixBlendMode::SoftLight => webrender_api::MixBlendMode::SoftLight, - MixBlendMode::Difference => webrender_api::MixBlendMode::Difference, - MixBlendMode::Exclusion => webrender_api::MixBlendMode::Exclusion, - MixBlendMode::Hue => webrender_api::MixBlendMode::Hue, - MixBlendMode::Saturation => webrender_api::MixBlendMode::Saturation, - MixBlendMode::Color => webrender_api::MixBlendMode::Color, - MixBlendMode::Luminosity => webrender_api::MixBlendMode::Luminosity, - } - } -} - -trait ToImageRendering { - fn to_image_rendering(&self) -> webrender_api::ImageRendering; -} - -impl ToImageRendering for ImageRendering { - fn to_image_rendering(&self) -> webrender_api::ImageRendering { - match *self { - ImageRendering::CrispEdges => webrender_api::ImageRendering::CrispEdges, - ImageRendering::Auto => webrender_api::ImageRendering::Auto, - ImageRendering::Pixelated => webrender_api::ImageRendering::Pixelated, - } - } -} - -trait ToFilterOps { - fn to_filter_ops(&self) -> Vec; -} - -impl ToFilterOps for Vec { - fn to_filter_ops(&self) -> Vec { - let mut result = Vec::with_capacity(self.len()); - for filter in self.iter() { - match *filter { - GenericFilter::Blur(radius) => { - result.push(webrender_api::FilterOp::Blur(radius.px())) - }, - GenericFilter::Brightness(amount) => { - result.push(webrender_api::FilterOp::Brightness(amount.0)) - }, - GenericFilter::Contrast(amount) => { - result.push(webrender_api::FilterOp::Contrast(amount.0)) - }, - GenericFilter::Grayscale(amount) => { - result.push(webrender_api::FilterOp::Grayscale(amount.0)) - }, - GenericFilter::HueRotate(angle) => { - result.push(webrender_api::FilterOp::HueRotate(angle.radians())) - }, - GenericFilter::Invert(amount) => { - result.push(webrender_api::FilterOp::Invert(amount.0)) - }, - GenericFilter::Opacity(amount) => { - result.push(webrender_api::FilterOp::Opacity(amount.0.into(), amount.0)); - }, - GenericFilter::Saturate(amount) => { - result.push(webrender_api::FilterOp::Saturate(amount.0)) - }, - GenericFilter::Sepia(amount) => { - result.push(webrender_api::FilterOp::Sepia(amount.0)) - }, - GenericFilter::DropShadow(ref shadow) => match *shadow {}, - } - } - result - } -} - -pub trait ToTransformStyle { - fn to_transform_style(&self) -> webrender_api::TransformStyle; -} - -impl ToTransformStyle for TransformStyle { - fn to_transform_style(&self) -> webrender_api::TransformStyle { - match *self { - TransformStyle::Auto | TransformStyle::Flat => webrender_api::TransformStyle::Flat, - TransformStyle::Preserve3d => webrender_api::TransformStyle::Preserve3D, + top_left: self.top_left.to_layout(), + top_right: self.top_right.to_layout(), + bottom_left: self.bottom_left.to_layout(), + bottom_right: self.bottom_right.to_layout(), } } } @@ -247,7 +51,7 @@ impl WebRenderDisplayListConverter for DisplayList { fn convert_to_webrender(&self, pipeline_id: PipelineId) -> DisplayListBuilder { let mut builder = DisplayListBuilder::with_capacity( pipeline_id.to_webrender(), - self.bounds().size.to_sizef(), + self.bounds().size.to_layout(), 1024 * 1024, ); // 1 MB of space @@ -277,7 +81,7 @@ impl WebRenderDisplayItemConverter for DisplayItem { None => None, }; webrender_api::LayoutPrimitiveInfo { - rect: self.base().bounds.to_rectf(), + rect: self.base().bounds.to_layout(), local_clip: self.base().local_clip, // TODO(gw): Make use of the WR backface visibility functionality. is_backface_visible: true, @@ -359,34 +163,34 @@ impl WebRenderDisplayItemConverter for DisplayItem { if item.stretch_size.width > Au(0) && item.stretch_size.height > Au(0) { builder.push_image( &self.prim_info(), - item.stretch_size.to_sizef(), - item.tile_spacing.to_sizef(), - item.image_rendering.to_image_rendering(), + item.stretch_size.to_layout(), + item.tile_spacing.to_layout(), + item.image_rendering.to_layout(), id, ); } } }, DisplayItem::Border(ref item) => { - let widths = item.border_widths.to_border_widths(); + let widths = item.border_widths.to_layout(); let details = match item.details { BorderDetails::Normal(ref border) => { let left = webrender_api::BorderSide { color: border.color.left, - style: border.style.left.to_border_style(), + style: border.style.left.to_layout(), }; let top = webrender_api::BorderSide { color: border.color.top, - style: border.style.top.to_border_style(), + style: border.style.top.to_layout(), }; let right = webrender_api::BorderSide { color: border.color.right, - style: border.style.right.to_border_style(), + style: border.style.right.to_layout(), }; let bottom = webrender_api::BorderSide { color: border.color.bottom, - style: border.style.bottom.to_border_style(), + style: border.style.bottom.to_layout(), }; let radius = border.radius.to_border_radius(); webrender_api::BorderDetails::Normal(webrender_api::NormalBorder { @@ -422,8 +226,8 @@ impl WebRenderDisplayItemConverter for DisplayItem { }; webrender_api::BorderDetails::Gradient(webrender_api::GradientBorder { gradient: builder.create_gradient( - gradient.gradient.start_point.to_pointf(), - gradient.gradient.end_point.to_pointf(), + gradient.gradient.start_point.to_layout(), + gradient.gradient.end_point.to_layout(), gradient.gradient.stops.clone(), extend_mode, ), @@ -439,8 +243,8 @@ impl WebRenderDisplayItemConverter for DisplayItem { webrender_api::BorderDetails::RadialGradient( webrender_api::RadialGradientBorder { gradient: builder.create_radial_gradient( - gradient.gradient.center.to_pointf(), - gradient.gradient.radius.to_sizef(), + gradient.gradient.center.to_layout(), + gradient.gradient.radius.to_layout(), gradient.gradient.stops.clone(), extend_mode, ), @@ -453,8 +257,8 @@ impl WebRenderDisplayItemConverter for DisplayItem { builder.push_border(&self.prim_info(), widths, details); }, DisplayItem::Gradient(ref item) => { - let start_point = item.gradient.start_point.to_pointf(); - let end_point = item.gradient.end_point.to_pointf(); + let start_point = item.gradient.start_point.to_layout(); + let end_point = item.gradient.end_point.to_layout(); let extend_mode = if item.gradient.repeating { ExtendMode::Repeat } else { @@ -469,13 +273,13 @@ impl WebRenderDisplayItemConverter for DisplayItem { builder.push_gradient( &self.prim_info(), gradient, - item.tile.to_sizef(), - item.tile_spacing.to_sizef(), + item.tile.to_layout(), + item.tile_spacing.to_layout(), ); }, DisplayItem::RadialGradient(ref item) => { - let center = item.gradient.center.to_pointf(); - let radius = item.gradient.radius.to_sizef(); + let center = item.gradient.center.to_layout(); + let radius = item.gradient.radius.to_layout(); let extend_mode = if item.gradient.repeating { ExtendMode::Repeat } else { @@ -490,8 +294,8 @@ impl WebRenderDisplayItemConverter for DisplayItem { builder.push_radial_gradient( &self.prim_info(), gradient, - item.tile.to_sizef(), - item.tile_spacing.to_sizef(), + item.tile.to_layout(), + item.tile_spacing.to_layout(), ); }, DisplayItem::Line(ref item) => { @@ -505,16 +309,16 @@ impl WebRenderDisplayItemConverter for DisplayItem { ); }, DisplayItem::BoxShadow(ref item) => { - let box_bounds = item.box_bounds.to_rectf(); + let box_bounds = item.box_bounds.to_layout(); builder.push_box_shadow( &self.prim_info(), box_bounds, - item.offset.to_vectorf(), + item.offset.to_layout(), item.color, item.blur_radius.to_f32_px(), item.spread_radius.to_f32_px(), item.border_radius.to_border_radius(), - item.clip_mode.to_clip_mode(), + item.clip_mode, ); }, DisplayItem::PushTextShadow(ref item) => { @@ -522,7 +326,7 @@ impl WebRenderDisplayItemConverter for DisplayItem { &self.prim_info(), webrender_api::Shadow { blur_radius: item.blur_radius.to_f32_px(), - offset: item.offset.to_vectorf(), + offset: item.offset.to_layout(), color: item.color, }, ); @@ -545,20 +349,24 @@ impl WebRenderDisplayItemConverter for DisplayItem { .map(|perspective| LayoutTransform::from_untyped(&perspective)); builder.push_stacking_context( - &webrender_api::LayoutPrimitiveInfo::new(stacking_context.bounds.to_rectf()), + &webrender_api::LayoutPrimitiveInfo::new(stacking_context.bounds.to_layout()), stacking_context.scroll_policy, transform, stacking_context.transform_style, perspective, stacking_context.mix_blend_mode, - stacking_context.filters.to_filter_ops(), + stacking_context + .filters + .iter() + .map(ToLayout::to_layout) + .collect(), ); }, DisplayItem::PopStackingContext(_) => builder.pop_stacking_context(), DisplayItem::DefineClipScrollNode(ref item) => { let node = &clip_scroll_nodes[item.node_index.0]; let parent_id = get_id(clip_ids, node.parent_index); - let item_rect = node.clip.main.to_rectf(); + let item_rect = node.clip.main.to_layout(); let webrender_id = match node.node_type { ClipScrollNodeType::Clip => builder.define_clip_with_parent( @@ -572,8 +380,8 @@ impl WebRenderDisplayItemConverter for DisplayItem { .define_scroll_frame_with_parent( node.id, parent_id, - node.content_rect.to_rectf(), - node.clip.main.to_rectf(), + node.content_rect.to_layout(), + node.clip.main.to_layout(), node.clip.get_complex_clips(), None, scroll_sensitivity, @@ -611,7 +419,7 @@ impl ToWebRenderClip for ClippingRegion { .iter() .map(|complex_clipping_region| { ComplexClipRegion::new( - complex_clipping_region.rect.to_rectf(), + complex_clipping_region.rect.to_layout(), complex_clipping_region.radii.to_border_radius(), ClipMode::Clip, ) diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index af99ec99c73..2c72bd6f4b7 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -69,7 +69,7 @@ use layout::context::LayoutContext; use layout::context::RegisteredPainter; use layout::context::RegisteredPainters; use layout::context::malloc_size_of_persistent_local_context; -use layout::display_list::{ToGfxColor, WebRenderDisplayListConverter}; +use layout::display_list::WebRenderDisplayListConverter; use layout::flow::{Flow, GetBaseFlow, ImmutableFlowUtils, MutableOwnedFlowUtils}; use layout::flow_ref::FlowRef; use layout::incremental::{LayoutDamageComputation, RelayoutMode, SpecialRestyleDamage}; @@ -1688,10 +1688,15 @@ fn get_root_flow_background_color(flow: &mut Flow) -> webrender_api::ColorF { } let kid_block_flow = kid.as_block(); - kid_block_flow.fragment + let color = kid_block_flow.fragment .style - .resolve_color(kid_block_flow.fragment.style.get_background().background_color) - .to_gfx_color() + .resolve_color(kid_block_flow.fragment.style.get_background().background_color); + webrender_api::ColorF::new( + color.red_f32(), + color.green_f32(), + color.blue_f32(), + color.alpha_f32(), + ) } fn get_ua_stylesheets() -> Result {