Fix GrContext::drawPaint with perspective, also never apply AA

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


git-svn-id: http://skia.googlecode.com/svn/trunk@2247 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrContext.h b/gpu/include/GrContext.h
index 3fe1a7b..37ac1c4 100644
--- a/gpu/include/GrContext.h
+++ b/gpu/include/GrContext.h
@@ -645,6 +645,7 @@
  */
 class GrAutoMatrix : GrNoncopyable {
 public:
+    GrAutoMatrix() : fContext(NULL) {}
     GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
         fMatrix = ctx->getMatrix();
     }
@@ -652,8 +653,25 @@
         fMatrix = ctx->getMatrix();
         ctx->setMatrix(matrix);
     }
+    void set(GrContext* ctx) {
+        if (NULL != fContext) {
+            fContext->setMatrix(fMatrix);
+        }
+        fMatrix = ctx->getMatrix();
+        fContext = ctx;
+    }
+    void set(GrContext* ctx, const GrMatrix& matrix) {
+        if (NULL != fContext) {
+            fContext->setMatrix(fMatrix);
+        }
+        fMatrix = ctx->getMatrix();
+        ctx->setMatrix(matrix);
+        fContext = ctx;
+    }
     ~GrAutoMatrix() {
-        fContext->setMatrix(fMatrix);
+        if (NULL != fContext) {
+            fContext->setMatrix(fMatrix);
+        }
     }
 
 private:
diff --git a/gpu/src/GrContext.cpp b/gpu/src/GrContext.cpp
index b857dda..8eb8c63 100644
--- a/gpu/src/GrContext.cpp
+++ b/gpu/src/GrContext.cpp
@@ -590,13 +590,26 @@
     r.setLTRB(0, 0,
               GrIntToScalar(getRenderTarget()->width()),
               GrIntToScalar(getRenderTarget()->height()));
+    GrAutoMatrix am;
     GrMatrix inverse;
-    if (fGpu->getViewInverse(&inverse)) {
+    // We attempt to map r by the inverse matrix and draw that. mapRect will
+    // map the four corners and bound them with a new rect. This will not
+    // produce a correct result for some perspective matrices.
+    if (!this->getMatrix().hasPerspective() &&
+        fGpu->getViewInverse(&inverse)) {
         inverse.mapRect(&r);
     } else {
-        GrPrintf("---- fGpu->getViewInverse failed\n");
+        am.set(this, GrMatrix::I());
     }
-    this->drawRect(paint, r);
+    GrPaint tmpPaint;
+    const GrPaint* p = &paint;
+    // by definition this fills the entire clip, no need for AA
+    if (paint.fAntiAlias) {
+        tmpPaint = paint;
+        tmpPaint.fAntiAlias = false;
+        p = &tmpPaint;
+    }
+    this->drawRect(*p, r);
 }
 
 ////////////////////////////////////////////////////////////////////////////////