OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "BenchTimer.h" | 8 #include "Timer.h" |
9 #include "PictureBenchmark.h" | 9 #include "PictureBenchmark.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkPicture.h" | 11 #include "SkPicture.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 #include "picture_utils.h" | 13 #include "picture_utils.h" |
14 | 14 |
15 namespace sk_tools { | 15 namespace sk_tools { |
16 | 16 |
17 PictureBenchmark::PictureBenchmark() | 17 PictureBenchmark::PictureBenchmark() |
18 : fRepeats(1) | 18 : fRepeats(1) |
(...skipping 16 matching lines...) Expand all Loading... |
35 bool truncatedCpu, | 35 bool truncatedCpu, |
36 bool gpu) { | 36 bool gpu) { |
37 fTimerTypes = 0; | 37 fTimerTypes = 0; |
38 fTimerTypes |= wall ? TimerData::kWall_Flag : 0; | 38 fTimerTypes |= wall ? TimerData::kWall_Flag : 0; |
39 fTimerTypes |= truncatedWall ? TimerData::kTruncatedWall_Flag : 0; | 39 fTimerTypes |= truncatedWall ? TimerData::kTruncatedWall_Flag : 0; |
40 fTimerTypes |= cpu ? TimerData::kCpu_Flag : 0; | 40 fTimerTypes |= cpu ? TimerData::kCpu_Flag : 0; |
41 fTimerTypes |= truncatedCpu ? TimerData::kTruncatedCpu_Flag : 0; | 41 fTimerTypes |= truncatedCpu ? TimerData::kTruncatedCpu_Flag : 0; |
42 fTimerTypes |= gpu ? TimerData::kGpu_Flag : 0; | 42 fTimerTypes |= gpu ? TimerData::kGpu_Flag : 0; |
43 } | 43 } |
44 | 44 |
45 BenchTimer* PictureBenchmark::setupTimer(bool useGLTimer) { | 45 Timer* PictureBenchmark::setupTimer(bool useGLTimer) { |
46 #if SK_SUPPORT_GPU | 46 #if SK_SUPPORT_GPU |
47 if (useGLTimer && fRenderer != NULL && fRenderer->isUsingGpuDevice()) { | 47 if (useGLTimer && fRenderer != NULL && fRenderer->isUsingGpuDevice()) { |
48 return SkNEW_ARGS(BenchTimer, (fRenderer->getGLContext())); | 48 return SkNEW_ARGS(Timer, (fRenderer->getGLContext())); |
49 } | 49 } |
50 #endif | 50 #endif |
51 return SkNEW_ARGS(BenchTimer, (NULL)); | 51 return SkNEW_ARGS(Timer, (NULL)); |
52 } | 52 } |
53 | 53 |
54 PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* render
er) { | 54 PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* render
er) { |
55 SkRefCnt_SafeAssign(fRenderer, renderer); | 55 SkRefCnt_SafeAssign(fRenderer, renderer); |
56 return renderer; | 56 return renderer; |
57 } | 57 } |
58 | 58 |
59 void PictureBenchmark::run(SkPicture* pict) { | 59 void PictureBenchmark::run(SkPicture* pict) { |
60 SkASSERT(pict); | 60 SkASSERT(pict); |
61 if (NULL == pict) { | 61 if (NULL == pict) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // The goal of this timer is to make up for a system timer that is n
ot precise enough to | 140 // The goal of this timer is to make up for a system timer that is n
ot precise enough to |
141 // measure the small amount of time it takes to draw one tile once. | 141 // measure the small amount of time it takes to draw one tile once. |
142 // | 142 // |
143 // 2) perTileTimer, along with perTileTimerData, will record each ru
n separately, and | 143 // 2) perTileTimer, along with perTileTimerData, will record each ru
n separately, and |
144 // then take the average. As such, it supports logPerIter and printM
in options. | 144 // then take the average. As such, it supports logPerIter and printM
in options. |
145 // | 145 // |
146 // Although "legal", having two gpu timers running at the same time | 146 // Although "legal", having two gpu timers running at the same time |
147 // seems to cause problems (i.e., INVALID_OPERATIONs) on several | 147 // seems to cause problems (i.e., INVALID_OPERATIONs) on several |
148 // platforms. To work around this, we disable the gpu timer on the | 148 // platforms. To work around this, we disable the gpu timer on the |
149 // long running timer. | 149 // long running timer. |
150 SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer()); | 150 SkAutoTDelete<Timer> longRunningTimer(this->setupTimer()); |
151 TimerData longRunningTimerData(numOuterLoops); | 151 TimerData longRunningTimerData(numOuterLoops); |
152 | 152 |
153 for (int outer = 0; outer < numOuterLoops; ++outer) { | 153 for (int outer = 0; outer < numOuterLoops; ++outer) { |
154 SkAutoTDelete<BenchTimer> perTileTimer(this->setupTimer(false)); | 154 SkAutoTDelete<Timer> perTileTimer(this->setupTimer(false)); |
155 TimerData perTileTimerData(numInnerLoops); | 155 TimerData perTileTimerData(numInnerLoops); |
156 | 156 |
157 longRunningTimer->start(); | 157 longRunningTimer->start(); |
158 for (int inner = 0; inner < numInnerLoops; ++inner) { | 158 for (int inner = 0; inner < numInnerLoops; ++inner) { |
159 perTileTimer->start(); | 159 perTileTimer->start(); |
160 tiledRenderer->drawCurrentTile(); | 160 tiledRenderer->drawCurrentTile(); |
161 perTileTimer->truncatedEnd(); | 161 perTileTimer->truncatedEnd(); |
162 tiledRenderer->resetState(false); // flush & swapBuffers, b
ut don't Finish | 162 tiledRenderer->resetState(false); // flush & swapBuffers, b
ut don't Finish |
163 perTileTimer->end(); | 163 perTileTimer->end(); |
164 SkAssertResult(perTileTimerData.appendTimes(perTileTimer.get
())); | 164 SkAssertResult(perTileTimerData.appendTimes(perTileTimer.get
())); |
(...skipping 29 matching lines...) Expand all Loading... |
194 } | 194 } |
195 fWriter->addTileFlag(PictureResultsWriter::kAvg); | 195 fWriter->addTileFlag(PictureResultsWriter::kAvg); |
196 fWriter->tileData( | 196 fWriter->tileData( |
197 &longRunningTimerData, | 197 &longRunningTimerData, |
198 tiledRenderer->getNormalTimeFormat().c_str(), | 198 tiledRenderer->getNormalTimeFormat().c_str(), |
199 TimerData::kAvg_Result, | 199 TimerData::kAvg_Result, |
200 timerTypes, | 200 timerTypes, |
201 numInnerLoops); | 201 numInnerLoops); |
202 } | 202 } |
203 } else { | 203 } else { |
204 SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer()); | 204 SkAutoTDelete<Timer> longRunningTimer(this->setupTimer()); |
205 TimerData longRunningTimerData(numOuterLoops); | 205 TimerData longRunningTimerData(numOuterLoops); |
206 | 206 |
207 for (int outer = 0; outer < numOuterLoops; ++outer) { | 207 for (int outer = 0; outer < numOuterLoops; ++outer) { |
208 SkAutoTDelete<BenchTimer> perRunTimer(this->setupTimer(false)); | 208 SkAutoTDelete<Timer> perRunTimer(this->setupTimer(false)); |
209 TimerData perRunTimerData(numInnerLoops); | 209 TimerData perRunTimerData(numInnerLoops); |
210 | 210 |
211 longRunningTimer->start(); | 211 longRunningTimer->start(); |
212 for (int inner = 0; inner < numInnerLoops; ++inner) { | 212 for (int inner = 0; inner < numInnerLoops; ++inner) { |
213 fRenderer->setup(); | 213 fRenderer->setup(); |
214 | 214 |
215 perRunTimer->start(); | 215 perRunTimer->start(); |
216 fRenderer->render(NULL); | 216 fRenderer->render(NULL); |
217 perRunTimer->truncatedEnd(); | 217 perRunTimer->truncatedEnd(); |
218 fRenderer->resetState(false); // flush & swapBuffers, but don'
t Finish | 218 fRenderer->resetState(false); // flush & swapBuffers, but don'
t Finish |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 fTimerResult, | 256 fTimerResult, |
257 timerTypes, | 257 timerTypes, |
258 numInnerLoops); | 258 numInnerLoops); |
259 #endif | 259 #endif |
260 } | 260 } |
261 | 261 |
262 fRenderer->end(); | 262 fRenderer->end(); |
263 } | 263 } |
264 | 264 |
265 } | 265 } |
OLD | NEW |