Small change to use a GrGeometryProcessor for all BitmapText draw calls

BUG=skia:

Review URL: https://codereview.chromium.org/914723002
diff --git a/bench/TextBench.cpp b/bench/TextBench.cpp
index 6c3bab1..39484a2 100644
--- a/bench/TextBench.cpp
+++ b/bench/TextBench.cpp
@@ -5,17 +5,21 @@
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
 #include "Benchmark.h"
+#include "Resources.h"
 #include "SkCanvas.h"
 #include "SkPaint.h"
 #include "SkRandom.h"
+#include "SkStream.h"
 #include "SkString.h"
 #include "SkTemplates.h"
+#include "SkTypeface.h"
 
 enum FontQuality {
     kBW,
     kAA,
-    kLCD
+    kLCD,
 };
 
 static const char* fontQualityName(const SkPaint& paint) {
@@ -43,13 +47,16 @@
     SkString    fName;
     FontQuality fFQ;
     bool        fDoPos;
+    bool        fDoColorEmoji;
+    SkAutoTUnref<SkTypeface> fColorEmojiTypeface;
     SkPoint*    fPos;
 public:
     TextBench(const char text[], int ps,
-              SkColor color, FontQuality fq, bool doPos = false)  {
+              SkColor color, FontQuality fq, bool doColorEmoji = false, bool doPos = false)  {
         fPos = NULL;
         fFQ = fq;
         fDoPos = doPos;
+        fDoColorEmoji = doColorEmoji;
         fText.set(text);
 
         fPaint.setAntiAlias(kBW != fq);
@@ -57,6 +64,17 @@
         fPaint.setTextSize(SkIntToScalar(ps));
         fPaint.setColor(color);
 
+        if (doColorEmoji) {
+            SkASSERT(kBW == fFQ);
+            SkString filename = GetResourcePath("/Funkster.ttf");
+            SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename.c_str()));
+            if (stream->isValid()) {
+                fColorEmojiTypeface.reset(SkTypeface::CreateFromStream(stream.detach()));
+            } else {
+                SkDebugf("Could not find Funkster.ttf, please set --resourcePath correctly.\n");
+            }
+        }
+
         if (doPos) {
             size_t len = strlen(text);
             SkScalar* adv = new SkScalar[len];
@@ -87,6 +105,11 @@
         } else {
             fName.append("_BK");
         }
+
+        if (fDoColorEmoji && fColorEmojiTypeface) {
+            fName.append("_ColorEmoji");
+        }
+
         return fName.c_str();
     }
 
@@ -101,6 +124,10 @@
         paint.setAntiAlias(kBW != fFQ);
         paint.setLCDRenderText(kLCD == fFQ);
 
+        if (fDoColorEmoji && fColorEmojiTypeface) {
+            paint.setTypeface(fColorEmojiTypeface);
+        }
+
         const SkScalar x0 = SkIntToScalar(-10);
         const SkScalar y0 = SkIntToScalar(-10);
 
@@ -141,4 +168,9 @@
 DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kLCD); )
 DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kLCD); )
 
-DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kAA, true); )
+DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kBW, true); )
+DEF_BENCH( return new TextBench(STR, 16, 0xFFFF0000, kBW, true); )
+DEF_BENCH( return new TextBench(STR, 16, 0x88FF0000, kBW, true); )
+
+DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kBW, true, true); )
+DEF_BENCH( return new TextBench(STR, 16, 0xFF000000, kAA, false, true); )
diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp
index 4af5c0a..5e5aa6a 100755
--- a/src/gpu/GrBitmapTextContext.cpp
+++ b/src/gpu/GrBitmapTextContext.cpp
@@ -561,33 +561,19 @@
         }
 
         GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNone_FilterMode);
