epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 7 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 8 | #ifndef skiagm_DEFINED |
| 9 | #define skiagm_DEFINED |
| 10 | |
Tyler Denniston | 45f94f8 | 2020-02-04 16:09:08 -0500 | [diff] [blame] | 11 | #include "gm/verifiers/gmverifier.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 12 | #include "include/core/SkColor.h" |
| 13 | #include "include/core/SkScalar.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkSize.h" |
| 15 | #include "include/core/SkString.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 16 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "include/private/SkMacros.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "tools/Registry.h" |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 19 | |
Hal Canary | edda565 | 2019-08-05 10:28:09 -0400 | [diff] [blame] | 20 | #include <memory> |
| 21 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 22 | class GrDirectContext; |
Robert Phillips | 95c250c | 2020-06-29 15:36:12 -0400 | [diff] [blame] | 23 | class GrRecordingContext; |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 24 | class GrRenderTargetContext; |
| 25 | class SkCanvas; |
Mike Reed | 88f5671 | 2019-02-04 16:50:10 -0500 | [diff] [blame] | 26 | class SkMetaData; |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 27 | struct GrContextOptions; |
mtklein@google.com | 62b50b7 | 2013-09-16 20:42:15 +0000 | [diff] [blame] | 28 | |
Hal Canary | edda565 | 2019-08-05 10:28:09 -0400 | [diff] [blame] | 29 | #define DEF_GM(CODE) \ |
| 30 | static skiagm::GMRegistry SK_MACRO_APPEND_LINE(REG_)(\ |
| 31 | [](){return std::unique_ptr<skiagm::GM>([](){ CODE ; }());}); |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 32 | |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 33 | // A Simple GM is a rendering test that does not store state between rendering calls or make use of |
| 34 | // the onOnceBeforeDraw() virtual; it consists of: |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 35 | // * A name. |
| 36 | // * Prefered width and height. |
| 37 | // * Optionally, a background color (default is white). |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 38 | // * A standalone function pointer that implements its onDraw method. |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 39 | #define DEF_SIMPLE_GM(NAME, CANVAS, W, H) \ |
| 40 | DEF_SIMPLE_GM_BG_NAME(NAME, CANVAS, W, H, SK_ColorWHITE, SkString(#NAME)) |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 41 | #define DEF_SIMPLE_GM_BG(NAME, CANVAS, W, H, BGCOLOR) \ |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 42 | DEF_SIMPLE_GM_BG_NAME(NAME, CANVAS, W, H, BGCOLOR, SkString(#NAME)) |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 43 | #define DEF_SIMPLE_GM_BG_NAME(NAME, CANVAS, W, H, BGCOLOR, NAME_STR) \ |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 44 | static void SK_MACRO_CONCAT(NAME,_GM_inner)(SkCanvas*); \ |
| 45 | DEF_SIMPLE_GM_BG_NAME_CAN_FAIL(NAME, CANVAS,, W, H, BGCOLOR, NAME_STR) { \ |
| 46 | SK_MACRO_CONCAT(NAME,_GM_inner)(CANVAS); \ |
| 47 | return skiagm::DrawResult::kOk; \ |
| 48 | } \ |
| 49 | void SK_MACRO_CONCAT(NAME,_GM_inner)(SkCanvas* CANVAS) |
| 50 | |
| 51 | #define DEF_SIMPLE_GM_CAN_FAIL(NAME, CANVAS, ERR_MSG, W, H) \ |
| 52 | DEF_SIMPLE_GM_BG_NAME_CAN_FAIL(NAME, CANVAS, ERR_MSG, W, H, SK_ColorWHITE, SkString(#NAME)) |
| 53 | #define DEF_SIMPLE_GM_BG_CAN_FAIL(NAME, CANVAS, ERR_MSG, W, H, BGCOLOR) \ |
| 54 | DEF_SIMPLE_GM_BG_NAME_CAN_FAIL(NAME, CANVAS, ERR_MSG, W, H, BGCOLOR, SkString(#NAME)) |
| 55 | #define DEF_SIMPLE_GM_BG_NAME_CAN_FAIL(NAME, CANVAS, ERR_MSG, W, H, BGCOLOR, NAME_STR) \ |
| 56 | static skiagm::DrawResult SK_MACRO_CONCAT(NAME,_GM)(SkCanvas*, SkString*); \ |
| 57 | DEF_GM(return new skiagm::SimpleGM(BGCOLOR, NAME_STR, {W,H}, SK_MACRO_CONCAT(NAME,_GM));) \ |
| 58 | skiagm::DrawResult SK_MACRO_CONCAT(NAME,_GM)(SkCanvas* CANVAS, SkString* ERR_MSG) |
| 59 | |
halcanary | 30b83d4 | 2014-10-26 05:23:53 -0700 | [diff] [blame] | 60 | |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 61 | // A Simple GpuGM makes direct GPU calls. Its onDraw hook that includes GPU objects as params, and |
| 62 | // is only invoked on GPU configs. Non-GPU configs automatically draw a GPU-only message and abort. |
| 63 | #define DEF_SIMPLE_GPU_GM(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS, W, H) \ |
| 64 | DEF_SIMPLE_GPU_GM_BG(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS, W, H, SK_ColorWHITE) |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 65 | #define DEF_SIMPLE_GPU_GM_BG(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS, W, H, BGCOLOR) \ |
Robert Phillips | 95c250c | 2020-06-29 15:36:12 -0400 | [diff] [blame] | 66 | static void SK_MACRO_CONCAT(NAME,_GM_inner)(GrRecordingContext*, GrRenderTargetContext*, \ |
| 67 | SkCanvas*); \ |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 68 | DEF_SIMPLE_GPU_GM_BG_CAN_FAIL(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS,, W, H, \ |
| 69 | BGCOLOR) { \ |
| 70 | SK_MACRO_CONCAT(NAME,_GM_inner)(GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS); \ |
| 71 | return skiagm::DrawResult::kOk; \ |
| 72 | } \ |
| 73 | void SK_MACRO_CONCAT(NAME,_GM_inner)( \ |
Robert Phillips | 95c250c | 2020-06-29 15:36:12 -0400 | [diff] [blame] | 74 | GrRecordingContext* GR_CONTEXT, GrRenderTargetContext* RENDER_TARGET_CONTEXT, \ |
| 75 | SkCanvas* CANVAS) |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 76 | |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 77 | #define DEF_SIMPLE_GPU_GM_CAN_FAIL(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS, ERR_MSG, W, H) \ |
| 78 | DEF_SIMPLE_GPU_GM_BG_CAN_FAIL(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS, \ |
| 79 | ERR_MSG, W, H, SK_ColorWHITE) |
| 80 | #define DEF_SIMPLE_GPU_GM_BG_CAN_FAIL(NAME, GR_CONTEXT, RENDER_TARGET_CONTEXT, CANVAS, ERR_MSG, W, \ |
| 81 | H, BGCOLOR) \ |
| 82 | static skiagm::DrawResult SK_MACRO_CONCAT(NAME,_GM)( \ |
Robert Phillips | 95c250c | 2020-06-29 15:36:12 -0400 | [diff] [blame] | 83 | GrRecordingContext*, GrRenderTargetContext*, SkCanvas*, SkString*); \ |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 84 | DEF_GM(return new skiagm::SimpleGpuGM(BGCOLOR, SkString(#NAME), {W,H}, \ |
| 85 | SK_MACRO_CONCAT(NAME,_GM));) \ |
| 86 | skiagm::DrawResult SK_MACRO_CONCAT(NAME,_GM)( \ |
Robert Phillips | 95c250c | 2020-06-29 15:36:12 -0400 | [diff] [blame] | 87 | GrRecordingContext* GR_CONTEXT, GrRenderTargetContext* RENDER_TARGET_CONTEXT, \ |
| 88 | SkCanvas* CANVAS, SkString* ERR_MSG) |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 89 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 90 | namespace skiagm { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 91 | |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 92 | enum class DrawResult { |
Robert Phillips | 83b749a | 2020-06-25 11:41:19 -0400 | [diff] [blame] | 93 | kOk, // Test drew successfully. |
| 94 | kFail, // Test failed to draw. |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 95 | kSkip // Test is not applicable in this context and should be skipped. |
| 96 | }; |
| 97 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 98 | class GM { |
| 99 | public: |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 100 | using DrawResult = skiagm::DrawResult; |
| 101 | |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 102 | GM(SkColor backgroundColor = SK_ColorWHITE); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 103 | virtual ~GM(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 104 | |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 105 | enum Mode { |
| 106 | kGM_Mode, |
| 107 | kSample_Mode, |
| 108 | kBench_Mode, |
| 109 | }; |
| 110 | |
| 111 | void setMode(Mode mode) { fMode = mode; } |
| 112 | Mode getMode() const { return fMode; } |
| 113 | |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 114 | static constexpr char kErrorMsg_DrawSkippedGpuOnly[] = "This test is for GPU configs only."; |
| 115 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 116 | DrawResult gpuSetup(GrDirectContext* context, SkCanvas* canvas) { |
Robert Phillips | d26d25e | 2020-06-25 13:26:22 -0400 | [diff] [blame] | 117 | SkString errorMsg; |
| 118 | return this->gpuSetup(context, canvas, &errorMsg); |
| 119 | } |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 120 | DrawResult gpuSetup(GrDirectContext*, SkCanvas*, SkString* errorMsg); |
Robert Phillips | b795bea | 2020-06-25 12:38:53 -0400 | [diff] [blame] | 121 | void gpuTeardown(); |
Robert Phillips | 889d613 | 2020-06-16 11:11:33 -0400 | [diff] [blame] | 122 | |
Robert Phillips | 83b749a | 2020-06-25 11:41:19 -0400 | [diff] [blame] | 123 | void onceBeforeDraw() { |
| 124 | if (!fHaveCalledOnceBeforeDraw) { |
| 125 | fHaveCalledOnceBeforeDraw = true; |
| 126 | this->onOnceBeforeDraw(); |
| 127 | } |
| 128 | } |
| 129 | |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 130 | DrawResult draw(SkCanvas* canvas) { |
| 131 | SkString errorMsg; |
| 132 | return this->draw(canvas, &errorMsg); |
| 133 | } |
| 134 | DrawResult draw(SkCanvas*, SkString* errorMsg); |
| 135 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 136 | void drawBackground(SkCanvas*); |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 137 | DrawResult drawContent(SkCanvas* canvas) { |
| 138 | SkString errorMsg; |
| 139 | return this->drawContent(canvas, &errorMsg); |
| 140 | } |
| 141 | DrawResult drawContent(SkCanvas*, SkString* errorMsg); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 142 | |
mtklein | f4ba321 | 2015-01-28 15:32:24 -0800 | [diff] [blame] | 143 | SkISize getISize() { return this->onISize(); } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 144 | const char* getName(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 145 | |
Mike Klein | 9707e90 | 2019-02-07 16:18:22 -0500 | [diff] [blame] | 146 | virtual bool runAsBench() const; |
mtklein | cf5d9c9 | 2015-01-23 10:31:45 -0800 | [diff] [blame] | 147 | |
reed@google.com | 487b560 | 2013-02-01 15:01:24 +0000 | [diff] [blame] | 148 | SkScalar width() { |
| 149 | return SkIntToScalar(this->getISize().width()); |
| 150 | } |
| 151 | SkScalar height() { |
scroggo@google.com | ab02627 | 2013-04-12 22:14:03 +0000 | [diff] [blame] | 152 | return SkIntToScalar(this->getISize().height()); |
reed@google.com | 487b560 | 2013-02-01 15:01:24 +0000 | [diff] [blame] | 153 | } |
| 154 | |
reed@google.com | b4b49cc | 2011-12-06 16:15:42 +0000 | [diff] [blame] | 155 | SkColor getBGColor() const { return fBGColor; } |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 156 | void setBGColor(SkColor); |
reed@google.com | 30db599 | 2011-08-29 17:41:02 +0000 | [diff] [blame] | 157 | |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 158 | // helper: fill a rect in the specified color based on the GM's getISize bounds. |
reed@google.com | 2d6ef52 | 2012-01-03 17:20:38 +0000 | [diff] [blame] | 159 | void drawSizeBounds(SkCanvas*, SkColor); |
| 160 | |
Hal Canary | 4124807 | 2019-07-11 16:32:53 -0400 | [diff] [blame] | 161 | bool animate(double /*nanos*/); |
Hal Canary | c74a550 | 2019-07-08 14:55:15 -0400 | [diff] [blame] | 162 | virtual bool onChar(SkUnichar); |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 163 | |
Mike Reed | 81f60ec | 2018-05-15 10:09:52 -0400 | [diff] [blame] | 164 | bool getControls(SkMetaData* controls) { return this->onGetControls(controls); } |
| 165 | void setControls(const SkMetaData& controls) { this->onSetControls(controls); } |
| 166 | |
Chris Dalton | 5b5403e | 2019-06-05 11:54:39 -0600 | [diff] [blame] | 167 | virtual void modifyGrContextOptions(GrContextOptions*); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 168 | |
Tyler Denniston | 45f94f8 | 2020-02-04 16:09:08 -0500 | [diff] [blame] | 169 | virtual std::unique_ptr<verifiers::VerifierList> getVerifiers() const; |
| 170 | |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 171 | protected: |
Robert Phillips | 889d613 | 2020-06-16 11:11:33 -0400 | [diff] [blame] | 172 | // onGpuSetup is called once before any other processing with a direct context. |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 173 | virtual DrawResult onGpuSetup(GrDirectContext*, SkString*) { return DrawResult::kOk; } |
Robert Phillips | b795bea | 2020-06-25 12:38:53 -0400 | [diff] [blame] | 174 | virtual void onGpuTeardown() {} |
Mike Klein | 9707e90 | 2019-02-07 16:18:22 -0500 | [diff] [blame] | 175 | virtual void onOnceBeforeDraw(); |
Robert Phillips | 889d613 | 2020-06-16 11:11:33 -0400 | [diff] [blame] | 176 | virtual DrawResult onDraw(SkCanvas*, SkString* errorMsg); |
Mike Klein | 9707e90 | 2019-02-07 16:18:22 -0500 | [diff] [blame] | 177 | virtual void onDraw(SkCanvas*); |
| 178 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 179 | virtual SkISize onISize() = 0; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 180 | virtual SkString onShortName() = 0; |
mtklein | 1c40292 | 2015-01-23 11:07:07 -0800 | [diff] [blame] | 181 | |
Hal Canary | 4124807 | 2019-07-11 16:32:53 -0400 | [diff] [blame] | 182 | virtual bool onAnimate(double /*nanos*/); |
Mike Klein | 9707e90 | 2019-02-07 16:18:22 -0500 | [diff] [blame] | 183 | virtual bool onGetControls(SkMetaData*); |
| 184 | virtual void onSetControls(const SkMetaData&); |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 185 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 186 | private: |
Robert Phillips | e922953 | 2020-06-26 10:10:49 -0400 | [diff] [blame] | 187 | Mode fMode; |
| 188 | SkString fShortName; |
| 189 | SkColor fBGColor; |
| 190 | bool fHaveCalledOnceBeforeDraw = false; |
| 191 | bool fGpuSetup = false; |
| 192 | DrawResult fGpuSetupResult = DrawResult::kOk; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 193 | }; |
| 194 | |
Hal Canary | edda565 | 2019-08-05 10:28:09 -0400 | [diff] [blame] | 195 | using GMFactory = std::unique_ptr<skiagm::GM> (*)(); |
| 196 | using GMRegistry = sk_tools::Registry<GMFactory>; |
halcanary | f62c634 | 2015-01-12 15:27:46 -0800 | [diff] [blame] | 197 | |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 198 | // A GpuGM replaces the onDraw method with one that also accepts GPU objects alongside the |
| 199 | // SkCanvas. Its onDraw is only invoked on GPU configs; on non-GPU configs it will automatically |
| 200 | // draw a GPU-only message and abort. |
| 201 | class GpuGM : public GM { |
halcanary | f62c634 | 2015-01-12 15:27:46 -0800 | [diff] [blame] | 202 | public: |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 203 | GpuGM(SkColor backgroundColor = SK_ColorWHITE) : GM(backgroundColor) {} |
Tyler Denniston | 45f94f8 | 2020-02-04 16:09:08 -0500 | [diff] [blame] | 204 | |
| 205 | // TODO(tdenniston): Currently GpuGMs don't have verifiers (because they do not render on |
| 206 | // CPU), but we may want to be able to verify the output images standalone, without |
| 207 | // requiring a gold image for comparison. |
| 208 | std::unique_ptr<verifiers::VerifierList> getVerifiers() const override { return nullptr; } |
| 209 | |
Chris Dalton | 382b122 | 2019-02-07 10:05:55 +0000 | [diff] [blame] | 210 | private: |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 211 | using GM::onDraw; |
| 212 | DrawResult onDraw(SkCanvas*, SkString* errorMsg) final; |
Mike Klein | 9707e90 | 2019-02-07 16:18:22 -0500 | [diff] [blame] | 213 | |
Robert Phillips | 95c250c | 2020-06-29 15:36:12 -0400 | [diff] [blame] | 214 | virtual DrawResult onDraw(GrRecordingContext*, GrRenderTargetContext*, SkCanvas*, |
Mike Klein | 9707e90 | 2019-02-07 16:18:22 -0500 | [diff] [blame] | 215 | SkString* errorMsg); |
Robert Phillips | 95c250c | 2020-06-29 15:36:12 -0400 | [diff] [blame] | 216 | virtual void onDraw(GrRecordingContext*, GrRenderTargetContext*, SkCanvas*); |
Chris Dalton | f5efa78 | 2019-02-05 17:42:14 -0700 | [diff] [blame] | 217 | }; |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 218 | |
| 219 | // SimpleGM is intended for basic GMs that can define their entire implementation inside a |
| 220 | // single "draw" function pointer. |
| 221 | class SimpleGM : public GM { |
| 222 | public: |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 223 | using DrawProc = DrawResult(*)(SkCanvas*, SkString*); |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 224 | SimpleGM(SkColor bgColor, const SkString& name, const SkISize& size, DrawProc drawProc) |
| 225 | : GM(bgColor), fName(name), fSize(size), fDrawProc(drawProc) {} |
| 226 | |
| 227 | private: |
Mike Klein | 9707e90 | 2019-02-07 16:18:22 -0500 | [diff] [blame] | 228 | SkISize onISize() override; |
| 229 | SkString onShortName() override; |
| 230 | DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override; |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 231 | |
| 232 | const SkString fName; |
| 233 | const SkISize fSize; |
| 234 | const DrawProc fDrawProc; |
| 235 | }; |
| 236 | |
| 237 | class SimpleGpuGM : public GpuGM { |
| 238 | public: |
Robert Phillips | 95c250c | 2020-06-29 15:36:12 -0400 | [diff] [blame] | 239 | using DrawProc = DrawResult(*)(GrRecordingContext*, GrRenderTargetContext*, |
| 240 | SkCanvas*, SkString* errorMsg); |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 241 | SimpleGpuGM(SkColor bgColor, const SkString& name, const SkISize& size, DrawProc drawProc) |
| 242 | : GpuGM(bgColor), fName(name), fSize(size), fDrawProc(drawProc) {} |
| 243 | |
| 244 | private: |
Mike Klein | 9707e90 | 2019-02-07 16:18:22 -0500 | [diff] [blame] | 245 | SkISize onISize() override; |
| 246 | SkString onShortName() override; |
Robert Phillips | 95c250c | 2020-06-29 15:36:12 -0400 | [diff] [blame] | 247 | DrawResult onDraw(GrRecordingContext* ctx, GrRenderTargetContext* rtc, SkCanvas* canvas, |
Mike Klein | 9707e90 | 2019-02-07 16:18:22 -0500 | [diff] [blame] | 248 | SkString* errorMsg) override; |
Chris Dalton | 3a77837 | 2019-02-07 15:23:36 -0700 | [diff] [blame] | 249 | |
| 250 | const SkString fName; |
| 251 | const SkISize fSize; |
| 252 | const DrawProc fDrawProc; |
| 253 | }; |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 254 | } // namespace skiagm |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 255 | |
Mike Klein | c9eace8 | 2018-10-31 10:49:38 -0400 | [diff] [blame] | 256 | void MarkGMGood(SkCanvas*, SkScalar x, SkScalar y); |
| 257 | void MarkGMBad (SkCanvas*, SkScalar x, SkScalar y); |
| 258 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 259 | #endif |