Skip to content

Commit

Permalink
Auto merge of #21348 - pyfisch:only-webrender-items, r=jdm
Browse files Browse the repository at this point in the history
Replace Servo DL items with WR ones

The Servo internal display list items are already pretty much
equivalent to the WebRender ones. Except that Servo items contain
base information and associated glyphs and gradient stops which are
stored implicitly in WebRender. Remove the display items for
rectangles, text, images, border, gradients and box shadow and
replace them with their WebRender counter parts.

Some more internal items like line, text shadow and iframe can definitively be replaced with WebRender equivalents but I think the PR is already quite huge. If WebRender would expose a quite minimal API which allowed servo to directly push items onto the display list most of webrender_helpers boilerplate code could go away. As WebRender performs normalization of gradients this would need to be called by servo explicitly in this case.

It should be noted that gradient borders don't actually work neither with the old version nor with this PR as the measurements are all set to zero.

Part of #19676

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21348)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Aug 23, 2018
2 parents 99099d8 + 1c438ed commit c5131a2
Show file tree
Hide file tree
Showing 5 changed files with 396 additions and 473 deletions.
42 changes: 25 additions & 17 deletions components/layout/display_list/background.rs
Expand Up @@ -13,7 +13,7 @@

use app_units::Au;
use display_list::ToLayout;
use display_list::items::{BorderDetails, Gradient, RadialGradient, WebRenderImageInfo};
use display_list::items::WebRenderImageInfo;
use euclid::{Point2D, Rect, SideOffsets2D, Size2D, Vector2D};
use model::{self, MaybeAuto};
use style::computed_values::background_attachment::single_value::T as BackgroundAttachment;
Expand All @@ -34,8 +34,9 @@ use style::values::generics::image::EndingShape as GenericEndingShape;
use style::values::generics::image::GradientItem as GenericGradientItem;
use style::values::specified::background::BackgroundRepeatKeyword;
use style::values::specified::position::{X, Y};
use webrender_api::{BorderRadius, BorderSide, BorderStyle, ColorF, ExtendMode, GradientStop};
use webrender_api::{LayoutSize, NinePatchBorder, NinePatchBorderSource, NormalBorder};
use webrender_api::{BorderDetails, BorderRadius, BorderSide, BorderStyle, ColorF, ExtendMode};
use webrender_api::{Gradient, GradientStop, LayoutSize, NinePatchBorder, NinePatchBorderSource};
use webrender_api::{NormalBorder, RadialGradient};

/// A helper data structure for gradients.
#[derive(Clone, Copy)]
Expand Down Expand Up @@ -543,7 +544,7 @@ pub fn convert_linear_gradient(
stops: &[GradientItem],
direction: LineDirection,
repeating: bool,
) -> Gradient {
) -> (Gradient, Vec<GradientStop>) {
let angle = match direction {
LineDirection::Angle(angle) => angle.radians(),
LineDirection::Horizontal(x) => match x {
Expand Down Expand Up @@ -591,12 +592,14 @@ pub fn convert_linear_gradient(

let center = Point2D::new(size.width / 2, size.height / 2);

Gradient {
start_point: (center - delta).to_layout(),
end_point: (center + delta).to_layout(),
(
Gradient {
start_point: (center - delta).to_layout(),
end_point: (center + delta).to_layout(),
extend_mode: as_gradient_extend_mode(repeating),
},
stops,
extend_mode: as_gradient_extend_mode(repeating),
}
)
}

pub fn convert_radial_gradient(
Expand All @@ -606,7 +609,7 @@ pub fn convert_radial_gradient(
shape: EndingShape,
center: Position,
repeating: bool,
) -> RadialGradient {
) -> (RadialGradient, Vec<GradientStop>) {
let center = Point2D::new(
center.horizontal.to_used_value(size.width),
center.vertical.to_used_value(size.height),
Expand All @@ -629,12 +632,17 @@ pub fn convert_radial_gradient(

let stops = convert_gradient_stops(style, stops, radius.width);

RadialGradient {
center: center.to_layout(),
radius: radius.to_layout(),
stops: stops,
extend_mode: as_gradient_extend_mode(repeating),
}
(
RadialGradient {
center: center.to_layout(),
radius: radius.to_layout(),
extend_mode: as_gradient_extend_mode(repeating),
// FIXME(pyfisch): These values are calculated by WR.
start_offset: 0.0,
end_offset: 0.0,
},
stops,
)
}

/// Returns the the distance to the nearest or farthest corner depending on the comperator.
Expand Down Expand Up @@ -799,7 +807,7 @@ pub fn build_image_border_details(
let corners = &border_style_struct.border_image_slice.offsets;
let border_image_repeat = &border_style_struct.border_image_repeat;
if let Some(image_key) = webrender_image.key {
Some(BorderDetails::Image(NinePatchBorder {
Some(BorderDetails::NinePatch(NinePatchBorder {
source: NinePatchBorderSource::Image(image_key),
width: webrender_image.width,
height: webrender_image.height,
Expand Down

0 comments on commit c5131a2

Please sign in to comment.