From 607c44fa2527ee213c559119e9a3ac7d59fc2f54 Mon Sep 17 00:00:00 2001 From: Hal Canary Date: Wed, 23 Jan 2019 10:40:02 -0500 Subject: [PATCH] gm: delete boilerplate Change-Id: I1fdcbadf8ec587637edfca29cd34f845a11ef045 Reviewed-on: https://skia-review.googlesource.com/c/186083 Commit-Queue: Hal Canary Reviewed-by: Hal Canary --- gm/aaa.cpp | 70 ++++------------------------------------------ gm/aaclip.cpp | 47 +++---------------------------- gm/aarectmodes.cpp | 32 +++------------------ gm/addarc.cpp | 54 ++++------------------------------- 4 files changed, 20 insertions(+), 183 deletions(-) diff --git a/gm/aaa.cpp b/gm/aaa.cpp index b2fc6337d9..e503eafe51 100644 --- a/gm/aaa.cpp +++ b/gm/aaa.cpp @@ -12,21 +12,7 @@ #define W 800 #define H 800 -class AnalyticAntiAliasConvexGM : public skiagm::GM { -public: - AnalyticAntiAliasConvexGM() {} - -protected: - - SkString onShortName() override { - return SkString("analytic_antialias_convex"); - } - - SkISize onISize() override { - return SkISize::Make(W, H); - } - - void onDraw(SkCanvas* canvas) override { +DEF_SIMPLE_GM(analytic_antialias_convex, canvas, W, H) { SkPaint p; p.setColor(SK_ColorRED); p.setAntiAlias(true); @@ -98,27 +84,9 @@ protected: path.lineTo(710, 534); path.lineTo(700, 534); canvas->drawPath(path, p); - } +} -private: - typedef skiagm::GM INHERITED; -}; - -class AnalyticAntiAliasGeneralGM : public skiagm::GM { -public: - AnalyticAntiAliasGeneralGM() {} - -protected: - - SkString onShortName() override { - return SkString("analytic_antialias_general"); - } - - SkISize onISize() override { - return SkISize::Make(W, H); - } - - void onDraw(SkCanvas* canvas) override { +DEF_SIMPLE_GM(analytic_antialias_general, canvas, W, H) { SkPaint p; p.setColor(SK_ColorRED); p.setAntiAlias(true); @@ -162,27 +130,9 @@ protected: path.addRect({20, 20, 100.1f, 100}); path.addRect({100.9f, 20, 200, 100}); canvas->drawPath(path, p); - } +} -private: - typedef skiagm::GM INHERITED; -}; - -class AnalyticAntiAliasInverseGM : public skiagm::GM { -public: - AnalyticAntiAliasInverseGM() {} - -protected: - - SkString onShortName() override { - return SkString("analytic_antialias_inverse"); - } - - SkISize onISize() override { - return SkISize::Make(W, H); - } - - void onDraw(SkCanvas* canvas) override { +DEF_SIMPLE_GM(analytic_antialias_inverse, canvas, W, H) { SkPaint p; p.setColor(SK_ColorRED); p.setAntiAlias(true); @@ -194,12 +144,4 @@ protected: path.setFillType(SkPath::kInverseWinding_FillType); canvas->drawPath(path, p); canvas->restore(); - } - -private: - typedef skiagm::GM INHERITED; -}; - -DEF_GM( return new AnalyticAntiAliasConvexGM; ) -DEF_GM( return new AnalyticAntiAliasGeneralGM; ) -DEF_GM( return new AnalyticAntiAliasInverseGM; ) +} diff --git a/gm/aaclip.cpp b/gm/aaclip.cpp index 1f7886c0cb..e475c74e06 100644 --- a/gm/aaclip.cpp +++ b/gm/aaclip.cpp @@ -124,23 +124,7 @@ static void draw_rect_tests(SkCanvas* canvas) { Each region should show as a blue center surrounded by a 2px green border, with no red. */ - -class AAClipGM : public skiagm::GM { -public: - AAClipGM() { - - } - -protected: - SkString onShortName() override { - return SkString("aaclip"); - } - - SkISize onISize() override { - return SkISize::Make(240, 120); - } - - void onDraw(SkCanvas* canvas) override { +DEF_SIMPLE_GM(aaclip, canvas, 240, 120) { // Initial pixel-boundary-aligned draw draw_rect_tests(canvas); @@ -160,13 +144,7 @@ protected: canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5); canvas->translate(SkIntToScalar(50), 0); draw_rect_tests(canvas); - } - -private: - typedef skiagm::GM INHERITED; -}; - -DEF_GM(return new AAClipGM;) +} ///////////////////////////////////////////////////////////////////////// @@ -210,20 +188,7 @@ static void test_image(SkCanvas* canvas, const SkImageInfo& info) { CGImageRelease(image); } -class CGImageGM : public skiagm::GM { -public: - CGImageGM() {} - -protected: - SkString onShortName() override { - return SkString("cgimage"); - } - - SkISize onISize() override { - return SkISize::Make(800, 250); - } - - void onDraw(SkCanvas* canvas) override { +DEF_SIMPLE_GM(cgimage, canvas, 800, 250) { const struct { SkColorType fCT; SkAlphaType fAT; @@ -244,12 +209,8 @@ protected: test_image(canvas, info); canvas->translate(info.width() + 10, 0); } - } +} -private: - typedef skiagm::GM INHERITED; -}; -//DEF_GM( return new CGImageGM; ) #endif /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gm/aarectmodes.cpp b/gm/aarectmodes.cpp index df11e5bdce..b9fa25d091 100644 --- a/gm/aarectmodes.cpp +++ b/gm/aarectmodes.cpp @@ -115,24 +115,9 @@ static sk_sp make_bg_shader() { &m); } -namespace skiagm { - - class AARectModesGM : public GM { - SkPaint fBGPaint; - public: - AARectModesGM () { - fBGPaint.setShader(make_bg_shader()); - } - - protected: - - SkString onShortName() override { - return SkString("aarectmodes"); - } - - SkISize onISize() override { return SkISize::Make(640, 480); } - - void onDraw(SkCanvas* canvas) override { +DEF_SIMPLE_GM(aarectmodes, canvas, 640, 480) { + SkPaint bgPaint; + bgPaint.setShader(make_bg_shader()); if (false) { // avoid bit rot, suppress warning test4(canvas); } @@ -150,7 +135,7 @@ namespace skiagm { canvas->translate(W * 5, 0); canvas->save(); } - canvas->drawRect(bounds, fBGPaint); + canvas->drawRect(bounds, bgPaint); canvas->saveLayer(&bounds, nullptr); SkScalar dy = drawCell(canvas, gModes[i], gAlphaValue[alpha & 1], @@ -163,13 +148,4 @@ namespace skiagm { canvas->restore(); canvas->translate(W * 5 / 4, 0); } - } - - private: - typedef GM INHERITED; - }; - -////////////////////////////////////////////////////////////////////////////// - - DEF_GM( return new AARectModesGM; ); } diff --git a/gm/addarc.cpp b/gm/addarc.cpp index 763135fac5..cfb8fed056 100644 --- a/gm/addarc.cpp +++ b/gm/addarc.cpp @@ -67,16 +67,7 @@ DEF_GM( return new AddArcGM; ) #define R 400 -class AddArcMeasGM : public skiagm::GM { -public: - AddArcMeasGM() {} - -protected: - SkString onShortName() override { return SkString("addarc_meas"); } - - SkISize onISize() override { return SkISize::Make(2*R + 40, 2*R + 40); } - - void onDraw(SkCanvas* canvas) override { +DEF_SIMPLE_GM(addarc_meas, canvas, 2*R + 40, 2*R + 40) { canvas->translate(R + 20, R + 20); SkPaint paint; @@ -106,12 +97,7 @@ protected: canvas->drawLine({0, 0}, pos, measPaint); } } - } - -private: - typedef skiagm::GM INHERITED; -}; -DEF_GM( return new AddArcMeasGM; ) +} /////////////////////////////////////////////////// @@ -230,16 +216,7 @@ static void html_canvas_arc(SkPath* path, SkScalar x, SkScalar y, SkScalar r, Sk } // Lifted from canvas-arc-circumference-fill-diffs.html -class ManyArcsGM : public skiagm::GM { -public: - ManyArcsGM() {} - -protected: - SkString onShortName() override { return SkString("manyarcs"); } - - SkISize onISize() override { return SkISize::Make(620, 330); } - - void onDraw(SkCanvas* canvas) override { +DEF_SIMPLE_GM(manyarcs, canvas, 620, 330) { SkPaint paint; paint.setAntiAlias(true); paint.setStyle(SkPaint::kStroke_Style); @@ -281,24 +258,10 @@ protected: canvas->restore(); canvas->translate(0, 40); } - } - -private: - typedef skiagm::GM INHERITED; -}; -DEF_GM( return new ManyArcsGM; ) +} // Lifted from https://bugs.chromium.org/p/chromium/issues/detail?id=640031 -class TinyAngleBigRadiusArcsGM : public skiagm::GM { -public: - TinyAngleBigRadiusArcsGM() {} - -protected: - SkString onShortName() override { return SkString("tinyanglearcs"); } - - SkISize onISize() override { return SkISize::Make(620, 330); } - - void onDraw(SkCanvas* canvas) override { +DEF_SIMPLE_GM(tinyanglearcs, canvas, 620, 330) { SkPaint paint; paint.setAntiAlias(true); paint.setStyle(SkPaint::kStroke_Style); @@ -331,9 +294,4 @@ protected: canvas->drawPath(path, paint); canvas->translate(20, 0); } - } - -private: - typedef skiagm::GM INHERITED; -}; -DEF_GM( return new TinyAngleBigRadiusArcsGM; ) +}