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"
|
|
|
|
#include "BenchTimer.h"
|
|
|
|
#include "PictureBenchmark.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPicture.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "picture_utils.h"
|
|
|
|
|
|
|
|
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-08-01 17:53:29 +00:00
|
|
|
void PipePictureBenchmark::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-08-01 17:53:29 +00:00
|
|
|
|
2012-08-20 15:03:41 +00:00
|
|
|
fRenderer.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-08-20 15:03:41 +00:00
|
|
|
fRenderer.render();
|
2012-08-20 15:03:52 +00:00
|
|
|
fRenderer.resetState();
|
2012-08-01 17:53:29 +00:00
|
|
|
|
2012-08-20 15:03:47 +00:00
|
|
|
BenchTimer* timer = this->setupTimer();
|
2012-08-20 15:03:52 +00:00
|
|
|
double wall_time = 0;
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
double gpu_time = 0;
|
|
|
|
#endif
|
2012-08-20 15:03:47 +00:00
|
|
|
|
2012-08-01 17:53:29 +00:00
|
|
|
for (int i = 0; i < fRepeats; ++i) {
|
2012-08-20 15:03:52 +00:00
|
|
|
timer->start();
|
2012-08-20 15:03:41 +00:00
|
|
|
fRenderer.render();
|
2012-08-20 15:03:52 +00:00
|
|
|
timer->end();
|
|
|
|
fRenderer.resetState();
|
|
|
|
|
|
|
|
wall_time += timer->fWall;
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
if (fRenderer.isUsingGpuDevice()) {
|
|
|
|
gpu_time += timer->fGpu;
|
|
|
|
}
|
|
|
|
#endif
|
2012-08-01 17:53:29 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 15:03:41 +00:00
|
|
|
fRenderer.end();
|
2012-08-07 17:11:33 +00:00
|
|
|
|
2012-08-20 15:03:52 +00:00
|
|
|
SkDebugf("pipe: msecs = %6.2f", wall_time / fRepeats);
|
|
|
|
#if SK_SUPPORT_GPU
|
2012-08-20 15:03:41 +00:00
|
|
|
if (fRenderer.isUsingGpuDevice()) {
|
2012-08-20 15:03:52 +00:00
|
|
|
SkDebugf(" gmsecs = %6.2f", gpu_time / fRepeats);
|
2012-08-20 15:03:41 +00:00
|
|
|
}
|
2012-08-20 15:03:52 +00:00
|
|
|
#endif
|
2012-08-20 15:03:41 +00:00
|
|
|
SkDebugf("\n");
|
2012-08-20 15:03:47 +00:00
|
|
|
|
2012-08-20 15:03:54 +00:00
|
|
|
SkDELETE(timer);
|
2012-08-01 17:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RecordPictureBenchmark::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-08-20 15:03:47 +00:00
|
|
|
BenchTimer* timer = setupTimer();
|
2012-08-01 17:53:29 +00:00
|
|
|
double wall_time = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < fRepeats + 1; ++i) {
|
|
|
|
SkPicture replayer;
|
|
|
|
SkCanvas* recorder = replayer.beginRecording(pict->width(), pict->height());
|
|
|
|
|
2012-08-20 15:03:47 +00:00
|
|
|
timer->start();
|
2012-08-01 17:53:29 +00:00
|
|
|
recorder->drawPicture(*pict);
|
2012-08-20 15:03:47 +00:00
|
|
|
timer->end();
|
2012-08-01 17:53:29 +00:00
|
|
|
|
|
|
|
// We want to ignore first time effects
|
|
|
|
if (i > 0) {
|
2012-08-20 15:03:47 +00:00
|
|
|
wall_time += timer->fWall;
|
2012-08-01 17:53:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkDebugf("record: msecs = %6.5f\n", wall_time / fRepeats);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimplePictureBenchmark::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-08-01 17:53:29 +00:00
|
|
|
|
2012-08-20 15:03:41 +00:00
|
|
|
fRenderer.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-08-20 15:03:41 +00:00
|
|
|
fRenderer.render();
|
2012-08-20 15:03:52 +00:00
|
|
|
fRenderer.resetState();
|
|
|
|
|
2012-08-01 17:53:29 +00:00
|
|
|
|
2012-08-20 15:03:47 +00:00
|
|
|
BenchTimer* timer = this->setupTimer();
|
2012-08-20 15:03:52 +00:00
|
|
|
double wall_time = 0;
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
double gpu_time = 0;
|
|
|
|
#endif
|
2012-08-20 15:03:47 +00:00
|
|
|
|
2012-08-01 17:53:29 +00:00
|
|
|
for (int i = 0; i < fRepeats; ++i) {
|
2012-08-20 15:03:52 +00:00
|
|
|
timer->start();
|
2012-08-20 15:03:41 +00:00
|
|
|
fRenderer.render();
|
2012-08-20 15:03:52 +00:00
|
|
|
timer->end();
|
|
|
|
fRenderer.resetState();
|
|
|
|
|
|
|
|
wall_time += timer->fWall;
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
if (fRenderer.isUsingGpuDevice()) {
|
|
|
|
gpu_time += timer->fGpu;
|
|
|
|
}
|
|
|
|
#endif
|
2012-08-01 17:53:29 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 15:03:41 +00:00
|
|
|
fRenderer.end();
|
2012-08-07 17:11:33 +00:00
|
|
|
|
2012-08-20 15:03:52 +00:00
|
|
|
SkDebugf("simple: msecs = %6.2f", wall_time / fRepeats);
|
|
|
|
#if SK_SUPPORT_GPU
|
2012-08-20 15:03:41 +00:00
|
|
|
if (fRenderer.isUsingGpuDevice()) {
|
2012-08-20 15:03:52 +00:00
|
|
|
SkDebugf(" gmsecs = %6.2f", gpu_time / fRepeats);
|
2012-08-20 15:03:41 +00:00
|
|
|
}
|
2012-08-20 15:03:52 +00:00
|
|
|
#endif
|
2012-08-20 15:03:41 +00:00
|
|
|
SkDebugf("\n");
|
2012-08-20 15:03:47 +00:00
|
|
|
|
2012-08-20 15:03:54 +00:00
|
|
|
SkDELETE(timer);
|
2012-08-01 17:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TiledPictureBenchmark::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-08-20 15:03:41 +00:00
|
|
|
fRenderer.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-08-20 15:03:41 +00:00
|
|
|
fRenderer.drawTiles();
|
2012-08-20 15:03:52 +00:00
|
|
|
fRenderer.resetState();
|
2012-08-01 17:53:29 +00:00
|
|
|
|
2012-08-20 15:03:47 +00:00
|
|
|
BenchTimer* timer = setupTimer();
|
2012-08-20 15:03:52 +00:00
|
|
|
double wall_time = 0;
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
double gpu_time = 0;
|
|
|
|
#endif
|
|
|
|
|
2012-08-01 17:53:29 +00:00
|
|
|
for (int i = 0; i < fRepeats; ++i) {
|
2012-08-20 15:03:52 +00:00
|
|
|
timer->start();
|
2012-08-20 15:03:41 +00:00
|
|
|
fRenderer.drawTiles();
|
2012-08-20 15:03:52 +00:00
|
|
|
timer->end();
|
|
|
|
fRenderer.resetState();
|
|
|
|
|
|
|
|
wall_time += timer->fWall;
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
if (fRenderer.isUsingGpuDevice()) {
|
|
|
|
gpu_time += timer->fGpu;
|
|
|
|
}
|
|
|
|
#endif
|
2012-08-01 17:53:29 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 15:03:41 +00:00
|
|
|
fRenderer.end();
|
2012-08-07 17:11:33 +00:00
|
|
|
|
2012-08-20 15:03:41 +00:00
|
|
|
SkDebugf("%i_tiles_%ix%i: msecs = %6.2f", fRenderer.numTiles(), fRenderer.getTileWidth(),
|
2012-08-20 15:03:52 +00:00
|
|
|
fRenderer.getTileHeight(), wall_time / fRepeats);
|
|
|
|
#if SK_SUPPORT_GPU
|
2012-08-20 15:03:41 +00:00
|
|
|
if (fRenderer.isUsingGpuDevice()) {
|
2012-08-20 15:03:52 +00:00
|
|
|
SkDebugf(" gmsecs = %6.2f", gpu_time / fRepeats);
|
2012-08-20 15:03:41 +00:00
|
|
|
}
|
2012-08-20 15:03:52 +00:00
|
|
|
#endif
|
2012-08-20 15:03:41 +00:00
|
|
|
SkDebugf("\n");
|
2012-08-20 15:03:54 +00:00
|
|
|
|
|
|
|
SkDELETE(timer);
|
2012-08-01 17:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnflattenPictureBenchmark::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-08-20 15:03:47 +00:00
|
|
|
BenchTimer* timer = setupTimer();
|
2012-08-01 17:53:29 +00:00
|
|
|
double wall_time = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < fRepeats + 1; ++i) {
|
|
|
|
SkPicture replayer;
|
|
|
|
SkCanvas* recorder = replayer.beginRecording(pict->width(), pict->height());
|
|
|
|
|
|
|
|
recorder->drawPicture(*pict);
|
|
|
|
|
2012-08-20 15:03:47 +00:00
|
|
|
timer->start();
|
2012-08-01 17:53:29 +00:00
|
|
|
replayer.endRecording();
|
2012-08-20 15:03:47 +00:00
|
|
|
timer->end();
|
2012-08-01 17:53:29 +00:00
|
|
|
|
|
|
|
// We want to ignore first time effects
|
|
|
|
if (i > 0) {
|
2012-08-20 15:03:47 +00:00
|
|
|
wall_time += timer->fWall;
|
2012-08-01 17:53:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkDebugf("unflatten: msecs = %6.4f\n", wall_time / fRepeats);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|