Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: gm/gm.h

Issue 1333553002: GM: replace boilerplate with macros (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-09-09 (Wednesday) 11:01:10 EDT Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gm/glyph_pos_align.cpp ('k') | gm/gm.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/gm.h
diff --git a/gm/gm.h b/gm/gm.h
index 7765dcab1153cc8bf615ab18403f24bce90b7cbf..e00a650f3352b241b6bccc628f9cda6068028a58 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;
« no previous file with comments | « gm/glyph_pos_align.cpp ('k') | gm/gm.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698