keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 8 | #include "SkBenchLogger.h" |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 9 | #include "BenchTimer.h" |
| 10 | #include "PictureBenchmark.h" |
| 11 | #include "SkCanvas.h" |
| 12 | #include "SkPicture.h" |
| 13 | #include "SkString.h" |
| 14 | #include "picture_utils.h" |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 15 | #include "TimerData.h" |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 16 | |
| 17 | namespace sk_tools { |
| 18 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 19 | PictureBenchmark::PictureBenchmark() |
| 20 | : fRepeats(1) |
| 21 | , fLogger(NULL) |
| 22 | , fRenderer(NULL) |
| 23 | , fLogPerIter(false) |
| 24 | , fPrintMin(false) |
| 25 | , fShowWallTime(false) |
| 26 | , fShowTruncatedWallTime(false) |
| 27 | , fShowCpuTime(true) |
| 28 | , fShowTruncatedCpuTime(false) |
| 29 | , fShowGpuTime(false) |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 30 | , fTimeIndividualTiles(false) |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 31 | {} |
| 32 | |
| 33 | PictureBenchmark::~PictureBenchmark() { |
| 34 | SkSafeUnref(fRenderer); |
| 35 | } |
| 36 | |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 37 | BenchTimer* PictureBenchmark::setupTimer() { |
| 38 | #if SK_SUPPORT_GPU |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 39 | if (fRenderer != NULL && fRenderer->isUsingGpuDevice()) { |
| 40 | return SkNEW_ARGS(BenchTimer, (fRenderer->getGLContext())); |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 41 | } |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 42 | #endif |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 43 | return SkNEW_ARGS(BenchTimer, (NULL)); |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 44 | } |
| 45 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 46 | void PictureBenchmark::logProgress(const char msg[]) { |
| 47 | if (fLogger != NULL) { |
| 48 | fLogger->logProgress(msg); |
| 49 | } |
| 50 | } |
| 51 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 52 | PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* renderer) { |
| 53 | SkRefCnt_SafeAssign(fRenderer, renderer); |
| 54 | return renderer; |
| 55 | } |
| 56 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 57 | void PictureBenchmark::run(SkPicture* pict) { |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 58 | SkASSERT(pict); |
keyar@chromium.org | 78a35c5 | 2012-08-20 15:03:44 +0000 | [diff] [blame] | 59 | if (NULL == pict) { |
keyar@chromium.org | 9d696c0 | 2012-08-07 17:11:33 +0000 | [diff] [blame] | 60 | return; |
| 61 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 62 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 63 | SkASSERT(fRenderer != NULL); |
| 64 | if (NULL == fRenderer) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 65 | return; |
| 66 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 67 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 68 | fRenderer->init(pict); |
| 69 | |
| 70 | // We throw this away to remove first time effects (such as paging in this program) |
| 71 | fRenderer->setup(); |
scroggo@google.com | 81f9d2e | 2012-09-20 14:54:21 +0000 | [diff] [blame] | 72 | fRenderer->render(NULL); |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 73 | fRenderer->resetState(); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 74 | |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 75 | BenchTimer* timer = this->setupTimer(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 76 | bool usingGpu = false; |
keyar@chromium.org | f8a513f | 2012-08-20 15:03:52 +0000 | [diff] [blame] | 77 | #if SK_SUPPORT_GPU |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 78 | usingGpu = fRenderer->isUsingGpuDevice(); |
keyar@chromium.org | f8a513f | 2012-08-20 15:03:52 +0000 | [diff] [blame] | 79 | #endif |
keyar@chromium.org | 77a5522 | 2012-08-20 15:03:47 +0000 | [diff] [blame] | 80 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 81 | if (fTimeIndividualTiles) { |
| 82 | TiledPictureRenderer* tiledRenderer = fRenderer->getTiledRenderer(); |
| 83 | SkASSERT(tiledRenderer); |
| 84 | if (NULL == tiledRenderer) { |
| 85 | return; |
| 86 | } |
| 87 | int xTiles, yTiles; |
| 88 | if (!tiledRenderer->tileDimensions(xTiles, yTiles)) { |
| 89 | return; |
| 90 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 91 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 92 | // Insert a newline so that each tile is reported on its own line (separate from the line |
| 93 | // that describes the skp being run). |
| 94 | this->logProgress("\n"); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 95 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 96 | int x, y; |
| 97 | while (tiledRenderer->nextTile(x, y)) { |
| 98 | TimerData timerData(tiledRenderer->getPerIterTimeFormat(), |
| 99 | tiledRenderer->getNormalTimeFormat()); |
| 100 | for (int i = 0; i < fRepeats; ++i) { |
| 101 | timer->start(); |
| 102 | tiledRenderer->drawCurrentTile(); |
| 103 | timer->truncatedEnd(); |
| 104 | tiledRenderer->resetState(); |
| 105 | timer->end(); |
| 106 | timerData.appendTimes(timer, fRepeats - 1 == i); |
| 107 | } |
| 108 | SkString configName = tiledRenderer->getConfigName(); |
| 109 | configName.appendf(": tile [%i,%i] out of [%i,%i]", x, y, xTiles, yTiles); |
| 110 | SkString result = timerData.getResult(fLogPerIter, fPrintMin, fRepeats, |
| 111 | configName.c_str(), fShowWallTime, |
| 112 | fShowTruncatedWallTime, fShowCpuTime, |
| 113 | fShowTruncatedCpuTime, usingGpu && fShowGpuTime); |
| 114 | result.append("\n"); |
| 115 | this->logProgress(result.c_str()); |
| 116 | } |
| 117 | } else { |
| 118 | TimerData timerData(fRenderer->getPerIterTimeFormat(), fRenderer->getNormalTimeFormat()); |
| 119 | for (int i = 0; i < fRepeats; ++i) { |
| 120 | fRenderer->setup(); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 121 | |
scroggo@google.com | cbcef70 | 2012-12-13 22:09:28 +0000 | [diff] [blame] | 122 | timer->start(); |
| 123 | fRenderer->render(NULL); |
| 124 | timer->truncatedEnd(); |
| 125 | |
| 126 | // Finishes gl context |
| 127 | fRenderer->resetState(); |
| 128 | timer->end(); |
| 129 | |
| 130 | timerData.appendTimes(timer, fRepeats - 1 == i); |
| 131 | } |
| 132 | |
| 133 | SkString configName = fRenderer->getConfigName(); |
| 134 | SkString result = timerData.getResult(fLogPerIter, fPrintMin, fRepeats, |
| 135 | configName.c_str(), fShowWallTime, |
| 136 | fShowTruncatedWallTime, fShowCpuTime, |
| 137 | fShowTruncatedCpuTime, usingGpu && fShowGpuTime); |
| 138 | result.append("\n"); |
| 139 | this->logProgress(result.c_str()); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 140 | } |
| 141 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 142 | fRenderer->end(); |
keyar@chromium.org | 378c97f | 2012-08-20 15:04:09 +0000 | [diff] [blame] | 143 | SkDELETE(timer); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | } |