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/GrGpuGLShaders.cpp b/gpu/src/GrGpuGLShaders.cpp
index fcfc120..125b820 100644
--- a/gpu/src/GrGpuGLShaders.cpp
+++ b/gpu/src/GrGpuGLShaders.cpp
@@ -309,8 +309,39 @@
     }
 }
 
+void GrGpuGLShaders::flushTextureDomain(int s) {
+    const GrGLint& uni = fProgramData->fUniLocations.fStages[s].fTexDomUni;
+    if (GrGLProgram::kUnusedUniform != uni) {
+        const GrRect &texDom = 
+            fCurrDrawState.fSamplerStates[s].getTextureDomain();
+
+        float values[4] = {
+            GrScalarToFloat(texDom.left()), 
+            GrScalarToFloat(texDom.top()), 
+            GrScalarToFloat(texDom.right()), 
+            GrScalarToFloat(texDom.bottom())            
+        };
+
+        GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s];
+        GrGLTexture::Orientation orientation = texture->orientation();
+
+        // vertical flip if necessary
+        if (GrGLTexture::kBottomUp_Orientation == orientation) {
+            values[1] = 1.0f - values[1];
+            values[3] = 1.0f - values[3];
+        }
+
+        values[0] *= SkScalarToFloat(texture->contentScaleX());
+        values[2] *= SkScalarToFloat(texture->contentScaleX());
+        values[1] *= SkScalarToFloat(texture->contentScaleY());
+        values[3] *= SkScalarToFloat(texture->contentScaleY());
+
+        GR_GL(Uniform4fv(uni, 1, values));
+    }
+}
+
 void GrGpuGLShaders::flushTextureMatrix(int s) {
-    const int& uni = fProgramData->fUniLocations.fStages[s].fTextureMatrixUni;
+    const GrGLint& uni = fProgramData->fUniLocations.fStages[s].fTextureMatrixUni;
     GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s];
     if (NULL != texture) {
         if (GrGLProgram::kUnusedUniform != uni &&
@@ -516,6 +547,8 @@
         this->flushRadial2(s);
 
         this->flushTexelSize(s);
+
+        this->flushTextureDomain(s);
     }
     this->flushEdgeAAData();
     resetDirtyFlags();
@@ -702,6 +735,16 @@
                     break;
             }
 
+            if (fCurrDrawState.fSamplerStates[s].hasTextureDomain()) {
+                GrAssert(GrSamplerState::kClamp_WrapMode == 
+                    fCurrDrawState.fSamplerStates[s].getWrapX() && 
+                    GrSamplerState::kClamp_WrapMode ==
+                    fCurrDrawState.fSamplerStates[s].getWrapY());
+                stage.fOptFlags |= 
+                    GrGLProgram::ProgramDesc::StageDesc::
+                    kCustomTextureDomain_OptFlagBit;
+            }
+
             if (GrPixelConfigIsAlphaOnly(texture->config())) {
                 stage.fModulation = GrGLProgram::ProgramDesc::StageDesc::kAlpha_Modulation;
             } else {
@@ -725,4 +768,3 @@
 }
 
 
-