blob: bf622b0683d4fee7884924bb7fe76c3f154c94a2 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 */
tfarinabcbc1782014-06-18 14:32:48 -07007
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
tfarinabcbc1782014-06-18 14:32:48 -07009
mtklein38c05872014-10-02 13:03:58 -070010#include "SkCanvas.h"
reed@android.com4bc19832009-01-19 20:08:35 +000011#include "SkPaint.h"
reed@android.com0c9da392010-02-22 19:50:13 +000012#include "SkParse.h"
reed@android.com4bc19832009-01-19 20:08:35 +000013
mtklein@google.comc2897432013-09-10 19:23:38 +000014const char* SkTriState::Name[] = { "default", "true", "false" };
15
reed@android.comf523e252009-01-26 23:15:37 +000016template BenchRegistry* BenchRegistry::gHead;
17
tfarinaf168b862014-06-19 12:32:29 -070018Benchmark::Benchmark() {
reed@android.com4bc19832009-01-19 20:08:35 +000019 fForceAlpha = 0xFF;
reed@android.com4e635f92009-10-19 17:39:46 +000020 fDither = SkTriState::kDefault;
reed@google.comef77ec22013-05-29 15:39:54 +000021 fOrMask = fClearMask = 0;
reed@android.com4bc19832009-01-19 20:08:35 +000022}
reed@android.combd700c32009-01-05 03:34:50 +000023
tfarinaf168b862014-06-19 12:32:29 -070024const char* Benchmark::getName() {
reed@android.combd700c32009-01-05 03:34:50 +000025 return this->onGetName();
26}
27
mtklein96289052014-09-10 12:05:59 -070028const char* Benchmark::getUniqueName() {
29 return this->onGetUniqueName();
30}
31
tfarinaf168b862014-06-19 12:32:29 -070032SkIPoint Benchmark::getSize() {
reed@android.combd700c32009-01-05 03:34:50 +000033 return this->onGetSize();
34}
35
tfarinaf168b862014-06-19 12:32:29 -070036void Benchmark::preDraw() {
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +000037 this->onPreDraw();
38}
39
robertphillips5b693772014-11-21 06:19:36 -080040void Benchmark::perCanvasPreDraw(SkCanvas* canvas) {
41 this->onPerCanvasPreDraw(canvas);
42}
43
44void Benchmark::perCanvasPostDraw(SkCanvas* canvas) {
45 this->onPerCanvasPostDraw(canvas);
46}
47
tfarinaf168b862014-06-19 12:32:29 -070048void Benchmark::draw(const int loops, SkCanvas* canvas) {
mtklein38c05872014-10-02 13:03:58 -070049 SkAutoCanvasRestore ar(canvas, true/*save now*/);
commit-bot@chromium.org33614712013-12-03 18:17:16 +000050 this->onDraw(loops, canvas);
reed@android.combd700c32009-01-05 03:34:50 +000051}
52
tfarinaf168b862014-06-19 12:32:29 -070053void Benchmark::setupPaint(SkPaint* paint) {
reed@android.com4bc19832009-01-19 20:08:35 +000054 paint->setAlpha(fForceAlpha);
kelvinly762c7182014-07-09 12:25:27 -070055 paint->setAntiAlias(true);
reed93a12152015-03-16 10:08:34 -070056 paint->setFilterQuality(kNone_SkFilterQuality);
reed@android.com4e635f92009-10-19 17:39:46 +000057
reed@google.comef77ec22013-05-29 15:39:54 +000058 paint->setFlags((paint->getFlags() & ~fClearMask) | fOrMask);
59
reed@android.com4e635f92009-10-19 17:39:46 +000060 if (SkTriState::kDefault != fDither) {
61 paint->setDither(SkTriState::kTrue == fDither);
62 }
reed@android.com4bc19832009-01-19 20:08:35 +000063}
64
tfarinaf168b862014-06-19 12:32:29 -070065SkIPoint Benchmark::onGetSize() {
reed@android.com0c9da392010-02-22 19:50:13 +000066 return SkIPoint::Make(640, 480);
reed@android.comf523e252009-01-26 23:15:37 +000067}