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 "Timer.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) |
19 , fRenderer(NULL) | 19 , fRenderer(nullptr) |
20 , fTimerResult(TimerData::kAvg_Result) | 20 , fTimerResult(TimerData::kAvg_Result) |
21 , fTimerTypes(0) | 21 , fTimerTypes(0) |
22 , fTimeIndividualTiles(false) | 22 , fTimeIndividualTiles(false) |
23 , fPurgeDecodedTex(false) | 23 , fPurgeDecodedTex(false) |
24 , fWriter(NULL) { | 24 , fWriter(nullptr) { |
25 } | 25 } |
26 | 26 |
27 PictureBenchmark::~PictureBenchmark() { | 27 PictureBenchmark::~PictureBenchmark() { |
28 SkSafeUnref(fRenderer); | 28 SkSafeUnref(fRenderer); |
29 } | 29 } |
30 | 30 |
31 void PictureBenchmark::setTimersToShow(bool wall, | 31 void PictureBenchmark::setTimersToShow(bool wall, |
32 bool truncatedWall, | 32 bool truncatedWall, |
33 bool cpu, | 33 bool cpu, |
34 bool truncatedCpu, | 34 bool truncatedCpu, |
35 bool gpu) { | 35 bool gpu) { |
36 fTimerTypes = 0; | 36 fTimerTypes = 0; |
37 fTimerTypes |= wall ? TimerData::kWall_Flag : 0; | 37 fTimerTypes |= wall ? TimerData::kWall_Flag : 0; |
38 fTimerTypes |= truncatedWall ? TimerData::kTruncatedWall_Flag : 0; | 38 fTimerTypes |= truncatedWall ? TimerData::kTruncatedWall_Flag : 0; |
39 fTimerTypes |= cpu ? TimerData::kCpu_Flag : 0; | 39 fTimerTypes |= cpu ? TimerData::kCpu_Flag : 0; |
40 fTimerTypes |= truncatedCpu ? TimerData::kTruncatedCpu_Flag : 0; | 40 fTimerTypes |= truncatedCpu ? TimerData::kTruncatedCpu_Flag : 0; |
41 fTimerTypes |= gpu ? TimerData::kGpu_Flag : 0; | 41 fTimerTypes |= gpu ? TimerData::kGpu_Flag : 0; |
42 } | 42 } |
43 | 43 |
44 Timer* PictureBenchmark::setupTimer(bool useGLTimer) { | 44 Timer* PictureBenchmark::setupTimer(bool useGLTimer) { |
45 #if SK_SUPPORT_GPU | 45 #if SK_SUPPORT_GPU |
46 if (useGLTimer && fRenderer != NULL && fRenderer->isUsingGpuDevice()) { | 46 if (useGLTimer && fRenderer != nullptr && fRenderer->isUsingGpuDevice()) { |
47 return new Timer(fRenderer->getGLContext()); | 47 return new Timer(fRenderer->getGLContext()); |
48 } | 48 } |
49 #endif | 49 #endif |
50 return new Timer(NULL); | 50 return new Timer(nullptr); |
51 } | 51 } |
52 | 52 |
53 PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* render
er) { | 53 PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* render
er) { |
54 SkRefCnt_SafeAssign(fRenderer, renderer); | 54 SkRefCnt_SafeAssign(fRenderer, renderer); |
55 return renderer; | 55 return renderer; |
56 } | 56 } |
57 | 57 |
58 void PictureBenchmark::run(SkPicture* pict, bool useMultiPictureDraw) { | 58 void PictureBenchmark::run(SkPicture* pict, bool useMultiPictureDraw) { |
59 SkASSERT(pict); | 59 SkASSERT(pict); |
60 if (NULL == pict) { | 60 if (nullptr == pict) { |
61 return; | 61 return; |
62 } | 62 } |
63 | 63 |
64 SkASSERT(fRenderer != NULL); | 64 SkASSERT(fRenderer != nullptr); |
65 if (NULL == fRenderer) { | 65 if (nullptr == fRenderer) { |
66 return; | 66 return; |
67 } | 67 } |
68 | 68 |
69 fRenderer->init(pict, NULL, NULL, NULL, false, useMultiPictureDraw); | 69 fRenderer->init(pict, nullptr, nullptr, nullptr, false, useMultiPictureDraw)
; |
70 | 70 |
71 // We throw this away to remove first time effects (such as paging in this p
rogram) | 71 // We throw this away to remove first time effects (such as paging in this p
rogram) |
72 fRenderer->setup(); | 72 fRenderer->setup(); |
73 | 73 |
74 fRenderer->render(NULL); | 74 fRenderer->render(nullptr); |
75 fRenderer->resetState(true); // flush, swapBuffers and Finish | 75 fRenderer->resetState(true); // flush, swapBuffers and Finish |
76 | 76 |
77 if (fPurgeDecodedTex) { | 77 if (fPurgeDecodedTex) { |
78 fRenderer->purgeTextures(); | 78 fRenderer->purgeTextures(); |
79 } | 79 } |
80 | 80 |
81 bool usingGpu = false; | 81 bool usingGpu = false; |
82 #if SK_SUPPORT_GPU | 82 #if SK_SUPPORT_GPU |
83 usingGpu = fRenderer->isUsingGpuDevice(); | 83 usingGpu = fRenderer->isUsingGpuDevice(); |
84 #endif | 84 #endif |
(...skipping 17 matching lines...) Expand all Loading... |
102 if (TimerData::kPerIter_Result == fTimerResult && fRepeats > 1) { | 102 if (TimerData::kPerIter_Result == fTimerResult && fRepeats > 1) { |
103 // interpret this flag combination to mean: generate 'fRepeats' | 103 // interpret this flag combination to mean: generate 'fRepeats' |
104 // numbers by averaging each rendering 'kNumInnerLoops' times | 104 // numbers by averaging each rendering 'kNumInnerLoops' times |
105 numOuterLoops = fRepeats; | 105 numOuterLoops = fRepeats; |
106 numInnerLoops = kNumInnerLoops; | 106 numInnerLoops = kNumInnerLoops; |
107 } | 107 } |
108 | 108 |
109 if (fTimeIndividualTiles) { | 109 if (fTimeIndividualTiles) { |
110 TiledPictureRenderer* tiledRenderer = fRenderer->getTiledRenderer(); | 110 TiledPictureRenderer* tiledRenderer = fRenderer->getTiledRenderer(); |
111 SkASSERT(tiledRenderer && tiledRenderer->supportsTimingIndividualTiles()
); | 111 SkASSERT(tiledRenderer && tiledRenderer->supportsTimingIndividualTiles()
); |
112 if (NULL == tiledRenderer || !tiledRenderer->supportsTimingIndividualTil
es()) { | 112 if (nullptr == tiledRenderer || !tiledRenderer->supportsTimingIndividual
Tiles()) { |
113 return; | 113 return; |
114 } | 114 } |
115 int xTiles, yTiles; | 115 int xTiles, yTiles; |
116 if (!tiledRenderer->tileDimensions(xTiles, yTiles)) { | 116 if (!tiledRenderer->tileDimensions(xTiles, yTiles)) { |
117 return; | 117 return; |
118 } | 118 } |
119 | 119 |
120 int x, y; | 120 int x, y; |
121 while (tiledRenderer->nextTile(x, y)) { | 121 while (tiledRenderer->nextTile(x, y)) { |
122 // There are two timers, which will behave slightly differently: | 122 // There are two timers, which will behave slightly differently: |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 193 |
194 for (int outer = 0; outer < numOuterLoops; ++outer) { | 194 for (int outer = 0; outer < numOuterLoops; ++outer) { |
195 SkAutoTDelete<Timer> perRunTimer(this->setupTimer(false)); | 195 SkAutoTDelete<Timer> perRunTimer(this->setupTimer(false)); |
196 TimerData perRunTimerData(numInnerLoops); | 196 TimerData perRunTimerData(numInnerLoops); |
197 | 197 |
198 longRunningTimer->start(); | 198 longRunningTimer->start(); |
199 for (int inner = 0; inner < numInnerLoops; ++inner) { | 199 for (int inner = 0; inner < numInnerLoops; ++inner) { |
200 fRenderer->setup(); | 200 fRenderer->setup(); |
201 | 201 |
202 perRunTimer->start(); | 202 perRunTimer->start(); |
203 fRenderer->render(NULL); | 203 fRenderer->render(nullptr); |
204 perRunTimer->truncatedEnd(); | 204 perRunTimer->truncatedEnd(); |
205 fRenderer->resetState(false); // flush & swapBuffers, but don'
t Finish | 205 fRenderer->resetState(false); // flush & swapBuffers, but don'
t Finish |
206 perRunTimer->end(); | 206 perRunTimer->end(); |
207 | 207 |
208 SkAssertResult(perRunTimerData.appendTimes(perRunTimer.get())); | 208 SkAssertResult(perRunTimerData.appendTimes(perRunTimer.get())); |
209 | 209 |
210 if (fPurgeDecodedTex) { | 210 if (fPurgeDecodedTex) { |
211 fRenderer->purgeTextures(); | 211 fRenderer->purgeTextures(); |
212 } | 212 } |
213 } | 213 } |
(...skipping 23 matching lines...) Expand all Loading... |
237 fTimerResult, | 237 fTimerResult, |
238 timerTypes, | 238 timerTypes, |
239 numInnerLoops); | 239 numInnerLoops); |
240 #endif | 240 #endif |
241 } | 241 } |
242 | 242 |
243 fRenderer->end(); | 243 fRenderer->end(); |
244 } | 244 } |
245 | 245 |
246 } | 246 } |
OLD | NEW |