Make GPU coord transforms automatic

Adds a GrCoordTransform class and updates the framework to handle
coord transforms similar to how it handles textures with
GrTextureAccess. Renames GrGLEffectMatrix to GrGLCoordTransform and
slightly repurposes it to be used by the framework instead of effects.

R=bsalomon@google.com, robertphillips@google.com

Review URL: https://codereview.chromium.org/24853002

git-svn-id: http://skia.googlecode.com/svn/trunk@11569 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index be6fdb0..74355b8 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -825,8 +825,7 @@
 
 GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory)
     : INHERITED(factory)
-    , fCachedYCoord(SK_ScalarMax)
-    , fEffectMatrix(kCoordsType) {
+    , fCachedYCoord(SK_ScalarMax) {
 }
 
 GrGLGradientEffect::~GrGLGradientEffect() { }
@@ -883,7 +882,6 @@
 
     if (GrGradientEffect::kTwo_ColorType == e.getColorType()){
 
-        fEffectMatrix.setData(uman, e.getMatrix(), drawEffect, NULL);
         if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) {
             set_mul_color_uni(uman, fColorStartUni, e.getColors(0));
             set_mul_color_uni(uman, fColorEndUni,   e.getColors(1));
@@ -894,7 +892,6 @@
 
     } else if (GrGradientEffect::kThree_ColorType == e.getColorType()){
 
-        fEffectMatrix.setData(uman, e.getMatrix(), drawEffect, NULL);
         if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) {
             set_mul_color_uni(uman, fColorStartUni, e.getColors(0));
             set_mul_color_uni(uman, fColorMidUni,   e.getColors(1));
@@ -905,8 +902,6 @@
             set_color_uni(uman, fColorEndUni,   e.getColors(2));
         }
     } else {
-        const GrTexture* texture = e.texture(0);
-        fEffectMatrix.setData(uman, e.getMatrix(), drawEffect, texture);
 
         SkScalar yCoord = e.getYCoord();
         if (yCoord != fCachedYCoord) {
@@ -919,13 +914,8 @@
 
 GrGLEffect::EffectKey GrGLGradientEffect::GenBaseGradientKey(const GrDrawEffect& drawEffect) {
     const GrGradientEffect& e = drawEffect.castEffect<GrGradientEffect>();
-    const GrTexture* texture = NULL;
 
-    if (GrGradientEffect::kTexture_ColorType == e.getColorType()){
-        texture = e.texture(0);
-    }
-
-    EffectKey key = GrGLEffectMatrix::GenKey(e.getMatrix(), drawEffect, kCoordsType, texture);
+    EffectKey key = 0;
 
     if (GrGradientEffect::kTwo_ColorType == e.getColorType()) {
         key |= kTwoColorKey;
@@ -940,18 +930,6 @@
     return key;
 }
 
-void GrGLGradientEffect::setupMatrix(GrGLShaderBuilder* builder,
-                                     EffectKey key,
-                                     SkString* fsCoordName,
-                                     SkString* vsVaryingName,
-                                     GrSLType* vsVaryingType) {
-    fEffectMatrix.emitCodeMakeFSCoords2D(builder,
-                                         key & kMatrixKeyMask,
-                                         fsCoordName,
-                                         vsVaryingName,
-                                         vsVaryingType);
-}
-
 void GrGLGradientEffect::emitColor(GrGLShaderBuilder* builder,
                                    const char* gradientTValue,
                                    EffectKey key,
@@ -1023,8 +1001,6 @@
                                    const SkMatrix& matrix,
                                    SkShader::TileMode tileMode) {
 
-
-    fMatrix = matrix;
     fIsOpaque = shader.isOpaque();
 
     SkShader::GradientInfo info;
@@ -1055,6 +1031,7 @@
         } else {
             fPremulType = kAfterInterp_PremulType;
         }
+        fCoordTransform.reset(kCoordSet, matrix);
     } else {
         // doesn't matter how this is set, just be consistent because it is part of the effect key.
         fPremulType = kBeforeInterp_PremulType;
@@ -1080,9 +1057,11 @@
         if (-1 != fRow) {
             fYCoord = fAtlas->getYOffset(fRow) + SK_ScalarHalf *
             fAtlas->getVerticalScaleFactor();
+            fCoordTransform.reset(kCoordSet, matrix, fAtlas->getTexture());
             fTextureAccess.reset(fAtlas->getTexture(), params);
         } else {
             GrTexture* texture = GrLockAndRefCachedBitmapTexture(ctx, bitmap, &params);
+            fCoordTransform.reset(kCoordSet, matrix, texture);
             fTextureAccess.reset(texture, params);
             fYCoord = SK_ScalarHalf;
 
@@ -1093,6 +1072,7 @@
         }
         this->addTextureAccess(&fTextureAccess);
     }
+    this->addCoordTransform(&fCoordTransform);
 }
 
 GrGradientEffect::~GrGradientEffect() {
@@ -1124,7 +1104,7 @@
                 s.fTextureAccess.getParams().getTileModeX() &&
             this->useAtlas() == s.useAtlas() &&
             fYCoord == s.getYCoord() &&
-            fMatrix.cheapEqualTo(s.getMatrix());
+            fCoordTransform.getMatrix().cheapEqualTo(s.fCoordTransform.getMatrix());
     }
 
     return false;