Revert "[svg] Perform colorspace conversions for filter effects"

This reverts commit a0880eda22cc9fb4db7ebc0b86b5b2170f2d93e5.

Reason for revert: visual artifacts in 10-bit color depth (10-10-10-2)

Original change's description:
> [svg] Perform colorspace conversions for filter effects
>
> A filter effect can optionally be specified to operate in either sRGB
> or linearRGB, according to the SVG spec:
>
> https://www.w3.org/TR/SVG11/painting.html#ColorInterpolationProperties
>
> This CL adds any necessary conversion steps (SkColorFilters) while
> constructing the filter DAG. The default filter effect color space is
> linearRGB. We should now be passing the filters-gauss-* W3C tests.
>
> Specific changes:
> - Tag filter effect results with their colorspace when storing them in
>   the filter context map
> - Add an SkColorFolor conversion step as necessary when resolving filter
>   effect inputs
>
> Bug: skia:10841
> Change-Id: Ide12698ea64c4d40f09df93a60718788809086fa
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353078
> Commit-Queue: Tyler Denniston <tdenniston@google.com>
> Reviewed-by: Florin Malita <fmalita@chromium.org>

TBR=fmalita@chromium.org,tdenniston@google.com

Change-Id: Id4a33c49643039cfb2d2867a1513e8ee1d7b181a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:10841
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353630
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
diff --git a/modules/svg/include/SkSVGFilterContext.h b/modules/svg/include/SkSVGFilterContext.h
index 19f1e15..7e2fc3b 100644
--- a/modules/svg/include/SkSVGFilterContext.h
+++ b/modules/svg/include/SkSVGFilterContext.h
@@ -30,18 +30,17 @@
 
     const SkSVGObjectBoundingBoxUnits& primitiveUnits() const { return fPrimitiveUnits; }
 
-    void registerResult(const SkSVGStringType&, const sk_sp<SkImageFilter>&, const SkRect&, SkSVGColorspace);
+    void registerResult(const SkSVGStringType&, const sk_sp<SkImageFilter>&, const SkRect&);
 
-    sk_sp<SkImageFilter> resolveInput(const SkSVGRenderContext&, const SkSVGFeInputType&, SkSVGColorspace) const;
+    sk_sp<SkImageFilter> resolveInput(const SkSVGRenderContext&, const SkSVGFeInputType&) const;
 
 private:
     struct Result {
         sk_sp<SkImageFilter> fImageFilter;
         SkRect fFilterSubregion;
-        SkSVGColorspace fColorspace;
     };
 
-    const Result* findResultById(const SkSVGStringType&) const;
+    sk_sp<SkImageFilter> findResultById(const SkSVGStringType&) const;
 
     SkRect fFilterEffectsRegion;
 
diff --git a/modules/svg/src/SkSVGFe.cpp b/modules/svg/src/SkSVGFe.cpp
index aa2b66c..66a8592 100644
--- a/modules/svg/src/SkSVGFe.cpp
+++ b/modules/svg/src/SkSVGFe.cpp
@@ -84,9 +84,7 @@
 }
 
 SkSVGColorspace SkSVGFe::resolveColorspace(const SkSVGRenderContext& ctx) const {
-    constexpr SkSVGColorspace kDefaultCS = SkSVGColorspace::kSRGB;
-    const SkSVGColorspace cs = *ctx.presentationContext().fInherited.fColorInterpolationFilters;
-    return cs == SkSVGColorspace::kAuto ? kDefaultCS : cs;
+    return *ctx.presentationContext().fInherited.fColorInterpolationFilters;
 }
 
 void SkSVGFe::applyProperties(SkSVGRenderContext* ctx) const { this->onPrepareToRender(ctx); }
