Add color type to the image filter DAG's OutputProperties

Don't try to guess the pixel config to use for intermediates. Instead,
just make the intermediates in the same color type (and space) as the
final destination. This removes some no-longer-correct logic that was
using sRGB configs, resulting in linear blending and precision loss.

Change-Id: I627c47193a9f2889c3dc121170ff3e7d5d315fa0
Reviewed-on: https://skia-review.googlesource.com/139547
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index f38b714..d452c11 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -544,7 +544,7 @@
     for (int i = 0; i < filters.count(); ++i) {
         SkImageFilter* filter = filters.getFilter(i);
         SkIPoint offset;
-        SkImageFilter::OutputProperties noColorSpace(nullptr);
+        SkImageFilter::OutputProperties noColorSpace(kN32_SkColorType, nullptr);
         SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr, noColorSpace);
         sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offset));
         REPORTER_ASSERT(reporter, resultImg, filters.getName(i));
@@ -567,7 +567,7 @@
                                                                 gradient));
 
     SkIPoint offset;
-    SkImageFilter::OutputProperties noColorSpace(nullptr);
+    SkImageFilter::OutputProperties noColorSpace(kN32_SkColorType, nullptr);
     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr, noColorSpace);
 
     sk_sp<SkSpecialImage> positiveResult1(positiveFilter->filterImage(imgSrc.get(), ctx, &offset));
@@ -644,7 +644,7 @@
     sk_sp<SkSpecialImage> image(surf->makeImageSnapshot());
 
     SkIPoint offset;
-    SkImageFilter::OutputProperties noColorSpace(nullptr);
+    SkImageFilter::OutputProperties noColorSpace(kN32_SkColorType, nullptr);
     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr, noColorSpace);
 
     sk_sp<SkSpecialImage> result(filter->filterImage(image.get(), ctx, &offset));
@@ -681,7 +681,7 @@
 static void test_fail_affects_transparent_black(skiatest::Reporter* reporter, GrContext* context) {
     sk_sp<FailImageFilter> failFilter(new FailImageFilter());
     sk_sp<SkSpecialImage> source(create_empty_special_image(context, 5));
-    SkImageFilter::OutputProperties noColorSpace(nullptr);
+    SkImageFilter::OutputProperties noColorSpace(kN32_SkColorType, nullptr);
     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nullptr, noColorSpace);
     sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkBlendMode::kSrc));
     SkASSERT(green->affectsTransparentBlack());
@@ -975,7 +975,7 @@
 
     sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, 1));
 
-    SkImageFilter::OutputProperties noColorSpace(nullptr);
+    SkImageFilter::OutputProperties noColorSpace(kN32_SkColorType, nullptr);
     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr,
                                noColorSpace);
     SkIPoint offset;
@@ -1144,7 +1144,7 @@
     SkASSERT(srcImg);
 
     SkIPoint offset;
-    SkImageFilter::OutputProperties noColorSpace(nullptr);
+    SkImageFilter::OutputProperties noColorSpace(kN32_SkColorType, nullptr);
     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr, noColorSpace);
     sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offset));
     REPORTER_ASSERT(reporter, resultImg);
@@ -1216,7 +1216,7 @@
     sk_sp<SkImageFilter> imageFilter(SkPictureImageFilter::Make(picture));
 
     SkIPoint offset;
-    SkImageFilter::OutputProperties noColorSpace(nullptr);
+    SkImageFilter::OutputProperties noColorSpace(kN32_SkColorType, nullptr);
     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nullptr, noColorSpace);
 
     sk_sp<SkSpecialImage> resultImage(imageFilter->filterImage(srcImg.get(), ctx, &offset));
@@ -1469,7 +1469,7 @@
     sk_sp<SkImageFilter> composedFilter(SkComposeImageFilter::Make(std::move(blurFilter),
                                                                    std::move(offsetFilter)));
     SkIPoint offset;
-    SkImageFilter::OutputProperties noColorSpace(nullptr);
+    SkImageFilter::OutputProperties noColorSpace(kN32_SkColorType, nullptr);
     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr, noColorSpace);
 
     sk_sp<SkSpecialImage> resultImg(composedFilter->filterImage(srcImg.get(), ctx, &offset));
@@ -1504,7 +1504,7 @@
                                                                    std::move(pictureFilter)));
 
     sk_sp<SkSpecialImage> sourceImage(create_empty_special_image(context, 100));
-    SkImageFilter::OutputProperties noColorSpace(nullptr);
+    SkImageFilter::OutputProperties noColorSpace(kN32_SkColorType, nullptr);
     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr, noColorSpace);
     SkIPoint offset;
     sk_sp<SkSpecialImage> result(composedFilter->filterImage(sourceImage.get(), ctx, &offset));
@@ -1532,7 +1532,7 @@
         SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::kHasHeight_CropEdge);
     sk_sp<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
     SkIPoint offset;
-    SkImageFilter::OutputProperties noColorSpace(nullptr);
+    SkImageFilter::OutputProperties noColorSpace(kN32_SkColorType, nullptr);
     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr, noColorSpace);
 
     sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offset));
diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp
index d2549c4..368e594 100644
--- a/tests/SpecialImageTest.cpp
+++ b/tests/SpecialImageTest.cpp
@@ -87,7 +87,7 @@
 
     //--------------
     // Test that draw restricts itself to the subset
-    SkImageFilter::OutputProperties outProps(img->getColorSpace());
+    SkImageFilter::OutputProperties outProps(kN32_SkColorType, img->getColorSpace());
     sk_sp<SkSpecialSurface> surf(img->makeSurface(outProps, SkISize::Make(kFullSize, kFullSize),
                                                   kPremul_SkAlphaType));
 
@@ -124,7 +124,7 @@
         REPORTER_ASSERT(reporter, isGPUBacked != !!tightImg->peekPixels(&tmpPixmap));
     }
     {
-        SkImageFilter::OutputProperties outProps(img->getColorSpace());
+        SkImageFilter::OutputProperties outProps(kN32_SkColorType, img->getColorSpace());
         sk_sp<SkSurface> tightSurf(img->makeTightSurface(outProps, subset.size()));
 
         REPORTER_ASSERT(reporter, tightSurf->width() == subset.width());