Revert "Revert "Use float colors for blend constant""

This reverts commit 5a4f2a341a4a32d8f175afe1828a7796155dbcb8.

Bug: skia:
Change-Id: I706009343dc1976311a88d57800a140efd776861
Reviewed-on: https://skia-review.googlesource.com/c/168363
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/include/private/GrColor.h b/include/private/GrColor.h
index f36a358..ab03ab2 100644
--- a/include/private/GrColor.h
+++ b/include/private/GrColor.h
@@ -103,15 +103,6 @@
     return GrColorPackRGBA(r, g, b, a);
 }
 
-/** Converts a GrColor to an rgba array of GrGLfloat */
-static inline void GrColorToRGBAFloat(GrColor color, float rgba[4]) {
-    static const float ONE_OVER_255 = 1.f / 255.f;
-    rgba[0] = GrColorUnpackR(color) * ONE_OVER_255;
-    rgba[1] = GrColorUnpackG(color) * ONE_OVER_255;
-    rgba[2] = GrColorUnpackB(color) * ONE_OVER_255;
-    rgba[3] = GrColorUnpackA(color) * ONE_OVER_255;
-}
-
 /** Normalizes and coverts an uint8_t to a float. [0, 255] -> [0.0, 1.0] */
 static inline float GrNormalizeByteToFloat(uint8_t value) {
     static const float ONE_OVER_255 = 1.f / 255.f;
@@ -123,22 +114,4 @@
     return (color & (0xFFU << GrColor_SHIFT_A)) == (0xFFU << GrColor_SHIFT_A);
 }
 
-/** Returns an unpremuled version of the GrColor. */
-static inline GrColor GrUnpremulColor(GrColor color) {
-    GrColorIsPMAssert(color);
-    unsigned r = GrColorUnpackR(color);
-    unsigned g = GrColorUnpackG(color);
-    unsigned b = GrColorUnpackB(color);
-    unsigned a = GrColorUnpackA(color);
-    SkPMColor colorPM = SkPackARGB32(a, r, g, b);
-    SkColor colorUPM = SkUnPreMultiply::PMColorToColor(colorPM);
-
-    r = SkColorGetR(colorUPM);
-    g = SkColorGetG(colorUPM);
-    b = SkColorGetB(colorUPM);
-    a = SkColorGetA(colorUPM);
-
-    return GrColorPackRGBA(r, g, b, a);
-}
-
 #endif
diff --git a/src/gpu/GrProcessorAnalysis.h b/src/gpu/GrProcessorAnalysis.h
index 28e6731..e8c7458 100644
--- a/src/gpu/GrProcessorAnalysis.h
+++ b/src/gpu/GrProcessorAnalysis.h
@@ -8,7 +8,6 @@
 #ifndef GrProcessorAnalysis_DEFINED
 #define GrProcessorAnalysis_DEFINED
 
-#include "GrColor.h"
 #include "SkColorData.h"
 
 class GrDrawOp;
@@ -42,16 +41,6 @@
 
     bool isOpaque() const { return SkToBool(kIsOpaque_Flag & fFlags); }
 
-    bool isConstant(GrColor* color) const {
-        if (kColorIsKnown_Flag & fFlags) {
-            if (color) {
-                *color = fColor.toBytes_RGBA();
-            }
-            return true;
-        }
-        return false;
-    }
-
     bool isConstant(SkPMColor4f* color = nullptr) const {
         if (kColorIsKnown_Flag & fFlags) {
             if (color) {
diff --git a/src/gpu/GrSwizzle.h b/src/gpu/GrSwizzle.h
index 2d900e3..51e01ef 100644
--- a/src/gpu/GrSwizzle.h
+++ b/src/gpu/GrSwizzle.h
@@ -57,25 +57,6 @@
     }
 
     /** Applies this swizzle to the input color and returns the swizzled color. */
-    GrColor applyTo(GrColor color) const {
-        int idx;
-        uint32_t key = fKey;
-        // Index of the input color that should be mapped to output r.
-        idx = (key & 3);
-        uint32_t outR = (color >> idx * 8)  & 0xFF;
-        key >>= 2;
-        idx = (key & 3);
-        uint32_t outG = (color >> idx * 8)  & 0xFF;
-        key >>= 2;
-        idx = (key & 3);
-        uint32_t outB = (color >> idx * 8)  & 0xFF;
-        key >>= 2;
-        idx = (key & 3);
-        uint32_t outA = (color >> idx * 8)  & 0xFF;
-        return GrColorPackRGBA(outR, outG, outB, outA);
-    }
-
-    /** Applies this swizzle to the input color and returns the swizzled color. */
     SkPMColor4f applyTo(const SkPMColor4f& color) const {
         int idx;
         uint32_t key = fKey;
diff --git a/src/gpu/GrXferProcessor.cpp b/src/gpu/GrXferProcessor.cpp
index a008e98..b32f25f 100644
--- a/src/gpu/GrXferProcessor.cpp
+++ b/src/gpu/GrXferProcessor.cpp
@@ -149,7 +149,7 @@
     SkString out;
     out.printf("write_color(%d) equation(%s) src_coeff(%s) dst_coeff:(%s) const(0x%08x)",
                fWriteColor, equation_string(fEquation), coeff_string(fSrcBlend),
-               coeff_string(fDstBlend), fBlendConstant);
+               coeff_string(fDstBlend), fBlendConstant.toBytes_RGBA());
     return out;
 }
 #endif
diff --git a/src/gpu/GrXferProcessor.h b/src/gpu/GrXferProcessor.h
index 6d80333..3d42dfd 100644
--- a/src/gpu/GrXferProcessor.h
+++ b/src/gpu/GrXferProcessor.h
@@ -9,7 +9,6 @@
 #define GrXferProcessor_DEFINED
 
 #include "GrBlend.h"
-#include "GrColor.h"
 #include "GrNonAtomicRef.h"
 #include "GrProcessor.h"
 #include "GrProcessorAnalysis.h"
@@ -132,7 +131,7 @@
             fEquation = kAdd_GrBlendEquation;
             fSrcBlend = kOne_GrBlendCoeff;
             fDstBlend = kZero_GrBlendCoeff;
-            fBlendConstant = 0;
+            fBlendConstant = SK_PMColor4fTRANSPARENT;
             fWriteColor = true;
         }
 
