1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "Benchmark.h"
9 
10 #include "SkCanvas.h"
11 #include "SkPaint.h"
12 #include "SkParse.h"
13 
14 const char* SkTriState::Name[] = { "default", "true", "false" };
15 
16 template BenchRegistry* BenchRegistry::gHead;
17 
Benchmark()18 Benchmark::Benchmark() {
19     fForceAlpha = 0xFF;
20     fDither = SkTriState::kDefault;
21     fOrMask = fClearMask = 0;
22 }
23 
getName()24 const char* Benchmark::getName() {
25     return this->onGetName();
26 }
27 
getUniqueName()28 const char* Benchmark::getUniqueName() {
29     return this->onGetUniqueName();
30 }
31 
getSize()32 SkIPoint Benchmark::getSize() {
33     return this->onGetSize();
34 }
35 
preDraw()36 void Benchmark::preDraw() {
37     this->onPreDraw();
38 }
39 
perCanvasPreDraw(SkCanvas * canvas)40 void Benchmark::perCanvasPreDraw(SkCanvas* canvas) {
41     this->onPerCanvasPreDraw(canvas);
42 }
43 
perCanvasPostDraw(SkCanvas * canvas)44 void Benchmark::perCanvasPostDraw(SkCanvas* canvas) {
45     this->onPerCanvasPostDraw(canvas);
46 }
47 
draw(const int loops,SkCanvas * canvas)48 void Benchmark::draw(const int loops, SkCanvas* canvas) {
49     SkAutoCanvasRestore ar(canvas, true/*save now*/);
50     this->onDraw(loops, canvas);
51 }
52 
setupPaint(SkPaint * paint)53 void Benchmark::setupPaint(SkPaint* paint) {
54     paint->setAlpha(fForceAlpha);
55     paint->setAntiAlias(true);
56     paint->setFilterQuality(kNone_SkFilterQuality);
57 
58     paint->setFlags((paint->getFlags() & ~fClearMask) | fOrMask);
59 
60     if (SkTriState::kDefault != fDither) {
61         paint->setDither(SkTriState::kTrue == fDither);
62     }
63 }
64 
onGetSize()65 SkIPoint Benchmark::onGetSize() {
66     return SkIPoint::Make(640, 480);
67 }
68