skia2/tools/PictureBenchmark.cpp
keyar@chromium.org 9d696c0d04 Refactored the bitmap creation into PictureRenderer.
Further, the picture is also stored in the PictureRenderer.

The main gain of all of this is that we will not have to change how the device in more than one place when we end up adding different devices.

Review URL: https://codereview.appspot.com/6458074

git-svn-id: http://skia.googlecode.com/svn/trunk@4990 2bbb7eff-a529-9590-31e7-b0007b416f81
2012-08-07 17:11:33 +00:00

146 lines
3.1 KiB
C++

/*
* 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 {
void PipePictureBenchmark::run(SkPicture* pict) {
SkASSERT(pict);
if (pict == NULL) {
return;
}
renderer.init(pict);
// We throw this away to remove first time effects (such as paging in this
// program)
renderer.render();
BenchTimer timer = BenchTimer(NULL);
timer.start();
for (int i = 0; i < fRepeats; ++i) {
renderer.render();
}
timer.end();
renderer.end();
SkDebugf("pipe: msecs = %6.2f\n", timer.fWall / fRepeats);
}
void RecordPictureBenchmark::run(SkPicture* pict) {
SkASSERT(pict);
if (pict == NULL) {
return;
}
BenchTimer timer = BenchTimer(NULL);
double wall_time = 0;
for (int i = 0; i < fRepeats + 1; ++i) {
SkPicture replayer;
SkCanvas* recorder = replayer.beginRecording(pict->width(), pict->height());
timer.start();
recorder->drawPicture(*pict);
timer.end();
// We want to ignore first time effects
if (i > 0) {
wall_time += timer.fWall;
}
}
SkDebugf("record: msecs = %6.5f\n", wall_time / fRepeats);
}
void SimplePictureBenchmark::run(SkPicture* pict) {
SkASSERT(pict);
if (pict == NULL) {
return;
}
renderer.init(pict);
// We throw this away to remove first time effects (such as paging in this
// program)
renderer.render();
BenchTimer timer = BenchTimer(NULL);
timer.start();
for (int i = 0; i < fRepeats; ++i) {
renderer.render();
}
timer.end();
renderer.end();
printf("simple: msecs = %6.2f\n", timer.fWall / fRepeats);
}
void TiledPictureBenchmark::run(SkPicture* pict) {
SkASSERT(pict);
if (pict == NULL) {
return;
}
renderer.init(pict);
// We throw this away to remove first time effects (such as paging in this
// program)
renderer.drawTiles();
BenchTimer timer = BenchTimer(NULL);
timer.start();
for (int i = 0; i < fRepeats; ++i) {
renderer.drawTiles();
}
timer.end();
renderer.end();
SkDebugf("%i_tiles_%ix%i: msecs = %6.2f\n", renderer.numTiles(), renderer.getTileWidth(),
renderer.getTileHeight(), timer.fWall / fRepeats);
}
void UnflattenPictureBenchmark::run(SkPicture* pict) {
SkASSERT(pict);
if (pict == NULL) {
return;
}
BenchTimer timer = BenchTimer(NULL);
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);
timer.start();
replayer.endRecording();
timer.end();
// We want to ignore first time effects
if (i > 0) {
wall_time += timer.fWall;
}
}
SkDebugf("unflatten: msecs = %6.4f\n", wall_time / fRepeats);
}
}