Make GrGLTextureDomainEffect use GrGLEffectMatrix.

Also, don't send redundant domain.
Review URL: https://codereview.appspot.com/6820082

git-svn-id: http://skia.googlecode.com/svn/trunk@6276 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkFloatingPoint.h b/include/core/SkFloatingPoint.h
index b3e490d..d388cdb 100644
--- a/include/core/SkFloatingPoint.h
+++ b/include/core/SkFloatingPoint.h
@@ -87,4 +87,10 @@
     #define sk_float_ceil2int(x)    (int)sk_float_ceil(x)
 #endif
 
+extern const uint32_t gIEEENotANumber;
+extern const uint32_t gIEEEInfinity;
+
+#define SK_FloatNaN                 (*reinterpret_cast<const float*>(&gIEEENotANumber))
+#define SK_FloatInfinity            (*reinterpret_cast<const float*>(&gIEEEInfinity))
+
 #endif
diff --git a/include/core/SkScalar.h b/include/core/SkScalar.h
index 82ac6e3..ea97a79 100644
--- a/include/core/SkScalar.h
+++ b/include/core/SkScalar.h
@@ -29,8 +29,6 @@
         as a 16.16 fixed point integer.
     */
     typedef float   SkScalar;
-    extern const uint32_t gIEEENotANumber;
-    extern const uint32_t gIEEEInfinity;
 
     /** SK_Scalar1 is defined to be 1.0 represented as an SkScalar
     */
@@ -40,7 +38,7 @@
     #define SK_ScalarHalf           (0.5f)
     /** SK_ScalarInfinity is defined to be infinity as an SkScalar
     */
-    #define SK_ScalarInfinity           (*SkTCast<const float*>(&gIEEEInfinity))
+    #define SK_ScalarInfinity       SK_FloatInfinity
     /** SK_ScalarMax is defined to be the largest value representable as an SkScalar
     */
     #define SK_ScalarMax            (3.402823466e+38f)
@@ -49,7 +47,7 @@
     #define SK_ScalarMin            (-SK_ScalarMax)
     /** SK_ScalarNaN is defined to be 'Not a Number' as an SkScalar
     */
-    #define SK_ScalarNaN      (*SkTCast<const float*>(&gIEEENotANumber))
+    #define SK_ScalarNaN            SK_FloatNaN
     /** SkScalarIsNaN(n) returns true if argument is not a number
     */
     static inline bool SkScalarIsNaN(float x) { return x != x; }
diff --git a/src/gpu/effects/GrTextureDomainEffect.cpp b/src/gpu/effects/GrTextureDomainEffect.cpp
index 14ada8e..9909c3a 100644
--- a/src/gpu/effects/GrTextureDomainEffect.cpp
+++ b/src/gpu/effects/GrTextureDomainEffect.cpp
@@ -8,6 +8,8 @@
 #include "GrTextureDomainEffect.h"
 #include "GrTBackendEffectFactory.h"
 #include "gl/GrGLEffect.h"
+#include "gl/GrGLEffectMatrix.h"
+#include "SkFloatingPoint.h"
 
 class GrGLTextureDomainEffect : public GrGLEffect {
 public:
@@ -23,10 +25,12 @@
 
     virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
 
-    static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&) { return 0; }
+    static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
 
 private:
     GrGLUniformManager::UniformHandle fNameUni;
+    GrGLEffectMatrix                  fEffectMatrix;
+    GrGLfloat                         fPrevDomain[4];
 
     typedef GrGLEffect INHERITED;
 };
@@ -35,21 +39,24 @@
                                                  const GrEffect&)
     : INHERITED(factory)
     , fNameUni(GrGLUniformManager::kInvalidUniformHandle) {
+    fRequiresTextureMatrix = false;
+    fPrevDomain[0] = SK_FloatNaN;
 }
 
 void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
                                        const GrEffectStage&,
-                                       EffectKey,
+                                       EffectKey key,
                                        const char* vertexCoords,
                                        const char* outputColor,
                                        const char* inputColor,
                                        const TextureSamplerArray& samplers) {
-
+    const char* coords;
+    fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
     fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
                                    kVec4f_GrSLType, "TexDom");
 
     builder->fFSCode.appendf("\tvec2 clampCoord = clamp(%s, %s.xy, %s.zw);\n",
-                           builder->defaultTexCoordsName(),
+                           coords,
                            builder->getUniformCStr(fNameUni),
                            builder->getUniformCStr(fNameUni));
 
@@ -80,7 +87,19 @@
         // of elements so that values = (l, t, r, b).
         SkTSwap(values[1], values[3]);
     }
-    uman.set4fv(fNameUni, 0, 1, values);
+    if (0 != memcmp(values, fPrevDomain, 4 * sizeof(GrGLfloat))) {
+        uman.set4fv(fNameUni, 0, 1, values);
+    }
+    fEffectMatrix.setData(uman,
+                          effect.getMatrix(),
+                          stage.getCoordChangeMatrix(),
+                          effect.texture(0));
+}   
+
+GrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+    const GrTextureDomainEffect& effect =
+        static_cast<const GrTextureDomainEffect&>(*stage.getEffect());
+    return GrGLEffectMatrix::GenKey(effect.getMatrix(), effect.getMatrix(), effect.texture(0));
 }