@@ -141,7 +140,7 @@
         GrBlendEquation fEquation;
         GrBlendCoeff    fSrcBlend;
         GrBlendCoeff    fDstBlend;
-        GrColor         fBlendConstant;
+        SkPMColor4f     fBlendConstant;
         bool            fWriteColor;
     };
 
diff --git a/src/gpu/effects/GrCoverageSetOpXP.cpp b/src/gpu/effects/GrCoverageSetOpXP.cpp
index e7ac874..8e1dbbb 100644
--- a/src/gpu/effects/GrCoverageSetOpXP.cpp
+++ b/src/gpu/effects/GrCoverageSetOpXP.cpp
@@ -117,7 +117,7 @@
             blendInfo->fDstBlend = kZero_GrBlendCoeff;
             break;
     }
-    blendInfo->fBlendConstant = 0;
+    blendInfo->fBlendConstant = SK_PMColor4fTRANSPARENT;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp
index 89f61ec..69d7126 100644
--- a/src/gpu/effects/GrPorterDuffXferProcessor.cpp
+++ b/src/gpu/effects/GrPorterDuffXferProcessor.cpp
@@ -588,10 +588,10 @@
 
     GrGLSLXferProcessor* createGLSLInstance() const override;
 
-    uint8_t alpha() const { return fAlpha; }
+    float alpha() const { return fAlpha; }
 
 private:
-    PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha);
+    PDLCDXferProcessor(const SkPMColor4f& blendConstant, float alpha);
 
     void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
 
@@ -609,8 +609,8 @@
         return true;
     }
 
-    GrColor fBlendConstant;
-    uint8_t fAlpha;
+    SkPMColor4f fBlendConstant;
+    float fAlpha;
 
     typedef GrXferProcessor INHERITED;
 };
@@ -619,7 +619,7 @@
 
 class GLPDLCDXferProcessor : public GrGLSLXferProcessor {
 public:
-    GLPDLCDXferProcessor(const GrProcessor&) : fLastAlpha(UINT32_MAX) {}
+    GLPDLCDXferProcessor(const GrProcessor&) : fLastAlpha(SK_FloatNaN) {}
 
     ~GLPDLCDXferProcessor() override {}
 
@@ -641,21 +641,21 @@
     }
 
     void onSetData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp) override {
-        uint32_t alpha = SkToU32(xp.cast<PDLCDXferProcessor>().alpha());
+        float alpha = xp.cast<PDLCDXferProcessor>().alpha();
         if (fLastAlpha != alpha) {
-            pdm.set1f(fAlphaUniform, alpha / 255.f);
+            pdm.set1f(fAlphaUniform, alpha);
             fLastAlpha = alpha;
         }
     }
 
     GrGLSLUniformHandler::UniformHandle fAlphaUniform;
-    uint32_t fLastAlpha;
+    float fLastAlpha;
     typedef GrGLSLXferProcessor INHERITED;
 };
 
 ///////////////////////////////////////////////////////////////////////////////
 
