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 | |
epoger@google.com | d4af56c | 2011-07-25 16:27:59 +0000 | [diff] [blame] | 11 | #include "SkBitmap.h" |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 12 | #include "SkCanvas.h" |
| 13 | #include "SkPaint.h" |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 14 | #include "SkSize.h" |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 15 | #include "SkString.h" |
| 16 | #include "SkTRegistry.h" |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 17 | #include "sk_tool_utils.h" |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 18 | |
mtklein@google.com | 62b50b7 | 2013-09-16 20:42:15 +0000 | [diff] [blame] | 19 | #if SK_SUPPORT_GPU |
| 20 | #include "GrContext.h" |
| 21 | #endif |
| 22 | |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 23 | #define DEF_GM(code) \ |
sugoi@google.com | 0f0d9b7 | 2013-02-27 15:41:12 +0000 | [diff] [blame] | 24 | static skiagm::GM* SK_MACRO_APPEND_LINE(F_)(void*) { code; } \ |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 25 | static skiagm::GMRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_)); |
| 26 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 27 | namespace skiagm { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 28 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 29 | class GM { |
| 30 | public: |
| 31 | GM(); |
| 32 | virtual ~GM(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 33 | |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 34 | enum Flags { |
commit-bot@chromium.org | 805df1a | 2013-08-16 19:18:12 +0000 | [diff] [blame] | 35 | kSkipPDF_Flag = 1 << 0, |
| 36 | kSkipPicture_Flag = 1 << 1, |
| 37 | kSkipPipe_Flag = 1 << 2, |
| 38 | kSkipPipeCrossProcess_Flag = 1 << 3, |
| 39 | kSkipTiled_Flag = 1 << 4, |
| 40 | kSkip565_Flag = 1 << 5, |
| 41 | kSkipScaledReplay_Flag = 1 << 6, |
| 42 | kSkipGPU_Flag = 1 << 7, |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 43 | kSkipPDFRasterization_Flag = 1 << 8, |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 44 | |
| 45 | kGPUOnly_Flag = 1 << 9, |
commit-bot@chromium.org | 6adce67 | 2014-02-03 14:48:17 +0000 | [diff] [blame] | 46 | |
| 47 | kAsBench_Flag = 1 << 10, // Run the GM as a benchmark in the bench tool |
mtklein | e4636aa | 2014-07-09 13:10:58 -0700 | [diff] [blame] | 48 | |
| 49 | kNoBBH_Flag = 1 << 11, // May draw wrong using a bounding-box hierarchy |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 52 | enum Mode { |
| 53 | kGM_Mode, |
| 54 | kSample_Mode, |
| 55 | kBench_Mode, |
| 56 | }; |
| 57 | |
| 58 | void setMode(Mode mode) { fMode = mode; } |
| 59 | Mode getMode() const { return fMode; } |
| 60 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 61 | void draw(SkCanvas*); |
| 62 | void drawBackground(SkCanvas*); |
| 63 | void drawContent(SkCanvas*); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 64 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 65 | SkISize getISize() { return this->onISize(); } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 66 | const char* getName(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 67 | |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 68 | uint32_t getFlags() const { |
| 69 | return this->onGetFlags(); |
| 70 | } |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 71 | |
reed@google.com | 487b560 | 2013-02-01 15:01:24 +0000 | [diff] [blame] | 72 | SkScalar width() { |
| 73 | return SkIntToScalar(this->getISize().width()); |
| 74 | } |
| 75 | SkScalar height() { |
scroggo@google.com | ab02627 | 2013-04-12 22:14:03 +0000 | [diff] [blame] | 76 | return SkIntToScalar(this->getISize().height()); |
reed@google.com | 487b560 | 2013-02-01 15:01:24 +0000 | [diff] [blame] | 77 | } |
| 78 | |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 79 | // TODO(vandebo) Instead of exposing this, we should run all the GMs |
| 80 | // with and without an initial transform. |
| 81 | // Most GMs will return the identity matrix, but some PDFs tests |
| 82 | // require setting the initial transform. |
| 83 | SkMatrix getInitialTransform() const { |
commit-bot@chromium.org | f4f9df4 | 2013-09-26 20:44:24 +0000 | [diff] [blame] | 84 | SkMatrix matrix = fStarterMatrix; |
| 85 | matrix.preConcat(this->onGetInitialTransform()); |
| 86 | return matrix; |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 87 | } |
| 88 | |
reed@google.com | b4b49cc | 2011-12-06 16:15:42 +0000 | [diff] [blame] | 89 | SkColor getBGColor() const { return fBGColor; } |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 90 | void setBGColor(SkColor); |
reed@google.com | 30db599 | 2011-08-29 17:41:02 +0000 | [diff] [blame] | 91 | |
reed@google.com | 2d6ef52 | 2012-01-03 17:20:38 +0000 | [diff] [blame] | 92 | // helper: fill a rect in the specified color based on the |
| 93 | // GM's getISize bounds. |
| 94 | void drawSizeBounds(SkCanvas*, SkColor); |
| 95 | |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 96 | bool isCanvasDeferred() const { return fCanvasIsDeferred; } |
| 97 | void setCanvasIsDeferred(bool isDeferred) { |
| 98 | fCanvasIsDeferred = isDeferred; |
| 99 | } |
| 100 | |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 101 | const SkMatrix& getStarterMatrix() { return fStarterMatrix; } |
| 102 | void setStarterMatrix(const SkMatrix& matrix) { |
| 103 | fStarterMatrix = matrix; |
| 104 | } |
commit-bot@chromium.org | f4f9df4 | 2013-09-26 20:44:24 +0000 | [diff] [blame] | 105 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 106 | protected: |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 107 | virtual void onOnceBeforeDraw() {} |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 108 | virtual void onDraw(SkCanvas*) = 0; |
| 109 | virtual void onDrawBackground(SkCanvas*); |
| 110 | virtual SkISize onISize() = 0; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 111 | virtual SkString onShortName() = 0; |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 112 | virtual uint32_t onGetFlags() const { return 0; } |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 113 | virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); } |
| 114 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 115 | private: |
commit-bot@chromium.org | b21fac1 | 2014-02-07 21:13:11 +0000 | [diff] [blame] | 116 | Mode fMode; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 117 | SkString fShortName; |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 118 | SkColor fBGColor; |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 119 | bool fCanvasIsDeferred; // work-around problem in srcmode.cpp |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 120 | bool fHaveCalledOnceBeforeDraw; |
commit-bot@chromium.org | f4f9df4 | 2013-09-26 20:44:24 +0000 | [diff] [blame] | 121 | SkMatrix fStarterMatrix; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
mtklein@google.com | bd6343b | 2013-09-04 17:20:18 +0000 | [diff] [blame] | 124 | typedef SkTRegistry<GM*(*)(void*)> GMRegistry; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | #endif |