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 | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 8 | #ifndef SkBenchmark_DEFINED |
| 9 | #define SkBenchmark_DEFINED |
| 10 | |
| 11 | #include "SkRefCnt.h" |
| 12 | #include "SkPoint.h" |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 13 | #include "SkTDict.h" |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 14 | #include "SkTRegistry.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 15 | |
tomhudson@google.com | ca529d3 | 2011-10-28 15:34:49 +0000 | [diff] [blame] | 16 | #ifdef SK_DEBUG |
| 17 | #define SkBENCHLOOP(n) 1 |
| 18 | #else |
| 19 | #define SkBENCHLOOP(n) n |
| 20 | #endif |
| 21 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 22 | class SkCanvas; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 23 | class SkPaint; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 24 | |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 25 | class SkTriState { |
| 26 | public: |
| 27 | enum State { |
| 28 | kDefault, |
| 29 | kTrue, |
| 30 | kFalse |
| 31 | }; |
| 32 | }; |
| 33 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 34 | class SkBenchmark : public SkRefCnt { |
| 35 | public: |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 36 | SK_DECLARE_INST_COUNT(SkBenchmark) |
| 37 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 38 | SkBenchmark(void* defineDict); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 39 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 40 | const char* getName(); |
| 41 | SkIPoint getSize(); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 42 | |
| 43 | // Call before draw, allows the benchmark to do setup work outside of the |
| 44 | // timer. When a benchmark is repeatedly drawn, this should be called once |
| 45 | // before the initial draw. |
| 46 | void preDraw(); |
| 47 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 48 | void draw(SkCanvas*); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 49 | |
| 50 | // Call after draw, allows the benchmark to do cleanup work outside of the |
| 51 | // timer. When a benchmark is repeatedly drawn, this is only called once |
| 52 | // after the last draw. |
| 53 | void postDraw(); |
| 54 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 55 | void setForceAlpha(int alpha) { |
| 56 | fForceAlpha = alpha; |
| 57 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 58 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 59 | void setForceAA(bool aa) { |
| 60 | fForceAA = aa; |
| 61 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 62 | |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 63 | void setForceFilter(bool filter) { |
| 64 | fForceFilter = filter; |
| 65 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 66 | |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 67 | void setDither(SkTriState::State state) { |
| 68 | fDither = state; |
| 69 | } |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 70 | |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 71 | void setStrokeWidth(SkScalar width) { |
| 72 | strokeWidth = width; |
| 73 | fHasStrokeWidth = true; |
| 74 | } |
| 75 | |
| 76 | SkScalar getStrokeWidth() { |
| 77 | return strokeWidth; |
| 78 | } |
| 79 | |
| 80 | bool hasStrokeWidth() { |
| 81 | return fHasStrokeWidth; |
| 82 | } |
| 83 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 84 | const char* findDefine(const char* key) const; |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 85 | bool findDefine32(const char* key, int32_t* value) const; |
| 86 | bool findDefineScalar(const char* key, SkScalar* value) const; |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 87 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 88 | protected: |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 89 | void setupPaint(SkPaint* paint); |
| 90 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 91 | virtual const char* onGetName() = 0; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 92 | virtual void onPreDraw() {} |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 93 | virtual void onDraw(SkCanvas*) = 0; |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 94 | virtual void onPostDraw() {} |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 95 | |
| 96 | virtual SkIPoint onGetSize(); |
| 97 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 98 | private: |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 99 | const SkTDict<const char*>* fDict; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 100 | int fForceAlpha; |
| 101 | bool fForceAA; |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 102 | bool fForceFilter; |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 103 | SkTriState::State fDither; |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 104 | bool fHasStrokeWidth; |
| 105 | SkScalar strokeWidth; |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 106 | |
| 107 | typedef SkRefCnt INHERITED; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 110 | typedef SkTRegistry<SkBenchmark*, void*> BenchRegistry; |
| 111 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 112 | #endif |