1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBenchLogger.h"
#include "BenchTimer.h"
#include "PictureBenchmark.h"
#include "SkCanvas.h"
#include "SkPicture.h"
#include "SkString.h"
#include "picture_utils.h"
#include "TimerData.h"
namespace sk_tools {
PictureBenchmark::PictureBenchmark()
: fRepeats(1)
, fLogger(NULL)
, fRenderer(NULL)
, fLogPerIter(false)
, fPrintMin(false)
, fShowWallTime(false)
, fShowTruncatedWallTime(false)
, fShowCpuTime(true)
, fShowTruncatedCpuTime(false)
, fShowGpuTime(false)
{}
PictureBenchmark::~PictureBenchmark() {
SkSafeUnref(fRenderer);
}
BenchTimer* PictureBenchmark::setupTimer() {
#if SK_SUPPORT_GPU
if (fRenderer != NULL && fRenderer->isUsingGpuDevice()) {
return SkNEW_ARGS(BenchTimer, (fRenderer->getGLContext()));
} else {
return SkNEW_ARGS(BenchTimer, (NULL));
}
#else
return SkNEW_ARGS(BenchTimer, (NULL));
#endif
}
void PictureBenchmark::logProgress(const char msg[]) {
if (fLogger != NULL) {
fLogger->logProgress(msg);
}
}
PictureRenderer* PictureBenchmark::setRenderer(sk_tools::PictureRenderer* renderer) {
SkRefCnt_SafeAssign(fRenderer, renderer);
return renderer;
}
void PictureBenchmark::run(SkPicture* pict) {
SkASSERT(pict);
if (NULL == pict) {
return;
}
SkASSERT(fRenderer != NULL);
if (NULL == fRenderer) {
return;
}
fRenderer->init(pict);
// We throw this away to remove first time effects (such as paging in this program)
fRenderer->setup();
fRenderer->render(NULL);
fRenderer->resetState();
BenchTimer* timer = this->setupTimer();
bool usingGpu = false;
#if SK_SUPPORT_GPU
usingGpu = fRenderer->isUsingGpuDevice();
#endif
TimerData timerData(fRenderer->getPerIterTimeFormat(), fRenderer->getNormalTimeFormat());
for (int i = 0; i < fRepeats; ++i) {
fRenderer->setup();
timer->start();
fRenderer->render(NULL);
timer->truncatedEnd();
// Finishes gl context
fRenderer->resetState();
timer->end();
timerData.appendTimes(timer, fRepeats - 1 == i);
}
const char* configName = usingGpu ? "gpu" : "raster";
SkString result = timerData.getResult(fLogPerIter, fPrintMin, fRepeats,
configName, fShowWallTime, fShowTruncatedWallTime,
fShowCpuTime, fShowTruncatedCpuTime,
usingGpu && fShowGpuTime);
result.append("\n");
this->logProgress(result.c_str());
fRenderer->end();
SkDELETE(timer);
}
}
|