blob: df1e34746b36633fe238222740e1cacaf25d2e4e [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
joshualitt8a6697a2015-09-30 12:11:07 -070036void Benchmark::delayedSetup() {
37 this->onDelayedSetup();
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +000038}
39
robertphillips5b693772014-11-21 06:19:36 -080040void Benchmark::perCanvasPreDraw(SkCanvas* canvas) {
41 this->onPerCanvasPreDraw(canvas);
42}
43
joshualitt8a6697a2015-09-30 12:11:07 -070044void Benchmark::preDraw(SkCanvas* canvas) {
45 this->onPreDraw(canvas);
46}
47
48void Benchmark::postDraw(SkCanvas* canvas) {
49 this->onPostDraw(canvas);
50}
51
robertphillips5b693772014-11-21 06:19:36 -080052void Benchmark::perCanvasPostDraw(SkCanvas* canvas) {
53 this->onPerCanvasPostDraw(canvas);
54}
55
mtkleina1ebeb22015-10-01 09:43:39 -070056void Benchmark::draw(int loops, SkCanvas* canvas) {
mtklein38c05872014-10-02 13:03:58 -070057 SkAutoCanvasRestore ar(canvas, true/*save now*/);
commit-bot@chromium.org33614712013-12-03 18:17:16 +000058 this->onDraw(loops, canvas);
reed@android.combd700c32009-01-05 03:34:50 +000059}
60
tfarinaf168b862014-06-19 12:32:29 -070061void Benchmark::setupPaint(SkPaint* paint) {
reed@android.com4bc19832009-01-19 20:08:35 +000062 paint->setAlpha(fForceAlpha);
kelvinly762c7182014-07-09 12:25:27 -070063 paint->setAntiAlias(true);
reed93a12152015-03-16 10:08:34 -070064 paint->setFilterQuality(kNone_SkFilterQuality);
reed@android.com4e635f92009-10-19 17:39:46 +000065
reed@google.comef77ec22013-05-29 15:39:54 +000066 paint->setFlags((paint->getFlags() & ~fClearMask) | fOrMask);
67
reed@android.com4e635f92009-10-19 17:39:46 +000068 if (SkTriState::kDefault != fDither) {
69 paint->setDither(SkTriState::kTrue == fDither);
70 }
reed@android.com4bc19832009-01-19 20:08:35 +000071}
72
tfarinaf168b862014-06-19 12:32:29 -070073SkIPoint Benchmark::onGetSize() {
reed@android.com0c9da392010-02-22 19:50:13 +000074 return SkIPoint::Make(640, 480);
reed@android.comf523e252009-01-26 23:15:37 +000075}