Bug 1370564 - Add suppport for blur filter. r=kats draft
authorMorris Tseng <mtseng@mozilla.com>
Fri, 20 Oct 2017 16:42:06 +0800
changeset 685209 de2b0549841fc5297d74011b9ab454a3cb0fd744
parent 685069 9056f2ee492fa481aa86146aba236c074628e9fd
child 685210 6bd4e727e2412a6e5e8143052fb88ef62b37163c
push id85845
push userbmo:mtseng@mozilla.com
push dateTue, 24 Oct 2017 04:50:27 +0000
reviewerskats
bugs1370564
milestone58.0a1
Bug 1370564 - Add suppport for blur filter. r=kats MozReview-Commit-ID: EYoYbbIs3wH
layout/painting/nsDisplayList.cpp
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -9564,16 +9564,23 @@ nsDisplayFilter::PaintAsLayer(nsDisplayL
                                                   mFrame,  mVisibleRect,
                                                   borderArea, aBuilder,
                                                   aManager,
                                                   mHandleOpacity, imgParams);
   nsSVGIntegrationUtils::PaintFilter(params);
   nsDisplayFilterGeometry::UpdateDrawResult(this, imgParams.result);
 }
 
+static float
+ClampStdDeviation(float aStdDeviation)
+{
+  // Cap software blur radius for performance reasons.
+  return std::min(std::max(0.0f, aStdDeviation), 100.0f);
+}
+
 bool
 nsDisplayFilter::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
                                          mozilla::wr::IpcResourceUpdateQueue& aResources,
                                          const StackingContextHelper& aSc,
                                          mozilla::layers::WebRenderLayerManager* aManager,
                                          nsDisplayListBuilder* aDisplayListBuilder)
 {
   if (mFrame->IsFrameOfType(nsIFrame::eSVG) || mFrame->StyleEffects()->mOpacity != 1.0f) {
@@ -9594,16 +9601,28 @@ nsDisplayFilter::CreateWebRenderCommands
       case NS_STYLE_FILTER_SEPIA: {
         mozilla::wr::WrFilterOp filterOp = {
           wr::ToWrFilterOpType(filter.GetType()),
           filter.GetFilterParameter().GetFactorOrPercentValue(),
         };
         wrFilters.AppendElement(filterOp);
         break;
       }
+      case NS_STYLE_FILTER_BLUR: {
+        float appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
+        mozilla::wr::WrFilterOp filterOp = {
+          wr::ToWrFilterOpType(filter.GetType()),
+          ClampStdDeviation(
+            NSAppUnitsToFloatPixels(
+              filter.GetFilterParameter().GetCoordValue(),
+              appUnitsPerDevPixel)),
+        };
+        wrFilters.AppendElement(filterOp);
+        break;
+      }
       default:
         return false;
     }
   }
 
   StackingContextHelper sc(aSc, aBuilder, wrFilters);
 
   nsDisplaySVGEffects::CreateWebRenderCommands(aBuilder, aResources, sc, aManager, aDisplayListBuilder);