2012-08-01 17:53:29 +00:00
|
|
|
/*
|
|
|
|
* 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 "SkTypes.h"
|
2012-09-07 15:21:18 +00:00
|
|
|
#include "SkBenchLogger.h"
|
2012-08-01 17:53:29 +00:00
|
|
|
#include "BenchTimer.h"
|
|
|
|
#include "PictureBenchmark.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPicture.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "picture_utils.h"
|
2012-09-07 15:21:18 +00:00
|
|
|
#include "TimerData.h"
|
2012-08-01 17:53:29 +00:00
|
|
|
|
|
|
|
namespace sk_tools {
|
|
|
|
|
2012-08-20 15:03:47 +00:00
|
|
|
BenchTimer* PictureBenchmark::setupTimer() {
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
PictureRenderer* renderer = getRenderer();
|
|
|
|
|
|
|
|
if (renderer != NULL && renderer->isUsingGpuDevice()) {
|
2012-08-20 15:03:54 +00:00
|
|
|
return SkNEW_ARGS(BenchTimer, (renderer->getGLContext()));
|
2012-08-20 15:03:47 +00:00
|
|
|
} else {
|
2012-08-20 15:03:54 +00:00
|
|
|
return SkNEW_ARGS(BenchTimer, (NULL));
|
2012-08-20 15:03:47 +00:00
|
|
|
}
|
|
|
|
#else
|
2012-08-20 15:03:54 +00:00
|
|
|
return SkNEW_ARGS(BenchTimer, (NULL));
|
2012-08-20 15:03:47 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
void PictureBenchmark::logProgress(const char msg[]) {
|
|
|
|
if (fLogger != NULL) {
|
|
|
|
fLogger->logProgress(msg);
|
2012-08-07 17:11:33 +00:00
|
|
|
}
|
2012-08-01 17:53:29 +00:00
|
|
|
}
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
void PictureBenchmark::run(SkPicture* pict) {
|
2012-08-07 17:11:33 +00:00
|
|
|
SkASSERT(pict);
|
2012-08-20 15:03:44 +00:00
|
|
|
if (NULL == pict) {
|
2012-08-07 17:11:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
PictureRenderer* renderer = this->getRenderer();
|
|
|
|
SkASSERT(renderer != NULL);
|
|
|
|
if (NULL == renderer) {
|
2012-08-07 17:11:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-09-07 15:21:18 +00:00
|
|
|
renderer->init(pict);
|
2012-08-01 17:53:29 +00:00
|
|
|
|
|
|
|
// We throw this away to remove first time effects (such as paging in this
|
|
|
|
// program)
|
2012-09-07 15:21:18 +00:00
|
|
|
renderer->setup();
|
|
|
|
renderer->render(false);
|
|
|
|
renderer->resetState();
|
2012-08-01 17:53:29 +00:00
|
|
|
|
2012-08-20 15:03:47 +00:00
|
|
|
BenchTimer* timer = this->setupTimer();
|
2012-09-07 15:21:18 +00:00
|
|
|
bool usingGpu = false;
|
2012-08-20 15:03:52 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-09-07 15:21:18 +00:00
|
|
|
usingGpu = renderer->isUsingGpuDevice();
|
2012-08-20 15:03:52 +00:00
|
|
|
#endif
|
2012-08-20 15:03:47 +00:00
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
TimerData timerData(renderer->getPerIterTimeFormat(), renderer->getNormalTimeFormat());
|
2012-08-01 17:53:29 +00:00
|
|
|
for (int i = 0; i < fRepeats; ++i) {
|
2012-09-07 15:21:18 +00:00
|
|
|
renderer->setup();
|
2012-08-01 17:53:29 +00:00
|
|
|
|
2012-08-20 15:03:52 +00:00
|
|
|
timer->start();
|
2012-09-07 15:21:18 +00:00
|
|
|
renderer->render(false);
|
|
|
|
timer->truncatedEnd();
|
2012-08-20 15:03:52 +00:00
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
// Finishes gl context
|
|
|
|
renderer->resetState();
|
2012-08-20 15:03:47 +00:00
|
|
|
timer->end();
|
2012-08-01 17:53:29 +00:00
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
timerData.appendTimes(timer, fRepeats - 1 == i);
|
2012-08-01 17:53:29 +00:00
|
|
|
}
|
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
// FIXME: Pass these options on the command line.
|
|
|
|
bool logPerIter = false;
|
|
|
|
bool printMin = false;
|
|
|
|
const char* configName = usingGpu ? "gpu" : "raster";
|
|
|
|
bool showWallTime = true;
|
|
|
|
bool showTruncatedWallTime = false;
|
|
|
|
bool showCpuTime = false;
|
|
|
|
bool showTruncatedCpuTime = false;
|
|
|
|
SkString result = timerData.getResult(logPerIter, printMin, fRepeats,
|
|
|
|
configName, showWallTime, showTruncatedWallTime,
|
|
|
|
showCpuTime, showTruncatedCpuTime, usingGpu);
|
|
|
|
result.append("\n");
|
|
|
|
this->logProgress(result.c_str());
|
2012-08-20 15:04:09 +00:00
|
|
|
|
2012-09-07 15:21:18 +00:00
|
|
|
renderer->end();
|
2012-08-20 15:04:09 +00:00
|
|
|
SkDELETE(timer);
|
2012-08-01 17:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|