Fixed color bleeding issue when drawing a sub region of a bitmap with filtering enabled.
Problem was resolved by adding the notion of a custom texture domain in generated shaders, when necessary.




git-svn-id: http://skia.googlecode.com/svn/trunk@1337 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/src/GrGLProgram.cpp b/gpu/src/GrGLProgram.cpp
index 5d2d8b3..ab327d0 100644
--- a/gpu/src/GrGLProgram.cpp
+++ b/gpu/src/GrGLProgram.cpp
@@ -120,6 +120,11 @@
     s->appendS32(stage);
 }
 
+static void tex_domain_name(int stage, GrStringBuilder* s) {
+    *s = "uTexDom";
+    s->appendS32(stage);
+}
+
 GrGLProgram::GrGLProgram() {
     for(int stage = 0; stage < GrDrawTarget::kNumStages; ++stage) {
         fStageEffects[stage] = NULL;
@@ -650,6 +655,15 @@
                                              radial2ParamName.c_str()));
                 GrAssert(kUnusedUniform != locations.fRadial2Uni);
             }
+
+            if (kUseUniform == locations.fTexDomUni) {
+                GrStringBuilder texDomName;
+                tex_domain_name(s, &texDomName);
+                locations.fTexDomUni = GR_GL(GetUniformLocation(
+                                             progID,
+                                             texDomName.c_str()));
+                GrAssert(kUnusedUniform != locations.fTexDomUni);
+            }
         }
     }
     GR_GL(UseProgram(progID));
@@ -869,6 +883,24 @@
         modulate.printf(" * %s", fsInColor);
     }
 
+    if (desc.fOptFlags & 
+        ProgramDesc::StageDesc::kCustomTextureDomain_OptFlagBit) {
+        GrStringBuilder texDomainName;
+        tex_domain_name(stageNum, &texDomainName);
+        segments->fFSUnis.appendf("uniform %s %s;\n", 
+                                  float_vector_type(4),
+                                  texDomainName.c_str());
+        GrStringBuilder coordVar("clampCoord");
+        segments->fFSCode.appendf("\t%s %s = clamp(%s, %s.xy, %s.zw);\n",
+                                  float_vector_type(coordDims),
+                                  coordVar.c_str(),
+                                  sampleCoords.c_str(),
+                                  texDomainName.c_str(),
+                                  texDomainName.c_str());
+        sampleCoords = coordVar;
+        locations->fTexDomUni = kUseUniform;
+    }
+
     if (ProgramDesc::StageDesc::k2x2_FetchMode == desc.fFetchMode) {
         locations->fNormalizedTexelSizeUni = kUseUniform;
         if (complexCoord) {