Enable CCPR for volatile paths

Enables for volatile paths and when path mask caching is disabled.

Bug: skia:
Change-Id: I644b17f2a4f77a4ddf85265f520599499c0800cf
Reviewed-on: https://skia-review.googlesource.com/60481
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/bench/PathTextBench.cpp b/bench/PathTextBench.cpp
index 6ee8f88..6551fa5 100644
--- a/bench/PathTextBench.cpp
+++ b/bench/PathTextBench.cpp
@@ -27,11 +27,12 @@
  */
 class PathTextBench : public Benchmark {
 public:
+    PathTextBench(bool cached) : fCached(cached) {}
     bool isVisual() override { return true; }
 
 private:
     const char* onGetName() override {
-        return "path_text";
+        return fCached ? "path_text" : "path_text_uncached";
     }
     SkIPoint onGetSize() override { return SkIPoint::Make(kScreenWidth, kScreenHeight); }
 
@@ -42,6 +43,7 @@
         for (int i = 0; i < kNumGlyphs; ++i) {
             SkGlyphID id = cache->unicharToGlyph(kGlyphs[i]);
             cache->getScalerContext()->getPath(SkPackedGlyphID(id), &fGlyphs[i]);
+            fGlyphs[i].setIsVolatile(!fCached);
         }
 
         SkRandom rand;
@@ -76,6 +78,7 @@
         }
     }
 
+    const bool fCached;
     SkPath fGlyphs[kNumGlyphs];
     SkPaint fPaints[kNumDraws];
     SkMatrix fXforms[kNumDraws];
@@ -83,4 +86,5 @@
     typedef Benchmark INHERITED;
 };
 
-DEF_BENCH(return new PathTextBench;)
+DEF_BENCH(return new PathTextBench(false);)
+DEF_BENCH(return new PathTextBench(true);)
diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h
index bb3fe50..2b01411 100644
--- a/include/private/GrTypesPriv.h
+++ b/include/private/GrTypesPriv.h
@@ -757,9 +757,7 @@
     kTessellating      = 1 << 7,
 
     kAll               = (kTessellating | (kTessellating - 1)),
-
-    // Temporarily disabling CCPR by default until it has had a time to soak.
-    kDefault           = kAll & ~kCoverageCounting,
+    kDefault           = kAll
 };
 
 /**
diff --git a/src/gpu/GrPathRendererChain.cpp b/src/gpu/GrPathRendererChain.cpp
index b982a32..3bb744a 100644
--- a/src/gpu/GrPathRendererChain.cpp
+++ b/src/gpu/GrPathRendererChain.cpp
@@ -51,7 +51,9 @@
     fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>());
 
     if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) {
-        if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(*context->caps())) {
+        bool drawCachablePaths = !options.fAllowPathMaskCaching;
+        if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(*context->caps(),
+                                                                          drawCachablePaths)) {
             context->contextPriv().addOnFlushCallbackObject(ccpr.get());
             fChain.push_back(std::move(ccpr));
         }
diff --git a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
index 877c872..86a4365 100644
--- a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
+++ b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
@@ -37,13 +37,17 @@
 }
 
 sk_sp<GrCoverageCountingPathRenderer>
-GrCoverageCountingPathRenderer::CreateIfSupported(const GrCaps& caps) {
-    return sk_sp<GrCoverageCountingPathRenderer>(IsSupported(caps) ?
-                                                 new GrCoverageCountingPathRenderer : nullptr);
+GrCoverageCountingPathRenderer::CreateIfSupported(const GrCaps& caps, bool drawCachablePaths) {
+    auto ccpr = IsSupported(caps) ? new GrCoverageCountingPathRenderer(drawCachablePaths) : nullptr;
+    return sk_sp<GrCoverageCountingPathRenderer>(ccpr);
 }
 
 GrPathRenderer::CanDrawPath
 GrCoverageCountingPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
+    if (args.fShape->hasUnstyledKey() && !fDrawCachablePaths) {
+        return CanDrawPath::kNo;
+    }
+
     if (!args.fShape->style().isSimpleFill() ||
         args.fShape->inverseFilled() ||
         args.fViewMatrix->hasPerspective() ||
diff --git a/src/gpu/ccpr/GrCoverageCountingPathRenderer.h b/src/gpu/ccpr/GrCoverageCountingPathRenderer.h
index 6025581..035898d 100644
--- a/src/gpu/ccpr/GrCoverageCountingPathRenderer.h
+++ b/src/gpu/ccpr/GrCoverageCountingPathRenderer.h
@@ -32,7 +32,8 @@
 
 public:
     static bool IsSupported(const GrCaps&);
-    static sk_sp<GrCoverageCountingPathRenderer> CreateIfSupported(const GrCaps&);
+    static sk_sp<GrCoverageCountingPathRenderer> CreateIfSupported(const GrCaps&,
+                                                                   bool drawCachablePaths);
 
     // GrPathRenderer overrides.
     StencilSupport onGetStencilSupport(const GrShape&) const override {
@@ -121,7 +122,8 @@
     };
 
 private:
-    GrCoverageCountingPathRenderer() = default;
+    GrCoverageCountingPathRenderer(bool drawCachablePaths)
+            : fDrawCachablePaths(drawCachablePaths) {}
 
     void setupPerFlushResources(GrOnFlushResourceProvider*, const uint32_t* opListIDs,
                                 int numOpListIDs, SkTArray<sk_sp<GrRenderTargetContext>>* results);
@@ -143,6 +145,8 @@
     GrSTAllocator<4, GrCCPRAtlas>      fPerFlushAtlases;
     bool                               fPerFlushResourcesAreValid;
     SkDEBUGCODE(bool                   fFlushing = false;)
+
+    const bool                         fDrawCachablePaths;
 };
 
 #endif
diff --git a/tests/GrCCPRTest.cpp b/tests/GrCCPRTest.cpp
index d8be726..d685b10 100644
--- a/tests/GrCCPRTest.cpp
+++ b/tests/GrCCPRTest.cpp
@@ -29,7 +29,7 @@
 public:
     CCPRPathDrawer(GrContext* ctx)
             : fCtx(ctx)
-            , fCCPR(GrCoverageCountingPathRenderer::CreateIfSupported(*fCtx->caps()))
+            , fCCPR(GrCoverageCountingPathRenderer::CreateIfSupported(*fCtx->caps(), true))
             , fRTC(fCtx->makeDeferredRenderTargetContext(SkBackingFit::kExact, kCanvasSize,
                                                          kCanvasSize, kRGBA_8888_GrPixelConfig,
                                                          nullptr)) {