Removed SoftwarePathRenderer from GrContext's path renderer chain

http://codereview.appspot.com/6221065/



git-svn-id: http://skia.googlecode.com/svn/trunk@4036 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index e05c48a..c9c15df 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -32,6 +32,7 @@
 class GrStencilBuffer;
 class GrVertexBuffer;
 class GrVertexBufferAllocPool;
+class GrSoftwarePathRenderer;
 
 class GR_API GrContext : public GrRefCnt {
 public:
@@ -695,7 +696,8 @@
     GrPathRenderer* getPathRenderer(const SkPath& path,
                                     GrPathFill fill,
                                     const GrDrawTarget* target,
-                                    bool antiAlias);
+                                    bool antiAlias,
+                                    bool allowSW);
 
 private:
     // used to keep track of when we need to flush the draw buffer
@@ -712,6 +714,7 @@
     GrFontCache*        fFontCache;
 
     GrPathRendererChain*        fPathRendererChain;
+    GrSoftwarePathRenderer*     fSoftwarePathRenderer;
 
     GrVertexBufferAllocPool*    fDrawBufferVBAllocPool;
     GrIndexBufferAllocPool*     fDrawBufferIBAllocPool;
diff --git a/src/gpu/GrAddPathRenderers_default.cpp b/src/gpu/GrAddPathRenderers_default.cpp
index 47c08b9..2c175e2 100644
--- a/src/gpu/GrAddPathRenderers_default.cpp
+++ b/src/gpu/GrAddPathRenderers_default.cpp
@@ -20,6 +20,5 @@
             chain->addPathRenderer(pr)->unref();
         }
         chain->addPathRenderer(new GrAAConvexPathRenderer())->unref();
-        chain->addPathRenderer(new GrSoftwarePathRenderer(ctx))->unref();
     }
 }
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index d930c06..c1a5bd1 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -393,9 +393,6 @@
     }
 }
 
-}
-
-namespace {
 ////////////////////////////////////////////////////////////////////////////////
 bool draw_path(GrContext* context,
                GrGpu* gpu,
@@ -403,7 +400,7 @@
                GrPathFill fill,
                bool doAA) {
 
-    GrPathRenderer* pr = context->getPathRenderer(path, fill, gpu, doAA);
+    GrPathRenderer* pr = context->getPathRenderer(path, fill, gpu, doAA, true);
     if (NULL == pr) {
         return false;
     }
@@ -411,7 +408,8 @@
     pr->drawPath(path, fill, NULL, gpu, 0, doAA);
     return true;
 }
-};
+
+}
 
 ////////////////////////////////////////////////////////////////////////////////
 bool GrClipMaskManager::drawClipShape(GrGpu* gpu,
@@ -796,7 +794,8 @@
                 fill = GrNonInvertedFill(fill);
                 clipPath = &clipCopy.getPath(c);
                 pr = this->getContext()->getPathRenderer(*clipPath,
-                                                         fill, gpu, false);
+                                                         fill, gpu, false,
+                                                         true);
                 if (NULL == pr) {
                     fClipMaskInStencil = false;
                     gpu->setClip(clipCopy);     // restore to the original
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index b45970b..80dd25e 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -18,6 +18,7 @@
 #include "GrPathRenderer.h"
 #include "GrPathUtils.h"
 #include "GrResourceCache.h"
+#include "GrSoftwarePathRenderer.h"
 #include "GrStencilBuffer.h"
 #include "GrTextStrike.h"
 #include "SkTLazy.h"
@@ -82,6 +83,7 @@
     GrSafeUnref(fAAStrokeRectIndexBuffer);
     fGpu->unref();
     GrSafeUnref(fPathRendererChain);
+    GrSafeUnref(fSoftwarePathRenderer);
     fDrawState->unref();
 }
 
@@ -98,6 +100,7 @@
     // a path renderer may be holding onto resources that
     // are now unusable
     GrSafeSetNull(fPathRendererChain);
+    GrSafeSetNull(fSoftwarePathRenderer);
 
     delete fDrawBuffer;
     fDrawBuffer = NULL;
@@ -129,6 +132,7 @@
     fFontCache->freeAll();
     // a path renderer may be holding onto resources
     GrSafeSetNull(fPathRendererChain);
+    GrSafeSetNull(fSoftwarePathRenderer);
 }
 
 size_t GrContext::getGpuTextureCacheBytes() const {
@@ -1454,7 +1458,7 @@
         prAA = false;
     }
 
-    GrPathRenderer* pr = this->getPathRenderer(path, fill, target, prAA);
+    GrPathRenderer* pr = this->getPathRenderer(path, fill, target, prAA, true);
     if (NULL == pr) {
 #if GR_DEBUG
         GrPrintf("Unable to find path renderer compatible with path.\n");
@@ -1916,15 +1920,35 @@
     return target;
 }
 
+/*
+ * This method finds a path renderer that can draw the specified path on
+ * the provided target.
+ * Due to its expense, the software path renderer has split out so it can 
+ * can be individually allowed/disallowed via the "allowSW" boolean.
+ */
 GrPathRenderer* GrContext::getPathRenderer(const SkPath& path,
                                            GrPathFill fill,
                                            const GrDrawTarget* target,
-                                           bool antiAlias) {
+                                           bool antiAlias,
+                                           bool allowSW) {
     if (NULL == fPathRendererChain) {
         fPathRendererChain = 
             new GrPathRendererChain(this, GrPathRendererChain::kNone_UsageFlag);
     }
-    return fPathRendererChain->getPathRenderer(path, fill, target, antiAlias);
+
+    GrPathRenderer* pr = fPathRendererChain->getPathRenderer(path, fill,
+                                                             target,
+                                                             antiAlias);
+
+    if (NULL == pr && allowSW) {
+        if (NULL == fSoftwarePathRenderer) {
+            fSoftwarePathRenderer = new GrSoftwarePathRenderer(this);
+        }
+
+        pr = fSoftwarePathRenderer;
+    }
+
+    return pr;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -1992,6 +2016,7 @@
     fGpu->setDrawState(fDrawState);
 
     fPathRendererChain = NULL;
+    fSoftwarePathRenderer = NULL;
 
     fTextureCache = new GrResourceCache(MAX_TEXTURE_CACHE_COUNT,
                                         MAX_TEXTURE_CACHE_BYTES);