diff --git a/modules/svg/src/SkSVGFeColorMatrix.cpp b/modules/svg/src/SkSVGFeColorMatrix.cpp
index 9f45bc8..be07e65 100644
--- a/modules/svg/src/SkSVGFeColorMatrix.cpp
+++ b/modules/svg/src/SkSVGFeColorMatrix.cpp
@@ -91,10 +91,9 @@
 
 sk_sp<SkImageFilter> SkSVGFeColorMatrix::onMakeImageFilter(const SkSVGRenderContext& ctx,
                                                            const SkSVGFilterContext& fctx) const {
-    return SkImageFilters::ColorFilter(
-            SkColorFilters::Matrix(makeMatrixForType()),
-            fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx)),
-            this->resolveFilterSubregion(ctx, fctx));
+    return SkImageFilters::ColorFilter(SkColorFilters::Matrix(makeMatrixForType()),
+                                       fctx.resolveInput(ctx, this->getIn()),
+                                       this->resolveFilterSubregion(ctx, fctx));
 }
 
 template <> bool SkSVGAttributeParser::parse(SkSVGFeColorMatrixValues* values) {
diff --git a/modules/svg/src/SkSVGFeComposite.cpp b/modules/svg/src/SkSVGFeComposite.cpp
index d21b456..5c88492 100644
--- a/modules/svg/src/SkSVGFeComposite.cpp
+++ b/modules/svg/src/SkSVGFeComposite.cpp
@@ -47,9 +47,8 @@
 sk_sp<SkImageFilter> SkSVGFeComposite::onMakeImageFilter(const SkSVGRenderContext& ctx,
                                                          const SkSVGFilterContext& fctx) const {
     const SkRect cropRect = this->resolveFilterSubregion(ctx, fctx);
-    const SkSVGColorspace colorspace = this->resolveColorspace(ctx);
-    const sk_sp<SkImageFilter> background = fctx.resolveInput(ctx, fIn2, colorspace);
-    const sk_sp<SkImageFilter> foreground = fctx.resolveInput(ctx, this->getIn(), colorspace);
+    const sk_sp<SkImageFilter> background = fctx.resolveInput(ctx, fIn2);
+    const sk_sp<SkImageFilter> foreground = fctx.resolveInput(ctx, this->getIn());
     if (fOperator == SkSVGFeCompositeOperator::kArithmetic) {
         constexpr bool enforcePMColor = true;
         return SkImageFilters::Arithmetic(
diff --git a/modules/svg/src/SkSVGFeGaussianBlur.cpp b/modules/svg/src/SkSVGFeGaussianBlur.cpp
index 6ee1399..9e4407b 100644
--- a/modules/svg/src/SkSVGFeGaussianBlur.cpp
+++ b/modules/svg/src/SkSVGFeGaussianBlur.cpp
@@ -30,7 +30,7 @@
     }
 
     return SkImageFilters::Blur(sigmaX, sigmaY,
-                                fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx)),
+                                fctx.resolveInput(ctx, this->getIn()),
                                 this->resolveFilterSubregion(ctx, fctx));
 }
 
diff --git a/modules/svg/src/SkSVGFilter.cpp b/modules/svg/src/SkSVGFilter.cpp
index 13de852..917c628 100644
--- a/modules/svg/src/SkSVGFilter.cpp
+++ b/modules/svg/src/SkSVGFilter.cpp
@@ -5,7 +5,6 @@
  * found in the LICENSE file.
  */
 
-#include "include/core/SkColorFilter.h"
 #include "include/effects/SkImageFilters.h"
 #include "modules/svg/include/SkSVGFe.h"
 #include "modules/svg/include/SkSVGFilter.h"
@@ -47,7 +46,6 @@
 sk_sp<SkImageFilter> SkSVGFilter::buildFilterDAG(const SkSVGRenderContext& ctx) const {
     sk_sp<SkImageFilter> filter;
     SkSVGFilterContext fctx(resolveFilterRegion(ctx), fPrimitiveUnits);
-    SkSVGColorspace cs = SkSVGColorspace::kSRGB;
     for (const auto& child : fChildren) {
         if (!SkSVGFe::IsFilterEffect(child)) {
             continue;
@@ -64,19 +62,14 @@
         feNode.applyProperties(&localCtx);
 
         // TODO: there are specific composition rules that need to be followed
-        cs = feNode.resolveColorspace(ctx);
+        // TODO: perform colorspace conversions depending on 'color-interpolation-filters' setting
+        // of the current node and its inputs.
         filter = feNode.makeImageFilter(localCtx, fctx);
 
         if (!feResultType.isEmpty()) {
-            fctx.registerResult(
-                    feResultType, filter, feNode.resolveFilterSubregion(localCtx, fctx), cs);
+            fctx.registerResult(feResultType, filter, feNode.resolveFilterSubregion(localCtx, fctx));
         }
     }
 
-    // Convert to final destination colorspace
-    if (cs != SkSVGColorspace::kSRGB) {
-        filter = SkImageFilters::ColorFilter(SkColorFilters::LinearToSRGBGamma(), filter);
-    }
-
     return filter;
 }
diff --git a/modules/svg/src/SkSVGFilterContext.cpp b/modules/svg/src/SkSVGFilterContext.cpp
index aa15341..a7d1cbb 100644
--- a/modules/svg/src/SkSVGFilterContext.cpp
+++ b/modules/svg/src/SkSVGFilterContext.cpp
@@ -5,33 +5,15 @@
  * found in the LICENSE file.
  */
 
-#include "include/core/SkColorFilter.h"
 #include "include/effects/SkImageFilters.h"
 #include "modules/svg/include/SkSVGFilterContext.h"
 #include "modules/svg/include/SkSVGNode.h"
 #include "modules/svg/include/SkSVGRenderContext.h"
 #include "modules/svg/include/SkSVGTypes.h"
 
-namespace {
-
-sk_sp<SkImageFilter> ConvertFilterColorspace(sk_sp<SkImageFilter>&& input,
-                                             SkSVGColorspace src,
-                                             SkSVGColorspace dst) {
-    if (src == dst) {
-        return std::move(input);
-    } else if (src == SkSVGColorspace::kSRGB && dst == SkSVGColorspace::kLinearRGB) {
-        return SkImageFilters::ColorFilter(SkColorFilters::SRGBToLinearGamma(), input);
-    } else {
-        SkASSERT(src == SkSVGColorspace::kLinearRGB && dst == SkSVGColorspace::kSRGB);
-        return SkImageFilters::ColorFilter(SkColorFilters::LinearToSRGBGamma(), input);
-    }
-}
-
-}  // namespace
-
-const SkSVGFilterContext::Result* SkSVGFilterContext::findResultById(
-        const SkSVGStringType& id) const {
-    return fResults.find(id);
+sk_sp<SkImageFilter> SkSVGFilterContext::findResultById(const SkSVGStringType& id) const {
+    const Result* res = fResults.find(id);
+    return res ? res->fImageFilter : nullptr;
 }
 
 const SkRect& SkSVGFilterContext::filterPrimitiveSubregion(const SkSVGFeInputType& input) const {
@@ -43,24 +25,18 @@
 
 void SkSVGFilterContext::registerResult(const SkSVGStringType& id,
                                         const sk_sp<SkImageFilter>& result,
-                                        const SkRect& subregion,
-                                        SkSVGColorspace resultColorspace) {
+                                        const SkRect& subregion) {
     SkASSERT(!id.isEmpty());
-    fResults[id] = {result, subregion, resultColorspace};
+    fResults[id] = {result, subregion};
 }
 
 sk_sp<SkImageFilter> SkSVGFilterContext::resolveInput(const SkSVGRenderContext& ctx,
-                                                      const SkSVGFeInputType& inputType,
-                                                      SkSVGColorspace colorspace) const {
-    SkSVGColorspace inputCS = SkSVGColorspace::kSRGB;
-    sk_sp<SkImageFilter> result;
+                                                      const SkSVGFeInputType& inputType) const {
     switch (inputType.type()) {
         case SkSVGFeInputType::Type::kSourceGraphic:
-            // Do nothing.
-            break;
+            return nullptr;
         case SkSVGFeInputType::Type::kFillPaint:
-            result = SkImageFilters::Paint(*ctx.fillPaint());
-            break;
+            return SkImageFilters::Paint(*ctx.fillPaint());
         case SkSVGFeInputType::Type::kStrokePaint: {
             // The paint filter doesn't handle stroke paints properly, so convert to fill for
             // simplicity.
@@ -68,21 +44,12 @@
             //       requires some extra work to handle all paint features (gradients, etc).
             SkPaint p = *ctx.strokePaint();
             p.setStyle(SkPaint::kFill_Style);
-            result = SkImageFilters::Paint(p);
-            break;
+            return SkImageFilters::Paint(p);
         }
-        case SkSVGFeInputType::Type::kFilterPrimitiveReference: {
-            const Result* res = findResultById(inputType.id());
-            if (res) {
-                result = res->fImageFilter;
-                inputCS = res->fColorspace;
-            }
-            break;
-        }
+        case SkSVGFeInputType::Type::kFilterPrimitiveReference:
+            return findResultById(inputType.id());
         default:
             SkDebugf("unhandled filter input type %d\n", inputType.type());
             return nullptr;
     }
-
-    return ConvertFilterColorspace(std::move(result), inputCS, colorspace);
 }