-PDLCDXferProcessor::PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha)
+PDLCDXferProcessor::PDLCDXferProcessor(const SkPMColor4f& blendConstant, float alpha)
     : INHERITED(kPDLCDXferProcessor_ClassID, false, false, GrProcessorAnalysisCoverage::kLCD)
     , fBlendConstant(blendConstant)
     , fAlpha(alpha) {
@@ -666,14 +666,14 @@
     if (SkBlendMode::kSrcOver != mode) {
         return nullptr;
     }
-    GrColor blendConstant;
-    if (!color.isConstant(&blendConstant)) {
+    SkPMColor4f blendConstantPM;
+    if (!color.isConstant(&blendConstantPM)) {
         return nullptr;
     }
-    blendConstant = GrUnpremulColor(blendConstant);
-    uint8_t alpha = GrColorUnpackA(blendConstant);
-    blendConstant |= (0xff << GrColor_SHIFT_A);
-    return sk_sp<GrXferProcessor>(new PDLCDXferProcessor(blendConstant, alpha));
+    SkColor4f blendConstantUPM = blendConstantPM.unpremul();
+    float alpha = blendConstantUPM.fA;
+    blendConstantPM = { blendConstantUPM.fR, blendConstantUPM.fG, blendConstantUPM.fB, 1 };
+    return sk_sp<GrXferProcessor>(new PDLCDXferProcessor(blendConstantPM, alpha));
 }
 
 PDLCDXferProcessor::~PDLCDXferProcessor() {
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 902509d..f9b6217 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -2795,12 +2795,9 @@
     }
 
     if ((BlendCoeffReferencesConstant(srcCoeff) || BlendCoeffReferencesConstant(dstCoeff))) {
-        GrColor blendConst = blendInfo.fBlendConstant;
-        blendConst = swizzle.applyTo(blendConst);
+        SkPMColor4f blendConst = swizzle.applyTo(blendInfo.fBlendConstant);
         if (!fHWBlendState.fConstColorValid || fHWBlendState.fConstColor != blendConst) {
-            GrGLfloat c[4];
-            GrColorToRGBAFloat(blendConst, c);
-            GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
+            GL_CALL(BlendColor(blendConst.fR, blendConst.fG, blendConst.fB, blendConst.fA));
             fHWBlendState.fConstColor = blendConst;
             fHWBlendState.fConstColorValid = true;
         }
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 8812a02..270e28a 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -561,7 +561,7 @@
         GrBlendEquation fEquation;
         GrBlendCoeff    fSrcCoeff;
         GrBlendCoeff    fDstCoeff;
-        GrColor         fConstColor;
+        SkPMColor4f     fConstColor;
         bool            fConstColorValid;
         TriState        fEnabled;
 
diff --git a/src/gpu/mtl/GrMtlPipelineState.mm b/src/gpu/mtl/GrMtlPipelineState.mm
index 590eff6..1d9562e 100644
--- a/src/gpu/mtl/GrMtlPipelineState.mm
+++ b/src/gpu/mtl/GrMtlPipelineState.mm
@@ -185,16 +185,14 @@
     GrBlendCoeff srcCoeff = blendInfo.fSrcBlend;
     GrBlendCoeff dstCoeff = blendInfo.fDstBlend;
     if (blend_coeff_refs_constant(srcCoeff) || blend_coeff_refs_constant(dstCoeff)) {
-        float floatColors[4];
         // Swizzle the blend to match what the shader will output.
         const GrSwizzle& swizzle = fGpu->caps()->shaderCaps()->configOutputSwizzle(config);
-        GrColor blendConst = swizzle.applyTo(blendInfo.fBlendConstant);
-        GrColorToRGBAFloat(blendConst, floatColors);
+        SkPMColor4f blendConst = swizzle.applyTo(blendInfo.fBlendConstant);
 
-        [renderCmdEncoder setBlendColorRed: floatColors[0]
-                                     green: floatColors[1]
-                                      blue: floatColors[2]
-                                     alpha: floatColors[3]];
+        [renderCmdEncoder setBlendColorRed: blendConst.fR
+                                     green: blendConst.fG
+                                      blue: blendConst.fB
+                                     alpha: blendConst.fA];
     }
 }
 
diff --git a/src/gpu/vk/GrVkPipeline.cpp b/src/gpu/vk/GrVkPipeline.cpp
index 15832cc..e0ede4c 100644
--- a/src/gpu/vk/GrVkPipeline.cpp
+++ b/src/gpu/vk/GrVkPipeline.cpp
@@ -624,8 +624,11 @@
     if (blend_coeff_refs_constant(srcCoeff) || blend_coeff_refs_constant(dstCoeff)) {
         // Swizzle the blend to match what the shader will output.
         const GrSwizzle& swizzle = gpu->caps()->shaderCaps()->configOutputSwizzle(pixelConfig);
-        GrColor blendConst = swizzle.applyTo(blendInfo.fBlendConstant);
-        GrColorToRGBAFloat(blendConst, floatColors);
+        SkPMColor4f blendConst = swizzle.applyTo(blendInfo.fBlendConstant);
+        floatColors[0] = blendConst.fR;
+        floatColors[1] = blendConst.fG;
+        floatColors[2] = blendConst.fB;
+        floatColors[3] = blendConst.fA;
     } else {
         memset(floatColors, 0, 4 * sizeof(float));
     }