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 | #include "SkBenchmark.h" |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 9 | #include "SkPaint.h" |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 10 | #include "SkParse.h" |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 11 | |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 12 | SK_DEFINE_INST_COUNT(SkBenchmark) |
| 13 | |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 14 | template BenchRegistry* BenchRegistry::gHead; |
| 15 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 16 | SkBenchmark::SkBenchmark(void* defineDict) { |
| 17 | fDict = reinterpret_cast<const SkTDict<const char*>*>(defineDict); |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 18 | fForceAlpha = 0xFF; |
| 19 | fForceAA = true; |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 20 | fDither = SkTriState::kDefault; |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 21 | fHasStrokeWidth = false; |
tomhudson@google.com | 9dc2713 | 2012-09-13 15:50:24 +0000 | [diff] [blame] | 22 | fIsRendering = true; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 23 | } |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 24 | |
| 25 | const char* SkBenchmark::getName() { |
| 26 | return this->onGetName(); |
| 27 | } |
| 28 | |
| 29 | SkIPoint SkBenchmark::getSize() { |
| 30 | return this->onGetSize(); |
| 31 | } |
| 32 | |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 33 | void SkBenchmark::preDraw() { |
| 34 | this->onPreDraw(); |
| 35 | } |
| 36 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 37 | void SkBenchmark::draw(SkCanvas* canvas) { |
| 38 | this->onDraw(canvas); |
| 39 | } |
| 40 | |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 41 | void SkBenchmark::postDraw() { |
| 42 | this->onPostDraw(); |
| 43 | } |
| 44 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 45 | void SkBenchmark::setupPaint(SkPaint* paint) { |
| 46 | paint->setAlpha(fForceAlpha); |
| 47 | paint->setAntiAlias(fForceAA); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 48 | paint->setFilterBitmap(fForceFilter); |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 49 | |
| 50 | if (SkTriState::kDefault != fDither) { |
| 51 | paint->setDither(SkTriState::kTrue == fDither); |
| 52 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 53 | } |
| 54 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 55 | const char* SkBenchmark::findDefine(const char* key) const { |
| 56 | if (fDict) { |
| 57 | const char* value; |
| 58 | if (fDict->find(key, &value)) { |
| 59 | return value; |
| 60 | } |
| 61 | } |
| 62 | return NULL; |
| 63 | } |
| 64 | |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 65 | bool SkBenchmark::findDefine32(const char* key, int32_t* value) const { |
| 66 | const char* valueStr = this->findDefine(key); |
| 67 | if (valueStr) { |
| 68 | SkParse::FindS32(valueStr, value); |
| 69 | return true; |
| 70 | } |
| 71 | return false; |
| 72 | } |
| 73 | |
| 74 | bool SkBenchmark::findDefineScalar(const char* key, SkScalar* value) const { |
| 75 | const char* valueStr = this->findDefine(key); |
| 76 | if (valueStr) { |
| 77 | SkParse::FindScalar(valueStr, value); |
| 78 | return true; |
| 79 | } |
| 80 | return false; |
| 81 | } |
| 82 | |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 83 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 84 | |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 85 | SkIPoint SkBenchmark::onGetSize() { |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 86 | return SkIPoint::Make(640, 480); |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 87 | } |