epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 7 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 9 | |
mtklein | 38c0587 | 2014-10-02 13:03:58 -0700 | [diff] [blame] | 10 | #include "SkCanvas.h" |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 11 | #include "SkPaint.h" |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 12 | #include "SkParse.h" |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 13 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 14 | const char* SkTriState::Name[] = { "default", "true", "false" }; |
| 15 | |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 16 | template BenchRegistry* BenchRegistry::gHead; |
| 17 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 18 | Benchmark::Benchmark() { |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 19 | fForceAlpha = 0xFF; |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 20 | fDither = SkTriState::kDefault; |
reed@google.com | ef77ec2 | 2013-05-29 15:39:54 +0000 | [diff] [blame] | 21 | fOrMask = fClearMask = 0; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 22 | } |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 23 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 24 | const char* Benchmark::getName() { |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 25 | return this->onGetName(); |
| 26 | } |
| 27 | |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 28 | const char* Benchmark::getUniqueName() { |
| 29 | return this->onGetUniqueName(); |
| 30 | } |
| 31 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 32 | SkIPoint Benchmark::getSize() { |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 33 | return this->onGetSize(); |
| 34 | } |
| 35 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 36 | void Benchmark::delayedSetup() { |
| 37 | this->onDelayedSetup(); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 38 | } |
| 39 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 40 | void Benchmark::perCanvasPreDraw(SkCanvas* canvas) { |
| 41 | this->onPerCanvasPreDraw(canvas); |
| 42 | } |
| 43 | |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 44 | void Benchmark::preDraw(SkCanvas* canvas) { |
| 45 | this->onPreDraw(canvas); |
| 46 | } |
| 47 | |
| 48 | void Benchmark::postDraw(SkCanvas* canvas) { |
| 49 | this->onPostDraw(canvas); |
| 50 | } |
| 51 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 52 | void Benchmark::perCanvasPostDraw(SkCanvas* canvas) { |
| 53 | this->onPerCanvasPostDraw(canvas); |
| 54 | } |
| 55 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 56 | void Benchmark::draw(int loops, SkCanvas* canvas) { |
mtklein | 38c0587 | 2014-10-02 13:03:58 -0700 | [diff] [blame] | 57 | SkAutoCanvasRestore ar(canvas, true/*save now*/); |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 58 | this->onDraw(loops, canvas); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 59 | } |
| 60 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 61 | void Benchmark::setupPaint(SkPaint* paint) { |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 62 | paint->setAlpha(fForceAlpha); |
kelvinly | 762c718 | 2014-07-09 12:25:27 -0700 | [diff] [blame] | 63 | paint->setAntiAlias(true); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 64 | paint->setFilterQuality(kNone_SkFilterQuality); |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 65 | |
reed@google.com | ef77ec2 | 2013-05-29 15:39:54 +0000 | [diff] [blame] | 66 | paint->setFlags((paint->getFlags() & ~fClearMask) | fOrMask); |
| 67 | |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 68 | if (SkTriState::kDefault != fDither) { |
| 69 | paint->setDither(SkTriState::kTrue == fDither); |
| 70 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 71 | } |
| 72 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 73 | SkIPoint Benchmark::onGetSize() { |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 74 | return SkIPoint::Make(640, 480); |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 75 | } |