SkScalerContext to use smart pointers.

CQ_INCLUDE_TRYBOTS=master.client.skia:Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-ASAN-Trybot;master.client.skia:Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-MSAN-Trybot

Change-Id: I27a714388b8ded7dfc968e322b0a587205f575f1
Reviewed-on: https://skia-review.googlesource.com/3731
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Ben Wagner <bungeman@google.com>
diff --git a/src/fonts/SkRandomScalerContext.cpp b/src/fonts/SkRandomScalerContext.cpp
index c9cb87c..96a2619 100644
--- a/src/fonts/SkRandomScalerContext.cpp
+++ b/src/fonts/SkRandomScalerContext.cpp
@@ -5,17 +5,19 @@
  * found in the LICENSE file.
  */
 
-#include "SkRandomScalerContext.h"
-#include "SkGlyph.h"
-#include "SkPath.h"
 #include "SkCanvas.h"
+#include "SkGlyph.h"
+#include "SkMakeUnique.h"
+#include "SkPath.h"
+#include "SkRandomScalerContext.h"
 #include "SkRasterizer.h"
 
+class SkDescriptor;
+
 class SkRandomScalerContext : public SkScalerContext {
 public:
-    SkRandomScalerContext(SkRandomTypeface*, const SkScalerContextEffects&,
+    SkRandomScalerContext(sk_sp<SkRandomTypeface>, const SkScalerContextEffects&,
                           const SkDescriptor*, bool fFakeIt);
-    virtual ~SkRandomScalerContext();
 
 protected:
     unsigned generateGlyphCount() override;
@@ -27,27 +29,22 @@
     void generateFontMetrics(SkPaint::FontMetrics*) override;
 
 private:
-    SkRandomTypeface*     fFace;
-    SkScalerContext* fProxy;
+    SkRandomTypeface* getRandomTypeface() const {
+        return static_cast<SkRandomTypeface*>(this->getTypeface());
+    }
+    std::unique_ptr<SkScalerContext> fProxy;
     bool fFakeIt;
 };
 
-#define STD_SIZE    1
-
-#include "SkDescriptor.h"
-
-SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face,
+SkRandomScalerContext::SkRandomScalerContext(sk_sp<SkRandomTypeface> face,
                                              const SkScalerContextEffects& effects,
                                              const SkDescriptor* desc,
                                              bool fakeIt)
-        : SkScalerContext(face, effects, desc)
-        , fFace(face)
+        : SkScalerContext(std::move(face), effects, desc)
         , fFakeIt(fakeIt) {
-    fProxy = face->proxy()->createScalerContext(effects, desc);
+    fProxy = this->getRandomTypeface()->proxy()->createScalerContext(effects, desc);
 }
 
-SkRandomScalerContext::~SkRandomScalerContext() { delete fProxy; }
-
 unsigned SkRandomScalerContext::generateGlyphCount() {
     return fProxy->getGlyphCount();
 }
@@ -90,7 +87,7 @@
         fProxy->getPath(*glyph, &path);
 
         SkRect storage;
-        const SkPaint& paint = fFace->paint();
+        const SkPaint& paint = this->getRandomTypeface()->paint();
         const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(),
                                                             &storage,
                                                             SkPaint::kFill_Style);
@@ -167,7 +164,7 @@
             SkCanvas canvas(bm);
             canvas.translate(-SkIntToScalar(glyph.fLeft),
                              -SkIntToScalar(glyph.fTop));
-            canvas.drawPath(path, fFace->paint());
+            canvas.drawPath(path, this->getRandomTypeface()->paint());
         } else {
             fProxy->forceGenerateImageFromPath();
             fProxy->getImage(glyph);
@@ -198,7 +195,8 @@
 
 SkScalerContext* SkRandomTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
                                                          const SkDescriptor* desc) const {
-    return new SkRandomScalerContext(const_cast<SkRandomTypeface*>(this), effects, desc, fFakeIt);
+    return new SkRandomScalerContext(sk_ref_sp(const_cast<SkRandomTypeface*>(this)),
+                                     effects, desc, fFakeIt);
 }
 
 void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const {