| 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 "SkStream.h" | 13 #include "SkStream.h" |
| 14 #include "SkString.h" | 14 #include "SkString.h" |
| 15 #include "SkTime.h" | 15 #include "SkTime.h" |
| 16 | 16 |
| 17 __SK_FORCE_IMAGE_DECODER_LINKING; | 17 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 18 | 18 |
| 19 // Just reading all the SKPs takes about 2 seconds for me, which is the same as
about 100 loops of | 19 // Just reading all the SKPs takes about 2 seconds for me, which is the same as
about 100 loops of |
| 20 // rerecording all the SKPs. So we default to --loops=900, which makes ~90% of
our time spent in | 20 // rerecording all the SKPs. So we default to --loops=900, which makes ~90% of
our time spent in |
| 21 // recording, and this should take ~20 seconds to run. | 21 // recording, and this should take ~20 seconds to run. |
| 22 | 22 |
| 23 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record
."); | 23 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record
."); |
| 24 DEFINE_int32(loops, 900, "Number of times to re-record each SKP."); | 24 DEFINE_int32(loops, 900, "Number of times to re-record each SKP."); |
| 25 DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFl
ags to use."); | 25 DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFl
ags to use."); |
| 26 DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()"
); | 26 DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()"
); |
| 27 DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture."); |
| 28 |
| 29 static void bench_record(SkPicture* src, const char* name) { |
| 30 const SkMSec start = SkTime::GetMSecs(); |
| 31 const int width = src ? src->width() : FLAGS_nullSize; |
| 32 const int height = src ? src->height() : FLAGS_nullSize; |
| 33 |
| 34 for (int i = 0; i < FLAGS_loops; i++) { |
| 35 SkPicture dst; |
| 36 SkCanvas* canvas = dst.beginRecording(width, height, FLAGS_flags); |
| 37 if (src) src->draw(canvas); |
| 38 if (FLAGS_endRecording) dst.endRecording(); |
| 39 } |
| 40 |
| 41 const SkMSec elapsed = SkTime::GetMSecs() - start; |
| 42 const double msPerLoop = elapsed / (double)FLAGS_loops; |
| 43 printf("%.2g\t%s\n", msPerLoop, name); |
| 44 } |
| 27 | 45 |
| 28 int tool_main(int argc, char** argv); | 46 int tool_main(int argc, char** argv); |
| 29 int tool_main(int argc, char** argv) { | 47 int tool_main(int argc, char** argv) { |
| 30 SkCommandLineFlags::Parse(argc, argv); | 48 SkCommandLineFlags::Parse(argc, argv); |
| 31 SkAutoGraphics autoGraphics; | 49 SkAutoGraphics autoGraphics; |
| 32 | 50 |
| 51 bench_record(NULL, "NULL"); |
| 52 if (FLAGS_skps.isEmpty()) return 0; |
| 53 |
| 33 SkOSFile::Iter it(FLAGS_skps[0], ".skp"); | 54 SkOSFile::Iter it(FLAGS_skps[0], ".skp"); |
| 34 SkString filename; | 55 SkString filename; |
| 56 bool failed = false; |
| 35 while (it.next(&filename)) { | 57 while (it.next(&filename)) { |
| 36 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str
()); | 58 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str
()); |
| 37 | 59 |
| 38 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str())); | 60 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str())); |
| 39 if (!stream) { | 61 if (!stream) { |
| 40 SkDebugf("Could not read %s.\n", path.c_str()); | 62 SkDebugf("Could not read %s.\n", path.c_str()); |
| 63 failed = true; |
| 41 continue; | 64 continue; |
| 42 } | 65 } |
| 43 SkAutoTUnref<SkPicture> src(SkPicture::CreateFromStream(stream)); | 66 SkAutoTUnref<SkPicture> src(SkPicture::CreateFromStream(stream)); |
| 44 if (!src) { | 67 if (!src) { |
| 45 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str()); | 68 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str()); |
| 69 failed = true; |
| 46 continue; | 70 continue; |
| 47 } | 71 } |
| 48 | 72 bench_record(src, filename.c_str()); |
| 49 const SkMSec start = SkTime::GetMSecs(); | |
| 50 for (int i = 0; i < FLAGS_loops; i++) { | |
| 51 SkPicture dst; | |
| 52 src->draw(dst.beginRecording(src->width(), src->height(), FLAGS_flag
s)); | |
| 53 if (FLAGS_endRecording) dst.endRecording(); | |
| 54 } | |
| 55 | |
| 56 const SkMSec elapsed = SkTime::GetMSecs() - start; | |
| 57 const double msPerLoop = elapsed / (double)FLAGS_loops; | |
| 58 printf("%4.2f\t%s\n", msPerLoop, filename.c_str()); | |
| 59 } | 73 } |
| 60 | 74 return failed ? 1 : 0; |
| 61 return 0; | |
| 62 } | 75 } |
| 63 | 76 |
| 64 #if !defined SK_BUILD_FOR_IOS | 77 #if !defined SK_BUILD_FOR_IOS |
| 65 int main(int argc, char * const argv[]) { | 78 int main(int argc, char * const argv[]) { |
| 66 return tool_main(argc, (char**) argv); | 79 return tool_main(argc, (char**) argv); |
| 67 } | 80 } |
| 68 #endif | 81 #endif |
| OLD | NEW |