ccpr: Initialize the atlas size more intelligently

Rather than always starting the atlas at 1024 x 1024, begin with the
first pow2 dimensions whose area is theoretically large enough to
contain the pending paths.

Bug: skia:
Change-Id: I263e77ff6a697e865f6b3b62b9df7002225f9544
Reviewed-on: https://skia-review.googlesource.com/133660
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/ccpr/GrCCPerFlushResources.cpp b/src/gpu/ccpr/GrCCPerFlushResources.cpp
index 3f02ac7..a80d789 100644
--- a/src/gpu/ccpr/GrCCPerFlushResources.cpp
+++ b/src/gpu/ccpr/GrCCPerFlushResources.cpp
@@ -14,13 +14,14 @@
 using PathInstance = GrCCPathProcessor::Instance;
 
 GrCCPerFlushResources::GrCCPerFlushResources(GrOnFlushResourceProvider* onFlushRP,
-                                             int numPathDraws, int numClipPaths,
-                                             const GrCCPathParser::PathStats& pathStats)
-        : fPathParser(sk_make_sp<GrCCPathParser>(numPathDraws + numClipPaths, pathStats))
+                                             const GrCCPerFlushResourceSpecs& specs)
+        : fPathParser(sk_make_sp<GrCCPathParser>(specs.fNumRenderedPaths + specs.fNumClipPaths,
+                                                 specs.fParsingPathStats))
+        , fAtlasSpecs(specs.fAtlasSpecs)
         , fIndexBuffer(GrCCPathProcessor::FindIndexBuffer(onFlushRP))
         , fVertexBuffer(GrCCPathProcessor::FindVertexBuffer(onFlushRP))
         , fInstanceBuffer(onFlushRP->makeBuffer(kVertex_GrBufferType,
-                                                numPathDraws * sizeof(PathInstance))) {
+                                                specs.fNumRenderedPaths * sizeof(PathInstance))) {
     if (!fIndexBuffer) {
         SkDebugf("WARNING: failed to allocate CCPR index buffer. No paths will be drawn.\n");
         return;
@@ -35,34 +36,31 @@
     }
     fPathInstanceData = static_cast<PathInstance*>(fInstanceBuffer->map());
     SkASSERT(fPathInstanceData);
-    SkDEBUGCODE(fPathInstanceBufferCount = numPathDraws);
+    SkDEBUGCODE(fPathInstanceBufferCount = specs.fNumRenderedPaths);
 }
 
-GrCCAtlas* GrCCPerFlushResources::renderPathInAtlas(const GrCaps& caps, const SkIRect& clipIBounds,
-                                                    const SkMatrix& m, const SkPath& path,
-                                                    SkRect* devBounds, SkRect* devBounds45,
-                                                    int16_t* atlasOffsetX, int16_t* atlasOffsetY) {
+GrCCAtlas* GrCCPerFlushResources::renderPathInAtlas(const SkIRect& clipIBounds, const SkMatrix& m,
+                                                    const SkPath& path, SkRect* devBounds,
+                                                    SkRect* devBounds45, int16_t* atlasOffsetX,
+                                                    int16_t* atlasOffsetY) {
     SkASSERT(this->isMapped());
     SkIRect devIBounds;
     fPathParser->parsePath(m, path, devBounds, devBounds45);
     devBounds->roundOut(&devIBounds);
-    return this->placeParsedPathInAtlas(caps, clipIBounds, devIBounds, atlasOffsetX, atlasOffsetY);
+    return this->placeParsedPathInAtlas(clipIBounds, devIBounds, atlasOffsetX, atlasOffsetY);
 }
 
-GrCCAtlas* GrCCPerFlushResources::renderDeviceSpacePathInAtlas(const GrCaps& caps,
-                                                               const SkIRect& clipIBounds,
+GrCCAtlas* GrCCPerFlushResources::renderDeviceSpacePathInAtlas(const SkIRect& clipIBounds,
                                                                const SkPath& devPath,
                                                                const SkIRect& devPathIBounds,
                                                                int16_t* atlasOffsetX,
                                                                int16_t* atlasOffsetY) {
     SkASSERT(this->isMapped());
     fPathParser->parseDeviceSpacePath(devPath);
-    return this->placeParsedPathInAtlas(caps, clipIBounds, devPathIBounds, atlasOffsetX,
-                                        atlasOffsetY);
+    return this->placeParsedPathInAtlas(clipIBounds, devPathIBounds, atlasOffsetX, atlasOffsetY);
 }
 
-GrCCAtlas* GrCCPerFlushResources::placeParsedPathInAtlas(const GrCaps& caps,
-                                                         const SkIRect& clipIBounds,
+GrCCAtlas* GrCCPerFlushResources::placeParsedPathInAtlas(const SkIRect& clipIBounds,
                                                          const SkIRect& pathIBounds,
                                                          int16_t* atlasOffsetX,
                                                          int16_t* atlasOffsetY) {
@@ -87,7 +85,7 @@
             auto coverageCountBatchID = fPathParser->closeCurrentBatch();
             fAtlases.back().setCoverageCountBatchID(coverageCountBatchID);
         }
-        fAtlases.emplace_back(caps, SkTMax(w, h));
+        fAtlases.emplace_back(fAtlasSpecs);
         SkAssertResult(fAtlases.back().addRect(w, h, &atlasLocation));
     }