| 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 "SkQuadTreePicture.h" |
| 14 #include "SkRecorder.h" |
| 14 #include "SkStream.h" | 15 #include "SkStream.h" |
| 15 #include "SkString.h" | 16 #include "SkString.h" |
| 16 #include "SkTileGridPicture.h" | 17 #include "SkTileGridPicture.h" |
| 17 #include "SkTime.h" | 18 #include "SkTime.h" |
| 18 #include "LazyDecodeBitmap.h" | 19 #include "LazyDecodeBitmap.h" |
| 19 | 20 |
| 20 __SK_FORCE_IMAGE_DECODER_LINKING; | 21 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 21 | 22 |
| 22 // Just reading all the SKPs takes about 2 seconds for me, which is the same as
about 100 loops of | 23 // Just reading all the SKPs takes about 2 seconds for me, which is the same as
about 100 loops of |
| 23 // rerecording all the SKPs. So we default to --loops=900, which makes ~90% of
our time spent in | 24 // rerecording all the SKPs. So we default to --loops=900, which makes ~90% of
our time spent in |
| 24 // recording, and this should take ~20 seconds to run. | 25 // recording, and this should take ~20 seconds to run. |
| 25 | 26 |
| 26 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
."); |
| 27 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."); |
| 28 DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFl
ags to use."); | 29 DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFl
ags to use."); |
| 29 DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()"
); | 30 DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()"
); |
| 30 DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture."); | 31 DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture."); |
| 31 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."); |
| 32 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."); |
| 33 | 35 |
| 34 typedef SkPicture* (*PictureFactory)(const int width, const int height, int* rec
ordingFlags); | 36 typedef SkPicture* (*PictureFactory)(const int width, const int height, int* rec
ordingFlags); |
| 35 | 37 |
| 36 static SkPicture* vanilla_factory(const int width, const int height, int* record
ingFlags) { | 38 static SkPicture* vanilla_factory(const int width, const int height, int* record
ingFlags) { |
| 37 return SkNEW(SkPicture); | 39 return SkNEW(SkPicture); |
| 38 } | 40 } |
| 39 | 41 |
| 40 static SkPicture* rtree_factory(const int width, const int height, int* recordin
gFlags) { | 42 static SkPicture* rtree_factory(const int width, const int height, int* recordin
gFlags) { |
| 41 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; | 43 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
| 42 return SkNEW(SkPicture); | 44 return SkNEW(SkPicture); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 68 SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n",
FLAGS_bbh[0]); | 70 SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n",
FLAGS_bbh[0]); |
| 69 return NULL; | 71 return NULL; |
| 70 } | 72 } |
| 71 | 73 |
| 72 static void bench_record(SkPicture* src, const char* name, PictureFactory pictur
eFactory) { | 74 static void bench_record(SkPicture* src, const char* name, PictureFactory pictur
eFactory) { |
| 73 const SkMSec start = SkTime::GetMSecs(); | 75 const SkMSec start = SkTime::GetMSecs(); |
| 74 const int width = src ? src->width() : FLAGS_nullSize; | 76 const int width = src ? src->width() : FLAGS_nullSize; |
| 75 const int height = src ? src->height() : FLAGS_nullSize; | 77 const int height = src ? src->height() : FLAGS_nullSize; |
| 76 | 78 |
| 77 for (int i = 0; i < FLAGS_loops; i++) { | 79 for (int i = 0; i < FLAGS_loops; i++) { |
| 78 int recordingFlags = FLAGS_flags; | 80 if (FLAGS_skr) { |
| 79 SkAutoTUnref<SkPicture> dst(pictureFactory(width, height, &recordingFlag
s)); | 81 SkRecord record; |
| 80 SkCanvas* canvas = dst->beginRecording(width, height, recordingFlags); | 82 SkRecorder canvas(&record, width, height); |
| 81 if (NULL != src) { | 83 if (NULL != src) { |
| 82 src->draw(canvas); | 84 src->draw(&canvas); |
| 83 } | 85 } |
| 84 if (FLAGS_endRecording) { | 86 } else { |
| 85 dst->endRecording(); | 87 int recordingFlags = FLAGS_flags; |
| 88 SkAutoTUnref<SkPicture> dst(pictureFactory(width, height, &recording
Flags)); |
| 89 SkCanvas* canvas = dst->beginRecording(width, height, recordingFlags
); |
| 90 if (NULL != src) { |
| 91 src->draw(canvas); |
| 92 } |
| 93 if (FLAGS_endRecording) { |
| 94 dst->endRecording(); |
| 95 } |
| 86 } | 96 } |
| 87 } | 97 } |
| 88 | 98 |
| 89 const SkMSec elapsed = SkTime::GetMSecs() - start; | 99 const SkMSec elapsed = SkTime::GetMSecs() - start; |
| 90 const double msPerLoop = elapsed / (double)FLAGS_loops; | 100 const double msPerLoop = elapsed / (double)FLAGS_loops; |
| 91 printf("%.2g\t%s\n", msPerLoop, name); | 101 printf("%.2g\t%s\n", msPerLoop, name); |
| 92 } | 102 } |
| 93 | 103 |
| 94 int tool_main(int argc, char** argv); | 104 int tool_main(int argc, char** argv); |
| 95 int tool_main(int argc, char** argv) { | 105 int tool_main(int argc, char** argv) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 bench_record(src, filename.c_str(), pictureFactory); | 137 bench_record(src, filename.c_str(), pictureFactory); |
| 128 } | 138 } |
| 129 return failed ? 1 : 0; | 139 return failed ? 1 : 0; |
| 130 } | 140 } |
| 131 | 141 |
| 132 #if !defined SK_BUILD_FOR_IOS | 142 #if !defined SK_BUILD_FOR_IOS |
| 133 int main(int argc, char * const argv[]) { | 143 int main(int argc, char * const argv[]) { |
| 134 return tool_main(argc, (char**) argv); | 144 return tool_main(argc, (char**) argv); |
| 135 } | 145 } |
| 136 #endif | 146 #endif |
| OLD | NEW |