Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more WebRender types in gfx/display_list. #19782

Merged
merged 2 commits into from Jan 18, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Some generated files are not rendered by default. Learn more.

@@ -14,3 +14,4 @@ app_units = "0.6"
euclid = "0.16"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
webrender_api = { git = "https://github.com/servo/webrender" }
@@ -6,9 +6,12 @@ extern crate app_units;
extern crate euclid;
extern crate malloc_size_of;
#[macro_use] extern crate malloc_size_of_derive;
extern crate webrender_api;

use app_units::{Au, MAX_AU, MIN_AU};
use euclid::{Point2D, Rect, Size2D};
use std::f32;
use webrender_api::{LayoutPoint, LayoutRect, LayoutSize};

// Units for use with euclid::length and euclid::scale_factor.

@@ -32,9 +35,27 @@ pub enum DeviceIndependentPixel {}
// originally proposed in 2002 as a standard unit of measure in Gecko.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=177805 for more info.

#[inline(always)]
pub fn max_rect() -> Rect<Au> {
Rect::new(Point2D::new(MIN_AU / 2, MIN_AU / 2), Size2D::new(MAX_AU, MAX_AU))
pub trait MaxRect {
#[inline(always)]
fn max_rect() -> Self;
}

impl MaxRect for Rect<Au> {
fn max_rect() -> Rect<Au> {
Rect::new(
Point2D::new(MIN_AU / 2, MIN_AU / 2),
Size2D::new(MAX_AU, MAX_AU)
)
}
}

impl MaxRect for LayoutRect {
fn max_rect() -> LayoutRect {
LayoutRect::new(
LayoutPoint::new(f32::MIN / 2.0, f32::MIN / 2.0),
LayoutSize::new(f32::MAX, f32::MAX),
)
}
}

/// A helper function to convert a rect of `f32` pixels to a rect of app units.
@@ -23,18 +23,20 @@ use ipc_channel::ipc::IpcSharedMemory;
use msg::constellation_msg::PipelineId;
use net_traits::image::base::{Image, PixelFormat};
use range::Range;
use servo_geometry::max_rect;
use servo_geometry::MaxRect;
use std::cmp::{self, Ordering};
use std::collections::HashMap;
use std::f32;
use std::fmt;
use std::sync::Arc;
use style::computed_values::{border_style, image_rendering};
use style::values::computed::Filter;
use style_traits::cursor::Cursor;
use text::TextRun;
use text::glyph::ByteIndex;
use webrender_api::{self, BoxShadowClipMode, ClipId, ColorF, GradientStop, LocalClip, MixBlendMode};
use webrender_api::{ScrollPolicy, ScrollSensitivity, StickyOffsetBounds, TransformStyle};
use webrender_api::{BoxShadowClipMode, ClipId, ColorF, ExtendMode, GradientStop, ImageKey};
use webrender_api::{ImageRendering, LayoutPoint, LayoutRect, LayoutSize, LayoutVector2D};
use webrender_api::{LineStyle, LocalClip, MixBlendMode, NormalBorder, RepeatMode, ScrollPolicy};
use webrender_api::{ScrollSensitivity, StickyOffsetBounds, TransformStyle};

pub use style::dom::OpaqueNode;

@@ -442,7 +444,8 @@ impl BaseDisplayItem {
node: OpaqueNode(0),
pointing: None,
},
local_clip: LocalClip::from(max_rect().to_rectf()),
// Create a rectangle of maximal size.
local_clip: LocalClip::from(LayoutRect::max_rect()),
section: DisplayListSection::Content,
stacking_context_id: StackingContextId::root(),
clipping_and_scrolling: ClippingAndScrolling::simple(ClipScrollNodeIndex(0)),
@@ -489,7 +492,7 @@ impl ClippingRegion {
#[inline]
pub fn max() -> ClippingRegion {
ClippingRegion {
main: max_rect(),
main: Rect::max_rect(),
complex: Vec::new(),
}
}
@@ -600,7 +603,7 @@ impl ClippingRegion {

#[inline]
pub fn is_max(&self) -> bool {
self.main == max_rect() && self.complex.is_empty()
self.main == Rect::max_rect() && self.complex.is_empty()
}
}

@@ -610,7 +613,7 @@ impl fmt::Debug for ClippingRegion {
write!(f, "ClippingRegion::Max")
} else if *self == ClippingRegion::empty() {
write!(f, "ClippingRegion::Empty")
} else if self.main == max_rect() {
} else if self.main == Rect::max_rect() {
write!(f, "ClippingRegion(Complex={:?})", self.complex)
} else {
write!(f, "ClippingRegion(Rect={:?}, Complex={:?})", self.main, self.complex)
@@ -699,15 +702,15 @@ pub struct ImageDisplayItem {
/// The dimensions to which the image display item should be stretched. If this is smaller than
/// the bounds of this display item, then the image will be repeated in the appropriate
/// direction to tile the entire bounds.
pub stretch_size: Size2D<Au>,
pub stretch_size: LayoutSize,

/// The amount of space to add to the right and bottom part of each tile, when the image
/// is tiled.
pub tile_spacing: Size2D<Au>,
pub tile_spacing: LayoutSize,

/// The algorithm we should use to stretch the image. See `image_rendering` in CSS-IMAGES-3 §
/// 5.3.
pub image_rendering: image_rendering::T,
pub image_rendering: ImageRendering,
}
/// Paints an iframe.
#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
@@ -720,16 +723,16 @@ pub struct IframeDisplayItem {
#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
pub struct Gradient {
/// The start point of the gradient (computed during display list construction).
pub start_point: Point2D<Au>,
pub start_point: LayoutPoint,

/// The end point of the gradient (computed during display list construction).
pub end_point: Point2D<Au>,
pub end_point: LayoutPoint,

/// A list of color stops.
pub stops: Vec<GradientStop>,

/// True if gradient repeats infinitly.
pub repeating: bool,
/// Whether the gradient is repeated or clamped.
pub extend_mode: ExtendMode,
}

#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
@@ -747,24 +750,24 @@ pub struct GradientDisplayItem {
/// the same gradient.
///
/// Without tiles, the tile will be the same size as the background.
pub tile: Size2D<Au>,
pub tile_spacing: Size2D<Au>,
pub tile: LayoutSize,
pub tile_spacing: LayoutSize,
}

/// Paints a radial gradient.
#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
pub struct RadialGradient {
/// The center point of the gradient.
pub center: Point2D<Au>,
pub center: LayoutPoint,

/// The radius of the gradient with an x and an y component.
pub radius: Size2D<Au>,
pub radius: LayoutSize,

/// A list of color stops.
pub stops: Vec<GradientStop>,

/// True if gradient repeats infinitly.
pub repeating: bool,
/// Whether the gradient is repeated or clamped.
pub extend_mode: ExtendMode,
}

#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
@@ -782,21 +785,8 @@ pub struct RadialGradientDisplayItem {
/// the same gradient.
///
/// Without tiles, the tile will be the same size as the background.
pub tile: Size2D<Au>,
pub tile_spacing: Size2D<Au>,
}

/// A normal border, supporting CSS border styles.
#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
pub struct NormalBorder {
/// Border colors.
pub color: SideOffsets2D<ColorF>,

/// Border styles.
pub style: SideOffsets2D<border_style::T>,

/// Border radii.
pub radius: BorderRadii<Au>,
pub tile: LayoutSize,
pub tile_spacing: LayoutSize,
}

/// A border that is made of image segments.
@@ -815,10 +805,10 @@ pub struct ImageBorder {
pub fill: bool,

/// How to repeat or stretch horizontal edges (border-image-repeat).
pub repeat_horizontal: webrender_api::RepeatMode,
pub repeat_horizontal: RepeatMode,

/// How to repeat or stretch vertical edges (border-image-repeat).
pub repeat_vertical: webrender_api::RepeatMode,
pub repeat_vertical: RepeatMode,
}

/// A border that is made of linear gradient
@@ -934,8 +924,7 @@ pub struct LineDisplayItem {
pub color: ColorF,

/// The line segment style.
#[ignore_malloc_size_of = "enum type in webrender"]
pub style: webrender_api::LineStyle,
pub style: LineStyle,
}

/// Paints a box shadow per CSS-BACKGROUNDS.
@@ -945,25 +934,24 @@ pub struct BoxShadowDisplayItem {
pub base: BaseDisplayItem,

/// The dimensions of the box that we're placing a shadow around.
pub box_bounds: Rect<Au>,
pub box_bounds: LayoutRect,

/// The offset of this shadow from the box.
pub offset: Vector2D<Au>,
pub offset: LayoutVector2D,

/// The color of this shadow.
pub color: ColorF,

/// The blur radius for this shadow.
pub blur_radius: Au,
pub blur_radius: f32,

/// The spread radius of this shadow.
pub spread_radius: Au,
pub spread_radius: f32,

/// The border radius of this shadow.
pub border_radius: BorderRadii<Au>,

/// How we should clip the result.
#[ignore_malloc_size_of = "enum type in webrender"]
pub clip_mode: BoxShadowClipMode,
}

@@ -974,13 +962,13 @@ pub struct PushTextShadowDisplayItem {
pub base: BaseDisplayItem,

/// The offset of this shadow from the text.
pub offset: Vector2D<Au>,
pub offset: LayoutVector2D,

/// The color of this shadow.
pub color: ColorF,

/// The blur radius for this shadow.
pub blur_radius: Au,
pub blur_radius: f32,
}

/// Defines a text shadow that affects all items until the next PopTextShadow.
@@ -1118,7 +1106,7 @@ pub struct WebRenderImageInfo {
pub width: u32,
pub height: u32,
pub format: PixelFormat,
pub key: Option<webrender_api::ImageKey>,
pub key: Option<ImageKey>,
}

impl WebRenderImageInfo {
@@ -1152,28 +1140,3 @@ impl SimpleMatrixDetection for Transform3D<f32> {
}
}

trait ToPointF {
fn to_pointf(&self) -> webrender_api::LayoutPoint;
}

impl ToPointF for Point2D<Au> {
fn to_pointf(&self) -> webrender_api::LayoutPoint {
webrender_api::LayoutPoint::new(self.x.to_f32_px(), self.y.to_f32_px())
}
}

trait ToRectF {
fn to_rectf(&self) -> webrender_api::LayoutRect;
}

impl ToRectF for Rect<Au> {
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)
}
}
@@ -44,7 +44,7 @@ use layout_debug;
use model::{AdjoiningMargins, CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo, MaybeAuto};
use sequential;
use serde::{Serialize, Serializer};
use servo_geometry::max_rect;
use servo_geometry::MaxRect;
use std::cmp::{max, min};
use std::fmt;
use std::sync::Arc;
@@ -1955,7 +1955,7 @@ impl Flow for BlockFlow {
let container_size = Size2D::new(self.base.block_container_inline_size, Au(0));

if self.is_root() {
self.base.clip = max_rect();
self.base.clip = Rect::max_rect();
}

if self.base.flags.contains(FlowFlags::IS_ABSOLUTELY_POSITIONED) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.