-        if (kARGB_GrMaskFormat == fCurrMaskFormat) {
-            uint32_t textureUniqueID = fCurrTexture->getUniqueID();
-            if (textureUniqueID != fEffectTextureUniqueID ||
-                fCachedGeometryProcessor->color() != color) {
-                uint32_t flags = GrDefaultGeoProcFactory::kLocalCoord_GPType;
-                fCachedGeometryProcessor.reset(GrDefaultGeoProcFactory::Create(flags, color));
-                fCachedTextureProcessor.reset(GrSimpleTextureEffect::Create(fCurrTexture,
-                                                                            SkMatrix::I(),
-                                                                            params));
-                fEffectTextureUniqueID = textureUniqueID;
-            }
-            pipelineBuilder.addColorProcessor(fCachedTextureProcessor.get());
-        } else {
-            uint32_t textureUniqueID = fCurrTexture->getUniqueID();
-            if (textureUniqueID != fEffectTextureUniqueID ||
-                fCachedGeometryProcessor->color() != color ||
-                !fCachedGeometryProcessor->localMatrix().cheapEqualTo(fLocalMatrix)) {
-                bool hasColor = kA8_GrMaskFormat == fCurrMaskFormat;
-                bool opaqueVertexColors = GrColorIsOpaque(fPaint.getColor());
-                fCachedGeometryProcessor.reset(GrBitmapTextGeoProc::Create(color,
-                                                                           fCurrTexture,
-                                                                           params,
-                                                                           hasColor,
-                                                                           opaqueVertexColors,
-                                                                           fLocalMatrix));
-                fEffectTextureUniqueID = textureUniqueID;
-            }
+        uint32_t textureUniqueID = fCurrTexture->getUniqueID();
+        if (textureUniqueID != fEffectTextureUniqueID ||
+            fCachedGeometryProcessor->color() != color ||
+            !fCachedGeometryProcessor->localMatrix().cheapEqualTo(fLocalMatrix)) {
+            // This will be ignored in the non A8 case
+            bool opaqueVertexColors = GrColorIsOpaque(fPaint.getColor());
+            fCachedGeometryProcessor.reset(GrBitmapTextGeoProc::Create(color,
+                                                                       fCurrTexture,
+                                                                       params,
+                                                                       fCurrMaskFormat,
+                                                                       opaqueVertexColors,
+                                                                       fLocalMatrix));
+            fEffectTextureUniqueID = textureUniqueID;
         }
 
         int nGlyphs = fCurrVertex / kVerticesPerGlyph;
diff --git a/src/gpu/GrBitmapTextContext.h b/src/gpu/GrBitmapTextContext.h
index bffacd5..5137f82 100644
--- a/src/gpu/GrBitmapTextContext.h
+++ b/src/gpu/GrBitmapTextContext.h
@@ -32,7 +32,6 @@
     GrTexture*                        fCurrTexture;
     GrMaskFormat                      fCurrMaskFormat;
     SkAutoTUnref<const GrGeometryProcessor> fCachedGeometryProcessor;
-    SkAutoTUnref<const GrFragmentProcessor> fCachedTextureProcessor;
     // Used to check whether fCachedEffect is still valid.
     uint32_t                          fEffectTextureUniqueID;
     SkMatrix                          fLocalMatrix;
diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp
index 3133265..a699b04 100644
--- a/src/gpu/effects/GrBitmapTextGeoProc.cpp
+++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp
@@ -47,17 +47,26 @@
         this->addUniformViewMatrix(pb);
 
         // Setup position
-        SetupPosition(vsBuilder, gpArgs, cte.inPosition()->fName,
-                      cte.viewMatrix(), this->uViewM());
+        SetupPosition(vsBuilder, gpArgs, cte.inPosition()->fName, cte.viewMatrix(), this->uViewM());
 
         // emit transforms
         this->emitTransforms(args.fPB, gpArgs->fPositionVar, cte.inPosition()->fName,
                              cte.localMatrix(), args.fTransformsIn, args.fTransformsOut);
 
         GrGLGPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
-        fsBuilder->codeAppendf("%s = ", args.fOutputCoverage);
-        fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_GrSLType);
-        fsBuilder->codeAppend(";");
+        if (cte.maskFormat() == kARGB_GrMaskFormat) {
+            fsBuilder->codeAppendf("%s = ", args.fOutputColor);
+            fsBuilder->appendTextureLookupAndModulate(args.fOutputColor,
+                                                      args.fSamplers[0],
+                                                      v.fsIn(),
+                                                      kVec2f_GrSLType);
+            fsBuilder->codeAppend(";");
+            fsBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage);
+        } else {
+            fsBuilder->codeAppendf("%s = ", args.fOutputCoverage);
+            fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_GrSLType);
+            fsBuilder->codeAppend(";");
+        }
     }
 
     virtual void setData(const GrGLProgramDataManager& pdman,
@@ -86,7 +95,8 @@
         uint32_t key = 0;
         key |= SkToBool(gp.inColor()) ? 0x1 : 0x0;
         key |= local.fUsesLocalCoords && proc.localMatrix().hasPerspective() ? 0x2 : 0x0;
-        key |= ComputePosKey(gp.viewMatrix()) << 2;
+        key |= gp.maskFormat() == kARGB_GrMaskFormat ? 0x4 : 0x0;
+        key |= ComputePosKey(gp.viewMatrix()) << 3;
         b->add32(local.fInputColorType << 16 | key);
     }
 
@@ -100,19 +110,22 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 GrBitmapTextGeoProc::GrBitmapTextGeoProc(GrColor color, GrTexture* texture,
-                                         const GrTextureParams& params, bool useColorAttrib,
+                                         const GrTextureParams& params, GrMaskFormat format,
                                          bool opaqueVertexColors, const SkMatrix& localMatrix)
     : INHERITED(color, SkMatrix::I(), localMatrix, opaqueVertexColors)
     , fTextureAccess(texture, params)
