epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 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" |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 12 | #include "SkBitmapDevice.h" |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 13 | #include "SkCanvas.h" |
| 14 | #include "SkPaint.h" |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 15 | #include "SkSize.h" |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 16 | #include "SkString.h" |
| 17 | #include "SkTRegistry.h" |
| 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 | |
epoger@google.com | 5efdd0c | 2013-03-13 14:18:40 +0000 | [diff] [blame] | 29 | static inline SkISize make_isize(int w, int h) { |
| 30 | SkISize sz; |
| 31 | sz.set(w, h); |
| 32 | return sz; |
| 33 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 34 | |
| 35 | class GM { |
| 36 | public: |
| 37 | GM(); |
| 38 | virtual ~GM(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 39 | |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 40 | enum Flags { |
commit-bot@chromium.org | 805df1a | 2013-08-16 19:18:12 +0000 | [diff] [blame] | 41 | kSkipPDF_Flag = 1 << 0, |
| 42 | kSkipPicture_Flag = 1 << 1, |
| 43 | kSkipPipe_Flag = 1 << 2, |
| 44 | kSkipPipeCrossProcess_Flag = 1 << 3, |
| 45 | kSkipTiled_Flag = 1 << 4, |
| 46 | kSkip565_Flag = 1 << 5, |
| 47 | kSkipScaledReplay_Flag = 1 << 6, |
| 48 | kSkipGPU_Flag = 1 << 7, |
vandebo@chromium.org | 0dcbece | 2013-08-20 23:08:40 +0000 | [diff] [blame] | 49 | kSkipPDFRasterization_Flag = 1 << 8, |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 50 | |
| 51 | kGPUOnly_Flag = 1 << 9, |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 54 | void draw(SkCanvas*); |
| 55 | void drawBackground(SkCanvas*); |
| 56 | void drawContent(SkCanvas*); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 57 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 58 | SkISize getISize() { return this->onISize(); } |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 59 | const char* shortName(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 60 | |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 61 | uint32_t getFlags() const { |
| 62 | return this->onGetFlags(); |
| 63 | } |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 64 | |
reed@google.com | 487b560 | 2013-02-01 15:01:24 +0000 | [diff] [blame] | 65 | SkScalar width() { |
| 66 | return SkIntToScalar(this->getISize().width()); |
| 67 | } |
| 68 | SkScalar height() { |
scroggo@google.com | ab02627 | 2013-04-12 22:14:03 +0000 | [diff] [blame] | 69 | return SkIntToScalar(this->getISize().height()); |
reed@google.com | 487b560 | 2013-02-01 15:01:24 +0000 | [diff] [blame] | 70 | } |
| 71 | |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 72 | // TODO(vandebo) Instead of exposing this, we should run all the GMs |
| 73 | // with and without an initial transform. |
| 74 | // Most GMs will return the identity matrix, but some PDFs tests |
| 75 | // require setting the initial transform. |
| 76 | SkMatrix getInitialTransform() const { |
commit-bot@chromium.org | f4f9df4 | 2013-09-26 20:44:24 +0000 | [diff] [blame] | 77 | SkMatrix matrix = fStarterMatrix; |
| 78 | matrix.preConcat(this->onGetInitialTransform()); |
| 79 | return matrix; |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 80 | } |
| 81 | |
reed@google.com | b4b49cc | 2011-12-06 16:15:42 +0000 | [diff] [blame] | 82 | SkColor getBGColor() const { return fBGColor; } |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 83 | void setBGColor(SkColor); |
reed@google.com | 30db599 | 2011-08-29 17:41:02 +0000 | [diff] [blame] | 84 | |
reed@google.com | 2d6ef52 | 2012-01-03 17:20:38 +0000 | [diff] [blame] | 85 | // helper: fill a rect in the specified color based on the |
| 86 | // GM's getISize bounds. |
| 87 | void drawSizeBounds(SkCanvas*, SkColor); |
| 88 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 89 | static void SetResourcePath(const char* resourcePath) { |
| 90 | gResourcePath = resourcePath; |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 91 | } |
| 92 | |
scroggo@google.com | 2bbc2c9 | 2013-06-14 15:33:20 +0000 | [diff] [blame] | 93 | static SkString& GetResourcePath() { |
| 94 | return gResourcePath; |
| 95 | } |
| 96 | |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 97 | bool isCanvasDeferred() const { return fCanvasIsDeferred; } |
| 98 | void setCanvasIsDeferred(bool isDeferred) { |
| 99 | fCanvasIsDeferred = isDeferred; |
| 100 | } |
| 101 | |
commit-bot@chromium.org | f4f9df4 | 2013-09-26 20:44:24 +0000 | [diff] [blame] | 102 | const SkMatrix& getStarterMatrix() { return fStarterMatrix; } |
| 103 | void setStarterMatrix(const SkMatrix& matrix) { |
| 104 | fStarterMatrix = matrix; |
| 105 | } |
| 106 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 107 | protected: |
| 108 | static SkString gResourcePath; |
| 109 | |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 110 | virtual void onOnceBeforeDraw() {} |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 111 | virtual void onDraw(SkCanvas*) = 0; |
| 112 | virtual void onDrawBackground(SkCanvas*); |
| 113 | virtual SkISize onISize() = 0; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 114 | virtual SkString onShortName() = 0; |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 115 | virtual uint32_t onGetFlags() const { return 0; } |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 116 | virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); } |
| 117 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 118 | private: |
| 119 | SkString fShortName; |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 120 | SkColor fBGColor; |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 121 | bool fCanvasIsDeferred; // work-around problem in srcmode.cpp |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 122 | bool fHaveCalledOnceBeforeDraw; |
commit-bot@chromium.org | f4f9df4 | 2013-09-26 20:44:24 +0000 | [diff] [blame] | 123 | SkMatrix fStarterMatrix; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
mtklein@google.com | bd6343b | 2013-09-04 17:20:18 +0000 | [diff] [blame] | 126 | typedef SkTRegistry<GM*(*)(void*)> GMRegistry; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | #endif |