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 "SkCommandLineFlags.h" | 8 #include "SkCommandLineFlags.h" |
9 #include "SkForceLinking.h" | 9 #include "SkForceLinking.h" |
10 #include "SkGraphics.h" | 10 #include "SkGraphics.h" |
11 #include "SkOSFile.h" | 11 #include "SkOSFile.h" |
12 #include "SkPicture.h" | 12 #include "SkPicture.h" |
13 #include "SkQuadTreePicture.h" | |
13 #include "SkStream.h" | 14 #include "SkStream.h" |
14 #include "SkString.h" | 15 #include "SkString.h" |
15 #include "SkTileGridPicture.h" | 16 #include "SkTileGridPicture.h" |
16 #include "SkTime.h" | 17 #include "SkTime.h" |
17 | 18 |
18 __SK_FORCE_IMAGE_DECODER_LINKING; | 19 __SK_FORCE_IMAGE_DECODER_LINKING; |
19 | 20 |
20 // Just reading all the SKPs takes about 2 seconds for me, which is the same as about 100 loops of | 21 // Just reading all the SKPs takes about 2 seconds for me, which is the same as about 100 loops of |
21 // rerecording all the SKPs. So we default to --loops=900, which makes ~90% of our time spent in | 22 // rerecording all the SKPs. So we default to --loops=900, which makes ~90% of our time spent in |
22 // recording, and this should take ~20 seconds to run. | 23 // recording, and this should take ~20 seconds to run. |
23 | 24 |
24 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record ."); | 25 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record ."); |
25 DEFINE_int32(loops, 900, "Number of times to re-record each SKP."); | 26 DEFINE_int32(loops, 900, "Number of times to re-record each SKP."); |
26 DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFl ags to use."); | 27 DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFl ags to use."); |
27 DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()" ); | 28 DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()" ); |
28 DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture."); | 29 DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture."); |
29 DEFINE_int32(tileGridSize, 0, "Set the tile grid size, if non zero switches to t ile grid picture and enables kOptimizeForClippedPlayback_RecordingFlag."); | 30 DEFINE_int32(tileGridSize, 512, "Set the tile grid size. Has no effect if bbh is not set to tilegrid."); |
31 DEFINE_string(bbh, "bbh", "Turn on the bbh and select the type"); | |
tomhudson
2014/03/03 15:00:03
If I'm reading correctly, this sets the default va
mtklein
2014/03/03 15:20:13
Yeah, why default this to an invalid choice?
List
iancottrell
2014/03/03 16:03:47
sorry, was meant to be the empty string so it defa
| |
30 | 32 |
31 static void bench_record(SkPicture* src, const char* name) { | 33 static bool bench_record(SkPicture* src, const char* name) { |
32 const SkMSec start = SkTime::GetMSecs(); | 34 const SkMSec start = SkTime::GetMSecs(); |
33 const int width = src ? src->width() : FLAGS_nullSize; | 35 const int width = src ? src->width() : FLAGS_nullSize; |
34 const int height = src ? src->height() : FLAGS_nullSize; | 36 const int height = src ? src->height() : FLAGS_nullSize; |
35 | 37 |
36 for (int i = 0; i < FLAGS_loops; i++) { | 38 for (int i = 0; i < FLAGS_loops; i++) { |
37 SkAutoTUnref<SkPicture> dst; | 39 SkAutoTUnref<SkPicture> dst; |
38 int recordingFlags = FLAGS_flags; | 40 int recordingFlags = FLAGS_flags; |
39 if (FLAGS_tileGridSize > 0) { | 41 if (FLAGS_bbh.isEmpty()) { |
mtklein
2014/03/03 15:20:13
This is getting a little hard to digest.
Let's mo
iancottrell
2014/03/03 16:03:47
Done, although it is a little more complicated as
| |
42 dst.reset(SkNEW(SkPicture)); | |
43 } else if (FLAGS_bbh.count() !=1 ) { | |
44 SkDebugf("More than one bbh type specified.\n"); | |
45 return false; | |
46 } else if (FLAGS_bbh.contains("rtree")) { | |
47 recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFl ag; | |
48 dst.reset(SkNEW(SkPicture)); | |
49 } else if (FLAGS_bbh.contains("tilegrid")) { | |
50 recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFl ag; | |
40 SkTileGridPicture::TileGridInfo info; | 51 SkTileGridPicture::TileGridInfo info; |
41 info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize); | 52 info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize); |
42 info.fMargin.setEmpty(); | 53 info.fMargin.setEmpty(); |
43 info.fOffset.setZero(); | 54 info.fOffset.setZero(); |
44 dst.reset(SkNEW_ARGS(SkTileGridPicture, (width, height, info))); | 55 dst.reset(SkNEW_ARGS(SkTileGridPicture, (width, height, info))); |
56 } else if (FLAGS_bbh.contains("quadtree")) { | |
45 recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFl ag; | 57 recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFl ag; |
58 dst.reset(SkNEW_ARGS(SkQuadTreePicture, (SkIRect::MakeWH(width, heig ht)))); | |
46 } else { | 59 } else { |
47 dst.reset(SkNEW(SkPicture)); | 60 SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadt ree.\n", FLAGS_bbh[0]); |
61 return false; | |
48 } | 62 } |
49 SkCanvas* canvas = dst->beginRecording(width, height, recordingFlags); | 63 SkCanvas* canvas = dst->beginRecording(width, height, recordingFlags); |
50 if (src) src->draw(canvas); | 64 if (src) src->draw(canvas); |
51 if (FLAGS_endRecording) dst->endRecording(); | 65 if (FLAGS_endRecording) dst->endRecording(); |
52 } | 66 } |
53 | 67 |
54 const SkMSec elapsed = SkTime::GetMSecs() - start; | 68 const SkMSec elapsed = SkTime::GetMSecs() - start; |
55 const double msPerLoop = elapsed / (double)FLAGS_loops; | 69 const double msPerLoop = elapsed / (double)FLAGS_loops; |
56 printf("%.2g\t%s\n", msPerLoop, name); | 70 printf("%.2g\t%s\n", msPerLoop, name); |
71 return true; | |
57 } | 72 } |
58 | 73 |
59 int tool_main(int argc, char** argv); | 74 int tool_main(int argc, char** argv); |
60 int tool_main(int argc, char** argv) { | 75 int tool_main(int argc, char** argv) { |
61 SkCommandLineFlags::Parse(argc, argv); | 76 SkCommandLineFlags::Parse(argc, argv); |
62 SkAutoGraphics autoGraphics; | 77 SkAutoGraphics autoGraphics; |
63 | 78 |
64 bench_record(NULL, "NULL"); | 79 if (!bench_record(NULL, "NULL")) { |
80 return 1; | |
81 } | |
65 if (FLAGS_skps.isEmpty()) return 0; | 82 if (FLAGS_skps.isEmpty()) return 0; |
66 | 83 |
67 SkOSFile::Iter it(FLAGS_skps[0], ".skp"); | 84 SkOSFile::Iter it(FLAGS_skps[0], ".skp"); |
68 SkString filename; | 85 SkString filename; |
69 bool failed = false; | 86 bool failed = false; |
70 while (it.next(&filename)) { | 87 while (it.next(&filename)) { |
71 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str ()); | 88 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str ()); |
72 | 89 |
73 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str())); | 90 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str())); |
74 if (!stream) { | 91 if (!stream) { |
(...skipping 10 matching lines...) Expand all Loading... | |
85 bench_record(src, filename.c_str()); | 102 bench_record(src, filename.c_str()); |
86 } | 103 } |
87 return failed ? 1 : 0; | 104 return failed ? 1 : 0; |
88 } | 105 } |
89 | 106 |
90 #if !defined SK_BUILD_FOR_IOS | 107 #if !defined SK_BUILD_FOR_IOS |
91 int main(int argc, char * const argv[]) { | 108 int main(int argc, char * const argv[]) { |
92 return tool_main(argc, (char**) argv); | 109 return tool_main(argc, (char**) argv); |
93 } | 110 } |
94 #endif | 111 #endif |
OLD | NEW |