aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/gm.h
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-09-09 08:16:41 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-09 08:16:41 -0700
commit2a24338c777462e04a2b26295f9c034155ee8f3e (patch)
treecab82add826f6d77e75c8265ea960f16929033a8 /gm/gm.h
parent157e6483fb089bf4d2e5cd2c18b521e5ab4ff32a (diff)
GM: replace boilerplate with macros
I have verified locally that nothing draws differently. Motivation: * SK_SIMPLE_GM makes it easier to write a GM. * Reducing 1100 lines of code makes maintenance easier. * Simple GMs are easy to convert to Fiddles. Review URL: https://codereview.chromium.org/1333553002
Diffstat (limited to 'gm/gm.h')
-rw-r--r--gm/gm.h34
1 files changed, 25 insertions, 9 deletions
diff --git a/gm/gm.h b/gm/gm.h
index 7765dcab11..e00a650f33 100644
--- a/gm/gm.h
+++ b/gm/gm.h
@@ -23,11 +23,21 @@ struct GrContextOptions;
static skiagm::GM* SK_MACRO_APPEND_LINE(F_)(void*) { code; } \
static skiagm::GMRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_));
-// See colorwheel.cpp for example usage.
-#define DEF_SIMPLE_GM(NAME, CANVAS, W, H) \
- static void SK_MACRO_CONCAT(NAME, _GM)(SkCanvas * CANVAS); \
- DEF_GM(return new skiagm::SimpleGM(SkString(#NAME), SK_MACRO_CONCAT(NAME, _GM), \
- SkISize::Make(W, H));) \
+// a Simple GM is a rendering test that does not store state between
+// rendering calls or make use of the onOnceBeforeDraw() virtual; it
+// consists of:
+// * A single void(*)(SkCanvas*) function.
+// * A name.
+// * Prefered width and height.
+// * Optionally, a background color (default is white).
+#define DEF_SIMPLE_GM(NAME, CANVAS, W, H) \
+ DEF_SIMPLE_GM_BG_NAME(NAME, CANVAS, W, H, SK_ColorWHITE, SkString(#NAME))
+#define DEF_SIMPLE_GM_BG(NAME, CANVAS, W, H, BGCOLOR)\
+ DEF_SIMPLE_GM_BG_NAME(NAME, CANVAS, W, H, BGCOLOR, SkString(#NAME))
+#define DEF_SIMPLE_GM_BG_NAME(NAME, CANVAS, W, H, BGCOLOR, NAME_STR) \
+ static void SK_MACRO_CONCAT(NAME, _GM)(SkCanvas * CANVAS); \
+ DEF_GM(return new skiagm::SimpleGM(NAME_STR, SK_MACRO_CONCAT(NAME, _GM), \
+ SkISize::Make(W, H), BGCOLOR);) \
void SK_MACRO_CONCAT(NAME, _GM)(SkCanvas * CANVAS)
namespace skiagm {
@@ -93,9 +103,10 @@ namespace skiagm {
virtual void modifyGrContextOptions(GrContextOptions* options) {}
- protected:
/** draws a standard message that the GM is only intended to be used with the GPU.*/
- void drawGpuOnlyMessage(SkCanvas*);
+ static void DrawGpuOnlyMessage(SkCanvas*);
+
+ protected:
virtual void onOnceBeforeDraw() {}
virtual void onDraw(SkCanvas*) = 0;
virtual void onDrawBackground(SkCanvas*);
@@ -120,8 +131,13 @@ namespace skiagm {
public:
SimpleGM(const SkString& name,
void (*drawProc)(SkCanvas*),
- const SkISize& size)
- : fName(name), fDrawProc(drawProc), fSize(size) {}
+ const SkISize& size,
+ SkColor backgroundColor)
+ : fName(name), fDrawProc(drawProc), fSize(size) {
+ if (backgroundColor != SK_ColorWHITE) {
+ this->setBGColor(backgroundColor);
+ }
+ }
protected:
void onDraw(SkCanvas* canvas) override;
SkISize onISize() override;