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 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 36 | void Benchmark::preDraw() { |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 37 | this->onPreDraw(); |
| 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 | |
| 44 | void Benchmark::perCanvasPostDraw(SkCanvas* canvas) { |
| 45 | this->onPerCanvasPostDraw(canvas); |
| 46 | } |
| 47 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 48 | void Benchmark::draw(const int loops, SkCanvas* canvas) { |
mtklein | 38c0587 | 2014-10-02 13:03:58 -0700 | [diff] [blame] | 49 | SkAutoCanvasRestore ar(canvas, true/*save now*/); |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 50 | this->onDraw(loops, canvas); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 51 | } |
| 52 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 53 | void Benchmark::setupPaint(SkPaint* paint) { |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 54 | paint->setAlpha(fForceAlpha); |
kelvinly | 762c718 | 2014-07-09 12:25:27 -0700 | [diff] [blame] | 55 | paint->setAntiAlias(true); |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 56 | paint->setFilterQuality(kNone_SkFilterQuality); |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 57 | |
reed@google.com | ef77ec2 | 2013-05-29 15:39:54 +0000 | [diff] [blame] | 58 | paint->setFlags((paint->getFlags() & ~fClearMask) | fOrMask); |
| 59 | |
reed@android.com | 4e635f9 | 2009-10-19 17:39:46 +0000 | [diff] [blame] | 60 | if (SkTriState::kDefault != fDither) { |
| 61 | paint->setDither(SkTriState::kTrue == fDither); |
| 62 | } |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 63 | } |
| 64 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 65 | SkIPoint Benchmark::onGetSize() { |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 66 | return SkIPoint::Make(640, 480); |
reed@android.com | f523e25 | 2009-01-26 23:15:37 +0000 | [diff] [blame] | 67 | } |