blob: 7a012d9f53211c0776f527f8cb2fa27fe9433cc6 [file] [log] [blame]
keyar@chromium.org163b5672012-08-01 17:53:29 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkTypes.h"
9#include "BenchTimer.h"
10#include "PictureBenchmark.h"
11#include "SkCanvas.h"
12#include "SkPicture.h"
13#include "SkString.h"
14#include "picture_utils.h"
15
16namespace sk_tools {
17
18void PipePictureBenchmark::run(SkPicture* pict) {
19 SkBitmap bitmap;
20 sk_tools::setup_bitmap(&bitmap, pict->width(), pict->height());
21
22 SkCanvas canvas(bitmap);
23
24 renderer.init(*pict);
25
26 // We throw this away to remove first time effects (such as paging in this
27 // program)
28 renderer.render(pict, &canvas);
29
30 BenchTimer timer = BenchTimer(NULL);
31 timer.start();
32 for (int i = 0; i < fRepeats; ++i) {
33 renderer.render(pict, &canvas);
34 }
35 timer.end();
36
37 SkDebugf("pipe: msecs = %6.2f\n", timer.fWall / fRepeats);
38}
39
40void RecordPictureBenchmark::run(SkPicture* pict) {
41 BenchTimer timer = BenchTimer(NULL);
42 double wall_time = 0;
43
44 for (int i = 0; i < fRepeats + 1; ++i) {
45 SkPicture replayer;
46 SkCanvas* recorder = replayer.beginRecording(pict->width(), pict->height());
47
48 timer.start();
49 recorder->drawPicture(*pict);
50 timer.end();
51
52 // We want to ignore first time effects
53 if (i > 0) {
54 wall_time += timer.fWall;
55 }
56 }
57
58 SkDebugf("record: msecs = %6.5f\n", wall_time / fRepeats);
59}
60
61void SimplePictureBenchmark::run(SkPicture* pict) {
62 SkBitmap bitmap;
63 sk_tools::setup_bitmap(&bitmap, pict->width(), pict->height());
64
65 SkCanvas canvas(bitmap);
66
67 renderer.init(*pict);
68
69 // We throw this away to remove first time effects (such as paging in this
70 // program)
71 renderer.render(pict, &canvas);
72
73 BenchTimer timer = BenchTimer(NULL);
74 timer.start();
75 for (int i = 0; i < fRepeats; ++i) {
76 renderer.render(pict, &canvas);
77 }
78 timer.end();
79
80 printf("simple: msecs = %6.2f\n", timer.fWall / fRepeats);
81}
82
83void TiledPictureBenchmark::run(SkPicture* pict) {
84 renderer.init(*pict);
85
86 // We throw this away to remove first time effects (such as paging in this
87 // program)
88 renderer.drawTiles(pict);
89
90 BenchTimer timer = BenchTimer(NULL);
91 timer.start();
92 for (int i = 0; i < fRepeats; ++i) {
93 renderer.drawTiles(pict);
94 }
95 timer.end();
96
97 SkDebugf("%i_tiles_%ix%i: msecs = %6.2f\n", renderer.numTiles(), renderer.getTileWidth(),
98 renderer.getTileHeight(), timer.fWall / fRepeats);
99}
100
101void UnflattenPictureBenchmark::run(SkPicture* pict) {
102 BenchTimer timer = BenchTimer(NULL);
103 double wall_time = 0;
104
105 for (int i = 0; i < fRepeats + 1; ++i) {
106 SkPicture replayer;
107 SkCanvas* recorder = replayer.beginRecording(pict->width(), pict->height());
108
109 recorder->drawPicture(*pict);
110
111 timer.start();
112 replayer.endRecording();
113 timer.end();
114
115 // We want to ignore first time effects
116 if (i > 0) {
117 wall_time += timer.fWall;
118 }
119 }
120
121 SkDebugf("unflatten: msecs = %6.4f\n", wall_time / fRepeats);
122}
123
124}