From d8302199511e7f9aa2289f8f2056afd3440fd081 Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Tue, 25 Sep 2018 13:04:02 -0400 Subject: [PATCH] Bug 1493890. Update webrender to commit 2549b791abb3a24c115d03616ddd82e14727b5a1 --- gfx/webrender/res/cs_border_segment.glsl | 2 +- gfx/webrender/res/cs_border_solid.glsl | 20 +++++++++++++++----- gfx/webrender/src/border.rs | 9 ++++++++- gfx/webrender_api/src/display_item.rs | 22 ++++++++++++++++++++++ gfx/webrender_bindings/revision.txt | 2 +- gfx/wrench/src/yaml_frame_reader.rs | 2 ++ gfx/wrench/src/yaml_frame_writer.rs | 1 + gfx/wrench/src/yaml_helper.rs | 1 + 8 files changed, 51 insertions(+), 8 deletions(-) diff --git a/gfx/webrender/res/cs_border_segment.glsl b/gfx/webrender/res/cs_border_segment.glsl index 0a5387b23512..395474d4a476 100644 --- a/gfx/webrender/res/cs_border_segment.glsl +++ b/gfx/webrender/res/cs_border_segment.glsl @@ -152,7 +152,7 @@ void main(void) { int segment = aFlags & 0xff; int style0 = (aFlags >> 8) & 0xff; int style1 = (aFlags >> 16) & 0xff; - int clip_mode = (aFlags >> 24) & 0xff; + int clip_mode = (aFlags >> 24) & 0x0f; vec2 outer_scale = get_outer_corner_scale(segment); vec2 outer = outer_scale * aRect.zw; diff --git a/gfx/webrender/res/cs_border_solid.glsl b/gfx/webrender/res/cs_border_solid.glsl index 2e3cf261ead2..17067aed9663 100644 --- a/gfx/webrender/res/cs_border_solid.glsl +++ b/gfx/webrender/res/cs_border_solid.glsl @@ -4,6 +4,10 @@ #include shared,ellipse +#define DONT_MIX 0 +#define MIX_AA 1 +#define MIX_NO_AA 2 + // For edges, the colors are the same. For corners, these // are the colors of each edge making up the corner. flat varying vec4 vColor0; @@ -70,6 +74,7 @@ vec2 get_outer_corner_scale(int segment) { void main(void) { int segment = aFlags & 0xff; + bool do_aa = ((aFlags >> 24) & 0xf0) != 0; vec2 outer_scale = get_outer_corner_scale(segment); vec2 outer = outer_scale * aRect.zw; @@ -81,10 +86,10 @@ void main(void) { case SEGMENT_TOP_RIGHT: case SEGMENT_BOTTOM_RIGHT: case SEGMENT_BOTTOM_LEFT: - mix_colors = 1; + mix_colors = do_aa ? MIX_AA : MIX_NO_AA; break; default: - mix_colors = 0; + mix_colors = DONT_MIX; break; } @@ -104,11 +109,16 @@ void main(void) { #ifdef WR_FRAGMENT_SHADER void main(void) { float aa_range = compute_aa_range(vPos); + bool do_aa = vMixColors != MIX_NO_AA; float mix_factor = 0.0; - if (vMixColors != 0) { + if (vMixColors != DONT_MIX) { float d_line = distance_to_line(vColorLine.xy, vColorLine.zw, vPos); - mix_factor = distance_aa(aa_range, -d_line); + if (do_aa) { + mix_factor = distance_aa(aa_range, -d_line); + } else { + mix_factor = d_line + EPSILON >= 0. ? 1.0 : 0.0; + } } // Check if inside corner clip-region @@ -122,7 +132,7 @@ void main(void) { d = max(d_radii_a, -d_radii_b); } - float alpha = distance_aa(aa_range, d); + float alpha = do_aa ? distance_aa(aa_range, d) : 1.0; vec4 color = mix(vColor0, vColor1, mix_factor); oFragColor = color * alpha; } diff --git a/gfx/webrender/src/border.rs b/gfx/webrender/src/border.rs index 96507691d7d9..ebb12cc9b467 100644 --- a/gfx/webrender/src/border.rs +++ b/gfx/webrender/src/border.rs @@ -103,6 +103,7 @@ pub struct BorderCacheKey { pub bottom: BorderSideAu, pub radius: BorderRadiusAu, pub widths: SideOffsets2D, + pub do_aa: bool, pub scale: Au, } @@ -120,6 +121,7 @@ impl BorderCacheKey { Au::from_f32_px(widths.left), ), radius: border.radius.into(), + do_aa: border.do_aa, scale: Au(0), } } @@ -574,6 +576,7 @@ pub struct BorderRenderTaskInfo { pub border_segments: Vec, pub size: DeviceIntSize, pub available_size_dependence: AvailableSizeDependence, + do_aa: bool, } #[derive(PartialEq, Eq)] @@ -961,6 +964,7 @@ impl BorderRenderTaskInfo { border_segments, size: size.to_i32(), available_size_dependence: size_dependence, + do_aa: border.do_aa, }) } @@ -1026,6 +1030,7 @@ impl BorderRenderTaskInfo { &mut instances, info.widths, info.radius, + self.do_aa, ); } @@ -1094,10 +1099,12 @@ fn add_segment( instances: &mut Vec, widths: DeviceSize, radius: DeviceSize, + do_aa: bool, ) { let base_flags = (segment as i32) | ((style0 as i32) << 8) | - ((style1 as i32) << 16); + ((style1 as i32) << 16) | + ((do_aa as i32) << 28); let base_instance = BorderInstance { task_origin: DevicePoint::zero(), diff --git a/gfx/webrender_api/src/display_item.rs b/gfx/webrender_api/src/display_item.rs index 52c870855545..2c1fdc374fea 100644 --- a/gfx/webrender_api/src/display_item.rs +++ b/gfx/webrender_api/src/display_item.rs @@ -262,6 +262,11 @@ pub struct NormalBorder { pub top: BorderSide, pub bottom: BorderSide, pub radius: BorderRadius, + /// Whether to apply anti-aliasing on the border corners. + /// + /// Note that for this to be `false` and work, this requires the borders to + /// be solid, and no border-radius. + pub do_aa: bool, } impl NormalBorder { @@ -275,10 +280,27 @@ impl NormalBorder { b } + fn can_disable_antialiasing(&self) -> bool { + fn is_valid(style: BorderStyle) -> bool { + style == BorderStyle::Solid || style == BorderStyle::None + } + + self.radius.is_zero() && + is_valid(self.top.style) && + is_valid(self.left.style) && + is_valid(self.bottom.style) && + is_valid(self.right.style) + } + /// Normalizes a border so that we don't render disallowed stuff, like inset /// borders that are less than two pixels wide. #[inline] pub fn normalize(&mut self, widths: &LayoutSideOffsets) { + debug_assert!( + self.do_aa || self.can_disable_antialiasing(), + "Unexpected disabled-antialising in a border, likely won't work or will be ignored" + ); + #[inline] fn renders_small_border_solid(style: BorderStyle) -> bool { match style { diff --git a/gfx/webrender_bindings/revision.txt b/gfx/webrender_bindings/revision.txt index ace18cea94dc..f6e2c6626d89 100644 --- a/gfx/webrender_bindings/revision.txt +++ b/gfx/webrender_bindings/revision.txt @@ -1 +1 @@ -b83ec3fd994b69f31e9c6b6ffa19426b2b98c66a +2549b791abb3a24c115d03616ddd82e14727b5a1 diff --git a/gfx/wrench/src/yaml_frame_reader.rs b/gfx/wrench/src/yaml_frame_reader.rs index 4dccbac57da4..6da15c3b2e88 100644 --- a/gfx/wrench/src/yaml_frame_reader.rs +++ b/gfx/wrench/src/yaml_frame_reader.rs @@ -870,12 +870,14 @@ impl YamlFrameReader { color: colors[3], style: styles[3], }; + let do_aa = item["do_aa"].as_bool().unwrap_or(true); Some(BorderDetails::Normal(NormalBorder { top, left, bottom, right, radius, + do_aa, })) } "image" | "gradient" | "radial-gradient" => { diff --git a/gfx/wrench/src/yaml_frame_writer.rs b/gfx/wrench/src/yaml_frame_writer.rs index 2e6e8bb06cd6..a60ca15a6f47 100644 --- a/gfx/wrench/src/yaml_frame_writer.rs +++ b/gfx/wrench/src/yaml_frame_writer.rs @@ -869,6 +869,7 @@ impl YamlFrameWriter { str_node(&mut v, "border-type", "normal"); yaml_node(&mut v, "color", string_vec_yaml(&colors, true)); yaml_node(&mut v, "style", string_vec_yaml(&styles, true)); + bool_node(&mut v, "do_aa", details.do_aa); if let Some(radius_node) = maybe_radius_yaml(&details.radius) { yaml_node(&mut v, "radius", radius_node); } diff --git a/gfx/wrench/src/yaml_helper.rs b/gfx/wrench/src/yaml_helper.rs index 1769fbc8deeb..9987efb2e3d7 100644 --- a/gfx/wrench/src/yaml_helper.rs +++ b/gfx/wrench/src/yaml_helper.rs @@ -46,6 +46,7 @@ fn string_to_color(color: &str) -> Option { "white" => Some(ColorF::new(1.0, 1.0, 1.0, 1.0)), "black" => Some(ColorF::new(0.0, 0.0, 0.0, 1.0)), "yellow" => Some(ColorF::new(1.0, 1.0, 0.0, 1.0)), + "transparent" => Some(ColorF::new(1.0, 1.0, 1.0, 0.0)), s => { let items: Vec = s.split_whitespace() .map(|s| f32::from_str(s).unwrap())