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; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 22 | } |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 23 | |
| 24 | const char* SkBenchmark::getName() { |
| 25 | return this->onGetName(); |
| 26 | } |
| 27 | |
| 28 | SkIPoint SkBenchmark::getSize() { |
| 29 | return this->onGetSize(); |
| 30 | } |
| 31 | |
| 32 | void SkBenchmark::draw(SkCanvas* canvas) { |
| 33 | this->onDraw(canvas); |
| 34 | } |
| 35 | |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 36 | void SkBenchmark::setupPaint(SkPaint* paint) { |
| 37 | paint->setAlpha(fForceAlpha); |
| 38 | paint->setAntiAlias(fForceAA); |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 39 | paint->setFilterBitmap(fForceFilter); |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 40 | |
| 41 | if (SkTriState::kDefault != fDither) { |
| 42 | paint->setDither(SkTriState::kTrue == fDither); |
| 43 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 44 | } |
| 45 | |
reed@android.com | e9d0060 | 2009-09-02 21:12:42 +0000 | [diff] [blame] | 46 | const char* SkBenchmark::findDefine(const char* key) const { |
| 47 | if (fDict) { |
| 48 | const char* value; |
| 49 | if (fDict->find(key, &value)) { |
| 50 | return value; |
| 51 | } |
| 52 | } |
| 53 | return NULL; |
| 54 | } |
| 55 | |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 56 | bool SkBenchmark::findDefine32(const char* key, int32_t* value) const { |
| 57 | const char* valueStr = this->findDefine(key); |
| 58 | if (valueStr) { |
| 59 | SkParse::FindS32(valueStr, value); |
| 60 | return true; |
| 61 | } |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | bool SkBenchmark::findDefineScalar(const char* key, SkScalar* value) const { |
| 66 | const char* valueStr = this->findDefine(key); |
| 67 | if (valueStr) { |
| 68 | SkParse::FindScalar(valueStr, value); |
| 69 | return true; |
| 70 | } |
| 71 | return false; |
| 72 | } |
| 73 | |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 74 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 75 | |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 76 | SkIPoint SkBenchmark::onGetSize() { |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 77 | return SkIPoint::Make(640, 480); |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 78 | } |