Updated useSWOnlyPath method to use path chain instead of raw path renderer methods

http://codereview.appspot.com/6211083/



git-svn-id: http://skia.googlecode.com/svn/trunk@4038 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp
index 3da4af2..ca7ecdc 100644
--- a/src/gpu/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/GrAAConvexPathRenderer.cpp
@@ -430,24 +430,17 @@
 
 }
 
-bool GrAAConvexPathRenderer::staticCanDrawPath(bool pathIsConvex,
-                                               GrPathFill fill,
-                                               const GrDrawTarget* target,
-                                               bool antiAlias) {
-    if (!target->getCaps().fShaderDerivativeSupport || !antiAlias ||
-        kHairLine_PathFill == fill || GrIsFillInverted(fill) ||
-        !pathIsConvex) {
-        return false;
-    }  else {
-        return true;
-    }
-}
-
 bool GrAAConvexPathRenderer::canDrawPath(const SkPath& path,
                                          GrPathFill fill,
                                          const GrDrawTarget* target,
                                          bool antiAlias) const {
-    return staticCanDrawPath(path.isConvex(), fill, target, antiAlias);
+    if (!target->getCaps().fShaderDerivativeSupport || !antiAlias ||
+        kHairLine_PathFill == fill || GrIsFillInverted(fill) ||
+        !path.isConvex()) {
+        return false;
+    }  else {
+        return true;
+    }
 }
 
 bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath,
diff --git a/src/gpu/GrAAConvexPathRenderer.h b/src/gpu/GrAAConvexPathRenderer.h
index 875560c..4c95e56 100644
--- a/src/gpu/GrAAConvexPathRenderer.h
+++ b/src/gpu/GrAAConvexPathRenderer.h
@@ -18,11 +18,6 @@
                              const GrDrawTarget* target,
                              bool antiAlias) const SK_OVERRIDE;
 
-    static bool staticCanDrawPath(bool pathIsConvex,
-                                  GrPathFill fill,
-                                  const GrDrawTarget* target,
-                                  bool antiAlias);
-
 protected:
     virtual bool onDrawPath(const SkPath& path,
                             GrPathFill fill,
diff --git a/src/gpu/GrAAHairLinePathRenderer.cpp b/src/gpu/GrAAHairLinePathRenderer.cpp
index 94d94a3..701bf3a 100644
--- a/src/gpu/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/GrAAHairLinePathRenderer.cpp
@@ -574,10 +574,10 @@
     return true;
 }
 
-bool GrAAHairLinePathRenderer::staticCanDrawPath(const SkPath& path,
-                                                 GrPathFill fill,
-                                                 const GrDrawTarget* target,
-                                                 bool antiAlias) {
+bool GrAAHairLinePathRenderer::canDrawPath(const SkPath& path,
+                                           GrPathFill fill,
+                                           const GrDrawTarget* target,
+                                           bool antiAlias) const {
     if (fill != kHairLine_PathFill || !antiAlias) {
         return false;
     }
@@ -591,13 +591,6 @@
     return true;
 }
 
-bool GrAAHairLinePathRenderer::canDrawPath(const SkPath& path,
-                                           GrPathFill fill,
-                                           const GrDrawTarget* target,
-                                           bool antiAlias) const {
-    return staticCanDrawPath(path, fill, target, antiAlias);
-}
-
 bool GrAAHairLinePathRenderer::onDrawPath(const SkPath& path,
                                           GrPathFill fill,
                                           const GrVec* translate,
diff --git a/src/gpu/GrAAHairLinePathRenderer.h b/src/gpu/GrAAHairLinePathRenderer.h
index e45fa35..ac43409 100644
--- a/src/gpu/GrAAHairLinePathRenderer.h
+++ b/src/gpu/GrAAHairLinePathRenderer.h
@@ -22,11 +22,6 @@
                             const GrDrawTarget* target,
                             bool antiAlias) const SK_OVERRIDE;
 
-    static bool staticCanDrawPath(const SkPath& path,
-                                  GrPathFill fill,
-                                  const GrDrawTarget* target,
-                                  bool antiAlias);
-
 protected:
     virtual bool onDrawPath(const SkPath& path,
                             GrPathFill fill,
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index c1a5bd1..6e84724 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -60,6 +60,15 @@
                 GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(maskStage));
 }
 
+bool path_needs_SW_renderer(GrContext* context,
+                           GrGpu* gpu,
+                           const SkPath& path,
+                           GrPathFill fill,
+                           bool doAA) {
+    // last (false) parameter disallows use of the SW path renderer
+    return NULL == context->getPathRenderer(path, fill, gpu, doAA, false);
+}
+
 }
 
 /*
@@ -74,7 +83,7 @@
         return false;
     }
 
-    // TODO: generalize this test so that when
+    // TODO: generalize this function so that when
     // a clip gets complex enough it can just be done in SW regardless
     // of whether it would invoke the GrSoftwarePathRenderer.
     bool useSW = false;
@@ -87,50 +96,32 @@
             useSW = false;
         }
 
-        if (!clipIn.getDoAA(i)) {
-            // non-anti-aliased rects and paths can always be drawn either
-            // directly or by the GrDefaultPathRenderer
-            continue;
-        }
-
         if (kRect_ClipType == clipIn.getElementType(i)) {
-            // Antialiased rects are converted to paths and then drawn with
-            // kEvenOdd_PathFill. 
-            if (!GrAAConvexPathRenderer::staticCanDrawPath(
-                                                    true,     // always convex
-                                                    kEvenOdd_PathFill,
-                                                    gpu, 
-                                                    true)) {  // anti-aliased
-                // if the GrAAConvexPathRenderer can't render this rect (due
-                // to lack of derivative support in the shaders) then 
-                // the GrSoftwarePathRenderer will be used
+            // Non-anti-aliased rects can always be drawn directly (w/o 
+            // using the software path) so the anti-aliased rects are all 
+            // that need to be checked here
+            if (clipIn.getDoAA(i)) {
+                // Antialiased rects are converted to paths and then drawn with
+                // kEvenOdd_PathFill. 
+
+                // TODO: wrap GrContext::fillAARect in a helper class and
+                // draw AA rects directly rather than converting to paths
+                SkPath temp;
+                temp.addRect(clipIn.getRect(i));	
+
+                if (path_needs_SW_renderer(this->getContext(), gpu, temp,
+                                           kEvenOdd_PathFill, true)) {
+                    useSW = true;
+                }
+            }
+        } else {
+            if (path_needs_SW_renderer(this->getContext(), gpu, 
+                                       clipIn.getPath(i), 
+                                       clipIn.getPathFill(i), 
+                                       clipIn.getDoAA(i))) {
                 useSW = true;
             }
-
-            continue;
         }
-
-        // only paths need to be considered in the rest of the loop body
-
-        if (GrAAHairLinePathRenderer::staticCanDrawPath(clipIn.getPath(i),
-                                                        clipIn.getPathFill(i),
-                                                        gpu,
-                                                        clipIn.getDoAA(i))) {
-            // the hair line path renderer can handle this one
-            continue;
-        }
-
-        if (GrAAConvexPathRenderer::staticCanDrawPath(
-                                                clipIn.getPath(i).isConvex(),
-                                                clipIn.getPathFill(i),
-                                                gpu,
-                                                clipIn.getDoAA(i))) {
-            // the convex path renderer can handle this one
-            continue;
-        }
-
-        // otherwise the GrSoftwarePathRenderer is going to be invoked
-        useSW = true;
     }
 
     return useSW;