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 | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 15 | #include "SkRefCnt.h" |
reed@android.com | dd0ac28 | 2009-06-20 02:38:16 +0000 | [diff] [blame] | 16 | #include "SkSize.h" |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 17 | #include "SkString.h" |
| 18 | #include "SkTRegistry.h" |
| 19 | |
| 20 | namespace skiagm { |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 21 | |
| 22 | static inline SkISize make_isize(int w, int h) { |
| 23 | SkISize sz; |
| 24 | sz.set(w, h); |
| 25 | return sz; |
| 26 | } |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 27 | |
| 28 | class GM { |
| 29 | public: |
| 30 | GM(); |
| 31 | virtual ~GM(); |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 32 | |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 33 | enum Flags { |
| 34 | kSkipPDF_Flag = 1 << 0, |
| 35 | kSkipPicture_Flag = 1 << 1 |
| 36 | }; |
| 37 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 38 | void draw(SkCanvas*); |
| 39 | void drawBackground(SkCanvas*); |
| 40 | void drawContent(SkCanvas*); |
| 41 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 42 | SkISize getISize() { return this->onISize(); } |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 43 | const char* shortName(); |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 44 | |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 45 | uint32_t getFlags() const { |
| 46 | return this->onGetFlags(); |
| 47 | } |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 48 | |
| 49 | // TODO(vandebo) Instead of exposing this, we should run all the GMs |
| 50 | // with and without an initial transform. |
| 51 | // Most GMs will return the identity matrix, but some PDFs tests |
| 52 | // require setting the initial transform. |
| 53 | SkMatrix getInitialTransform() const { |
| 54 | return this->onGetInitialTransform(); |
| 55 | } |
| 56 | |
reed@google.com | b4b49cc | 2011-12-06 16:15:42 +0000 | [diff] [blame] | 57 | SkColor getBGColor() const { return fBGColor; } |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 58 | void setBGColor(SkColor); |
reed@google.com | 30db599 | 2011-08-29 17:41:02 +0000 | [diff] [blame] | 59 | |
reed@google.com | 2d6ef52 | 2012-01-03 17:20:38 +0000 | [diff] [blame] | 60 | // helper: fill a rect in the specified color based on the |
| 61 | // GM's getISize bounds. |
| 62 | void drawSizeBounds(SkCanvas*, SkColor); |
| 63 | |
robertphillips@google.com | 8570b5c | 2012-03-20 17:40:58 +0000 | [diff] [blame] | 64 | static void SetResourcePath(const char* resourcePath) { |
| 65 | gResourcePath = resourcePath; |
| 66 | } |
| 67 | |
| 68 | protected: |
| 69 | static SkString gResourcePath; |
| 70 | |
| 71 | virtual void onDraw(SkCanvas*) = 0; |
| 72 | virtual void onDrawBackground(SkCanvas*); |
| 73 | virtual SkISize onISize() = 0; |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 74 | virtual SkString onShortName() = 0; |
reed@google.com | fbc2117 | 2011-09-19 19:08:33 +0000 | [diff] [blame] | 75 | virtual uint32_t onGetFlags() const { return 0; } |
vandebo@chromium.org | 79d3cb4 | 2012-03-21 17:34:30 +0000 | [diff] [blame] | 76 | virtual SkMatrix onGetInitialTransform() const { return SkMatrix::I(); } |
| 77 | |
reed@android.com | 8015dd8 | 2009-06-21 00:49:18 +0000 | [diff] [blame] | 78 | private: |
| 79 | SkString fShortName; |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 80 | SkColor fBGColor; |
reed@android.com | 00dae86 | 2009-06-10 15:38:48 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | typedef SkTRegistry<GM*, void*> GMRegistry; |
| 84 | } |
| 85 | |
| 86 | #endif |