| 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 12 matching lines...) Expand all Loading... |
| 23 // recording, and this should take ~20 seconds to run. | 23 // recording, and this should take ~20 seconds to run. |
| 24 | 24 |
| 25 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
."); |
| 26 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."); |
| 27 DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFl
ags to use."); | 27 DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFl
ags to use."); |
| 28 DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()"
); | 28 DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()"
); |
| 29 DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture."); | 29 DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture."); |
| 30 DEFINE_int32(tileGridSize, 512, "Set the tile grid size. Has no effect if bbh is
not set to tilegrid."); | 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"); | 31 DEFINE_string(bbh, "", "Turn on the bbh and select the type, one of rtree, tileg
rid, quadtree"); |
| 32 | 32 |
| 33 typedef SkPicture* (*PictureFactory)(const int width, const int height, int* rec
ordingFlags); | 33 typedef SkPictureFactory* (*PictureFactory)(int* recordingFlags); |
| 34 | 34 |
| 35 static SkPicture* vanilla_factory(const int width, const int height, int* record
ingFlags) { | 35 static SkPictureFactory* vanilla_factory(int* recordingFlags) { |
| 36 return SkNEW(SkPicture); | 36 return NULL; |
| 37 } | 37 } |
| 38 | 38 |
| 39 static SkPicture* rtree_factory(const int width, const int height, int* recordin
gFlags) { | 39 static SkPictureFactory* rtree_factory(int* recordingFlags) { |
| 40 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; | 40 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
| 41 return SkNEW(SkPicture); | 41 return NULL; |
| 42 } | 42 } |
| 43 | 43 |
| 44 static SkPicture* tilegrid_factory(const int width, const int height, int* recor
dingFlags) { | 44 static SkPictureFactory* tilegrid_factory(int* recordingFlags) { |
| 45 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; | 45 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
| 46 SkTileGridPicture::TileGridInfo info; | 46 SkTileGridPicture::TileGridInfo info; |
| 47 info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize); | 47 info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize); |
| 48 info.fMargin.setEmpty(); | 48 info.fMargin.setEmpty(); |
| 49 info.fOffset.setZero(); | 49 info.fOffset.setZero(); |
| 50 return SkNEW_ARGS(SkTileGridPicture, (width, height, info)); | 50 return SkNEW_ARGS(SkTileGridPictureFactory, (info)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static SkPicture* quadtree_factory(const int width, const int height, int* recor
dingFlags) { | 53 static SkPictureFactory* quadtree_factory(int* recordingFlags) { |
| 54 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; | 54 *recordingFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
| 55 return SkNEW_ARGS(SkQuadTreePicture, (SkIRect::MakeWH(width, height))); | 55 return SkNEW(SkQuadTreePictureFactory); |
| 56 } | 56 } |
| 57 | 57 |
| 58 static PictureFactory parse_FLAGS_bbh() { | 58 static PictureFactory parse_FLAGS_bbh() { |
| 59 if (FLAGS_bbh.isEmpty()) { return &vanilla_factory; } | 59 if (FLAGS_bbh.isEmpty()) { |
| 60 return &vanilla_factory; |
| 61 } |
| 60 if (FLAGS_bbh.count() != 1) { | 62 if (FLAGS_bbh.count() != 1) { |
| 61 SkDebugf("Multiple bbh arguments supplied.\n"); | 63 SkDebugf("Multiple bbh arguments supplied.\n"); |
| 62 return NULL; | 64 return NULL; |
| 63 } | 65 } |
| 64 if (FLAGS_bbh.contains("rtree")) { return rtree_factory; } | 66 if (FLAGS_bbh.contains("rtree")) { |
| 65 if (FLAGS_bbh.contains("tilegrid")) { return tilegrid_factory; } | 67 return rtree_factory; |
| 66 if (FLAGS_bbh.contains("quadtree")) { return quadtree_factory; } | 68 } |
| 69 if (FLAGS_bbh.contains("tilegrid")) { |
| 70 return tilegrid_factory; |
| 71 } |
| 72 if (FLAGS_bbh.contains("quadtree")) { |
| 73 return quadtree_factory; |
| 74 } |
| 67 SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n",
FLAGS_bbh[0]); | 75 SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n",
FLAGS_bbh[0]); |
| 68 return NULL; | 76 return NULL; |
| 69 } | 77 } |
| 70 | 78 |
| 71 static void bench_record(SkPicture* src, const char* name, PictureFactory pictur
eFactory) { | 79 static void bench_record(SkPicture* src, const char* name, PictureFactory pictur
eFactory) { |
| 72 const SkMSec start = SkTime::GetMSecs(); | 80 const SkMSec start = SkTime::GetMSecs(); |
| 73 const int width = src ? src->width() : FLAGS_nullSize; | 81 const int width = src ? src->width() : FLAGS_nullSize; |
| 74 const int height = src ? src->height() : FLAGS_nullSize; | 82 const int height = src ? src->height() : FLAGS_nullSize; |
| 75 | 83 |
| 76 for (int i = 0; i < FLAGS_loops; i++) { | 84 for (int i = 0; i < FLAGS_loops; i++) { |
| 77 int recordingFlags = FLAGS_flags; | 85 int recordingFlags = FLAGS_flags; |
| 78 SkAutoTUnref<SkPicture> dst(pictureFactory(width, height, &recordingFlag
s)); | 86 SkAutoTUnref<SkPictureFactory> factory(pictureFactory(&recordingFlags)); |
| 79 SkCanvas* canvas = dst->beginRecording(width, height, recordingFlags); | 87 SkPictureRecorder recorder(factory); |
| 88 SkCanvas* canvas = recorder.beginRecording(width, height, recordingFlags
); |
| 80 if (NULL != src) { | 89 if (NULL != src) { |
| 81 src->draw(canvas); | 90 src->draw(canvas); |
| 82 } | 91 } |
| 83 if (FLAGS_endRecording) { | 92 if (FLAGS_endRecording) { |
| 84 dst->endRecording(); | 93 SkAutoTUnref<SkPicture> dst(recorder.endRecording()); |
| 85 } | 94 } |
| 86 } | 95 } |
| 87 | 96 |
| 88 const SkMSec elapsed = SkTime::GetMSecs() - start; | 97 const SkMSec elapsed = SkTime::GetMSecs() - start; |
| 89 const double msPerLoop = elapsed / (double)FLAGS_loops; | 98 const double msPerLoop = elapsed / (double)FLAGS_loops; |
| 90 printf("%.2g\t%s\n", msPerLoop, name); | 99 printf("%.2g\t%s\n", msPerLoop, name); |
| 91 } | 100 } |
| 92 | 101 |
| 93 int tool_main(int argc, char** argv); | 102 int tool_main(int argc, char** argv); |
| 94 int tool_main(int argc, char** argv) { | 103 int tool_main(int argc, char** argv) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 125 bench_record(src, filename.c_str(), pictureFactory); | 134 bench_record(src, filename.c_str(), pictureFactory); |
| 126 } | 135 } |
| 127 return failed ? 1 : 0; | 136 return failed ? 1 : 0; |
| 128 } | 137 } |
| 129 | 138 |
| 130 #if !defined SK_BUILD_FOR_IOS | 139 #if !defined SK_BUILD_FOR_IOS |
| 131 int main(int argc, char * const argv[]) { | 140 int main(int argc, char * const argv[]) { |
| 132 return tool_main(argc, (char**) argv); | 141 return tool_main(argc, (char**) argv); |
| 133 } | 142 } |
| 134 #endif | 143 #endif |
| OLD | NEW |