Add blend constant color and use it for lcd text common case (no fancy blend or shaded text)

Review URL: http://codereview.appspot.com/4274057/

git-svn-id: http://skia.googlecode.com/svn/trunk@941 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/src/GrGpuGL.cpp b/gpu/src/GrGpuGL.cpp
index 94e9bfd..f2a2a8f 100644
--- a/gpu/src/GrGpuGL.cpp
+++ b/gpu/src/GrGpuGL.cpp
@@ -45,8 +45,50 @@
     GL_ONE_MINUS_SRC_ALPHA,
     GL_DST_ALPHA,
     GL_ONE_MINUS_DST_ALPHA,
+    GL_CONSTANT_COLOR,
+    GL_ONE_MINUS_CONSTANT_COLOR,
+    GL_CONSTANT_ALPHA,
+    GL_ONE_MINUS_CONSTANT_ALPHA,
 };
 
+bool GrGpuGL::BlendCoefReferencesConstant(GrBlendCoeff coeff) {
+    static const bool gCoeffReferencesBlendConst[] = {
+        false,
+        false,
+        false,
+        false,
+        false,
+        false,
+        false,
+        false,
+        false,
+        false,
+        true,
+        true,
+        true,
+        true,
+    };
+    return gCoeffReferencesBlendConst[coeff];
+    GR_STATIC_ASSERT(kBlendCoeffCount == GR_ARRAY_COUNT(gCoeffReferencesBlendConst));
+}
+
+GR_STATIC_ASSERT(0 == kZero_BlendCoeff);
+GR_STATIC_ASSERT(1 == kOne_BlendCoeff);
+GR_STATIC_ASSERT(2 == kSC_BlendCoeff);
+GR_STATIC_ASSERT(3 == kISC_BlendCoeff);
+GR_STATIC_ASSERT(4 == kDC_BlendCoeff);
+GR_STATIC_ASSERT(5 == kIDC_BlendCoeff);
+GR_STATIC_ASSERT(6 == kSA_BlendCoeff);
+GR_STATIC_ASSERT(7 == kISA_BlendCoeff);
+GR_STATIC_ASSERT(8 == kDA_BlendCoeff);
+GR_STATIC_ASSERT(9 == kIDA_BlendCoeff);
+GR_STATIC_ASSERT(10 == kConstC_BlendCoeff);
+GR_STATIC_ASSERT(11 == kIConstC_BlendCoeff);
+GR_STATIC_ASSERT(12 == kConstA_BlendCoeff);
+GR_STATIC_ASSERT(13 == kIConstA_BlendCoeff);
+
+GR_STATIC_ASSERT(kBlendCoeffCount == GR_ARRAY_COUNT(gXfermodeCoeff2Blend));
+
 ///////////////////////////////////////////////////////////////////////////////
 
 void GrGpuGL::AdjustTextureMatrix(const GrGLTexture* texture,
@@ -458,6 +500,10 @@
     // illegal values
     fHWDrawState.fSrcBlend = (GrBlendCoeff)-1;
     fHWDrawState.fDstBlend = (GrBlendCoeff)-1;
+
+    fHWDrawState.fBlendConstant = 0x00000000;
+    GR_GL(BlendColor(0,0,0,0));
+
     fHWDrawState.fColor = GrColor_ILLEGAL;
 
     fHWDrawState.fViewMatrix = GrMatrix::InvalidMatrix();
@@ -1615,6 +1661,19 @@
             fHWDrawState.fSrcBlend = fCurrDrawState.fSrcBlend;
             fHWDrawState.fDstBlend = fCurrDrawState.fDstBlend;
         }
+        if ((BlendCoefReferencesConstant(fCurrDrawState.fSrcBlend) ||
+             BlendCoefReferencesConstant(fCurrDrawState.fDstBlend)) &&
+            fHWDrawState.fBlendConstant != fCurrDrawState.fBlendConstant) {
+
+            float c[] = {
+                GrColorUnpackR(fCurrDrawState.fBlendConstant) / 255.f,
+                GrColorUnpackG(fCurrDrawState.fBlendConstant) / 255.f,
+                GrColorUnpackB(fCurrDrawState.fBlendConstant) / 255.f,
+                GrColorUnpackA(fCurrDrawState.fBlendConstant) / 255.f
+            };
+            GR_GL(BlendColor(c[0], c[1], c[2], c[3]));
+            fHWDrawState.fBlendConstant = fCurrDrawState.fBlendConstant;
+        }
     }
 
     if (fHWDrawState.fDrawFace != fCurrDrawState.fDrawFace) {