Bug 1477366 - Only support SVG filters with a single input with WebRender. r=mstange
authorMatt Woodrow <mwoodrow@mozilla.com>
Mon, 21 Jan 2019 20:00:57 +0000
changeset 454725 4e1eb0b0b422a44b882bef43b86a756d8f25eb8a
parent 454724 3d23cfc9df06f8ab77e83cafbb7792ed8a97d9c9
child 454726 719acee85b9a35d20def0570776748668f1a9648
push id35411
push usercsabou@mozilla.com
push dateTue, 22 Jan 2019 03:53:40 +0000
treeherdermozilla-central@ada22b635f8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1477366
milestone66.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 1477366 - Only support SVG filters with a single input with WebRender. r=mstange Differential Revision: https://phabricator.services.mozilla.com/D17088
layout/painting/nsDisplayList.cpp
layout/svg/nsFilterInstance.cpp
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -9342,22 +9342,23 @@ bool nsDisplayFilters::CreateWebRenderCS
       default:
         return false;
     }
   }
 
   return true;
 }
 
-bool nsDisplayFilters::CanCreateWebRenderCommands(nsDisplayListBuilder* aBuilder) {
+bool nsDisplayFilters::CanCreateWebRenderCommands(
+    nsDisplayListBuilder* aBuilder) {
   nsTArray<mozilla::wr::FilterOp> wrFilters;
   Maybe<nsRect> filterClip;
   if (!CreateWebRenderCSSFilters(wrFilters) &&
-      !nsSVGIntegrationUtils::BuildWebRenderFilters(
-          mFrame, wrFilters, filterClip)) {
+      !nsSVGIntegrationUtils::BuildWebRenderFilters(mFrame, wrFilters,
+                                                    filterClip)) {
     return false;
   }
   return true;
 }
 
 bool nsDisplayFilters::CreateWebRenderCommands(
     mozilla::wr::DisplayListBuilder& aBuilder,
     mozilla::wr::IpcResourceUpdateQueue& aResources,
--- a/layout/svg/nsFilterInstance.cpp
+++ b/layout/svg/nsFilterInstance.cpp
@@ -125,18 +125,36 @@ bool nsFilterInstance::BuildWebRenderFil
   // We currently apply the clip on the stacking context after applying filters,
   // but primitive subregions imply clipping after each filter and not just the
   // end of the chain. For some types of filter it doesn't matter, but for those
   // which sample outside of the location of the destination pixel like blurs,
   // only clipping after could produce incorrect results, so we bail out in this
   // case.
   // We can lift this restriction once we have added support for primitive
   // subregions to WebRender's filters.
+  for (uint32_t i = 0; i < instance.mFilterDescription.mPrimitives.Length();
+       i++) {
+    const auto& primitive = instance.mFilterDescription.mPrimitives[i];
 
-  for (const auto& primitive : instance.mFilterDescription.mPrimitives) {
+    // WebRender only supports filters with one input.
+    if (primitive.NumberOfInputs() != 1) {
+      return false;
+    }
+    // The first primitive must have the source graphic as the input, all
+    // other primitives must have the prior primitive as the input, otherwise
+    // it's not supported by WebRender.
+    if (i == 0) {
+      if (primitive.InputPrimitiveIndex(0) !=
+          FilterPrimitiveDescription::kPrimitiveIndexSourceGraphic) {
+        return false;
+      }
+    } else if (primitive.InputPrimitiveIndex(0) != int32_t(i - 1)) {
+      return false;
+    }
+
     bool primIsSrgb = primitive.OutputColorSpace() == gfx::ColorSpace::SRGB;
     if (srgb && !primIsSrgb) {
       aWrFilters.AppendElement(wr::FilterOp::SrgbToLinear());
       srgb = false;
     } else if (!srgb && primIsSrgb) {
       aWrFilters.AppendElement(wr::FilterOp::LinearToSrgb());
       srgb = true;
     }