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, "", "Turn on the bbh and select the type, one of rtree, tileg
rid, quadtree"); |
30 | 32 |
31 static void bench_record(SkPicture* src, const char* name) { | 33 typedef SkPicture* (*PictureFactory)(const int width, const int height, int* rec
ordingFlags); |
| 34 |
| 35 static SkPicture* vanilla_factory(const int width, const int height, int* record
ingFlags) { |
| 36 return SkNEW(SkPicture); |
| 37 } |
| 38 |
| 39 static SkPicture* rtree_factory(const int width, const int height, int* recordin
gFlags) { |
| 40 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
| 41 return SkNEW(SkPicture); |
| 42 } |
| 43 |
| 44 static SkPicture* tilegrid_factory(const int width, const int height, int* recor
dingFlags) { |
| 45 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
| 46 SkTileGridPicture::TileGridInfo info; |
| 47 info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize); |
| 48 info.fMargin.setEmpty(); |
| 49 info.fOffset.setZero(); |
| 50 return SkNEW_ARGS(SkTileGridPicture, (width, height, info)); |
| 51 } |
| 52 |
| 53 static SkPicture* quadtree_factory(const int width, const int height, int* recor
dingFlags) { |
| 54 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
| 55 return SkNEW_ARGS(SkQuadTreePicture, (SkIRect::MakeWH(width, height))); |
| 56 } |
| 57 |
| 58 static PictureFactory parse_FLAGS_bbh() { |
| 59 if (FLAGS_bbh.isEmpty()) { return &vanilla_factory; } |
| 60 if (FLAGS_bbh.count() != 1) { |
| 61 SkDebugf("Multiple bbh arguments supplied.\n"); |
| 62 return NULL; |
| 63 } |
| 64 if (FLAGS_bbh.contains("rtree")) { return rtree_factory; } |
| 65 if (FLAGS_bbh.contains("tilegrid")) { return tilegrid_factory; } |
| 66 if (FLAGS_bbh.contains("quadtree")) { return quadtree_factory; } |
| 67 SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n",
FLAGS_bbh[0]); |
| 68 return NULL; |
| 69 } |
| 70 |
| 71 static void bench_record(SkPicture* src, const char* name, PictureFactory pictur
eFactory) { |
32 const SkMSec start = SkTime::GetMSecs(); | 72 const SkMSec start = SkTime::GetMSecs(); |
33 const int width = src ? src->width() : FLAGS_nullSize; | 73 const int width = src ? src->width() : FLAGS_nullSize; |
34 const int height = src ? src->height() : FLAGS_nullSize; | 74 const int height = src ? src->height() : FLAGS_nullSize; |
35 | 75 |
36 for (int i = 0; i < FLAGS_loops; i++) { | 76 for (int i = 0; i < FLAGS_loops; i++) { |
37 SkAutoTUnref<SkPicture> dst; | |
38 int recordingFlags = FLAGS_flags; | 77 int recordingFlags = FLAGS_flags; |
39 if (FLAGS_tileGridSize > 0) { | 78 SkAutoTUnref<SkPicture> dst(pictureFactory(width, height, &recordingFlag
s)); |
40 SkTileGridPicture::TileGridInfo info; | |
41 info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize); | |
42 info.fMargin.setEmpty(); | |
43 info.fOffset.setZero(); | |
44 dst.reset(SkNEW_ARGS(SkTileGridPicture, (width, height, info))); | |
45 recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFl
ag; | |
46 } else { | |
47 dst.reset(SkNEW(SkPicture)); | |
48 } | |
49 SkCanvas* canvas = dst->beginRecording(width, height, recordingFlags); | 79 SkCanvas* canvas = dst->beginRecording(width, height, recordingFlags); |
50 if (src) src->draw(canvas); | 80 if (src) src->draw(canvas); |
51 if (FLAGS_endRecording) dst->endRecording(); | 81 if (FLAGS_endRecording) dst->endRecording(); |
52 } | 82 } |
53 | 83 |
54 const SkMSec elapsed = SkTime::GetMSecs() - start; | 84 const SkMSec elapsed = SkTime::GetMSecs() - start; |
55 const double msPerLoop = elapsed / (double)FLAGS_loops; | 85 const double msPerLoop = elapsed / (double)FLAGS_loops; |
56 printf("%.2g\t%s\n", msPerLoop, name); | 86 printf("%.2g\t%s\n", msPerLoop, name); |
57 } | 87 } |
58 | 88 |
59 int tool_main(int argc, char** argv); | 89 int tool_main(int argc, char** argv); |
60 int tool_main(int argc, char** argv) { | 90 int tool_main(int argc, char** argv) { |
61 SkCommandLineFlags::Parse(argc, argv); | 91 SkCommandLineFlags::Parse(argc, argv); |
62 SkAutoGraphics autoGraphics; | 92 SkAutoGraphics autoGraphics; |
63 | 93 |
64 bench_record(NULL, "NULL"); | 94 PictureFactory pictureFactory = parse_FLAGS_bbh(); |
| 95 if (pictureFactory == NULL) { |
| 96 return 1; |
| 97 } |
| 98 bench_record(NULL, "NULL", pictureFactory); |
65 if (FLAGS_skps.isEmpty()) return 0; | 99 if (FLAGS_skps.isEmpty()) return 0; |
66 | 100 |
67 SkOSFile::Iter it(FLAGS_skps[0], ".skp"); | 101 SkOSFile::Iter it(FLAGS_skps[0], ".skp"); |
68 SkString filename; | 102 SkString filename; |
69 bool failed = false; | 103 bool failed = false; |
70 while (it.next(&filename)) { | 104 while (it.next(&filename)) { |
71 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str
()); | 105 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str
()); |
72 | 106 |
73 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str())); | 107 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str())); |
74 if (!stream) { | 108 if (!stream) { |
75 SkDebugf("Could not read %s.\n", path.c_str()); | 109 SkDebugf("Could not read %s.\n", path.c_str()); |
76 failed = true; | 110 failed = true; |
77 continue; | 111 continue; |
78 } | 112 } |
79 SkAutoTUnref<SkPicture> src(SkPicture::CreateFromStream(stream)); | 113 SkAutoTUnref<SkPicture> src(SkPicture::CreateFromStream(stream)); |
80 if (!src) { | 114 if (!src) { |
81 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str()); | 115 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str()); |
82 failed = true; | 116 failed = true; |
83 continue; | 117 continue; |
84 } | 118 } |
85 bench_record(src, filename.c_str()); | 119 bench_record(src, filename.c_str(), pictureFactory); |
86 } | 120 } |
87 return failed ? 1 : 0; | 121 return failed ? 1 : 0; |
88 } | 122 } |
89 | 123 |
90 #if !defined SK_BUILD_FOR_IOS | 124 #if !defined SK_BUILD_FOR_IOS |
91 int main(int argc, char * const argv[]) { | 125 int main(int argc, char * const argv[]) { |
92 return tool_main(argc, (char**) argv); | 126 return tool_main(argc, (char**) argv); |
93 } | 127 } |
94 #endif | 128 #endif |
OLD | NEW |