Reland "[graphite] Enable SmallPathAtlas."

This is a reland of commit 87c2058eba6c4deadf076781e5e6565c6b4e4884

Original change's description:
> [graphite] Enable SmallPathAtlas.
>
> Uses the transformed and conservatively clipped path bounds to
> determine whether a path is small enough to be stored in this atlas
> rather than the RasterPathAtlas.
>
> Also fixes some minor bugs in initialization and sets up atlas
> compaction.
>
> Bug: b/294378744
> Change-Id: I6d9b71b5737bc39809e51a22aa037be51775f144
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/816558
> Reviewed-by: Arman Uguray <armansito@google.com>
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Jim Van Verth <jvanverth@google.com>

Bug: b/294378744
Change-Id: Id0c40ee1e1f4c1e0f12319d99bfa7a493c1bb25a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/819677
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/graphite/AtlasProvider.cpp b/src/gpu/graphite/AtlasProvider.cpp
index 732e6b4..a3ad44e 100644
--- a/src/gpu/graphite/AtlasProvider.cpp
+++ b/src/gpu/graphite/AtlasProvider.cpp
@@ -111,6 +111,9 @@
 
 void AtlasProvider::postFlush() {
     fTextAtlasManager->postFlush();
+    if (fSmallPathAtlas) {
+        fSmallPathAtlas->postFlush();
+    }
 }
 
 }  // namespace skgpu::graphite
diff --git a/src/gpu/graphite/Device.cpp b/src/gpu/graphite/Device.cpp
index 8d2c8dc..fb2c5a3 100644
--- a/src/gpu/graphite/Device.cpp
+++ b/src/gpu/graphite/Device.cpp
@@ -31,6 +31,7 @@
 #include "src/gpu/graphite/Renderer.h"
 #include "src/gpu/graphite/RendererProvider.h"
 #include "src/gpu/graphite/SharedContext.h"
+#include "src/gpu/graphite/SmallPathAtlas.h"
 #include "src/gpu/graphite/SpecialImage_Graphite.h"
 #include "src/gpu/graphite/Surface_Graphite.h"
 #include "src/gpu/graphite/TextureProxy.h"
@@ -1429,7 +1430,19 @@
     } else if (atlasProvider->isAvailable(AtlasProvider::PathAtlasFlags::kRaster) &&
                (strategy == PathRendererStrategy::kRasterAA ||
                 (strategy == PathRendererStrategy::kDefault && !msaaSupported))) {
-        pathAtlas = atlasProvider->getRasterPathAtlas();
+        if (shape.hasKey()) {
+            static constexpr float kSmallPathSizeThreshold = 73;
+            Rect drawBounds = localToDevice.mapRect(shape.bounds());
+            drawBounds.intersect(fClip.conservativeBounds());
+            drawBounds = drawBounds.makeRoundOut();
+            skvx::float2 size = drawBounds.size();
+            if (size.x() < kSmallPathSizeThreshold && size.y() < kSmallPathSizeThreshold) {
+                pathAtlas = atlasProvider->getSmallPathAtlas();
+            }
+        }
+        if (!pathAtlas) {
+            pathAtlas = atlasProvider->getRasterPathAtlas();
+        }
     }
 
     // Use an atlas only if an MSAA technique isn't required.
@@ -1440,8 +1453,7 @@
         //
         // If the hardware doesn't support MSAA and anti-aliasing is required, then we always render
         // paths with atlasing.
-        if (!msaaSupported || strategy == PathRendererStrategy::kComputeAnalyticAA ||
-            strategy == PathRendererStrategy::kRasterAA) {
+        if (!msaaSupported || strategy != PathRendererStrategy::kDefault) {
             return {nullptr, pathAtlas};
         }
 
diff --git a/src/gpu/graphite/SmallPathAtlas.cpp b/src/gpu/graphite/SmallPathAtlas.cpp
index 406b7cd..ed6dd0f 100644
--- a/src/gpu/graphite/SmallPathAtlas.cpp
+++ b/src/gpu/graphite/SmallPathAtlas.cpp
@@ -17,6 +17,7 @@
 
 SmallPathAtlas::SmallPathAtlas(Recorder* recorder)
         : PathAtlas(recorder, kDefaultAtlasDim, kDefaultAtlasDim) {
+    SkASSERT(fRecorder);
     static constexpr size_t kPlotWidth = 512;
     static constexpr size_t kPlotHeight = 256;
     static constexpr SkColorType colorType = kAlpha_8_SkColorType;
@@ -29,13 +30,21 @@
                                  DrawAtlas::AllowMultitexturing::kYes,
                                  this,
                                  /*label=*/"SmallPathAtlas");
+    SkASSERT(fDrawAtlas);
     fKeyLists.resize(fDrawAtlas->numPlots() * fDrawAtlas->maxPages());
+    for (int i = 0; i < fKeyLists.size(); ++i) {
+        fKeyLists[i].reset();
+    }
 }
 
 bool SmallPathAtlas::recordUploads(DrawContext* dc) {
     return fDrawAtlas->recordUploads(dc, fRecorder);
 }
 
+void SmallPathAtlas::postFlush() {
+    fDrawAtlas->compact(fRecorder->priv().tokenTracker()->nextFlushToken());
+}
+
 namespace {
 uint32_t shape_key_list_index(const PlotLocator& locator, const DrawAtlas* drawAtlas) {
     return locator.pageIndex() * drawAtlas->numPlots() + locator.plotIndex();
diff --git a/src/gpu/graphite/SmallPathAtlas.h b/src/gpu/graphite/SmallPathAtlas.h
index 1b6788c..b59119d 100644
--- a/src/gpu/graphite/SmallPathAtlas.h
+++ b/src/gpu/graphite/SmallPathAtlas.h
@@ -36,6 +36,8 @@
 
     bool recordUploads(DrawContext*);
 
+    void postFlush();
+
 protected:
     const TextureProxy* onAddShape(const Shape&,
                                    const Transform& transform,