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 "SkPictureRecorder.h" | 14 #include "SkPictureRecorder.h" |
15 #include "SkRecordDraw.h" | 15 #include "SkRecording.h" |
16 #include "SkRecordOpts.h" | |
17 #include "SkRecorder.h" | |
18 #include "SkStream.h" | 16 #include "SkStream.h" |
19 #include "SkString.h" | 17 #include "SkString.h" |
20 | 18 |
21 __SK_FORCE_IMAGE_DECODER_LINKING; | 19 __SK_FORCE_IMAGE_DECODER_LINKING; |
22 | 20 |
23 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record
."); | 21 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record
."); |
24 DEFINE_int32(loops, 10, "Number of times to play back each SKP."); | 22 DEFINE_int32(loops, 10, "Number of times to play back each SKP."); |
25 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); | 23 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); |
26 DEFINE_int32(tile, 1000000000, "Simulated tile size."); | 24 DEFINE_int32(tile, 1000000000, "Simulated tile size."); |
27 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench."); | 25 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench."); |
28 DEFINE_string(timescale, "ms", "Print times in ms, us, or ns"); | 26 DEFINE_string(timescale, "ms", "Print times in ms, us, or ns"); |
29 | 27 |
30 static double scale_time(double ms) { | 28 static double scale_time(double ms) { |
31 if (FLAGS_timescale.contains("us")) ms *= 1000; | 29 if (FLAGS_timescale.contains("us")) ms *= 1000; |
32 if (FLAGS_timescale.contains("ns")) ms *= 1000000; | 30 if (FLAGS_timescale.contains("ns")) ms *= 1000000; |
33 return ms; | 31 return ms; |
34 } | 32 } |
35 | 33 |
| 34 static SkPicture* rerecord_with_tilegrid(SkPicture& src) { |
| 35 SkTileGridFactory::TileGridInfo info; |
| 36 info.fTileInterval.set(FLAGS_tile, FLAGS_tile); |
| 37 info.fMargin.setEmpty(); |
| 38 info.fOffset.setZero(); |
| 39 SkTileGridFactory factory(info); |
| 40 |
| 41 SkPictureRecorder recorder; |
| 42 src.draw(recorder.beginRecording(src.width(), src.height(), &factory, |
| 43 SkPicture::kUsePathBoundsForClip_RecordingF
lag)); |
| 44 return recorder.endRecording(); |
| 45 } |
| 46 |
| 47 static EXPERIMENTAL::SkPlayback* rerecord_with_skr(SkPicture& src) { |
| 48 EXPERIMENTAL::SkRecording recording(src.width(), src.height()); |
| 49 src.draw(recording.canvas()); |
| 50 return recording.releasePlayback(); |
| 51 } |
| 52 |
36 static void bench(SkPMColor* scratch, SkPicture& src, const char* name) { | 53 static void bench(SkPMColor* scratch, SkPicture& src, const char* name) { |
37 // We don't use the public SkRecording interface here because we need kWrite
Only_Mode. | 54 SkAutoTUnref<SkPicture> picture(rerecord_with_tilegrid(src)); |
38 // (We don't want SkPicturePlayback to be able to optimize playing into our
SkRecord.) | 55 SkAutoTDelete<EXPERIMENTAL::SkPlayback> record(rerecord_with_skr(src)); |
39 SkRecord record; | |
40 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, src.width(), src.h
eight()); | |
41 src.draw(&recorder); | |
42 | |
43 SkRecordOptimize(&record); | |
44 | 56 |
45 SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(), | 57 SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(), |
46 src.height(), | 58 src.height(), |
47 scratch, | 59 scratch, |
48 src.width() * si
zeof(SkPMColor))); | 60 src.width() * si
zeof(SkPMColor))); |
49 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA
GS_tile))); | 61 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA
GS_tile))); |
50 | 62 |
51 BenchTimer timer; | 63 BenchTimer timer; |
52 timer.start(); | 64 timer.start(); |
53 for (int i = 0; i < FLAGS_loops; i++) { | 65 for (int i = 0; i < FLAGS_loops; i++) { |
54 if (FLAGS_skr) { | 66 if (FLAGS_skr) { |
55 SkRecordDraw(record, canvas.get()); | 67 record->draw(canvas.get()); |
56 } else { | 68 } else { |
57 src.draw(canvas.get()); | 69 picture->draw(canvas.get()); |
58 } | 70 } |
59 } | 71 } |
60 timer.end(); | 72 timer.end(); |
61 | 73 |
62 const double msPerLoop = timer.fCpu / (double)FLAGS_loops; | 74 const double msPerLoop = timer.fCpu / (double)FLAGS_loops; |
63 printf("%f\t%s\n", scale_time(msPerLoop), name); | 75 printf("%f\t%s\n", scale_time(msPerLoop), name); |
64 } | 76 } |
65 | 77 |
66 int tool_main(int argc, char** argv); | 78 int tool_main(int argc, char** argv); |
67 int tool_main(int argc, char** argv) { | 79 int tool_main(int argc, char** argv) { |
(...skipping 27 matching lines...) Expand all Loading... |
95 continue; | 107 continue; |
96 } | 108 } |
97 | 109 |
98 if (src->width() * src->height() > kMaxArea) { | 110 if (src->width() * src->height() > kMaxArea) { |
99 SkDebugf("%s (%dx%d) is larger than hardcoded scratch bitmap (%dpx).
\n", | 111 SkDebugf("%s (%dx%d) is larger than hardcoded scratch bitmap (%dpx).
\n", |
100 path.c_str(), src->width(), src->height(), kMaxArea); | 112 path.c_str(), src->width(), src->height(), kMaxArea); |
101 failed = true; | 113 failed = true; |
102 continue; | 114 continue; |
103 } | 115 } |
104 | 116 |
105 // Rerecord into a picture using a tile grid. | 117 bench(scratch.get(), *src, filename.c_str()); |
106 SkTileGridFactory::TileGridInfo info; | |
107 info.fTileInterval.set(FLAGS_tile, FLAGS_tile); | |
108 info.fMargin.setEmpty(); | |
109 info.fOffset.setZero(); | |
110 SkTileGridFactory factory(info); | |
111 | |
112 SkPictureRecorder recorder; | |
113 SkCanvas* canvas = recorder.beginRecording(src->width(), src->height(), | |
114 &factory, | |
115 SkPicture::kUsePathBoundsForC
lip_RecordingFlag); | |
116 src->draw(canvas); | |
117 SkAutoTUnref<SkPicture> replay(recorder.endRecording()); | |
118 | |
119 bench(scratch.get(), *replay, filename.c_str()); | |
120 } | 118 } |
121 return failed ? 1 : 0; | 119 return failed ? 1 : 0; |
122 } | 120 } |
123 | 121 |
124 #if !defined SK_BUILD_FOR_IOS | 122 #if !defined SK_BUILD_FOR_IOS |
125 int main(int argc, char * const argv[]) { | 123 int main(int argc, char * const argv[]) { |
126 return tool_main(argc, (char**) argv); | 124 return tool_main(argc, (char**) argv); |
127 } | 125 } |
128 #endif | 126 #endif |
OLD | NEW |