Revert "Convert GrConfigConversionEffect to a runtime FP"

This reverts commit 4a778130080c181dd7fb3df7d7aeb0e35b049f1e.

Reason for revert: Memory regression in Chrome.

Original change's description:
> Convert GrConfigConversionEffect to a runtime FP
>
> Change-Id: I7f22447cf3356b1558d73665ff3e9b61639ebe83
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/423576
> Auto-Submit: Brian Osman <brianosman@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>

TBR=bsalomon@google.com,brianosman@google.com,ethannicholas@google.com

Change-Id: I05497295b88b378f0aa236f18118fe676bbf05c9
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/424256
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrDirectContextPriv.cpp b/src/gpu/GrDirectContextPriv.cpp
index dc770f9..b00a1a2 100644
--- a/src/gpu/GrDirectContextPriv.cpp
+++ b/src/gpu/GrDirectContextPriv.cpp
@@ -9,7 +9,6 @@
 
 #include "include/gpu/GrContextThreadSafeProxy.h"
 #include "include/gpu/GrDirectContext.h"
-#include "src/core/SkRuntimeEffectPriv.h"
 #include "src/gpu/GrAuditTrail.h"
 #include "src/gpu/GrContextThreadSafeProxyPriv.h"
 #include "src/gpu/GrDrawingManager.h"
@@ -22,6 +21,7 @@
 #include "src/gpu/GrThreadSafePipelineBuilder.h"
 #include "src/gpu/SkGr.h"
 #include "src/gpu/effects/GrSkSLFP.h"
+#include "src/gpu/effects/generated/GrConfigConversionEffect.h"
 #include "src/gpu/text/GrAtlasManager.h"
 #include "src/gpu/text/GrTextBlobCache.h"
 #include "src/image/SkImage_Base.h"
@@ -192,129 +192,12 @@
 }
 #endif
 
-// Both of these effects aggressively round to the nearest exact (N / 255) floating point values.
-// This lets us find a round-trip preserving pair on some GPUs that do odd byte to float conversion.
-static std::unique_ptr<GrFragmentProcessor> make_premul_effect(
-        std::unique_ptr<GrFragmentProcessor> fp) {
-    if (!fp) {
-        return nullptr;
-    }
-
-    static auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForColorFilter, R"(
-        half4 main(half4 color) {
-            color = floor(color * 255 + 0.5) / 255;
-            color.rgb = floor(color.rgb * color.a * 255 + 0.5) / 255;
-            return color;
-        }
-    )");
-
-    fp = GrSkSLFP::Make(effect, "ToPremul", std::move(fp), GrSkSLFP::OptFlags::kNone);
-    return GrFragmentProcessor::HighPrecision(std::move(fp));
-}
-
-static std::unique_ptr<GrFragmentProcessor> make_unpremul_effect(
-        std::unique_ptr<GrFragmentProcessor> fp) {
-    if (!fp) {
-        return nullptr;
-    }
-
-    static auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForColorFilter, R"(
-        half4 main(half4 color) {
-            color = floor(color * 255 + 0.5) / 255;
-            color.rgb = color.a <= 0 ? half3(0) : floor(color.rgb / color.a * 255 + 0.5) / 255;
-            return color;
-        }
-    )");
-
-    fp = GrSkSLFP::Make(effect, "ToUnpremul", std::move(fp), GrSkSLFP::OptFlags::kNone);
-    return GrFragmentProcessor::HighPrecision(std::move(fp));
-}
-
-static bool test_for_preserving_PM_conversions(GrDirectContext* dContext) {
-    static constexpr int kSize = 256;
-    SkAutoTMalloc<uint32_t> data(kSize * kSize * 3);
-    uint32_t* srcData = data.get();
-
-    // Fill with every possible premultiplied A, color channel value. There will be 256-y duplicate
-    // values in row y. We set r, g, and b to the same value since they are handled identically.
-    for (int y = 0; y < kSize; ++y) {
-        for (int x = 0; x < kSize; ++x) {
-            uint8_t* color = reinterpret_cast<uint8_t*>(&srcData[kSize*y + x]);
-            color[3] = y;
-            color[2] = std::min(x, y);
-            color[1] = std::min(x, y);
-            color[0] = std::min(x, y);
-        }
-    }
-
-    const SkImageInfo pmII =
-            SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
-    const SkImageInfo upmII = pmII.makeAlphaType(kUnpremul_SkAlphaType);
-
-    auto readSFC = GrSurfaceFillContext::Make(dContext, upmII, SkBackingFit::kExact);
-    auto tempSFC = GrSurfaceFillContext::Make(dContext,  pmII, SkBackingFit::kExact);
-    if (!readSFC || !tempSFC) {
-        return false;
-    }
-
-    // This function is only ever called if we are in a GrDirectContext since we are calling read
-    // pixels here. Thus the pixel data will be uploaded immediately and we don't need to keep the
-    // pixel data alive in the proxy. Therefore the ReleaseProc is nullptr.
-    SkBitmap bitmap;
-    bitmap.installPixels(pmII, srcData, 4 * kSize);
-    bitmap.setImmutable();
-
-    auto dataView = std::get<0>(GrMakeUncachedBitmapProxyView(dContext, bitmap));
-    if (!dataView) {
-        return false;
-    }
-
-    uint32_t* firstRead  = data.get() +   kSize*kSize;
-    uint32_t* secondRead = data.get() + 2*kSize*kSize;
-    std::fill_n( firstRead, kSize*kSize, 0);
-    std::fill_n(secondRead, kSize*kSize, 0);
-
-    GrPixmap firstReadPM( upmII,  firstRead, kSize*sizeof(uint32_t));
-    GrPixmap secondReadPM(upmII, secondRead, kSize*sizeof(uint32_t));
-
-    // We do a PM->UPM draw from dataTex to readTex and read the data. Then we do a UPM->PM draw
-    // from readTex to tempTex followed by a PM->UPM draw to readTex and finally read the data.
-    // We then verify that two reads produced the same values.
-
-    auto fp1 = make_unpremul_effect(GrTextureEffect::Make(std::move(dataView), bitmap.alphaType()));
-    readSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp1));
-    if (!readSFC->readPixels(dContext, firstReadPM, {0, 0})) {
-        return false;
-    }
-
-    auto fp2 = make_premul_effect(
-            GrTextureEffect::Make(readSFC->readSurfaceView(), readSFC->colorInfo().alphaType()));
-    tempSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp2));
-
-    auto fp3 = make_unpremul_effect(
-            GrTextureEffect::Make(tempSFC->readSurfaceView(), tempSFC->colorInfo().alphaType()));
-    readSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp3));
-
-    if (!readSFC->readPixels(dContext, secondReadPM, {0, 0})) {
-        return false;
-    }
-
-    for (int y = 0; y < kSize; ++y) {
-        for (int x = 0; x <= y; ++x) {
-            if (firstRead[kSize*y + x] != secondRead[kSize*y + x]) {
-                return false;
-            }
-        }
-    }
-
-    return true;
-}
-
 bool GrDirectContextPriv::validPMUPMConversionExists() {
     ASSERT_SINGLE_OWNER
 
     if (!fContext->fDidTestPMConversions) {
-        fContext->fPMUPMConversionsRoundTrip = test_for_preserving_PM_conversions(fContext);
+        fContext->fPMUPMConversionsRoundTrip =
+                GrConfigConversionEffect::TestForPreservingPMConversions(fContext);
         fContext->fDidTestPMConversions = true;
     }
 
@@ -330,7 +213,7 @@
     // ...and it should have succeeded
     SkASSERT(this->validPMUPMConversionExists());
 
-    return make_unpremul_effect(std::move(fp));
+    return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToUnpremul);
 }
 
 std::unique_ptr<GrFragmentProcessor> GrDirectContextPriv::createUPMToPMEffect(
@@ -341,7 +224,7 @@
     // ...and it should have succeeded
     SkASSERT(this->validPMUPMConversionExists());
 
-    return make_premul_effect(std::move(fp));
+    return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToPremul);
 }
 
 sk_sp<SkBaseGpuDevice> GrDirectContextPriv::createDevice(GrColorType colorType,
diff --git a/src/gpu/GrDirectContextPriv.h b/src/gpu/GrDirectContextPriv.h
index ac17868..fd8f9af 100644
--- a/src/gpu/GrDirectContextPriv.h
+++ b/src/gpu/GrDirectContextPriv.h
@@ -105,7 +105,8 @@
     bool validPMUPMConversionExists();
 
     /**
-     * These functions create premul <-> unpremul effects, using specialized round-trip effects.
+     * These functions create premul <-> unpremul effects, using the specialized round-trip effects
+     * from GrConfigConversionEffect.
      */
     std::unique_ptr<GrFragmentProcessor> createPMToUPMEffect(std::unique_ptr<GrFragmentProcessor>);
     std::unique_ptr<GrFragmentProcessor> createUPMToPMEffect(std::unique_ptr<GrFragmentProcessor>);
diff --git a/src/gpu/GrProcessor.h b/src/gpu/GrProcessor.h
index b10fa96..edb2c8a 100644
--- a/src/gpu/GrProcessor.h
+++ b/src/gpu/GrProcessor.h
@@ -56,6 +56,7 @@
         kGrBicubicEffect_ClassID,
         kGrBitmapTextGeoProc_ClassID,
         kGrColorSpaceXformEffect_ClassID,
+        kGrConfigConversionEffect_ClassID,
         kGrConicEffect_ClassID,
         kGrConvexPolyEffect_ClassID,
         kGrDiffuseLightingEffect_ClassID,
diff --git a/src/gpu/GrProcessorUnitTest.cpp b/src/gpu/GrProcessorUnitTest.cpp
index b4c673f..3a6f0d1 100644
--- a/src/gpu/GrProcessorUnitTest.cpp
+++ b/src/gpu/GrProcessorUnitTest.cpp
@@ -146,7 +146,7 @@
  * we verify the count is as expected.  If a new factory is added, then these numbers must be
  * manually adjusted.
  */
-static constexpr int kFPFactoryCount = 17;
+static constexpr int kFPFactoryCount = 18;
 static constexpr int kGPFactoryCount = 14;
 static constexpr int kXPFactoryCount = 4;
 
diff --git a/src/gpu/effects/GrConfigConversionEffect.fp b/src/gpu/effects/GrConfigConversionEffect.fp
new file mode 100644
index 0000000..14be17d
--- /dev/null
+++ b/src/gpu/effects/GrConfigConversionEffect.fp
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+in fragmentProcessor inputFP;
+
+@header {
+    #include "include/gpu/GrDirectContext.h"
+    #include "src/gpu/GrDirectContextPriv.h"
+    #include "src/gpu/GrImageInfo.h"
+    #include "src/gpu/GrSurfaceDrawContext.h"
+    #include "src/gpu/SkGr.h"
+}
+
+@class {
+    static bool TestForPreservingPMConversions(GrDirectContext* dContext);
+}
+
+@cppEnd {
+    bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* dContext) {
+        static constexpr int kSize = 256;
+        SkAutoTMalloc<uint32_t> data(kSize * kSize * 3);
+        uint32_t* srcData = data.get();
+
+        // Fill with every possible premultiplied A, color channel value. There will be 256-y
+        // duplicate values in row y. We set r, g, and b to the same value since they are handled
+        // identically.
+        for (int y = 0; y < kSize; ++y) {
+            for (int x = 0; x < kSize; ++x) {
+                uint8_t* color = reinterpret_cast<uint8_t*>(&srcData[kSize*y + x]);
+                color[3] = y;
+                color[2] = std::min(x, y);
+                color[1] = std::min(x, y);
+                color[0] = std::min(x, y);
+            }
+        }
+
+        const SkImageInfo pmII =
+                SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
+        const SkImageInfo upmII = pmII.makeAlphaType(kUnpremul_SkAlphaType);
+
+        auto readSFC = GrSurfaceFillContext::Make(dContext, upmII, SkBackingFit::kExact);
+        auto tempSFC = GrSurfaceFillContext::Make(dContext,  pmII, SkBackingFit::kExact);
+        if (!readSFC || !tempSFC) {
+            return false;
+        }
+
+        // This function is only ever called if we are in a GrDirectContext since we are
+        // calling read pixels here. Thus the pixel data will be uploaded immediately and we don't
+        // need to keep the pixel data alive in the proxy. Therefore the ReleaseProc is nullptr.
+        SkBitmap bitmap;
+        bitmap.installPixels(pmII, srcData, 4 * kSize);
+        bitmap.setImmutable();
+
+        auto dataView = std::get<0>(GrMakeUncachedBitmapProxyView(dContext, bitmap));
+        if (!dataView) {
+            return false;
+        }
+
+        uint32_t* firstRead  = data.get() +   kSize*kSize;
+        uint32_t* secondRead = data.get() + 2*kSize*kSize;
+        std::fill_n( firstRead, kSize*kSize, 0);
+        std::fill_n(secondRead, kSize*kSize, 0);
+
+        GrPixmap firstReadPM( upmII,  firstRead, kSize*sizeof(uint32_t));
+        GrPixmap secondReadPM(upmII, secondRead, kSize*sizeof(uint32_t));
+
+        // We do a PM->UPM draw from dataTex to readTex and read the data. Then we do a UPM->PM draw
+        // from readTex to tempTex followed by a PM->UPM draw to readTex and finally read the data.
+        // We then verify that two reads produced the same values.
+
+        auto fp1 = GrConfigConversionEffect::Make(GrTextureEffect::Make(std::move(dataView),
+                                                                        bitmap.alphaType()),
+                                                  PMConversion::kToUnpremul);
+        readSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp1));
+        if (!readSFC->readPixels(dContext, firstReadPM, {0, 0})) {
+            return false;
+        }
+
+        auto fp2 = GrConfigConversionEffect::Make(
+                GrTextureEffect::Make(readSFC->readSurfaceView(),
+                                      readSFC->colorInfo().alphaType()),
+                PMConversion::kToPremul);
+        tempSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp2));
+
+        auto fp3 = GrConfigConversionEffect::Make(
+                GrTextureEffect::Make(tempSFC->readSurfaceView(),
+                                      tempSFC->colorInfo().alphaType()),
+                PMConversion::kToUnpremul);
+        readSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp3));
+
+        if (!readSFC->readPixels(dContext, secondReadPM, {0, 0})) {
+            return false;
+        }
+
+        for (int y = 0; y < kSize; ++y) {
+            for (int x = 0; x <= y; ++x) {
+                if (firstRead[kSize*y + x] != secondRead[kSize*y + x]) {
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+}
+
+@make {
+    static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp,
+                                                     PMConversion pmConversion) {
+        if (!fp) {
+            return nullptr;
+        }
+        fp = std::unique_ptr<GrFragmentProcessor>(
+                new GrConfigConversionEffect(std::move(fp), pmConversion));
+        return GrFragmentProcessor::HighPrecision(std::move(fp));
+    }
+}
+
+layout(key) in PMConversion pmConversion;
+
+half4 main() {
+    // Aggressively round to the nearest exact (N / 255) floating point value. This lets us find a
+    // round-trip preserving pair on some GPUs that do odd byte to float conversion.
+    half4 color = floor(sample(inputFP) * 255 + 0.5) / 255;
+
+    @switch (pmConversion) {
+        case PMConversion::kToPremul:
+            color.rgb = floor(color.rgb * color.a * 255 + 0.5) / 255;
+            break;
+
+        case PMConversion::kToUnpremul:
+            color.rgb = color.a <= 0.0
+                            ? half3(0)
+                            : floor(color.rgb / color.a * 255 + 0.5) / 255;
+            break;
+    }
+
+    return color;
+}
+
+@test(data) {
+    PMConversion pmConv = static_cast<PMConversion>(
+            data->fRandom->nextRangeU(0, (int)PMConversion::kLast));
+    return std::unique_ptr<GrFragmentProcessor>(
+            new GrConfigConversionEffect(GrProcessorUnitTest::MakeChildFP(data), pmConv));
+}
diff --git a/src/gpu/effects/generated/GrConfigConversionEffect.cpp b/src/gpu/effects/generated/GrConfigConversionEffect.cpp
new file mode 100644
index 0000000..0c096b3
--- /dev/null
+++ b/src/gpu/effects/generated/GrConfigConversionEffect.cpp
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**************************************************************************************************
+ *** This file was autogenerated from GrConfigConversionEffect.fp; do not modify.
+ **************************************************************************************************/
+#include "GrConfigConversionEffect.h"
+
+#include "src/core/SkUtils.h"
+#include "src/gpu/GrTexture.h"
+#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
+#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
+#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
+#include "src/sksl/SkSLCPP.h"
+#include "src/sksl/SkSLUtil.h"
+class GrGLSLConfigConversionEffect : public GrGLSLFragmentProcessor {
+public:
+    GrGLSLConfigConversionEffect() {}
+    void emitCode(EmitArgs& args) override {
+        GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
+        const GrConfigConversionEffect& _outer = args.fFp.cast<GrConfigConversionEffect>();
+        (void)_outer;
+        auto pmConversion = _outer.pmConversion;
+        (void)pmConversion;
+        SkString _sample0 = this->invokeChild(0, args);
+        fragBuilder->codeAppendf(
+                R"SkSL(half4 color = floor(%s * 255.0 + 0.5) / 255.0;
+@switch (%d) {
+    case 0:
+        color.xyz = floor((color.xyz * color.w) * 255.0 + 0.5) / 255.0;
+        break;
+    case 1:
+        color.xyz = color.w <= 0.0 ? half3(0.0) : floor((color.xyz / color.w) * 255.0 + 0.5) / 255.0;
+        break;
+}
+return color;
+)SkSL",
+                _sample0.c_str(),
+                (int)_outer.pmConversion);
+    }
+
+private:
+    void onSetData(const GrGLSLProgramDataManager& pdman,
+                   const GrFragmentProcessor& _proc) override {}
+};
+std::unique_ptr<GrGLSLFragmentProcessor> GrConfigConversionEffect::onMakeProgramImpl() const {
+    return std::make_unique<GrGLSLConfigConversionEffect>();
+}
+void GrConfigConversionEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
+                                                     GrProcessorKeyBuilder* b) const {
+    b->addBits(1, (uint32_t)pmConversion, "pmConversion");
+}
+bool GrConfigConversionEffect::onIsEqual(const GrFragmentProcessor& other) const {
+    const GrConfigConversionEffect& that = other.cast<GrConfigConversionEffect>();
+    (void)that;
+    if (pmConversion != that.pmConversion) return false;
+    return true;
+}
+GrConfigConversionEffect::GrConfigConversionEffect(const GrConfigConversionEffect& src)
+        : INHERITED(kGrConfigConversionEffect_ClassID, src.optimizationFlags())
+        , pmConversion(src.pmConversion) {
+    this->cloneAndRegisterAllChildProcessors(src);
+}
+std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::clone() const {
+    return std::make_unique<GrConfigConversionEffect>(*this);
+}
+#if GR_TEST_UTILS
+SkString GrConfigConversionEffect::onDumpInfo() const {
+    return SkStringPrintf("(pmConversion=%d)", (int)pmConversion);
+}
+#endif
+GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect);
+#if GR_TEST_UTILS
+std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::TestCreate(
+        GrProcessorTestData* data) {
+    PMConversion pmConv =
+            static_cast<PMConversion>(data->fRandom->nextRangeU(0, (int)PMConversion::kLast));
+    return std::unique_ptr<GrFragmentProcessor>(
+            new GrConfigConversionEffect(GrProcessorUnitTest::MakeChildFP(data), pmConv));
+}
+#endif
+
+bool GrConfigConversionEffect::TestForPreservingPMConversions(GrDirectContext* dContext) {
+    static constexpr int kSize = 256;
+    SkAutoTMalloc<uint32_t> data(kSize * kSize * 3);
+    uint32_t* srcData = data.get();
+
+    // Fill with every possible premultiplied A, color channel value. There will be 256-y
+    // duplicate values in row y. We set r, g, and b to the same value since they are handled
+    // identically.
+    for (int y = 0; y < kSize; ++y) {
+        for (int x = 0; x < kSize; ++x) {
+            uint8_t* color = reinterpret_cast<uint8_t*>(&srcData[kSize * y + x]);
+            color[3] = y;
+            color[2] = std::min(x, y);
+            color[1] = std::min(x, y);
+            color[0] = std::min(x, y);
+        }
+    }
+
+    const SkImageInfo pmII =
+            SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
+    const SkImageInfo upmII = pmII.makeAlphaType(kUnpremul_SkAlphaType);
+
+    auto readSFC = GrSurfaceFillContext::Make(dContext, upmII, SkBackingFit::kExact);
+    auto tempSFC = GrSurfaceFillContext::Make(dContext, pmII, SkBackingFit::kExact);
+    if (!readSFC || !tempSFC) {
+        return false;
+    }
+
+    // This function is only ever called if we are in a GrDirectContext since we are
+    // calling read pixels here. Thus the pixel data will be uploaded immediately and we don't
+    // need to keep the pixel data alive in the proxy. Therefore the ReleaseProc is nullptr.
+    SkBitmap bitmap;
+    bitmap.installPixels(pmII, srcData, 4 * kSize);
+    bitmap.setImmutable();
+
+    auto dataView = std::get<0>(GrMakeUncachedBitmapProxyView(dContext, bitmap));
+    if (!dataView) {
+        return false;
+    }
+
+    uint32_t* firstRead = data.get() + kSize * kSize;
+    uint32_t* secondRead = data.get() + 2 * kSize * kSize;
+    std::fill_n(firstRead, kSize * kSize, 0);
+    std::fill_n(secondRead, kSize * kSize, 0);
+
+    GrPixmap firstReadPM(upmII, firstRead, kSize * sizeof(uint32_t));
+    GrPixmap secondReadPM(upmII, secondRead, kSize * sizeof(uint32_t));
+
+    // We do a PM->UPM draw from dataTex to readTex and read the data. Then we do a UPM->PM draw
+    // from readTex to tempTex followed by a PM->UPM draw to readTex and finally read the data.
+    // We then verify that two reads produced the same values.
+
+    auto fp1 = GrConfigConversionEffect::Make(
+            GrTextureEffect::Make(std::move(dataView), bitmap.alphaType()),
+            PMConversion::kToUnpremul);
+    readSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp1));
+    if (!readSFC->readPixels(dContext, firstReadPM, {0, 0})) {
+        return false;
+    }
+
+    auto fp2 = GrConfigConversionEffect::Make(
+            GrTextureEffect::Make(readSFC->readSurfaceView(), readSFC->colorInfo().alphaType()),
+            PMConversion::kToPremul);
+    tempSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp2));
+
+    auto fp3 = GrConfigConversionEffect::Make(
+            GrTextureEffect::Make(tempSFC->readSurfaceView(), tempSFC->colorInfo().alphaType()),
+            PMConversion::kToUnpremul);
+    readSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp3));
+
+    if (!readSFC->readPixels(dContext, secondReadPM, {0, 0})) {
+        return false;
+    }
+
+    for (int y = 0; y < kSize; ++y) {
+        for (int x = 0; x <= y; ++x) {
+            if (firstRead[kSize * y + x] != secondRead[kSize * y + x]) {
+                return false;
+            }
+        }
+    }
+
+    return true;
+}
diff --git a/src/gpu/effects/generated/GrConfigConversionEffect.h b/src/gpu/effects/generated/GrConfigConversionEffect.h
new file mode 100644
index 0000000..1bcb57d
--- /dev/null
+++ b/src/gpu/effects/generated/GrConfigConversionEffect.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**************************************************************************************************
+ *** This file was autogenerated from GrConfigConversionEffect.fp; do not modify.
+ **************************************************************************************************/
+#ifndef GrConfigConversionEffect_DEFINED
+#define GrConfigConversionEffect_DEFINED
+
+#include "include/core/SkM44.h"
+#include "include/core/SkTypes.h"
+
+#include "include/gpu/GrDirectContext.h"
+#include "src/gpu/GrDirectContextPriv.h"
+#include "src/gpu/GrImageInfo.h"
+#include "src/gpu/GrSurfaceDrawContext.h"
+#include "src/gpu/SkGr.h"
+
+#include "src/gpu/GrFragmentProcessor.h"
+
+class GrConfigConversionEffect : public GrFragmentProcessor {
+public:
+    static bool TestForPreservingPMConversions(GrDirectContext* dContext);
+
+    static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp,
+                                                     PMConversion pmConversion) {
+        if (!fp) {
+            return nullptr;
+        }
+        fp = std::unique_ptr<GrFragmentProcessor>(
+                new GrConfigConversionEffect(std::move(fp), pmConversion));
+        return GrFragmentProcessor::HighPrecision(std::move(fp));
+    }
+    GrConfigConversionEffect(const GrConfigConversionEffect& src);
+    std::unique_ptr<GrFragmentProcessor> clone() const override;
+    const char* name() const override { return "ConfigConversionEffect"; }
+    PMConversion pmConversion;
+
+private:
+    GrConfigConversionEffect(std::unique_ptr<GrFragmentProcessor> inputFP,
+                             PMConversion pmConversion)
+            : INHERITED(kGrConfigConversionEffect_ClassID, kNone_OptimizationFlags)
+            , pmConversion(pmConversion) {
+        this->registerChild(std::move(inputFP), SkSL::SampleUsage::PassThrough());
+    }
+    std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override;
+    void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
+    bool onIsEqual(const GrFragmentProcessor&) const override;
+#if GR_TEST_UTILS
+    SkString onDumpInfo() const override;
+#endif
+    GR_DECLARE_FRAGMENT_PROCESSOR_TEST
+    using INHERITED = GrFragmentProcessor;
+};
+#endif
diff --git a/src/sksl/generated/sksl_fp.dehydrated.sksl b/src/sksl/generated/sksl_fp.dehydrated.sksl
index 0b765d8..4574f56 100644
--- a/src/sksl/generated/sksl_fp.dehydrated.sksl
+++ b/src/sksl/generated/sksl_fp.dehydrated.sksl
@@ -1,5 +1,6 @@
-static uint8_t SKSL_INCLUDE_sksl_fp[] = {220,0,
+static uint8_t SKSL_INCLUDE_sksl_fp[] = {255,0,
 14,71,114,67,108,105,112,69,100,103,101,84,121,112,101,
+12,80,77,67,111,110,118,101,114,115,105,111,110,
 0,
 12,115,107,95,70,114,97,103,67,111,111,114,100,
 6,102,108,111,97,116,52,
@@ -19,132 +20,153 @@
 14,107,73,110,118,101,114,115,101,70,105,108,108,66,87,
 14,107,73,110,118,101,114,115,101,70,105,108,108,65,65,
 5,107,76,97,115,116,
-49,22,0,
+9,107,84,111,80,114,101,109,117,108,
+11,107,84,111,85,110,112,114,101,109,117,108,
+49,23,0,
 22,1,0,2,0,
-53,2,0,
+22,2,0,17,0,
+53,3,0,
 37,
-36,0,4,0,0,255,255,255,255,255,15,0,255,255,255,255,17,0,0,2,18,0,
-50,3,0,31,0,0,
-0,4,0,
-47,3,0,1,
-53,5,0,
-37,
-36,0,4,0,0,255,255,255,255,255,15,39,255,255,255,255,17,0,0,0,38,0,
-47,4,0,0,
+36,0,4,0,0,255,255,255,255,255,15,0,255,255,255,255,30,0,0,2,31,0,
+50,4,0,44,0,0,
+0,5,0,
+47,4,0,1,
 53,6,0,
 37,
-36,0,4,0,0,255,255,255,255,255,15,39,255,255,255,255,17,0,0,0,54,0,
-50,7,0,71,0,0,
-53,8,0,
+36,0,4,0,0,255,255,255,255,255,15,39,255,255,255,255,30,0,0,0,51,0,
+47,5,0,0,
+53,7,0,
 37,
-36,0,4,0,0,255,255,255,255,255,15,39,255,255,255,255,17,0,0,0,77,0,
-47,7,0,0,
+36,0,4,0,0,255,255,255,255,255,15,39,255,255,255,255,30,0,0,0,67,0,
+50,8,0,84,0,0,
 53,9,0,
 37,
-36,0,4,0,0,255,255,255,255,255,15,39,255,255,255,255,17,0,0,0,97,0,
-47,7,0,0,
+36,0,4,0,0,255,255,255,255,255,15,39,255,255,255,255,30,0,0,0,90,0,
+47,8,0,0,
 53,10,0,
-16,122,0,
-50,11,0,125,0,3,
-30,12,0,
-16,143,0,1,10,0,
-47,7,0,
-53,13,0,
-16,122,0,
-47,11,0,3,
+37,
+36,0,4,0,0,255,255,255,255,255,15,39,255,255,255,255,30,0,0,0,110,0,
+47,8,0,0,
+53,11,0,
+16,135,0,
+50,12,0,138,0,3,
+30,13,0,
+16,156,0,1,11,0,
+47,8,0,
 53,14,0,
-16,150,0,
-50,15,0,157,0,3,
-52,16,0,2,
-47,12,0,
-30,17,0,
-16,143,0,2,13,0,14,0,
-47,7,0,
-47,17,0,
-53,18,0,
-16,122,0,
-47,11,0,3,
+16,135,0,
+47,12,0,3,
+53,15,0,
+16,163,0,
+50,16,0,170,0,3,
+52,17,0,2,
+47,13,0,
+30,18,0,
+16,156,0,2,14,0,15,0,
+47,8,0,
+47,18,0,
 53,19,0,
-16,164,0,
-47,7,0,3,
-52,20,0,3,
-47,12,0,
-47,17,0,
-30,21,0,
-16,143,0,2,18,0,19,0,
-47,7,0,
-47,21,0,
-53,22,0,
-16,122,0,
-47,11,0,3,
+16,135,0,
+47,12,0,3,
+53,20,0,
+16,177,0,
+47,8,0,3,
+52,21,0,3,
+47,13,0,
+47,18,0,
+30,22,0,
+16,156,0,2,19,0,20,0,
+47,8,0,
+47,22,0,
 53,23,0,
-16,150,0,
-47,15,0,3,
+16,135,0,
+47,12,0,3,
 53,24,0,
-16,164,0,
-47,7,0,3,
-52,25,0,4,
-47,12,0,
-47,17,0,
-47,21,0,
-30,26,0,
-16,143,0,3,22,0,23,0,24,0,
-47,7,0,
-47,26,0,7,0,
+16,163,0,
+47,16,0,3,
+53,25,0,
+16,177,0,
+47,8,0,3,
+52,26,0,4,
+47,13,0,
+47,18,0,
+47,22,0,
+30,27,0,
+16,156,0,3,23,0,24,0,25,0,
+47,8,0,
+47,27,0,8,0,
 0,0,
-4,0,
-5,0,
-3,0,
-6,0,
-20,0,
 1,0,
+5,0,
+6,0,
+4,0,
+7,0,
+21,0,
+2,0,
 19,
 21,2,0,
 49,5,0,
-53,27,0,
-37,
-15,1,170,0,
-47,1,0,0,
 53,28,0,
 37,
-15,1,178,0,
+15,1,183,0,
 47,1,0,0,
 53,29,0,
 37,
-15,1,186,0,
+15,1,191,0,
 47,1,0,0,
 53,30,0,
 37,
-15,1,201,0,
+15,1,199,0,
 47,1,0,0,
 53,31,0,
 37,
-15,1,216,0,
+15,1,214,0,
+47,1,0,0,
+53,32,0,
+37,
+15,1,229,0,
 47,1,0,0,5,0,
 1,0,
 0,0,
 3,0,
 2,0,
 4,0,0,0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,3,0,0,0,
+21,17,0,
+49,3,0,
+53,33,0,
+37,
+15,1,235,0,
+47,2,0,0,
+53,34,0,
+37,
+15,1,245,0,
+47,2,0,0,
+53,35,0,
+37,
+15,1,229,0,
+47,2,0,0,3,0,
+2,0,
+0,0,
+1,0,0,0,0,0,1,0,0,0,1,0,0,0,
 55,
-54,2,0,
-47,3,0,0,
-57,
-55,
-54,5,0,
-47,3,0,1,
+54,3,0,
+47,4,0,0,
 57,
 55,
 54,6,0,
-47,7,0,0,
+47,4,0,1,
 57,
 55,
-54,8,0,
-47,7,0,0,
+54,7,0,
+47,8,0,0,
 57,
 55,
 54,9,0,
-47,7,0,0,
+47,8,0,0,
+57,
+55,
+54,10,0,
+47,8,0,0,
 57,
 20,};
 static constexpr size_t SKSL_INCLUDE_sksl_fp_LENGTH = sizeof(SKSL_INCLUDE_sksl_fp);