Smarter use of glyph cache

Change-Id: Ic9bea7310b375575503042881d9d54ff13996729
Reviewed-on: https://skia-review.googlesource.com/131924
Reviewed-by: Mike Klein <mtklein@chromium.org>
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index dcff1b0..4a6251f 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -590,6 +590,8 @@
 
         device->androidFramework_setDeviceClipRestriction(&fClipRestrictionRect);
     }
+
+    fScratchGlyphSet = skstd::make_unique<SkGlyphSet>();
 }
 
 SkCanvas::SkCanvas()
@@ -2448,7 +2450,7 @@
 
     while (iter.next()) {
         auto glyphRun = SkGlyphRun::MakeFromDrawText(
-                looper.paint(), text, byteLength, SkPoint::Make(x, y));
+                looper.paint(), text, byteLength, SkPoint::Make(x, y), fScratchGlyphSet.get());
         iter.fDevice->drawGlyphRun(looper.paint(), &glyphRun);
     }
 
@@ -2461,7 +2463,8 @@
     LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, nullptr)
 
     while (iter.next()) {
-        auto glyphRun = SkGlyphRun::MakeFromDrawPosText(looper.paint(), text, byteLength, pos);
+        auto glyphRun = SkGlyphRun::MakeFromDrawPosText(
+                looper.paint(), text, byteLength, pos, fScratchGlyphSet.get());
         iter.fDevice->drawGlyphRun(looper.paint(), &glyphRun);
     }
 
@@ -2475,7 +2478,8 @@
 
     while (iter.next()) {
         auto glyphRun =
-                SkGlyphRun::MakeFromDrawPosTextH(looper.paint(), text, byteLength, xpos, constY);
+                SkGlyphRun::MakeFromDrawPosTextH(
+                        looper.paint(), text, byteLength, xpos, constY, fScratchGlyphSet.get());
         iter.fDevice->drawGlyphRun(looper.paint(), &glyphRun);
     }