Bug 1536021 - Sanitize filters in place. r=kvark
authorNicolas Silva <nsilva@mozilla.com>
Fri, 10 May 2019 01:23:54 +0200
changeset 473550 82e5affb98af1ae4e697c32e1a83d40b6ced69ea
parent 473549 d8bd0fd8057945c2798d0cc489bd84a50607da95
child 473551 bcbaf50dca2841ec7a86f208661a5c27c49fd5fb
push id36003
push userncsoregi@mozilla.com
push dateSun, 12 May 2019 21:42:32 +0000
treeherdermozilla-central@b83d8a064f16 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskvark
bugs1536021
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1536021 - Sanitize filters in place. r=kvark
gfx/wr/webrender/src/display_list_flattener.rs
gfx/wr/webrender/src/internal_types.rs
--- a/gfx/wr/webrender/src/display_list_flattener.rs
+++ b/gfx/wr/webrender/src/display_list_flattener.rs
@@ -1751,20 +1751,20 @@ impl<'a> DisplayListFlattener<'a> {
                 ClipChainId::NONE,
                 stacking_context.spatial_node_index,
                 &mut self.interners,
             );
         }
 
         // For each filter, create a new image with that composite mode.
         let mut current_filter_data_index = 0;
-        for filter in &stacking_context.composite_ops.filters {
-            let filter = filter.sanitize();
+        for filter in &mut stacking_context.composite_ops.filters {
+            filter.sanitize();
 
-            let composite_mode = Some(match filter {
+            let composite_mode = Some(match *filter {
                 Filter::ComponentTransfer => {
                     let filter_data =
                         &stacking_context.composite_ops.filter_datas[current_filter_data_index];
                     let filter_data = filter_data.sanitize();
                     current_filter_data_index = current_filter_data_index + 1;
                     if filter_data.is_identity() {
                         continue
                     } else {
@@ -2199,17 +2199,18 @@ impl<'a> DisplayListFlattener<'a> {
 
                     // No point in adding a shadow here if there were no primitives
                     // added to the shadow.
                     if !prims.is_empty() {
                         // Create a picture that the shadow primitives will be added to. If the
                         // blur radius is 0, the code in Picture::prepare_for_render will
                         // detect this and mark the picture to be drawn directly into the
                         // parent picture, which avoids an intermediate surface and blur.
-                        let blur_filter = Filter::Blur(std_deviation).sanitize();
+                        let mut blur_filter = Filter::Blur(std_deviation);
+                        blur_filter.sanitize();
                         let composite_mode = PictureCompositeMode::Filter(blur_filter);
                         let composite_mode_key = Some(composite_mode.clone()).into();
                         let is_backface_visible = true; //TODO: double check this
 
                         // Pass through configuration information about whether WR should
                         // do the bounding rect inflation for text shadows.
                         let options = PictureOptions {
                             inflate_if_required: pending_shadow.should_inflate,
--- a/gfx/wr/webrender/src/internal_types.rs
+++ b/gfx/wr/webrender/src/internal_types.rs
@@ -56,35 +56,30 @@ pub enum Filter {
     SrgbToLinear,
     LinearToSrgb,
     ComponentTransfer,
 }
 
 impl Filter {
     /// Ensure that the parameters for a filter operation
     /// are sensible.
-    pub fn sanitize(&self) -> Self {
+    pub fn sanitize(&mut self) {
         match self {
-            Filter::Blur(radius) => Filter::Blur(radius.min(MAX_BLUR_RADIUS)),
-            Filter::DropShadow(shadow) => Filter::DropShadow(Shadow {
-                offset: shadow.offset,
-                blur_radius: shadow.blur_radius.min(MAX_BLUR_RADIUS),
-                color: shadow.color
-            }),
-            Filter::DropShadowStack(ref stack) => {
-                let mut shadows = Vec::with_capacity(stack.len());
+            Filter::Blur(ref mut radius) => {
+                *radius = radius.min(MAX_BLUR_RADIUS);
+            }
+            Filter::DropShadow(ref mut shadow) => {
+                shadow.blur_radius = shadow.blur_radius.min(MAX_BLUR_RADIUS);
+            }
+            Filter::DropShadowStack(ref mut stack) => {
                 for shadow in stack {
-                    shadows.push(Shadow {
-                        blur_radius: shadow.blur_radius.min(MAX_BLUR_RADIUS),
-                        ..*shadow
-                    });
+                    shadow.blur_radius = shadow.blur_radius.min(MAX_BLUR_RADIUS);
                 }
-                Filter::DropShadowStack(shadows)
             }
-            filter => filter.clone(),
+            _ => {},
         }
     }
 
     pub fn is_visible(&self) -> bool {
         match *self {
             Filter::Identity |
             Filter::Blur(..) |
             Filter::Brightness(..) |