4x4 SSAA with improvements in determination of when to apply. Still disabled at compile time.

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




git-svn-id: http://skia.googlecode.com/svn/trunk@1218 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrContext_impl.h b/gpu/include/GrContext_impl.h
index b0faa2c..0fa3b8d 100644
--- a/gpu/include/GrContext_impl.h
+++ b/gpu/include/GrContext_impl.h
@@ -18,10 +18,11 @@
 #define GrContext_impl_DEFINED
 
 struct GrContext::OffscreenRecord {
-    OffscreenRecord() { fEntry = NULL; }
-    ~OffscreenRecord() { GrAssert(NULL == fEntry); }
+    OffscreenRecord() { fEntry0 = NULL; fEntry1 = NULL; }
+    ~OffscreenRecord() { GrAssert(NULL == fEntry0 && NULL == fEntry1); }
 
-    GrTextureEntry*                fEntry;
+    GrTextureEntry*                fEntry0;
+    GrTextureEntry*                fEntry1;
     GrDrawTarget::SavedDrawState   fSavedState;
 };
 
@@ -52,16 +53,6 @@
         layout |= GrDrawTarget::kColor_VertexLayoutBit;
     }
 
-    bool doOffscreenAA = false;
-    OffscreenRecord record;
-    if (paint.fAntiAlias &&
-        !this->getRenderTarget()->isMultisampled() &&
-        !(GrIsPrimTypeLines(primitiveType) && fGpu->supportsAALines()) &&
-        this->setupOffscreenAAPass1(target, false, &record)) {
-        doOffscreenAA = true;
-        layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(kOffscreenStage);
-    }
-
     int vertexCount = posSrc.count();
     int indexCount = (NULL != idxSrc) ? idxSrc->count() : 0;
 
@@ -94,51 +85,30 @@
         idxSrc->writeValue(i, indices + i);
     }
 
+    bool doAA = false;
+    OffscreenRecord record;
+    GrIRect bounds;
+
+    if (-1 == texOffsets[0] && -1 == colorOffset && 
+        this->doOffscreenAA(target, paint, GrIsPrimTypeLines(primitiveType))) {
+        GrRect b;
+        b.setBounds(geo.positions(), vertexCount);
+        target->getViewMatrix().mapRect(&b);
+        b.roundOut(&bounds);
+        if (this->setupOffscreenAAPass1(target, false, bounds, &record)) {
+            doAA = true;
+        }
+    }
+
     if (NULL == idxSrc) {
         target->drawNonIndexed(primitiveType, 0, vertexCount);
     } else {
         target->drawIndexed(primitiveType, 0, 0, vertexCount, indexCount);
     }
 
-    if (doOffscreenAA) {
-        // draw to the offscreen
-        if (NULL != indices) {
-            target->drawIndexed(primitiveType, 0, 0, vertexCount, indexCount);
-        } else {
-            target->drawNonIndexed(primitiveType, 0, vertexCount);
-        }
-        // When there are custom texture coordinates we can't just draw
-        // a quad to sample the offscreen. Instead we redraw the geometry to
-        // specify the texture coords. This isn't quite right either, primitives
-        // will only be eroded at the edges, not expanded into partial pixels.
-        bool useRect = 0 == (layout & GrDrawTarget::StageTexCoordVertexLayoutBit(0,0));
-        if (useRect) {
-            target->setViewMatrix(GrMatrix::I());
-        }
-        this->setupOffscreenAAPass2(target, paint, &record);
-        if (useRect) {
-            geo.set(NULL, 0, 0, 0);
-            int stages = (NULL != paint.getTexture()) ? 0x1 : 0x0;
-            stages |= (1 << kOffscreenStage);
-            GrRect dstRect(0, 0, 
-                        target->getRenderTarget()->width(),
-                        target->getRenderTarget()->height());
-                        target->drawSimpleRect(dstRect, NULL, stages);
-            target->drawSimpleRect(dstRect, NULL, stages);
-        } else {
-            if (NULL != indices) {
-                target->drawIndexed (primitiveType, 0, 0, vertexCount, indexCount);
-            } else {
-                target->drawNonIndexed(primitiveType, 0, vertexCount);
-            }
-        }
-        this->endOffscreenAA(target, &record);
-    } else {
-        if (NULL != indices) {
-            target->drawIndexed(primitiveType, 0, 0, vertexCount, indexCount);
-        } else {
-            target->drawNonIndexed(primitiveType, 0, vertexCount);
-        }
+    if (doAA) {
+        geo.set(NULL, 0, 0, 0); // have to release geom before can draw again
+        this->offscreenAAPass2(target, paint, bounds, &record);
     }
 }