mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Use more WebRender types in gfx/display_list
This uses floating-point (Layout) coordinates in where possible. Replace NormalBorder struct with WebRender equivalent. Remove ToPointF and ToRectF traits. Convert border RepeatKeyword with ToLayout. Add some definitions to malloc_size_of for WebRender types.
This commit is contained in:
parent
8612a87ed2
commit
8c7c5f6e79
10 changed files with 181 additions and 240 deletions
|
@ -26,15 +26,17 @@ use range::Range;
|
|||
use servo_geometry::max_rect;
|
||||
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,11 @@ 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::new(
|
||||
LayoutPoint::new(f32::MIN / 2.0, f32::MIN / 2.0),
|
||||
LayoutSize::new(f32::MAX, f32::MAX),
|
||||
)),
|
||||
section: DisplayListSection::Content,
|
||||
stacking_context_id: StackingContextId::root(),
|
||||
clipping_and_scrolling: ClippingAndScrolling::simple(ClipScrollNodeIndex(0)),
|
||||
|
@ -699,15 +705,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 +726,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 +753,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 +788,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 +808,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 +927,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 +937,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 +965,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 +1109,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 +1143,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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue