Skip to content

Commit

Permalink
layout_2020: Implement support for backface-visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mrobinson committed May 16, 2020
1 parent 7d7e987 commit c287548
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 32 deletions.
4 changes: 2 additions & 2 deletions components/layout_2020/display_list/background.rs
Expand Up @@ -50,10 +50,10 @@ pub(super) fn painting_area<'a>(
builder: &mut super::DisplayListBuilder,
layer_index: usize,
) -> (&'a units::LayoutRect, wr::CommonItemProperties) {
let fb = fragment_builder;
let (painting_area, clip) = match source {
Source::Canvas { painting_area, .. } => (painting_area, None),
Source::Fragment => {
let fb = fragment_builder;
let b = fb.fragment.style.get_background();
match get_cyclic(&b.background_clip.0, layer_index) {
Clip::ContentBox => (fb.content_rect(), fb.content_edge_clip(builder)),
Expand All @@ -63,7 +63,7 @@ pub(super) fn painting_area<'a>(
},
};
// The 'backgound-clip' property maps directly to `clip_rect` in `CommonItemProperties`:
let mut common = builder.common_properties(*painting_area);
let mut common = builder.common_properties(*painting_area, &fb.fragment.style);
if let Some(clip_id) = clip {
common.clip_id = clip_id
}
Expand Down
29 changes: 21 additions & 8 deletions components/layout_2020/display_list/mod.rs
Expand Up @@ -7,6 +7,7 @@ use crate::display_list::conversions::ToWebRender;
use crate::fragments::{BoxFragment, Fragment, TextFragment};
use crate::geom::{PhysicalPoint, PhysicalRect};
use crate::replaced::IntrinsicSizes;
use crate::style_ext::ComputedValuesExt;
use embedder_traits::Cursor;
use euclid::{Point2D, SideOffsets2D, Size2D};
use gfx::text::glyph::GlyphStore;
Expand Down Expand Up @@ -67,9 +68,21 @@ impl<'a> DisplayListBuilder<'a> {
}
}

fn common_properties(&self, clip_rect: units::LayoutRect) -> wr::CommonItemProperties {
// TODO(gw): Make use of the WR backface visibility functionality.
wr::CommonItemProperties::new(clip_rect, self.current_space_and_clip)
fn common_properties(
&self,
clip_rect: units::LayoutRect,
style: &ComputedValues,
) -> wr::CommonItemProperties {
// TODO(mrobinson): We should take advantage of this field to pass hit testing
// information. This will allow us to avoid creating hit testing display items
// for fragments that paint their entire border rectangle.
wr::CommonItemProperties {
clip_rect,
spatial_id: self.current_space_and_clip.spatial_id,
clip_id: self.current_space_and_clip.clip_id,
hit_info: None,
flags: style.get_webrender_primitive_flags(),
}
}
}

Expand All @@ -90,7 +103,7 @@ impl Fragment {
.to_physical(i.style.writing_mode, containing_block)
.translate(containing_block.origin.to_vector());

let common = builder.common_properties(rect.clone().to_webrender());
let common = builder.common_properties(rect.to_webrender(), &i.style);
builder.wr.push_image(
&common,
rect.to_webrender(),
Expand Down Expand Up @@ -128,7 +141,7 @@ impl Fragment {
return;
}

let mut common = builder.common_properties(rect.to_webrender());
let mut common = builder.common_properties(rect.to_webrender(), &fragment.parent_style);
common.hit_info = hit_info(&fragment.parent_style, fragment.tag, Cursor::Text);

let color = fragment.parent_style.clone_color();
Expand Down Expand Up @@ -196,7 +209,7 @@ impl Fragment {
return;
}
builder.wr.push_line(
&builder.common_properties(rect),
&builder.common_properties(rect, &fragment.parent_style),
&rect,
wavy_line_thickness,
wr::LineOrientation::Horizontal,
Expand Down Expand Up @@ -325,7 +338,7 @@ impl<'a> BuilderForBoxFragment<'a> {
fn build_hit_test(&self, builder: &mut DisplayListBuilder) {
let hit_info = hit_info(&self.fragment.style, self.fragment.tag, Cursor::Default);
if hit_info.is_some() {
let mut common = builder.common_properties(self.border_rect);
let mut common = builder.common_properties(self.border_rect, &self.fragment.style);
common.hit_info = hit_info;
if let Some(clip_id) = self.border_edge_clip(builder) {
common.clip_id = clip_id
Expand Down Expand Up @@ -476,7 +489,7 @@ impl<'a> BuilderForBoxFragment<'a> {
BorderStyle::Outset => wr::BorderStyle::Outset,
},
};
let common = builder.common_properties(self.border_rect);
let common = builder.common_properties(self.border_rect, &self.fragment.style);
let details = wr::BorderDetails::Normal(wr::NormalBorder {
top: side(b.border_top_style, b.border_top_color),
right: side(b.border_right_style, b.border_right_color),
Expand Down
4 changes: 2 additions & 2 deletions components/layout_2020/display_list/stacking_context.rs
Expand Up @@ -238,7 +238,7 @@ impl StackingContext {
builder.wr.push_stacking_context(
LayoutPoint::zero(), // origin
self.spatial_id,
wr::PrimitiveFlags::default(),
style.get_webrender_primitive_flags(),
None, // clip_id
style.get_used_transform_style().to_webrender(),
effects.mix_blend_mode.to_webrender(),
Expand Down Expand Up @@ -283,7 +283,7 @@ impl StackingContext {

let background_color = style.resolve_color(style.get_background().background_color);
if background_color.alpha > 0 {
let common = builder.common_properties(painting_area);
let common = builder.common_properties(painting_area, &style);
let color = super::rgba(background_color);
builder.wr.push_rect(&common, painting_area, color)
}
Expand Down
12 changes: 12 additions & 0 deletions components/layout_2020/style_ext.rs
Expand Up @@ -8,6 +8,7 @@ use crate::ContainingBlock;
use style::computed_values::mix_blend_mode::T as ComputedMixBlendMode;
use style::computed_values::position::T as ComputedPosition;
use style::computed_values::transform_style::T as ComputedTransformStyle;
use style::properties::longhands::backface_visibility::computed_value::T as BackfaceVisiblity;
use style::properties::longhands::box_sizing::computed_value::T as BoxSizing;
use style::properties::ComputedValues;
use style::values::computed::image::Image as ComputedImageLayer;
Expand All @@ -17,6 +18,7 @@ use style::values::generics::box_::Perspective;
use style::values::generics::length::MaxSize;
use style::values::specified::box_ as stylo;
use style::Zero;
use webrender_api as wr;

#[derive(Clone, Copy, Eq, PartialEq)]
pub(crate) enum Display {
Expand Down Expand Up @@ -90,6 +92,7 @@ pub(crate) trait ComputedValuesExt {
fn establishes_containing_block(&self) -> bool;
fn establishes_containing_block_for_all_descendants(&self) -> bool;
fn background_is_transparent(&self) -> bool;
fn get_webrender_primitive_flags(&self) -> wr::PrimitiveFlags;
}

impl ComputedValuesExt for ComputedValues {
Expand Down Expand Up @@ -375,6 +378,15 @@ impl ComputedValuesExt for ComputedValues {
.iter()
.all(|layer| matches!(layer, ComputedImageLayer::None))
}

/// Generate appropriate WebRender `PrimitiveFlags` that should be used
/// for display items generated by the `Fragment` which owns this style.
fn get_webrender_primitive_flags(&self) -> wr::PrimitiveFlags {
match self.get_box().backface_visibility {
BackfaceVisiblity::Visible => wr::PrimitiveFlags::default(),
BackfaceVisiblity::Hidden => wr::PrimitiveFlags::empty(),
}
}
}

impl From<stylo::Display> for Display {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit c287548

Please sign in to comment.