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" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record
."); | 27 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record
."); |
28 DEFINE_int32(loops, 900, "Number of times to re-record each SKP."); | 28 DEFINE_int32(loops, 900, "Number of times to re-record each SKP."); |
29 DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFl
ags to use."); | 29 DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFl
ags to use."); |
30 DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()"
); | 30 DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()"
); |
31 DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture."); | 31 DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture."); |
32 DEFINE_int32(tileGridSize, 512, "Set the tile grid size. Has no effect if bbh is
not set to tilegrid."); | 32 DEFINE_int32(tileGridSize, 512, "Set the tile grid size. Has no effect if bbh is
not set to tilegrid."); |
33 DEFINE_string(bbh, "", "Turn on the bbh and select the type, one of rtree, tileg
rid, quadtree"); | 33 DEFINE_string(bbh, "", "Turn on the bbh and select the type, one of rtree, tileg
rid, quadtree"); |
34 DEFINE_bool(skr, false, "Record SKR instead of SKP."); | 34 DEFINE_bool(skr, false, "Record SKR instead of SKP."); |
35 | 35 |
36 typedef SkPicture* (*PictureFactory)(const int width, const int height, int* rec
ordingFlags); | 36 typedef SkPictureFactory* (*PictureFactory)(int* recordingFlags); |
37 | 37 |
38 static SkPicture* vanilla_factory(const int width, const int height, int* record
ingFlags) { | 38 static SkPictureFactory* vanilla_factory(int* recordingFlags) { |
39 return SkNEW(SkPicture); | 39 return NULL; |
40 } | 40 } |
41 | 41 |
42 static SkPicture* rtree_factory(const int width, const int height, int* recordin
gFlags) { | 42 static SkPictureFactory* rtree_factory(int* recordingFlags) { |
43 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; | 43 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
44 return SkNEW(SkPicture); | 44 return NULL; |
45 } | 45 } |
46 | 46 |
47 static SkPicture* tilegrid_factory(const int width, const int height, int* recor
dingFlags) { | 47 static SkPictureFactory* tilegrid_factory(int* recordingFlags) { |
48 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; | 48 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
49 SkTileGridPicture::TileGridInfo info; | 49 SkTileGridPicture::TileGridInfo info; |
50 info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize); | 50 info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize); |
51 info.fMargin.setEmpty(); | 51 info.fMargin.setEmpty(); |
52 info.fOffset.setZero(); | 52 info.fOffset.setZero(); |
53 return SkNEW_ARGS(SkTileGridPicture, (width, height, info)); | 53 return SkNEW_ARGS(SkTileGridPictureFactory, (info)); |
54 } | 54 } |
55 | 55 |
56 static SkPicture* quadtree_factory(const int width, const int height, int* recor
dingFlags) { | 56 static SkPictureFactory* quadtree_factory(int* recordingFlags) { |
57 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; | 57 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
58 return SkNEW_ARGS(SkQuadTreePicture, (SkIRect::MakeWH(width, height))); | 58 return SkNEW(SkQuadTreePictureFactory); |
59 } | 59 } |
60 | 60 |
61 static PictureFactory parse_FLAGS_bbh() { | 61 static PictureFactory parse_FLAGS_bbh() { |
62 if (FLAGS_bbh.isEmpty()) { return &vanilla_factory; } | 62 if (FLAGS_bbh.isEmpty()) { |
| 63 return &vanilla_factory; |
| 64 } |
63 if (FLAGS_bbh.count() != 1) { | 65 if (FLAGS_bbh.count() != 1) { |
64 SkDebugf("Multiple bbh arguments supplied.\n"); | 66 SkDebugf("Multiple bbh arguments supplied.\n"); |
65 return NULL; | 67 return NULL; |
66 } | 68 } |
67 if (FLAGS_bbh.contains("rtree")) { return rtree_factory; } | 69 if (FLAGS_bbh.contains("rtree")) { |
68 if (FLAGS_bbh.contains("tilegrid")) { return tilegrid_factory; } | 70 return rtree_factory; |
69 if (FLAGS_bbh.contains("quadtree")) { return quadtree_factory; } | 71 } |
| 72 if (FLAGS_bbh.contains("tilegrid")) { |
| 73 return tilegrid_factory; |
| 74 } |
| 75 if (FLAGS_bbh.contains("quadtree")) { |
| 76 return quadtree_factory; |
| 77 } |
70 SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n",
FLAGS_bbh[0]); | 78 SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n",
FLAGS_bbh[0]); |
71 return NULL; | 79 return NULL; |
72 } | 80 } |
73 | 81 |
74 static void bench_record(SkPicture* src, const char* name, PictureFactory pictur
eFactory) { | 82 static void bench_record(SkPicture* src, const char* name, PictureFactory pictur
eFactory) { |
75 const SkMSec start = SkTime::GetMSecs(); | 83 const SkMSec start = SkTime::GetMSecs(); |
76 const int width = src ? src->width() : FLAGS_nullSize; | 84 const int width = src ? src->width() : FLAGS_nullSize; |
77 const int height = src ? src->height() : FLAGS_nullSize; | 85 const int height = src ? src->height() : FLAGS_nullSize; |
78 | 86 |
79 for (int i = 0; i < FLAGS_loops; i++) { | 87 for (int i = 0; i < FLAGS_loops; i++) { |
80 if (FLAGS_skr) { | 88 if (FLAGS_skr) { |
81 SkRecord record; | 89 SkRecord record; |
82 SkRecorder canvas(SkRecorder::kWriteOnly_Mode, &record, width, heigh
t); | 90 SkRecorder canvas(SkRecorder::kWriteOnly_Mode, &record, width, heigh
t); |
83 if (NULL != src) { | 91 if (NULL != src) { |
84 src->draw(&canvas); | 92 src->draw(&canvas); |
85 } | 93 } |
86 } else { | 94 } else { |
87 int recordingFlags = FLAGS_flags; | 95 int recordingFlags = FLAGS_flags; |
88 SkAutoTUnref<SkPicture> dst(pictureFactory(width, height, &recording
Flags)); | 96 SkAutoTUnref<SkPictureFactory> factory(pictureFactory(&recordingFlag
s)); |
89 SkCanvas* canvas = dst->beginRecording(width, height, recordingFlags
); | 97 SkPictureRecorder recorder(factory); |
| 98 SkCanvas* canvas = recorder.beginRecording(width, height, recordingF
lags); |
90 if (NULL != src) { | 99 if (NULL != src) { |
91 src->draw(canvas); | 100 src->draw(canvas); |
92 } | 101 } |
93 if (FLAGS_endRecording) { | 102 if (FLAGS_endRecording) { |
94 dst->endRecording(); | 103 SkAutoTUnref<SkPicture> dst(recorder.endRecording()); |
95 } | 104 } |
96 } | 105 } |
97 } | 106 } |
98 | 107 |
99 const SkMSec elapsed = SkTime::GetMSecs() - start; | 108 const SkMSec elapsed = SkTime::GetMSecs() - start; |
100 const double msPerLoop = elapsed / (double)FLAGS_loops; | 109 const double msPerLoop = elapsed / (double)FLAGS_loops; |
101 printf("%.2g\t%s\n", msPerLoop, name); | 110 printf("%.2g\t%s\n", msPerLoop, name); |
102 } | 111 } |
103 | 112 |
104 int tool_main(int argc, char** argv); | 113 int tool_main(int argc, char** argv); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 bench_record(src, filename.c_str(), pictureFactory); | 146 bench_record(src, filename.c_str(), pictureFactory); |
138 } | 147 } |
139 return failed ? 1 : 0; | 148 return failed ? 1 : 0; |
140 } | 149 } |
141 | 150 |
142 #if !defined SK_BUILD_FOR_IOS | 151 #if !defined SK_BUILD_FOR_IOS |
143 int main(int argc, char * const argv[]) { | 152 int main(int argc, char * const argv[]) { |
144 return tool_main(argc, (char**) argv); | 153 return tool_main(argc, (char**) argv); |
145 } | 154 } |
146 #endif | 155 #endif |
OLD | NEW |