Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef skiagm_DEFINED | 8 #ifndef skiagm_DEFINED |
| 9 #define skiagm_DEFINED | 9 #define skiagm_DEFINED |
| 10 | 10 |
| 11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkPaint.h" | 13 #include "SkPaint.h" |
| 14 #include "SkSize.h" | 14 #include "SkSize.h" |
| 15 #include "SkString.h" | 15 #include "SkString.h" |
| 16 #include "SkTRegistry.h" | 16 #include "SkTRegistry.h" |
| 17 #include "sk_tool_utils.h" | 17 #include "sk_tool_utils.h" |
| 18 | 18 |
| 19 #if SK_SUPPORT_GPU | 19 #if SK_SUPPORT_GPU |
| 20 #include "GrContext.h" | 20 #include "GrContext.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 #define DEF_GM(code) \ | 23 #define DEF_GM(code) \ |
| 24 static skiagm::GM* SK_MACRO_APPEND_LINE(F_)(void*) { code; } \ | 24 static skiagm::GM* SK_MACRO_APPEND_LINE(F_)(void*) { code; } \ |
| 25 static skiagm::GMRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_ )); | 25 static skiagm::GMRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_ )); |
| 26 | 26 |
| 27 // See colorwheel.cpp for example usage. | 27 // See colorwheel.cpp for example usage. |
| 28 #define DEF_SIMPLE_GM(NAME, CANVAS, W, H) \ | 28 #define DEF_SIMPLE_GM(NAME, CANVAS, W, H) \ |
| 29 class SK_MACRO_CONCAT(NAME, _GM) : public skiagm::GM { \ | 29 static void SK_MACRO_CONCAT(NAME, _GM)(SkCanvas* CANVAS); \ |
| 30 void onDraw(SkCanvas* canvas) SK_OVERRIDE; \ | 30 DEF_GM( return SkNEW_ARGS(skiagm::SimpleGM, \ |
| 31 SkISize onISize() SK_OVERRIDE { \ | 31 (SkString(#NAME), \ |
| 32 return SkISize::Make((W), (H)); \ | 32 SK_MACRO_CONCAT(NAME, _GM), \ |
| 33 } \ | 33 SkISize::Make(W, H))); ) \ |
| 34 SkString onShortName() SK_OVERRIDE { \ | 34 void SK_MACRO_CONCAT(NAME, _GM)(SkCanvas* CANVAS) |
| 35 return SkString(#NAME); \ | |
| 36 } \ | |
| 37 }; \ | |
| 38 DEF_GM( return SkNEW(SK_MACRO_CONCAT(NAME, _GM)); ) \ | |
| 39 void SK_MACRO_CONCAT(NAME, _GM)::onDraw(SkCanvas* CANVAS) | |
| 40 | 35 |
| 41 namespace skiagm { | 36 namespace skiagm { |
| 42 | 37 |
| 43 class GM { | 38 class GM { |
| 44 public: | 39 public: |
| 45 GM(); | 40 GM(); |
| 46 virtual ~GM(); | 41 virtual ~GM(); |
| 47 | 42 |
| 48 enum Flags { | 43 enum Flags { |
| 49 kSkipPDF_Flag = 1 << 0, | 44 kSkipPDF_Flag = 1 << 0, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 private: | 124 private: |
| 130 Mode fMode; | 125 Mode fMode; |
| 131 SkString fShortName; | 126 SkString fShortName; |
| 132 SkColor fBGColor; | 127 SkColor fBGColor; |
| 133 bool fCanvasIsDeferred; // work-around problem in srcmode.cpp | 128 bool fCanvasIsDeferred; // work-around problem in srcmode.cpp |
| 134 bool fHaveCalledOnceBeforeDraw; | 129 bool fHaveCalledOnceBeforeDraw; |
| 135 SkMatrix fStarterMatrix; | 130 SkMatrix fStarterMatrix; |
| 136 }; | 131 }; |
| 137 | 132 |
| 138 typedef SkTRegistry<GM*(*)(void*)> GMRegistry; | 133 typedef SkTRegistry<GM*(*)(void*)> GMRegistry; |
| 134 | |
| 135 class SimpleGM : public skiagm::GM { | |
| 136 public: | |
| 137 SimpleGM(const SkString& name, | |
|
mtklein
2015/01/12 23:13:35
Looks like you can simplify a little further by de
| |
| 138 void (*drawProc)(SkCanvas*), | |
| 139 const SkISize& size) | |
| 140 : fName(name), fDrawProc(drawProc), fSize(size) {} | |
| 141 protected: | |
| 142 void onDraw(SkCanvas* canvas) SK_OVERRIDE; | |
| 143 SkISize onISize() SK_OVERRIDE; | |
| 144 SkString onShortName() SK_OVERRIDE; | |
| 145 private: | |
| 146 SkString fName; | |
| 147 void (*fDrawProc)(SkCanvas*); | |
| 148 SkISize fSize; | |
| 149 }; | |
| 139 } | 150 } |
| 140 | 151 |
| 141 #endif | 152 #endif |
| OLD | NEW |