blob: a69402b7ca62534ba5604441341973d704f352b0 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.combd700c32009-01-05 03:34:50 +00008#include "SkBenchmark.h"
reed@android.com4bc19832009-01-19 20:08:35 +00009#include "SkPaint.h"
reed@android.com0c9da392010-02-22 19:50:13 +000010#include "SkParse.h"
reed@android.com4bc19832009-01-19 20:08:35 +000011
reed@android.comf523e252009-01-26 23:15:37 +000012template BenchRegistry* BenchRegistry::gHead;
13
reed@android.come9d00602009-09-02 21:12:42 +000014SkBenchmark::SkBenchmark(void* defineDict) {
15 fDict = reinterpret_cast<const SkTDict<const char*>*>(defineDict);
reed@android.com4bc19832009-01-19 20:08:35 +000016 fForceAlpha = 0xFF;
17 fForceAA = true;
reed@android.com4e635f92009-10-19 17:39:46 +000018 fDither = SkTriState::kDefault;
agl@chromium.org652807b2010-04-27 15:47:34 +000019 fHasStrokeWidth = false;
reed@android.com4bc19832009-01-19 20:08:35 +000020}
reed@android.combd700c32009-01-05 03:34:50 +000021
22const char* SkBenchmark::getName() {
23 return this->onGetName();
24}
25
26SkIPoint SkBenchmark::getSize() {
27 return this->onGetSize();
28}
29
30void SkBenchmark::draw(SkCanvas* canvas) {
31 this->onDraw(canvas);
32}
33
reed@android.com4bc19832009-01-19 20:08:35 +000034void SkBenchmark::setupPaint(SkPaint* paint) {
35 paint->setAlpha(fForceAlpha);
36 paint->setAntiAlias(fForceAA);
reed@android.com29348cb2009-08-04 18:17:15 +000037 paint->setFilterBitmap(fForceFilter);
reed@android.com4e635f92009-10-19 17:39:46 +000038
39 if (SkTriState::kDefault != fDither) {
40 paint->setDither(SkTriState::kTrue == fDither);
41 }
reed@android.com4bc19832009-01-19 20:08:35 +000042}
43
reed@android.come9d00602009-09-02 21:12:42 +000044const char* SkBenchmark::findDefine(const char* key) const {
45 if (fDict) {
46 const char* value;
47 if (fDict->find(key, &value)) {
48 return value;
49 }
50 }
51 return NULL;
52}
53
reed@android.com0c9da392010-02-22 19:50:13 +000054bool SkBenchmark::findDefine32(const char* key, int32_t* value) const {
55 const char* valueStr = this->findDefine(key);
56 if (valueStr) {
57 SkParse::FindS32(valueStr, value);
58 return true;
59 }
60 return false;
61}
62
63bool SkBenchmark::findDefineScalar(const char* key, SkScalar* value) const {
64 const char* valueStr = this->findDefine(key);
65 if (valueStr) {
66 SkParse::FindScalar(valueStr, value);
67 return true;
68 }
69 return false;
70}
71
reed@android.comf523e252009-01-26 23:15:37 +000072///////////////////////////////////////////////////////////////////////////////
reed@android.com4bc19832009-01-19 20:08:35 +000073
reed@android.comf523e252009-01-26 23:15:37 +000074SkIPoint SkBenchmark::onGetSize() {
reed@android.com0c9da392010-02-22 19:50:13 +000075 return SkIPoint::Make(640, 480);
reed@android.comf523e252009-01-26 23:15:37 +000076}