gm: add some overrides

Change-Id: I5348e2da1a2034b629d43b9e9faadb6db333abe8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228348
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/gm/gradients.cpp b/gm/gradients.cpp
index 7b1a1f7..34cfec4 100644
--- a/gm/gradients.cpp
+++ b/gm/gradients.cpp
@@ -27,7 +27,7 @@
 
 #include <math.h>
 
-namespace skiagm {
+namespace {
 
 struct GradData {
     int              fCount;
@@ -185,22 +185,14 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-class GradientsGM : public GM {
+class GradientsGM : public skiagm::GM {
 public:
-    GradientsGM(bool dither) : fDither(dither) {
-        this->setBGColor(0xFFDDDDDD);
-    }
+    GradientsGM(bool dither) : fDither(dither) {}
 
 protected:
+    const bool fDither;
 
-    SkString onShortName() {
-        return SkString(fDither ? "gradients" : "gradients_nodither");
-    }
-
-    virtual SkISize onISize() { return SkISize::Make(840, 815); }
-
-    virtual void onDraw(SkCanvas* canvas) {
-
+    void onDraw(SkCanvas* canvas) override {
         SkPoint pts[2] = {
             { 0, 0 },
             { SkIntToScalar(100), SkIntToScalar(100) }
@@ -231,32 +223,33 @@
         }
     }
 
-protected:
-    bool fDither;
-
 private:
-    typedef GM INHERITED;
+    void onOnceBeforeDraw() override { this->setBGColor(0xFFDDDDDD); }
+
+    SkString onShortName() override {
+        return SkString(fDither ? "gradients" : "gradients_nodither");
+    }
+
+    SkISize onISize() override { return {840, 815}; }
 };
 DEF_GM( return new GradientsGM(true); )
 DEF_GM( return new GradientsGM(false); )
 
 // Like the original gradients GM, but using the SkColor4f shader factories. Should be identical.
-class Gradients4fGM : public GM {
+class Gradients4fGM : public skiagm::GM {
 public:
-    Gradients4fGM(bool dither) : fDither(dither) {
-        this->setBGColor(0xFFDDDDDD);
-    }
+    Gradients4fGM(bool dither) : fDither(dither) {}
 
-protected:
+private:
+    void onOnceBeforeDraw() override { this->setBGColor(0xFFDDDDDD); }
 
-    SkString onShortName() {
+    SkString onShortName() override {
         return SkString(fDither ? "gradients4f" : "gradients4f_nodither");
     }
 
-    virtual SkISize onISize() { return SkISize::Make(840, 815); }
+    SkISize onISize() override { return {840, 815}; }
 
-    virtual void onDraw(SkCanvas* canvas) {
-
+    void onDraw(SkCanvas* canvas) override {
         SkPoint pts[2] ={
             { 0, 0 },
             { SkIntToScalar(100), SkIntToScalar(100) }
@@ -287,34 +280,28 @@
         }
     }
 
-protected:
     bool fDither;
-
-private:
-    typedef GM INHERITED;
 };
 DEF_GM(return new Gradients4fGM(true); )
 DEF_GM(return new Gradients4fGM(false); )
 
 // Based on the original gradient slide, but with perspective applied to the
 // gradient shaders' local matrices
-class GradientsLocalPerspectiveGM : public GM {
+class GradientsLocalPerspectiveGM : public skiagm::GM {
 public:
     GradientsLocalPerspectiveGM(bool dither) : fDither(dither) {
         this->setBGColor(0xFFDDDDDD);
     }
 
-protected:
-
-    SkString onShortName() {
+private:
+    SkString onShortName() override {
         return SkString(fDither ? "gradients_local_perspective" :
                                   "gradients_local_perspective_nodither");
     }
 
-    virtual SkISize onISize() { return SkISize::Make(840, 815); }
+    SkISize onISize() override { return {840, 815}; }
 
-    virtual void onDraw(SkCanvas* canvas) {
-
+    void onDraw(SkCanvas* canvas) override {
         SkPoint pts[2] = {
             { 0, 0 },
             { SkIntToScalar(100), SkIntToScalar(100) }
@@ -344,10 +331,7 @@
         }
     }
 
-private:
     bool fDither;
-
-    typedef GM INHERITED;
 };
 DEF_GM( return new GradientsLocalPerspectiveGM(true); )
 DEF_GM( return new GradientsLocalPerspectiveGM(false); )
@@ -358,21 +342,21 @@
 public:
     GradientsViewPerspectiveGM(bool dither) : INHERITED(dither) { }
 
-protected:
-    SkString onShortName() {
+private:
+    SkString onShortName() override {
         return SkString(fDither ? "gradients_view_perspective" :
                                   "gradients_view_perspective_nodither");
     }
 
-    virtual SkISize onISize() { return SkISize::Make(840, 500); }
+    SkISize onISize() override { return {840, 500}; }
 
-    virtual void onDraw(SkCanvas* canvas) {
+    void onDraw(SkCanvas* canvas) override {
         SkMatrix perspective;
         perspective.setIdentity();
         perspective.setPerspY(0.001f);
         perspective.setSkewX(SkIntToScalar(8) / 25);
         canvas->concat(perspective);
-        INHERITED::onDraw(canvas);
+        this->INHERITED::onDraw(canvas);
     }
 
 private:
@@ -397,23 +381,19 @@
  ctx.fillStyle = g;
  ctx.fillRect(0, 0, 100, 50);
  */
-class GradientsDegenrate2PointGM : public GM {
+class GradientsDegenrate2PointGM : public skiagm::GM {
 public:
     GradientsDegenrate2PointGM(bool dither) : fDither(dither) {}
 
-protected:
-    SkString onShortName() {
+private:
+    SkString onShortName() override {
         return SkString(fDither ? "gradients_degenerate_2pt" : "gradients_degenerate_2pt_nodither");
     }
 
-    virtual SkISize onISize() { return SkISize::Make(320, 320); }
+    SkISize onISize() override { return {320, 320}; }
 
-    void drawBG(SkCanvas* canvas) {
+    void onDraw(SkCanvas* canvas) override {
         canvas->drawColor(SK_ColorBLUE);
-    }
-
-    virtual void onDraw(SkCanvas* canvas) {
-        this->drawBG(canvas);
 
         SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorRED };
         SkScalar pos[] = { 0, 0.01f, 0.99f, SK_Scalar1 };
@@ -431,10 +411,7 @@
         canvas->drawPaint(paint);
     }
 
-private:
     bool fDither;
-
-    typedef GM INHERITED;
 };
 DEF_GM( return new GradientsDegenrate2PointGM(true); )
 DEF_GM( return new GradientsDegenrate2PointGM(false); )
@@ -477,23 +454,19 @@
 
 /// Tests correctness of *optimized* codepaths in gradients.
 
-class ClampedGradientsGM : public GM {
+class ClampedGradientsGM : public skiagm::GM {
 public:
     ClampedGradientsGM(bool dither) : fDither(dither) {}
 
-protected:
-    SkString onShortName() {
+private:
+    SkString onShortName() override {
         return SkString(fDither ? "clamped_gradients" : "clamped_gradients_nodither");
     }
 
-    virtual SkISize onISize() { return SkISize::Make(640, 510); }
+    SkISize onISize() override { return {640, 510}; }
 
-    void drawBG(SkCanvas* canvas) {
+    void onDraw(SkCanvas* canvas) override {
         canvas->drawColor(0xFFDDDDDD);
-    }
-
-    virtual void onDraw(SkCanvas* canvas) {
-        this->drawBG(canvas);
 
         SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(300) };
         SkPaint paint;
@@ -510,10 +483,7 @@
         canvas->drawRect(r, paint);
     }
 
-private:
     bool fDither;
-
-    typedef GM INHERITED;
 };
 DEF_GM( return new ClampedGradientsGM(true); )
 DEF_GM( return new ClampedGradientsGM(false); )
@@ -521,21 +491,15 @@
 /// Checks quality of large radial gradients, which may display
 /// some banding.
 
-class RadialGradientGM : public GM {
-public:
-    RadialGradientGM() {}
-
-protected:
-
+class RadialGradientGM : public skiagm::GM {
     SkString onShortName() override { return SkString("radial_gradient"); }
-    SkISize onISize() override { return SkISize::Make(1280, 1280); }
-    void drawBG(SkCanvas* canvas) {
-        canvas->drawColor(0xFF000000);
-    }
+
+    SkISize onISize() override { return {1280, 1280}; }
+
     void onDraw(SkCanvas* canvas) override {
         const SkISize dim = this->getISize();
 
-        this->drawBG(canvas);
+        canvas->drawColor(0xFF000000);
 
         SkPaint paint;
         paint.setDither(true);
@@ -554,25 +518,19 @@
         };
         canvas->drawRect(r, paint);
     }
-private:
-    typedef GM INHERITED;
 };
 DEF_GM( return new RadialGradientGM; )
 
-class RadialGradient2GM : public GM {
+class RadialGradient2GM : public skiagm::GM {
 public:
     RadialGradient2GM(bool dither) : fDither(dither) {}
 
-protected:
-
+private:
     SkString onShortName() override {
         return SkString(fDither ? "radial_gradient2" : "radial_gradient2_nodither");
     }
 
-    SkISize onISize() override { return SkISize::Make(800, 400); }
-    void drawBG(SkCanvas* canvas) {
-        canvas->drawColor(0xFF000000);
-    }
+    SkISize onISize() override { return {800, 400}; }
 
     // Reproduces the example given in bug 7671058.
     void onDraw(SkCanvas* canvas) override {
@@ -627,16 +585,16 @@
 DEF_GM( return new RadialGradient2GM(false); )
 
 // Shallow radial (shows banding on raster)
-class RadialGradient3GM : public GM {
+class RadialGradient3GM : public skiagm::GM {
 public:
     RadialGradient3GM(bool dither) : fDither(dither) { }
 
-protected:
+private:
     SkString onShortName() override {
         return SkString(fDither ? "radial_gradient3" : "radial_gradient3_nodither");
     }
 
-    SkISize onISize() override { return SkISize::Make(500, 500); }
+    SkISize onISize() override { return {500, 500}; }
 
     bool runAsBench() const override { return true; }
 
@@ -664,16 +622,16 @@
 DEF_GM( return new RadialGradient3GM(true); )
 DEF_GM( return new RadialGradient3GM(false); )
 
-class RadialGradient4GM : public GM {
+class RadialGradient4GM : public skiagm::GM {
 public:
     RadialGradient4GM(bool dither) : fDither(dither) { }
 
-protected:
+private:
     SkString onShortName() override {
         return SkString(fDither ? "radial_gradient4" : "radial_gradient4_nodither");
     }
 
-    SkISize onISize() override { return SkISize::Make(500, 500); }
+    SkISize onISize() override { return {500, 500}; }
 
     void onOnceBeforeDraw() override {
         const SkPoint center = { 250, 250 };
@@ -702,11 +660,11 @@
 DEF_GM( return new RadialGradient4GM(true); )
 DEF_GM( return new RadialGradient4GM(false); )
 
-class LinearGradientGM : public GM {
+class LinearGradientGM : public skiagm::GM {
 public:
     LinearGradientGM(bool dither) : fDither(dither) { }
 
-protected:
+private:
     SkString onShortName() override {
         return SkString(fDither ? "linear_gradient" : "linear_gradient_nodither");
     }
@@ -715,7 +673,7 @@
     const SkScalar kHeight = 5.f;
     const SkScalar kMinWidth = 540.f;
 
-    SkISize onISize() override { return SkISize::Make(500, 500); }
+    SkISize onISize() override { return {500, 500}; }
 
     void onOnceBeforeDraw() override {
         SkPoint pts[2] = { {0, 0}, {0, 0} };
@@ -754,22 +712,12 @@
 DEF_GM( return new LinearGradientGM(true); )
 DEF_GM( return new LinearGradientGM(false); )
 
-class LinearGradientTinyGM : public GM {
-public:
-    LinearGradientTinyGM(uint32_t flags, const char* suffix = nullptr)
-    : fName("linear_gradient_tiny")
-    , fFlags(flags) {
-        fName.append(suffix);
-    }
+class LinearGradientTinyGM : public skiagm::GM {
+    static constexpr uint32_t kFlags = 0;
 
-protected:
-    SkString onShortName() override {
-        return fName;
-    }
+    SkString onShortName() override { return SkString("linear_gradient_tiny"); }
 
-    SkISize onISize() override {
-        return SkISize::Make(600, 500);
-    }
+    SkISize onISize() override { return {600, 500}; }
 
     void onDraw(SkCanvas* canvas) override {
         const SkScalar kRectSize = 100;
@@ -800,22 +748,17 @@
             SkAutoCanvasRestore acr(canvas, true);
             paint.setShader(SkGradientShader::MakeLinear(configs[i].pts, colors, configs[i].pos,
                                                          kStopCount, SkTileMode::kClamp,
-                                                         fFlags, nullptr));
+                                                         kFlags, nullptr));
             canvas->translate(kRectSize * ((i % 4) * 1.5f + 0.25f),
                               kRectSize * ((i / 4) * 1.5f + 0.25f));
 
             canvas->drawRect(SkRect::MakeWH(kRectSize, kRectSize), paint);
         }
     }
-
-private:
-    typedef GM INHERITED;
-
-    SkString fName;
-    uint32_t fFlags;
 };
-DEF_GM( return new LinearGradientTinyGM(0); )
-}
+
+DEF_GM( return new LinearGradientTinyGM; )
+}  // namespace
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////