Samples: clean up cruft

  - replace virtual with override.
  - remove default constructor.
  - use default field initializers
  - move work from constructor into onOnceBeforeDraw
  - mark everything private
  - enum { N = 100 }; constants to constexpr
  - remove unused variables

Change-Id: I8c7a19bc24fec416a6b88d634ee948d3e842b986
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228056
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/samplecode/SampleChineseFling.cpp b/samplecode/SampleChineseFling.cpp
index bb749e5..1cdf784 100644
--- a/samplecode/SampleChineseFling.cpp
+++ b/samplecode/SampleChineseFling.cpp
@@ -38,18 +38,18 @@
 }
 
 class ChineseFlingView : public Sample {
-public:
-    ChineseFlingView() : fBlobs(kNumBlobs) {}
+    static constexpr int kNumBlobs = 200;
+    static constexpr int kWordLength = 16;
 
-protected:
+    sk_sp<SkTypeface>    fTypeface;
+    SkFontMetrics        fMetrics;
+    sk_sp<SkTextBlob>    fBlobs[kNumBlobs];
+    SkRandom             fRand;
+    int                  fIndex = 0;
+
     SkString name() override { return SkString("chinese-fling"); }
 
     void onDrawContent(SkCanvas* canvas) override {
-        if (!fInitialized) {
-            this->init();
-            fInitialized = true;
-        }
-
         canvas->clear(0xFFDDDDDD);
 
         SkPaint paint;
@@ -64,18 +64,14 @@
 
             y += fMetrics.fDescent + fMetrics.fLeading;
             ++index;
-            index %= fBlobs.count();
+            index %= kNumBlobs;
         }
         // now "fling" a random amount
         fIndex += fRand.nextRangeU(5, 20);
-        fIndex %= fBlobs.count();
+        fIndex %= kNumBlobs;
     }
 
-private:
-    static constexpr auto kNumBlobs = 200;
-    static constexpr auto kWordLength = 16;
-
-    void init() {
+    void onOnceBeforeDraw() override {
         fTypeface = chinese_typeface();
 
         SkFont font(fTypeface, 56);
@@ -94,10 +90,8 @@
                                               0,
                                               0);
 
-            fBlobs.emplace_back(builder.make());
+            fBlobs[i] = builder.make();
         }
-
-        fIndex = 0;
     }
 
     // Construct a random kWordLength character 'word' drawing from the full Chinese set
@@ -106,22 +100,20 @@
             glyphs[i] = fRand.nextRangeU(0x4F00, 0x9FA0);
         }
     }
-
-    bool                        fInitialized = false;
-    sk_sp<SkTypeface>           fTypeface;
-    SkFontMetrics               fMetrics;
-    SkTArray<sk_sp<SkTextBlob>> fBlobs;
-    SkRandom                    fRand;
-    int                         fIndex;
-
-    typedef Sample INHERITED;
 };
 
 class ChineseZoomView : public Sample {
-public:
-    ChineseZoomView() : fBlobs(kNumBlobs), fScale(15.0f), fTranslate(0.0f) {}
+    static constexpr int kNumBlobs = 8;
+    static constexpr int kParagraphLength = 175;
 
-protected:
+    bool                 fAfterFirstFrame = false;
+    sk_sp<SkTypeface>    fTypeface;
+    SkFontMetrics        fMetrics;
+    sk_sp<SkTextBlob>    fBlobs[kNumBlobs];
+    SkRandom             fRand;
+    SkScalar             fScale = 15;
+    SkScalar             fTranslate = 0;
+
     SkString name() override { return SkString("chinese-zoom"); }
 
     bool onChar(SkUnichar uni) override {
@@ -137,37 +129,30 @@
     }
 
     void onDrawContent(SkCanvas* canvas) override {
-        bool afterFirstFrame = fInitialized;
-        if (!fInitialized) {
-            this->init();
-            fInitialized = true;
-        }
-
         canvas->clear(0xFFDDDDDD);
 
         SkPaint paint;
         paint.setAntiAlias(true);
         paint.setColor(0xDE000000);
 
-        if (afterFirstFrame) {
+        if (fAfterFirstFrame) {
 #if SK_SUPPORT_GPU
             GrContext* grContext = canvas->getGrContext();
             if (grContext) {
-                sk_sp<SkImage> image =
-                grContext->priv().testingOnly_getFontAtlasImage(
-                                                            GrMaskFormat::kA8_GrMaskFormat, 0);
+                sk_sp<SkImage> image = grContext->priv().testingOnly_getFontAtlasImage(
+                            GrMaskFormat::kA8_GrMaskFormat, 0);
                 canvas->drawImageRect(image,
                                       SkRect::MakeXYWH(10.0f, 10.0f, 512.0f, 512.0), &paint);
                 image = grContext->priv().testingOnly_getFontAtlasImage(
-                                                            GrMaskFormat::kA8_GrMaskFormat, 1);
+                        GrMaskFormat::kA8_GrMaskFormat, 1);
                 canvas->drawImageRect(image,
                                       SkRect::MakeXYWH(522.0f, 10.0f, 512.f, 512.0f), &paint);
                 image = grContext->priv().testingOnly_getFontAtlasImage(
-                                                            GrMaskFormat::kA8_GrMaskFormat, 2);
+                        GrMaskFormat::kA8_GrMaskFormat, 2);
                 canvas->drawImageRect(image,
                                       SkRect::MakeXYWH(10.0f, 522.0f, 512.0f, 512.0f), &paint);
                 image = grContext->priv().testingOnly_getFontAtlasImage(
-                                                            GrMaskFormat::kA8_GrMaskFormat, 3);
+                        GrMaskFormat::kA8_GrMaskFormat, 3);
                 canvas->drawImageRect(image,
                                       SkRect::MakeXYWH(522.0f, 522.0f, 512.0f, 512.0f), &paint);
             }
@@ -186,13 +171,12 @@
 
             y += 3*(fMetrics.fDescent - fMetrics.fAscent + fMetrics.fLeading);
         }
+        if (!fAfterFirstFrame) {
+            fAfterFirstFrame = true;
+        }
     }
 
-private:
-    static constexpr auto kNumBlobs = 8;
-    static constexpr auto kParagraphLength = 175;
-
-    void init() {
+    void onOnceBeforeDraw() override {
         fTypeface = chinese_typeface();
 
         SkFont font(fTypeface, 11);
@@ -220,10 +204,8 @@
                 y += fMetrics.fDescent - fMetrics.fAscent + fMetrics.fLeading;
                 paragraphLength -= 45;
             }
-            fBlobs.emplace_back(builder.make());
+            fBlobs[i] = builder.make();
         }
-
-        fIndex = 0;
     }
 
     // Construct a random kWordLength character 'word' drawing from the full Chinese set
@@ -232,17 +214,6 @@
             glyphs[i] = fRand.nextRangeU(0x4F00, 0x9FA0);
         }
     }
-
-    bool                        fInitialized = false;
-    sk_sp<SkTypeface>           fTypeface;
-    SkFontMetrics               fMetrics;
-    SkTArray<sk_sp<SkTextBlob>> fBlobs;
-    SkRandom                    fRand;
-    SkScalar                    fScale;
-    SkScalar                    fTranslate;
-    int                         fIndex;
-
-    typedef Sample INHERITED;
 };
 
 //////////////////////////////////////////////////////////////////////////////