Use texture cache for writePixels temp

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



git-svn-id: http://skia.googlecode.com/svn/trunk@1887 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/src/GrContext.cpp b/gpu/src/GrContext.cpp
index dc4bac8..dcaba1d 100644
--- a/gpu/src/GrContext.cpp
+++ b/gpu/src/GrContext.cpp
@@ -1464,17 +1464,19 @@
     // TODO: when underlying api has a direct way to do this we should use it
     // (e.g. glDrawPixels on desktop GL).
 
+    this->flush(true);
+
     const GrTextureDesc desc = {
         kNone_GrTextureFlags, kNone_GrAALevel, width, height, config
     };
-    GrTexture* texture = fGpu->createTexture(desc, buffer, stride);
+    GrAutoUnlockTextureEntry aute(this,
+                                    this->findApproximateKeylessTexture(desc));
+    GrTexture* texture = aute.texture();
     if (NULL == texture) {
         return;
     }
+    texture->uploadTextureData(0, 0, width, height, buffer, stride);
 
-    this->flush(true);
-
-    GrAutoUnref                     aur(texture);
     GrDrawTarget::AutoStateRestore  asr(fGpu);
 
     GrMatrix matrix;
@@ -1490,7 +1492,7 @@
 
     GrSamplerState sampler;
     sampler.setClampNoFilter();
-    matrix.setScale(GR_Scalar1 / width, GR_Scalar1 / height);
+    matrix.setIDiv(texture->width(), texture->height());
     sampler.setMatrix(matrix);
     fGpu->setSamplerState(0, sampler);
 
diff --git a/include/core/SkMatrix.h b/include/core/SkMatrix.h
index a8c50fc..b5864eb 100644
--- a/include/core/SkMatrix.h
+++ b/include/core/SkMatrix.h
@@ -176,6 +176,10 @@
     /** Set the matrix to scale by sx and sy.
     */
     void setScale(SkScalar sx, SkScalar sy);
+    /** Set the matrix to scale by 1/divx and 1/divy. Returns false and doesn't
+        touch the matrix if either divx or divy is zero.
+    */
+    bool setIDiv(int divx, int divy);
     /** Set the matrix to rotate by the specified number of degrees, with a
         pivot point at (px, py). The pivot point is the coordinate that should
         remain unchanged by the specified transformation.
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 8a08bca..cf4fe8f 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -220,6 +220,14 @@
     this->setTypeMask(kScale_Mask | kRectStaysRect_Mask);
 }
 
+bool SkMatrix::setIDiv(int divx, int divy) {
+    if (!divx || !divy) {
+        return false;
+    }
+    this->setScale(SK_Scalar1 / divx, SK_Scalar1 / divy);
+    return true;
+}
+
 bool SkMatrix::preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) {
     SkMatrix    m;
     m.setScale(sx, sy, px, py);