commit-bot@chromium.org | 15ac322 | 2014-01-13 12:03:47 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 23 | DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record."); |
| 24 | DEFINE_int32(loops, 900, "Number of times to re-record each SKP."); |
| 25 | DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFlags to use."); |
| 26 | DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()"); |
commit-bot@chromium.org | a858223 | 2014-01-13 19:09:36 +0000 | [diff] [blame] | 27 | DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture."); |
| 28 | |
| 29 | static 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.org | 15ac322 | 2014-01-13 12:03:47 +0000 | [diff] [blame] | 45 | |
| 46 | int tool_main(int argc, char** argv); |
| 47 | int tool_main(int argc, char** argv) { |
| 48 | SkCommandLineFlags::Parse(argc, argv); |
| 49 | SkAutoGraphics autoGraphics; |
| 50 | |
commit-bot@chromium.org | a858223 | 2014-01-13 19:09:36 +0000 | [diff] [blame] | 51 | bench_record(NULL, "NULL"); |
| 52 | if (FLAGS_skps.isEmpty()) return 0; |
| 53 | |
commit-bot@chromium.org | 15ac322 | 2014-01-13 12:03:47 +0000 | [diff] [blame] | 54 | SkOSFile::Iter it(FLAGS_skps[0], ".skp"); |
| 55 | SkString filename; |
commit-bot@chromium.org | a858223 | 2014-01-13 19:09:36 +0000 | [diff] [blame] | 56 | bool failed = false; |
commit-bot@chromium.org | 15ac322 | 2014-01-13 12:03:47 +0000 | [diff] [blame] | 57 | 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.org | a858223 | 2014-01-13 19:09:36 +0000 | [diff] [blame] | 63 | failed = true; |
commit-bot@chromium.org | 15ac322 | 2014-01-13 12:03:47 +0000 | [diff] [blame] | 64 | 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.org | a858223 | 2014-01-13 19:09:36 +0000 | [diff] [blame] | 69 | failed = true; |
commit-bot@chromium.org | 15ac322 | 2014-01-13 12:03:47 +0000 | [diff] [blame] | 70 | continue; |
| 71 | } |
commit-bot@chromium.org | a858223 | 2014-01-13 19:09:36 +0000 | [diff] [blame] | 72 | bench_record(src, filename.c_str()); |
commit-bot@chromium.org | 15ac322 | 2014-01-13 12:03:47 +0000 | [diff] [blame] | 73 | } |
commit-bot@chromium.org | a858223 | 2014-01-13 19:09:36 +0000 | [diff] [blame] | 74 | return failed ? 1 : 0; |
commit-bot@chromium.org | 15ac322 | 2014-01-13 12:03:47 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | #if !defined SK_BUILD_FOR_IOS |
| 78 | int main(int argc, char * const argv[]) { |
| 79 | return tool_main(argc, (char**) argv); |
| 80 | } |
| 81 | #endif |