Skip to content

Commit

Permalink
dependencies: Upgrade to WebRender 0.64
Browse files Browse the repository at this point in the history
This brings the version of WebRender used in Servo up-to-date with Gecko
upstream. The big change here is that HiDPI is no longer handled via
WebRender. Instead this happens via a scale applied to the root layer in
the compositor. In addition to this change, various changes are made to
Servo to adapt to the new WebRender API.

Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
  • Loading branch information
mrobinson and mukilan committed Mar 14, 2024
1 parent ed99128 commit 351bcfb
Show file tree
Hide file tree
Showing 102 changed files with 704 additions and 600 deletions.
183 changes: 103 additions & 80 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -123,8 +123,8 @@ uuid = { version = "1.7.0", features = ["v4"] }
webdriver = "0.49.0"
webpki = "0.22"
webpki-roots = "0.25"
webrender = { git = "https://github.com/servo/webrender", rev = "f91b68a61", features = ["capture"] }
webrender_api = { git = "https://github.com/servo/webrender", rev = "f91b68a61" }
webrender = { git = "https://github.com/servo/webrender", branch = "0.64", features = ["capture"] }
webrender_api = { git = "https://github.com/servo/webrender", branch = "0.64" }
webrender_traits = { path = "components/shared/webrender" }
wgpu-core = "0.18"
wgpu-types = "0.18"
Expand Down
369 changes: 204 additions & 165 deletions components/compositing/compositor.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion components/compositing/windowing.rs
Expand Up @@ -219,7 +219,7 @@ impl EmbedderCoordinates {
pub fn get_flipped_viewport(&self) -> DeviceIntRect {
let fb_height = self.framebuffer.height;
let mut view = self.viewport;
view.origin.y = fb_height - view.origin.y - view.size.height;
view.min.y = fb_height - view.min.y - view.size().height;
DeviceIntRect::from_untyped(&view.to_untyped())
}
}
2 changes: 1 addition & 1 deletion components/geometry/lib.rs
Expand Up @@ -51,7 +51,7 @@ impl MaxRect for Rect<Au> {
impl MaxRect for LayoutRect {
#[inline]
fn max_rect() -> LayoutRect {
LayoutRect::new(
LayoutRect::from_origin_and_size(
LayoutPoint::new(f32::MIN / 2.0, f32::MIN / 2.0),
LayoutSize::new(f32::MAX, f32::MAX),
)
Expand Down
10 changes: 8 additions & 2 deletions components/gfx/platform/macos/font_template.rs
Expand Up @@ -125,8 +125,14 @@ impl FontTemplateData {

/// Returns the native font that underlies this font template, if applicable.
pub fn native_font(&self) -> Option<NativeFontHandle> {
self.ctfont(0.0)
.map(|ctfont| NativeFontHandle(ctfont.copy_to_CGFont()))
let local_identifier = match &self.identifier {
FontIdentifier::Local(local_identifier) => local_identifier,
FontIdentifier::Web(_) => return None,
};
Some(NativeFontHandle {
name: local_identifier.postscript_name.to_string(),
path: local_identifier.path.to_string(),
})
}
}

Expand Down
51 changes: 40 additions & 11 deletions components/layout/display_list/builder.rs
Expand Up @@ -29,6 +29,7 @@ use log::{debug, warn};
use msg::constellation_msg::{BrowsingContextId, PipelineId};
use net_traits::image_cache::UsePlaceholder;
use range::Range;
use script_traits::compositor::ScrollSensitivity;
use servo_config::opts;
use servo_geometry::{self, MaxRect};
use style::color::AbsoluteColor;
Expand All @@ -51,7 +52,7 @@ use webrender_api::units::{LayoutRect, LayoutTransform, LayoutVector2D};
use webrender_api::{
self, BorderDetails, BorderRadius, BorderSide, BoxShadowClipMode, ColorF, ColorU,
ExternalScrollId, FilterOp, GlyphInstance, ImageRendering, LineStyle, NinePatchBorder,
NinePatchBorderSource, NormalBorder, PropertyBinding, ScrollSensitivity, StickyOffsetBounds,
NinePatchBorderSource, NormalBorder, PropertyBinding, StickyOffsetBounds,
};

use crate::block::BlockFlow;
Expand Down Expand Up @@ -384,6 +385,7 @@ impl<'a> DisplayListBuildState<'a> {
&self,
clip_rect: Rect<Au>,
node: OpaqueNode,
unique_id: u64,
cursor: Option<Cursor>,
section: DisplayListSection,
) -> BaseDisplayItem {
Expand All @@ -397,6 +399,7 @@ impl<'a> DisplayListBuildState<'a> {
self.create_base_display_item_with_clipping_and_scrolling(
clip_rect,
node,
unique_id,
cursor,
section,
clipping_and_scrolling,
Expand All @@ -407,12 +410,17 @@ impl<'a> DisplayListBuildState<'a> {
&self,
clip_rect: Rect<Au>,
node: OpaqueNode,
unique_id: u64,
cursor: Option<Cursor>,
section: DisplayListSection,
clipping_and_scrolling: ClippingAndScrolling,
) -> BaseDisplayItem {
BaseDisplayItem::new(
DisplayItemMetadata { node, cursor },
DisplayItemMetadata {
node,
unique_id,
cursor,
},
clip_rect.to_layout(),
section,
self.current_stacking_context_id,
Expand Down Expand Up @@ -702,6 +710,7 @@ impl Fragment {
let base = state.create_base_display_item(
bounds,
self.node,
self.unique_id(),
get_cursor(style, Cursor::Default),
display_list_section,
);
Expand Down Expand Up @@ -842,6 +851,7 @@ impl Fragment {
let base = state.create_base_display_item(
placement.clip_rect,
self.node,
self.unique_id(),
get_cursor(style, Cursor::Default),
display_list_section,
);
Expand Down Expand Up @@ -964,6 +974,7 @@ impl Fragment {
let base = state.create_base_display_item(
placement.clip_rect,
self.node,
self.unique_id(),
get_cursor(style, Cursor::Default),
display_list_section,
);
Expand Down Expand Up @@ -1040,6 +1051,7 @@ impl Fragment {
let base = state.create_base_display_item(
clip,
self.node,
self.unique_id(),
get_cursor(style, Cursor::Default),
display_list_section,
);
Expand Down Expand Up @@ -1126,6 +1138,7 @@ impl Fragment {
let base = state.create_base_display_item(
clip,
self.node,
self.unique_id(),
get_cursor(style, Cursor::Default),
display_list_section,
);
Expand Down Expand Up @@ -1221,7 +1234,7 @@ impl Fragment {
)?;
width = image.width;
height = image.height;
NinePatchBorderSource::Image(image.key?)
NinePatchBorderSource::Image(image.key?, ImageRendering::Auto)
},
Image::PaintWorklet(ref paint_worklet) => {
let image = self.get_webrender_image_for_paint_worklet(
Expand All @@ -1232,7 +1245,7 @@ impl Fragment {
)?;
width = image.width;
height = image.height;
NinePatchBorderSource::Image(image.key?)
NinePatchBorderSource::Image(image.key?, ImageRendering::Auto)
},
Image::Gradient(ref gradient) => match **gradient {
Gradient::Linear {
Expand Down Expand Up @@ -1288,7 +1301,6 @@ impl Fragment {
fill: border_image_fill,
repeat_horizontal: border_image_repeat.0.to_layout(),
repeat_vertical: border_image_repeat.1.to_layout(),
outset: SideOffsets2D::zero(),
});
state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data(
base,
Expand Down Expand Up @@ -1340,6 +1352,7 @@ impl Fragment {
let base = state.create_base_display_item(
clip,
self.node,
self.unique_id(),
get_cursor(style, Cursor::Default),
DisplayListSection::Outlines,
);
Expand Down Expand Up @@ -1372,6 +1385,7 @@ impl Fragment {
let base = state.create_base_display_item(
clip,
self.node,
self.unique_id(),
get_cursor(style, Cursor::Default),
DisplayListSection::Content,
);
Expand Down Expand Up @@ -1402,12 +1416,13 @@ impl Fragment {
let base = state.create_base_display_item(
clip,
self.node,
self.unique_id(),
get_cursor(style, Cursor::Default),
DisplayListSection::Content,
);
// TODO(gw): Use a better estimate for wavy line thickness.
let area = baseline.to_layout();
let wavy_line_thickness = (0.33 * area.size.height).ceil();
let wavy_line_thickness = (0.33 * area.size().height).ceil();
state.add_display_item(DisplayItem::Line(CommonDisplayItem::new(
base,
webrender_api::LineDisplayItem {
Expand All @@ -1432,6 +1447,7 @@ impl Fragment {
let base = state.create_base_display_item(
clip,
self.node,
self.unique_id(),
get_cursor(&self.style, Cursor::Default),
DisplayListSection::Content,
);
Expand Down Expand Up @@ -1475,6 +1491,7 @@ impl Fragment {
let base = state.create_base_display_item(
stacking_relative_border_box,
self.node,
self.unique_id(),
get_cursor(&self.style, Cursor::Default),
display_list_section,
);
Expand Down Expand Up @@ -1522,6 +1539,7 @@ impl Fragment {
let base = state.create_base_display_item(
insertion_point_bounds,
self.node,
self.unique_id(),
get_cursor(&self.style, cursor),
display_list_section,
);
Expand Down Expand Up @@ -1709,6 +1727,7 @@ impl Fragment {
let base = state.create_base_display_item_with_clipping_and_scrolling(
content_size,
self.node,
self.unique_id(),
// FIXME(emilio): Why does this ignore pointer-events?
get_cursor(&self.style, Cursor::Default).or(Some(Cursor::Default)),
display_list_section,
Expand Down Expand Up @@ -1773,6 +1792,7 @@ impl Fragment {
state.create_base_display_item(
stacking_relative_border_box,
self.node,
self.unique_id(),
get_cursor(&self.style, Cursor::Default),
DisplayListSection::Content,
)
Expand Down Expand Up @@ -1859,7 +1879,7 @@ impl Fragment {
// looks bogus.
state.iframe_sizes.insert(
browsing_context_id,
euclid::Size2D::new(bounds.size.width, bounds.size.height),
euclid::Size2D::new(bounds.size().width, bounds.size().height),
);

let pipeline_id = match fragment_info.pipeline_id {
Expand Down Expand Up @@ -2067,6 +2087,7 @@ impl Fragment {
let base = state.create_base_display_item(
clip,
self.node,
self.unique_id(),
get_cursor(&self.style, cursor),
DisplayListSection::Content,
);
Expand Down Expand Up @@ -2230,13 +2251,14 @@ impl Fragment {
let base = state.create_base_display_item(
clip,
self.node,
self.unique_id(),
get_cursor(&self.style, Cursor::Default),
DisplayListSection::Content,
);

// TODO(gw): Use a better estimate for wavy line thickness.
let area = stacking_relative_box.to_layout();
let wavy_line_thickness = (0.33 * area.size.height).ceil();
let wavy_line_thickness = (0.33 * area.size().height).ceil();
state.add_display_item(DisplayItem::Line(CommonDisplayItem::new(
base,
webrender_api::LineDisplayItem {
Expand Down Expand Up @@ -2945,8 +2967,15 @@ impl BaseFlow {

let mut color = THREAD_TINT_COLORS[thread_id as usize % THREAD_TINT_COLORS.len()];
color.a = 1.0;
let base =
state.create_base_display_item(self.clip, node, None, DisplayListSection::Content);
let base = state.create_base_display_item(
self.clip,
node,
// This item will never become a spatial tree node, so it's fine
// to pass 0 here.
0,
None,
DisplayListSection::Content,
);
let bounds = stacking_context_relative_bounds.inflate(Au::from_px(2), Au::from_px(2));
state.add_display_item(DisplayItem::Border(CommonDisplayItem::with_data(
base,
Expand Down Expand Up @@ -3123,6 +3152,6 @@ trait ToF32Px {
impl ToF32Px for Rect<Au> {
type Output = LayoutRect;
fn to_f32_px(&self) -> LayoutRect {
LayoutRect::from_untyped(&servo_geometry::au_rect_to_f32_rect(*self))
LayoutRect::from_untyped(&servo_geometry::au_rect_to_f32_rect(*self).to_box2d())
}
}
2 changes: 1 addition & 1 deletion components/layout/display_list/conversions.rs
Expand Up @@ -139,7 +139,7 @@ impl ToLayout for Point2D<Au> {
impl ToLayout for Rect<Au> {
type Type = wr::units::LayoutRect;
fn to_layout(&self) -> Self::Type {
wr::units::LayoutRect::new(self.origin.to_layout(), self.size.to_layout())
wr::units::LayoutRect::from_origin_and_size(self.origin.to_layout(), self.size.to_layout())
}
}

Expand Down
13 changes: 8 additions & 5 deletions components/layout/display_list/items.rs
Expand Up @@ -24,17 +24,17 @@ use gfx_traits::print_tree::PrintTree;
use gfx_traits::{self, StackingContextId};
use msg::constellation_msg::PipelineId;
use net_traits::image::base::Image;
use script_traits::compositor::ScrollTreeNodeId;
use script_traits::compositor::{ScrollSensitivity, ScrollTreeNodeId};
use serde::Serialize;
use servo_geometry::MaxRect;
use style::computed_values::_servo_top_layer::T as InTopLayer;
pub use style::dom::OpaqueNode;
use webrender_api as wr;
use webrender_api::units::{LayoutPixel, LayoutRect, LayoutTransform};
use webrender_api::{
BorderRadius, ClipChainId, ClipId, ClipMode, CommonItemProperties, ComplexClipRegion,
ExternalScrollId, FilterOp, GlyphInstance, GradientStop, ImageKey, MixBlendMode,
PrimitiveFlags, ScrollSensitivity, Shadow, SpatialId, StickyOffsetBounds, TransformStyle,
BorderRadius, ClipChainId, ClipMode, CommonItemProperties, ComplexClipRegion, ExternalScrollId,
FilterOp, GlyphInstance, GradientStop, ImageKey, MixBlendMode, PrimitiveFlags, Shadow,
SpatialId, StickyOffsetBounds, TransformStyle,
};

/// The factor that we multiply the blur radius by in order to inflate the boundaries of display
Expand Down Expand Up @@ -479,6 +479,7 @@ impl BaseDisplayItem {
BaseDisplayItem {
metadata: DisplayItemMetadata {
node: OpaqueNode(0),
unique_id: 0,
cursor: None,
},
// Create a rectangle of maximal size.
Expand All @@ -495,7 +496,7 @@ impl BaseDisplayItem {
pub fn empty_common_item_properties() -> CommonItemProperties {
CommonItemProperties {
clip_rect: LayoutRect::max_rect(),
clip_id: ClipId::root(wr::PipelineId::dummy()),
clip_chain_id: ClipChainId::INVALID,
spatial_id: SpatialId::root_scroll_node(wr::PipelineId::dummy()),
flags: PrimitiveFlags::empty(),
}
Expand Down Expand Up @@ -553,6 +554,8 @@ impl fmt::Debug for ClippingRegion {
pub struct DisplayItemMetadata {
/// The DOM node from which this display item originated.
pub node: OpaqueNode,
/// The unique fragment id of the fragment of this item.
pub unique_id: u64,
/// The value of the `cursor` property when the mouse hovers over this display item. If `None`,
/// this display item is ineligible for pointer events (`pointer-events: none`).
pub cursor: Option<Cursor>,
Expand Down

0 comments on commit 351bcfb

Please sign in to comment.