OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "BenchTimer.h" | 8 #include "BenchTimer.h" |
9 #include "SkCommandLineFlags.h" | 9 #include "SkCommandLineFlags.h" |
10 #include "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
11 #include "SkGraphics.h" | 11 #include "SkGraphics.h" |
12 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
13 #include "SkPicture.h" | 13 #include "SkPicture.h" |
14 #include "SkRecordDraw.h" | 14 #include "SkRecordDraw.h" |
15 #include "SkRecordOpts.h" | 15 #include "SkRecordOpts.h" |
16 #include "SkRecorder.h" | 16 #include "SkRecorder.h" |
17 #include "SkStream.h" | 17 #include "SkStream.h" |
18 #include "SkString.h" | 18 #include "SkString.h" |
19 | 19 |
20 __SK_FORCE_IMAGE_DECODER_LINKING; | 20 __SK_FORCE_IMAGE_DECODER_LINKING; |
21 | 21 |
22 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record
."); | 22 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record
."); |
23 DEFINE_int32(loops, 10, "Number of times to play back each SKP."); | 23 DEFINE_int32(loops, 10, "Number of times to play back each SKP."); |
24 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); | 24 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); |
25 DEFINE_int32(tile, 1000000000, "Simulated tile size."); | 25 DEFINE_int32(tile, 1000000000, "Simulated tile size."); |
26 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench."); | 26 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench."); |
| 27 DEFINE_string(timescale, "ms", "Print times in ms, us, or ns"); |
| 28 |
| 29 static double scale_time(double ms) { |
| 30 if (FLAGS_timescale.contains("us")) ms *= 1000; |
| 31 if (FLAGS_timescale.contains("ns")) ms *= 1000000; |
| 32 return ms; |
| 33 } |
27 | 34 |
28 static void bench(SkPMColor* scratch, SkPicture& src, const char* name) { | 35 static void bench(SkPMColor* scratch, SkPicture& src, const char* name) { |
29 // We don't use the public SkRecording interface here because we need kWrite
Only_Mode. | 36 // We don't use the public SkRecording interface here because we need kWrite
Only_Mode. |
30 // (We don't want SkPicturePlayback to be able to optimize playing into our
SkRecord.) | 37 // (We don't want SkPicturePlayback to be able to optimize playing into our
SkRecord.) |
31 SkRecord record; | 38 SkRecord record; |
32 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, src.width(), src.h
eight()); | 39 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, src.width(), src.h
eight()); |
33 src.draw(&recorder); | 40 src.draw(&recorder); |
34 | 41 |
35 SkRecordOptimize(&record); | 42 SkRecordOptimize(&record); |
36 | 43 |
37 SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(), | 44 SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(), |
38 src.height(), | 45 src.height(), |
39 scratch, | 46 scratch, |
40 src.width() * si
zeof(SkPMColor))); | 47 src.width() * si
zeof(SkPMColor))); |
41 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA
GS_tile))); | 48 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA
GS_tile))); |
42 | 49 |
43 BenchTimer timer; | 50 BenchTimer timer; |
44 timer.start(); | 51 timer.start(); |
45 for (int i = 0; i < FLAGS_loops; i++) { | 52 for (int i = 0; i < FLAGS_loops; i++) { |
46 if (FLAGS_skr) { | 53 if (FLAGS_skr) { |
47 SkRecordDraw(record, canvas.get()); | 54 SkRecordDraw(record, canvas.get()); |
48 } else { | 55 } else { |
49 src.draw(canvas.get()); | 56 src.draw(canvas.get()); |
50 } | 57 } |
51 } | 58 } |
52 timer.end(); | 59 timer.end(); |
53 | 60 |
54 const double msPerLoop = timer.fCpu / (double)FLAGS_loops; | 61 const double msPerLoop = timer.fCpu / (double)FLAGS_loops; |
55 printf("%u\t%s\n", unsigned(1000 * msPerLoop), name); | 62 printf("%f\t%s\n", scale_time(msPerLoop), name); |
56 } | 63 } |
57 | 64 |
58 int tool_main(int argc, char** argv); | 65 int tool_main(int argc, char** argv); |
59 int tool_main(int argc, char** argv) { | 66 int tool_main(int argc, char** argv) { |
60 SkCommandLineFlags::Parse(argc, argv); | 67 SkCommandLineFlags::Parse(argc, argv); |
61 SkAutoGraphics autoGraphics; | 68 SkAutoGraphics autoGraphics; |
62 | 69 |
63 // We share a single scratch bitmap among benches to reduce the profile nois
e from allocation. | 70 // We share a single scratch bitmap among benches to reduce the profile nois
e from allocation. |
64 static const int kMaxArea = 209825221; // tabl_mozilla is this big. | 71 static const int kMaxArea = 209825221; // tabl_mozilla is this big. |
65 SkAutoTMalloc<SkPMColor> scratch(kMaxArea); | 72 SkAutoTMalloc<SkPMColor> scratch(kMaxArea); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 bench(scratch.get(), *src, filename.c_str()); | 104 bench(scratch.get(), *src, filename.c_str()); |
98 } | 105 } |
99 return failed ? 1 : 0; | 106 return failed ? 1 : 0; |
100 } | 107 } |
101 | 108 |
102 #if !defined SK_BUILD_FOR_IOS | 109 #if !defined SK_BUILD_FOR_IOS |
103 int main(int argc, char * const argv[]) { | 110 int main(int argc, char * const argv[]) { |
104 return tool_main(argc, (char**) argv); | 111 return tool_main(argc, (char**) argv); |
105 } | 112 } |
106 #endif | 113 #endif |
OLD | NEW |