From 98a7cccf2fc4c5ba9b283ac0dafe4aed521082ba Mon Sep 17 00:00:00 2001 From: Pyfisch Date: Mon, 17 Sep 2018 09:33:24 +0200 Subject: [PATCH] Replace BorderWidths with SideOffsets2D closes #3053 --- examples/basic.rs | 7 +------ webrender/src/border.rs | 16 ++++++++-------- webrender/src/prim_store.rs | 11 ++++++----- webrender_api/src/display_item.rs | 14 +++----------- webrender_api/src/display_list.rs | 18 +++++++++--------- webrender_api/src/units.rs | 1 + wrench/src/yaml_frame_reader.rs | 7 +------ 7 files changed, 29 insertions(+), 45 deletions(-) diff --git a/examples/basic.rs b/examples/basic.rs index 1b557fbaee..c3a725291a 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -228,12 +228,7 @@ impl Example for App { color: ColorF::new(0.0, 0.0, 1.0, 1.0), style: BorderStyle::Groove, }; - let border_widths = BorderWidths { - top: 10.0, - left: 10.0, - bottom: 10.0, - right: 10.0, - }; + let border_widths = LayoutSideOffsets::new_all_same(10.0); let border_details = BorderDetails::Normal(NormalBorder { top: border_side, right: border_side, diff --git a/webrender/src/border.rs b/webrender/src/border.rs index 11360a6581..b4e51b220b 100644 --- a/webrender/src/border.rs +++ b/webrender/src/border.rs @@ -2,8 +2,8 @@ * 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 api::{BorderRadius, BorderSide, BorderStyle, BorderWidths, ColorF}; -use api::{ColorU, DeviceRect, DeviceSize, LayoutSizeAu, LayoutPrimitiveInfo, LayoutToDeviceScale}; +use api::{BorderRadius, BorderSide, BorderStyle, ColorF, ColorU, DeviceRect, DeviceSize}; +use api::{LayoutSizeAu, LayoutSideOffsets, LayoutPrimitiveInfo, LayoutToDeviceScale}; use api::{DeviceVector2D, DevicePoint, DeviceIntSize, LayoutRect, LayoutSize, NormalBorder}; use app_units::Au; use ellipse::Ellipse; @@ -75,8 +75,8 @@ pub struct BorderWidthsAu { pub bottom: Au, } -impl From for BorderWidthsAu { - fn from(widths: BorderWidths) -> Self { +impl From for BorderWidthsAu { + fn from(widths: LayoutSideOffsets) -> Self { BorderWidthsAu { left: Au::from_f32_px(widths.left), top: Au::from_f32_px(widths.top), @@ -117,7 +117,7 @@ pub struct BorderCacheKey { } impl BorderCacheKey { - pub fn new(border: &NormalBorder, widths: &BorderWidths) -> Self { + pub fn new(border: &NormalBorder, widths: &LayoutSideOffsets) -> Self { BorderCacheKey { left: border.left.into(), top: border.top.into(), @@ -180,7 +180,7 @@ impl<'a> DisplayListFlattener<'a> { &mut self, info: &LayoutPrimitiveInfo, border: &NormalBorder, - widths: &BorderWidths, + widths: &LayoutSideOffsets, clip_and_scroll: ScrollNodeAndClipChain, ) { let mut border = *border; @@ -628,7 +628,7 @@ impl BorderRenderTaskInfo { pub fn new( rect: &LayoutRect, border: &NormalBorder, - widths: &BorderWidths, + widths: &LayoutSideOffsets, scale: LayoutToDeviceScale, brush_segments: &mut Vec, ) -> Option { @@ -948,7 +948,7 @@ impl BorderRenderTaskInfo { /// blurrier. pub fn get_max_scale( radii: &BorderRadius, - widths: &BorderWidths + widths: &LayoutSideOffsets ) -> LayoutToDeviceScale { let r = radii.top_left.width .max(radii.top_left.height) diff --git a/webrender/src/prim_store.rs b/webrender/src/prim_store.rs index 290b8c66f6..d849c7d395 100644 --- a/webrender/src/prim_store.rs +++ b/webrender/src/prim_store.rs @@ -5,9 +5,10 @@ use api::{AlphaType, BorderRadius, BuiltDisplayList, ClipMode, ColorF, PictureRect}; use api::{DeviceIntRect, DeviceIntSize, DevicePixelScale, ExtendMode, DeviceRect, PictureToRasterTransform}; use api::{FilterOp, GlyphInstance, GradientStop, ImageKey, ImageRendering, ItemRange, ItemTag, TileOffset}; -use api::{GlyphRasterSpace, LayoutPoint, LayoutRect, LayoutSize, LayoutToWorldTransform, LayoutVector2D}; -use api::{PremultipliedColorF, PropertyBinding, Shadow, YuvColorSpace, YuvFormat, DeviceIntSideOffsets, WorldPixel}; -use api::{BorderWidths, BoxShadowClipMode, LayoutToWorldScale, NormalBorder, WorldRect, PicturePixel, RasterPixel}; +use api::{GlyphRasterSpace, LayoutPoint, LayoutRect, LayoutSideOffsets, LayoutSize, LayoutToWorldTransform}; +use api::{LayoutVector2D, PremultipliedColorF, PropertyBinding, Shadow, YuvColorSpace, YuvFormat}; +use api::{DeviceIntSideOffsets, WorldPixel, BoxShadowClipMode, LayoutToWorldScale, NormalBorder, WorldRect}; +use api::{PicturePixel, RasterPixel}; use app_units::Au; use border::{BorderCacheKey, BorderRenderTaskInfo}; use clip_scroll_tree::{ClipScrollTree, CoordinateSystemId, SpatialNodeIndex}; @@ -350,7 +351,7 @@ pub enum BorderSource { cache_key: BorderCacheKey, task_info: Option, border: NormalBorder, - widths: BorderWidths, + widths: LayoutSideOffsets, }, } @@ -442,7 +443,7 @@ impl BrushKind { // Construct a brush that is a border with `border` style and `widths` // dimensions. - pub fn new_border(mut border: NormalBorder, widths: BorderWidths) -> BrushKind { + pub fn new_border(mut border: NormalBorder, widths: LayoutSideOffsets) -> BrushKind { // FIXME(emilio): Is this the best place to do this? border.normalize(&widths); diff --git a/webrender_api/src/display_item.rs b/webrender_api/src/display_item.rs index 4cfe09ec3c..0d63486472 100644 --- a/webrender_api/src/display_item.rs +++ b/webrender_api/src/display_item.rs @@ -8,6 +8,7 @@ use euclid::{SideOffsets2D, TypedRect}; use std::ops::Not; use {ColorF, FontInstanceKey, GlyphOptions, ImageKey, LayoutPixel, LayoutPoint}; use {LayoutRect, LayoutSize, LayoutTransform, LayoutVector2D, PipelineId, PropertyBinding}; +use LayoutSideOffsets; // NOTE: some of these structs have an "IMPLICIT" comment. @@ -277,7 +278,7 @@ impl NormalBorder { /// Normalizes a border so that we don't render disallowed stuff, like inset /// borders that are less than two pixels wide. #[inline] - pub fn normalize(&mut self, widths: &BorderWidths) { + pub fn normalize(&mut self, widths: &LayoutSideOffsets) { #[inline] fn renders_small_border_solid(style: BorderStyle) -> bool { match style { @@ -364,7 +365,7 @@ pub enum BorderDetails { #[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)] pub struct BorderDisplayItem { - pub widths: BorderWidths, + pub widths: LayoutSideOffsets, pub details: BorderDetails, } @@ -384,15 +385,6 @@ pub struct BorderRadius { pub bottom_right: LayoutSize, } -#[repr(C)] -#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)] -pub struct BorderWidths { - pub left: f32, - pub top: f32, - pub right: f32, - pub bottom: f32, -} - #[repr(C)] #[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)] pub struct BorderSide { diff --git a/webrender_api/src/display_list.rs b/webrender_api/src/display_list.rs index 9b5b35c857..dce99deaef 100644 --- a/webrender_api/src/display_list.rs +++ b/webrender_api/src/display_list.rs @@ -13,18 +13,18 @@ use std::io::{Read, Write}; use std::marker::PhantomData; use std::{io, mem, ptr, slice}; use time::precise_time_ns; -use {AlphaType, BorderDetails, BorderDisplayItem, BorderRadius, BorderWidths, BoxShadowClipMode}; +use {AlphaType, BorderDetails, BorderDisplayItem, BorderRadius, BoxShadowClipMode}; use {BoxShadowDisplayItem, ClipAndScrollInfo, ClipChainId, ClipChainItem, ClipDisplayItem, ClipId}; use {ColorF, ComplexClipRegion, DisplayItem, ExtendMode, ExternalScrollId, FilterOp}; use {FontInstanceKey, GlyphInstance, GlyphOptions, GlyphRasterSpace, Gradient, GradientBuilder}; use {GradientDisplayItem, GradientStop, IframeDisplayItem, ImageDisplayItem, ImageKey, ImageMask}; -use {ImageRendering, LayoutPoint, LayoutPrimitiveInfo, LayoutRect, LayoutSize, LayoutTransform}; -use {LayoutVector2D, LineDisplayItem, LineOrientation, LineStyle, MixBlendMode, PipelineId}; -use {PropertyBinding, PushReferenceFrameDisplayListItem, PushStackingContextDisplayItem}; -use {RadialGradient, RadialGradientDisplayItem, RectangleDisplayItem, ReferenceFrame}; -use {ScrollFrameDisplayItem, ScrollSensitivity, Shadow, SpecificDisplayItem, StackingContext}; -use {StickyFrameDisplayItem, StickyOffsetBounds, TextDisplayItem, TransformStyle, YuvColorSpace}; -use {YuvData, YuvImageDisplayItem}; +use {ImageRendering, LayoutPoint, LayoutPrimitiveInfo, LayoutRect, LayoutSideOffsets, LayoutSize}; +use {LayoutTransform, LayoutVector2D, LineDisplayItem, LineOrientation, LineStyle, MixBlendMode}; +use {PipelineId, PropertyBinding, PushReferenceFrameDisplayListItem}; +use {PushStackingContextDisplayItem, RadialGradient, RadialGradientDisplayItem}; +use {RectangleDisplayItem, ReferenceFrame, ScrollFrameDisplayItem, ScrollSensitivity, Shadow}; +use {SpecificDisplayItem, StackingContext, StickyFrameDisplayItem, StickyOffsetBounds}; +use {TextDisplayItem, TransformStyle, YuvColorSpace, YuvData, YuvImageDisplayItem}; // We don't want to push a long text-run. If a text-run is too long, split it into several parts. // This needs to be set to (renderer::MAX_VERTEX_TEXTURE_WIDTH - VECS_PER_TEXT_RUN) * 2 @@ -1154,7 +1154,7 @@ impl DisplayListBuilder { pub fn push_border( &mut self, info: &LayoutPrimitiveInfo, - widths: BorderWidths, + widths: LayoutSideOffsets, details: BorderDetails, ) { let item = SpecificDisplayItem::Border(BorderDisplayItem { details, widths }); diff --git a/webrender_api/src/units.rs b/webrender_api/src/units.rs index 45ec7e8409..c9c528c2cf 100644 --- a/webrender_api/src/units.rs +++ b/webrender_api/src/units.rs @@ -77,6 +77,7 @@ pub type LayoutPoint3D = TypedPoint3D; pub type LayoutVector2D = TypedVector2D; pub type LayoutVector3D = TypedVector3D; pub type LayoutSize = TypedSize2D; +pub type LayoutSideOffsets = TypedSideOffsets2D; /// Geometry in the document's coordinate space (logical pixels). #[derive(Hash, Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)] diff --git a/wrench/src/yaml_frame_reader.rs b/wrench/src/yaml_frame_reader.rs index d8b81f66aa..4377481f29 100644 --- a/wrench/src/yaml_frame_reader.rs +++ b/wrench/src/yaml_frame_reader.rs @@ -819,12 +819,7 @@ impl YamlFrameReader { .as_vec_f32() .expect("borders must have width(s)"); let widths = broadcast(&widths, 4); - let widths = BorderWidths { - top: widths[0], - left: widths[1], - bottom: widths[2], - right: widths[3], - }; + let widths = LayoutSideOffsets::new(widths[0], widths[3], widths[2], widths[1]); let border_details = if let Some(border_type) = item["border-type"].as_str() { match border_type { "normal" => {