impl SkFont::getPath

Replacement for SkPaint::getTextPath and getPosTextPath
- only works with glyphIDs
- doesn't try to do positioning
- doesn't force caller to consolidate all the glyphs into one giant path

Much of the time is spent transforming the path from the cache's size to the callers.
Might consider passing the raw path + matrix rather than scaling it for them???

Bug: skia:
Change-Id: Ie13015c61ebe410eaec084282d600338cfccb51a
Reviewed-on: https://skia-review.googlesource.com/c/170881
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/bench/FontCacheBench.cpp b/bench/FontCacheBench.cpp
index de629f6..98caa2b 100644
--- a/bench/FontCacheBench.cpp
+++ b/bench/FontCacheBench.cpp
@@ -8,7 +8,9 @@
 #include "Benchmark.h"
 #include "SkCanvas.h"
 #include "SkChecksum.h"
+#include "SkFont.h"
 #include "SkPaint.h"
+#include "SkPath.h"
 #include "SkString.h"
 #include "SkTemplates.h"
 
@@ -139,10 +141,60 @@
 private:
     typedef Benchmark INHERITED;
 };
-
-///////////////////////////////////////////////////////////////////////////////
-
 DEF_BENCH( return new FontCacheBench(); )
 
 // undefine this to run the efficiency test
 //DEF_BENCH( return new FontCacheEfficiency(); )
+
+///////////////////////////////////////////////////////////////////////////////
+
+class FontPathBench : public Benchmark {
+    SkFont fFont;
+    uint16_t fGlyphs[100];
+    SkString fName;
+    const bool fOneAtATime;
+
+public:
+    FontPathBench(bool oneAtATime) : fOneAtATime(oneAtATime) {
+        fName.printf("font-path-%s", oneAtATime ? "loop" : "batch");
+    }
+
+protected:
+    const char* onGetName() override {
+        return fName.c_str();
+    }
+
+    bool isSuitableFor(Backend backend) override {
+        return backend == kNonRendering_Backend;
+    }
+
+    void onDelayedSetup() override {
+        fFont.setSize(32);
+        for (size_t i = 0; i < SK_ARRAY_COUNT(fGlyphs); ++i) {
+            fGlyphs[i] = i;
+        }
+    }
+
+    void onDraw(int loops, SkCanvas* canvas) override {
+        SkPath path;
+        for (int i = 0; i < loops; ++i) {
+            if (fOneAtATime) {
+                for (size_t i = 0; i < SK_ARRAY_COUNT(fGlyphs); ++i) {
+                    fFont.getPath(fGlyphs[i], &path);
+                }
+            } else {
+                fFont.getPaths(fGlyphs, SK_ARRAY_COUNT(fGlyphs),
+                               [](uint16_t, const SkPath* src, void* ctx) {
+                                   if (src) {
+                                       *static_cast<SkPath*>(ctx) = *src;
+                                   }
+                               }, &path);
+            }
+        }
+    }
+
+private:
+    typedef Benchmark INHERITED;
+};
+DEF_BENCH( return new FontPathBench(true); )
+DEF_BENCH( return new FontPathBench(false); )