blob: 6afcd8e9f39e9db09792d148f2c92c6652e6b528 [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
robertphillips@google.com15e9d3e2012-06-21 20:25:03 +000012SK_DEFINE_INST_COUNT(SkBenchmark)
13
reed@android.comf523e252009-01-26 23:15:37 +000014template BenchRegistry* BenchRegistry::gHead;
15
reed@android.come9d00602009-09-02 21:12:42 +000016SkBenchmark::SkBenchmark(void* defineDict) {
17 fDict = reinterpret_cast<const SkTDict<const char*>*>(defineDict);
reed@android.com4bc19832009-01-19 20:08:35 +000018 fForceAlpha = 0xFF;
19 fForceAA = true;
reed@android.com4e635f92009-10-19 17:39:46 +000020 fDither = SkTriState::kDefault;
agl@chromium.org652807b2010-04-27 15:47:34 +000021 fHasStrokeWidth = false;
tomhudson@google.com9dc27132012-09-13 15:50:24 +000022 fIsRendering = true;
reed@android.com4bc19832009-01-19 20:08:35 +000023}
reed@android.combd700c32009-01-05 03:34:50 +000024
25const char* SkBenchmark::getName() {
26 return this->onGetName();
27}
28
29SkIPoint SkBenchmark::getSize() {
30 return this->onGetSize();
31}
32
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +000033void SkBenchmark::preDraw() {
34 this->onPreDraw();
35}
36
reed@android.combd700c32009-01-05 03:34:50 +000037void SkBenchmark::draw(SkCanvas* canvas) {
38 this->onDraw(canvas);
39}
40
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +000041void SkBenchmark::postDraw() {
42 this->onPostDraw();
43}
44
reed@android.com4bc19832009-01-19 20:08:35 +000045void SkBenchmark::setupPaint(SkPaint* paint) {
46 paint->setAlpha(fForceAlpha);
47 paint->setAntiAlias(fForceAA);
reed@android.com29348cb2009-08-04 18:17:15 +000048 paint->setFilterBitmap(fForceFilter);
reed@android.com4e635f92009-10-19 17:39:46 +000049
50 if (SkTriState::kDefault != fDither) {
51 paint->setDither(SkTriState::kTrue == fDither);
52 }
reed@android.com4bc19832009-01-19 20:08:35 +000053}
54
reed@android.come9d00602009-09-02 21:12:42 +000055const 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.com0c9da392010-02-22 19:50:13 +000065bool 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
74bool 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.comf523e252009-01-26 23:15:37 +000083///////////////////////////////////////////////////////////////////////////////
reed@android.com4bc19832009-01-19 20:08:35 +000084
reed@android.comf523e252009-01-26 23:15:37 +000085SkIPoint SkBenchmark::onGetSize() {
reed@android.com0c9da392010-02-22 19:50:13 +000086 return SkIPoint::Make(640, 480);
reed@android.comf523e252009-01-26 23:15:37 +000087}