-    , fInColor(NULL) {
+    , fInColor(NULL)
+    , fMaskFormat(format) {
     this->initClassID<GrBitmapTextGeoProc>();
     fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType));
-    if (useColorAttrib) {
+
+    bool hasVertexColor = kA8_GrMaskFormat == fMaskFormat;
+    if (hasVertexColor) {
         fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType));
         this->setHasVertexColor();
     }
     fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
-                                                          kVec2f_GrVertexAttribType));
+                                                        kVec2f_GrVertexAttribType));
     this->addTextureAccess(&fTextureAccess);
 }
 
@@ -121,15 +134,25 @@
     return SkToBool(this->inColor()) == SkToBool(gp.inColor());
 }
 
-void GrBitmapTextGeoProc::onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const {
-    if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) {
-        out->setUnknownSingleComponent();
-    } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) {
-        out->setUnknownOpaqueFourComponents();
-        out->setUsingLCDCoverage();
-    } else {
+void GrBitmapTextGeoProc::onGetInvariantOutputColor(GrInitInvariantOutput* out) const {
+    if (kARGB_GrMaskFormat == fMaskFormat) {
         out->setUnknownFourComponents();
-        out->setUsingLCDCoverage();
+    }
+}
+
+void GrBitmapTextGeoProc::onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const {
+    if (kARGB_GrMaskFormat != fMaskFormat) {
+        if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) {
+            out->setUnknownSingleComponent();
+        } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) {
+            out->setUnknownOpaqueFourComponents();
+            out->setUsingLCDCoverage();
+        } else {
+            out->setUnknownFourComponents();
+            out->setUsingLCDCoverage();
+        }
+    } else {
+        out->setKnownSingleComponent(0xff);
     }
 }
 
@@ -185,7 +208,22 @@
     GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
                                                            GrTextureParams::kNone_FilterMode);
 
+    GrMaskFormat format;
+    switch (random->nextULessThan(3)) {
+        default:
+            SkFAIL("Incomplete enum\n");
+        case 0:
+            format = kA8_GrMaskFormat;
+            break;
+        case 1:
+            format = kA565_GrMaskFormat;
+            break;
+        case 2:
+            format = kARGB_GrMaskFormat;
+            break;
+    }
+
     return GrBitmapTextGeoProc::Create(GrRandomColor(random), textures[texIdx], params,
-                                       random->nextBool(), random->nextBool(),
+                                       format, random->nextBool(),
                                        GrProcessorUnitTest::TestMatrix(random));
 }
diff --git a/src/gpu/effects/GrBitmapTextGeoProc.h b/src/gpu/effects/GrBitmapTextGeoProc.h
index d5684d7..b5a4145 100644
--- a/src/gpu/effects/GrBitmapTextGeoProc.h
+++ b/src/gpu/effects/GrBitmapTextGeoProc.h
@@ -22,9 +22,9 @@
 class GrBitmapTextGeoProc : public GrGeometryProcessor {
 public:
     static GrGeometryProcessor* Create(GrColor color, GrTexture* tex, const GrTextureParams& p,
-                                       bool useColorAttrib, bool opaqueVertexColors,
+                                       GrMaskFormat format, bool opaqueVertexColors,
                                        const SkMatrix& localMatrix) {
-        return SkNEW_ARGS(GrBitmapTextGeoProc, (color, tex, p, useColorAttrib, opaqueVertexColors,
+        return SkNEW_ARGS(GrBitmapTextGeoProc, (color, tex, p, format, opaqueVertexColors,
                                                 localMatrix));
     }
 
@@ -35,6 +35,7 @@
     const Attribute* inPosition() const { return fInPosition; }
     const Attribute* inColor() const { return fInColor; }
     const Attribute* inTextureCoords() const { return fInTextureCoords; }
+    GrMaskFormat maskFormat() const { return fMaskFormat; }
 
     virtual void getGLProcessorKey(const GrBatchTracker& bt,
                                    const GrGLCaps& caps,
@@ -50,16 +51,19 @@
 
 private:
     GrBitmapTextGeoProc(GrColor, GrTexture* texture, const GrTextureParams& params,
-                        bool useColorAttrib, bool opaqueVertexColors, const SkMatrix& localMatrix);
+                        GrMaskFormat format, bool opaqueVertexColors, const SkMatrix& localMatrix);
 
     bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE;
 
+    void onGetInvariantOutputColor(GrInitInvariantOutput*) const SK_OVERRIDE;
+
     void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_OVERRIDE;
 
-    GrTextureAccess    fTextureAccess;
+    GrTextureAccess  fTextureAccess;
     const Attribute* fInPosition;
     const Attribute* fInColor;
     const Attribute* fInTextureCoords;
+    GrMaskFormat     fMaskFormat;
 
     GR_DECLARE_GEOMETRY_PROCESSOR_TEST;