blob: cea3f0b6267ac34fcb4cfab0c55559bae11e0bcb [file] [log] [blame]
commit-bot@chromium.org15ac3222014-01-13 12:03:47 +00001/*
2 * Copyright 2014 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 "SkCommandLineFlags.h"
9#include "SkForceLinking.h"
10#include "SkGraphics.h"
11#include "SkOSFile.h"
12#include "SkPicture.h"
13#include "SkStream.h"
14#include "SkString.h"
15#include "SkTime.h"
16
17__SK_FORCE_IMAGE_DECODER_LINKING;
18
19// Just reading all the SKPs takes about 2 seconds for me, which is the same as about 100 loops of
20// rerecording all the SKPs. So we default to --loops=900, which makes ~90% of our time spent in
21// recording, and this should take ~20 seconds to run.
22
23DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record.");
24DEFINE_int32(loops, 900, "Number of times to re-record each SKP.");
25DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFlags to use.");
26DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()");
commit-bot@chromium.orga8582232014-01-13 19:09:36 +000027DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture.");
28
29static void bench_record(SkPicture* src, const char* name) {
30 const SkMSec start = SkTime::GetMSecs();
31 const int width = src ? src->width() : FLAGS_nullSize;
32 const int height = src ? src->height() : FLAGS_nullSize;
33
34 for (int i = 0; i < FLAGS_loops; i++) {
35 SkPicture dst;
36 SkCanvas* canvas = dst.beginRecording(width, height, FLAGS_flags);
37 if (src) src->draw(canvas);
38 if (FLAGS_endRecording) dst.endRecording();
39 }
40
41 const SkMSec elapsed = SkTime::GetMSecs() - start;
42 const double msPerLoop = elapsed / (double)FLAGS_loops;
43 printf("%.2g\t%s\n", msPerLoop, name);
44}
commit-bot@chromium.org15ac3222014-01-13 12:03:47 +000045
46int tool_main(int argc, char** argv);
47int tool_main(int argc, char** argv) {
48 SkCommandLineFlags::Parse(argc, argv);
49 SkAutoGraphics autoGraphics;
50
commit-bot@chromium.orga8582232014-01-13 19:09:36 +000051 bench_record(NULL, "NULL");
52 if (FLAGS_skps.isEmpty()) return 0;
53
commit-bot@chromium.org15ac3222014-01-13 12:03:47 +000054 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
55 SkString filename;
commit-bot@chromium.orga8582232014-01-13 19:09:36 +000056 bool failed = false;
commit-bot@chromium.org15ac3222014-01-13 12:03:47 +000057 while (it.next(&filename)) {
58 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str());
59
60 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str()));
61 if (!stream) {
62 SkDebugf("Could not read %s.\n", path.c_str());
commit-bot@chromium.orga8582232014-01-13 19:09:36 +000063 failed = true;
commit-bot@chromium.org15ac3222014-01-13 12:03:47 +000064 continue;
65 }
66 SkAutoTUnref<SkPicture> src(SkPicture::CreateFromStream(stream));
67 if (!src) {
68 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
commit-bot@chromium.orga8582232014-01-13 19:09:36 +000069 failed = true;
commit-bot@chromium.org15ac3222014-01-13 12:03:47 +000070 continue;
71 }
commit-bot@chromium.orga8582232014-01-13 19:09:36 +000072 bench_record(src, filename.c_str());
commit-bot@chromium.org15ac3222014-01-13 12:03:47 +000073 }
commit-bot@chromium.orga8582232014-01-13 19:09:36 +000074 return failed ? 1 : 0;
commit-bot@chromium.org15ac3222014-01-13 12:03:47 +000075}
76
77#if !defined SK_BUILD_FOR_IOS
78int main(int argc, char * const argv[]) {
79 return tool_main(argc, (char**) argv);
80}
81#endif