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" |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 12 | #include "SkCanvas.h" |
epoger@google.com | d4af56c | 2011-07-25 16:27:59 +0000 | [diff] [blame] | 13 | #include "SkDevice.h" |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 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 | |
reed@google.com | 4117a24 | 2012-10-30 20:26:58 +0000 | [diff] [blame] | 19 | #define DEF_GM(code) \ |
| 20 | static skiagm::GM* SK_MACRO_APPEND_LINE(F_)(void* p) { code; } \ |
| 21 | static skiagm::GMRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_)); |
| 22 | |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 23 | namespace skiagm { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 24 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 25 | static inline SkISize make_isize(int w, int h) { |
| 26 | SkISize sz; |
| 27 | sz.set(w, h); |
| 28 | return sz; |
| 29 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 30 | |
| 31 | class GM { |
| 32 | public: |
| 33 | GM(); |
| 34 | virtual ~GM(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 35 | |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 36 | enum Flags { |
| 37 | kSkipPDF_Flag = 1 << 0, |
scroggo@google.com | 5af9b20 | 2012-06-04 17:17:36 +0000 | [diff] [blame] | 38 | kSkipPicture_Flag = 1 << 1, |
scroggo@google.com | 6325886 | 2012-08-15 16:32:19 +0000 | [diff] [blame] | 39 | kSkipPipe_Flag = 1 << 2, |
| 40 | kSkipTiled_Flag = 1 << 3, |
reed@google.com | 1b6c73d | 2012-10-10 15:17:24 +0000 | [diff] [blame] | 41 | kSkip565_Flag = 1 << 4, |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 44 | void draw(SkCanvas*); |
| 45 | void drawBackground(SkCanvas*); |
| 46 | void drawContent(SkCanvas*); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 47 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 48 | SkISize getISize() { return this->onISize(); } |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 49 | const char* shortName(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 50 | |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 51 | uint32_t getFlags() const { |
| 52 | return this->onGetFlags(); |
| 53 | } |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 54 | |
| 55 | // TODO(vandebo) Instead of exposing this, we should run all the GMs |
| 56 | // with and without an initial transform. |
| 57 | // Most GMs will return the identity matrix, but some PDFs tests |
| 58 | // require setting the initial transform. |
| 59 | SkMatrix getInitialTransform() const { |
| 60 | return this->onGetInitialTransform(); |
| 61 | } |
| 62 | |
reed@google.com | b4b49cc | 2011-12-06 16:15:42 +0000 | [diff] [blame] | 63 | SkColor getBGColor() const { return fBGColor; } |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 64 | void setBGColor(SkColor); |
reed@google.com | 30db599 | 2011-08-29 17:41:02 +0000 | [diff] [blame] | 65 | |
reed@google.com | 2d6ef52 | 2012-01-03 17:20:38 +0000 | [diff] [blame] | 66 | // helper: fill a rect in the specified color based on the |
| 67 | // GM's getISize bounds. |
| 68 | void drawSizeBounds(SkCanvas*, SkColor); |
| 69 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 70 | static void SetResourcePath(const char* resourcePath) { |
| 71 | gResourcePath = resourcePath; |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 72 | } |
| 73 | |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 74 | bool isCanvasDeferred() const { return fCanvasIsDeferred; } |
| 75 | void setCanvasIsDeferred(bool isDeferred) { |
| 76 | fCanvasIsDeferred = isDeferred; |
| 77 | } |
| 78 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 79 | protected: |
| 80 | static SkString gResourcePath; |
| 81 | |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 82 | virtual void onOnceBeforeDraw() {} |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 83 | virtual void onDraw(SkCanvas*) = 0; |
| 84 | virtual void onDrawBackground(SkCanvas*); |
| 85 | virtual SkISize onISize() = 0; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 86 | virtual SkString onShortName() = 0; |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 87 | virtual uint32_t onGetFlags() const { return 0; } |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 88 | virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); } |
| 89 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 90 | private: |
| 91 | SkString fShortName; |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 92 | SkColor fBGColor; |
reed@google.com | aef7361 | 2012-11-16 13:41:45 +0000 | [diff] [blame] | 93 | bool fCanvasIsDeferred; // work-around problem in srcmode.cpp |
reed@google.com | 7775d66 | 2012-11-27 15:15:58 +0000 | [diff] [blame] | 94 | bool fHaveCalledOnceBeforeDraw; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | typedef SkTRegistry<GM*, void*> GMRegistry; |
| 98 | } |
| 99 | |
| 100 | #endif |