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 "BenchTimer.h" |
8 #include "SkCommandLineFlags.h" | 9 #include "SkCommandLineFlags.h" |
9 #include "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
10 #include "SkGraphics.h" | 11 #include "SkGraphics.h" |
11 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
12 #include "SkPicture.h" | 13 #include "SkPicture.h" |
13 #include "SkPictureRecorder.h" | 14 #include "SkPictureRecorder.h" |
14 #include "SkRecording.h" | 15 #include "SkRecording.h" |
15 #include "SkStream.h" | 16 #include "SkStream.h" |
16 #include "SkString.h" | 17 #include "SkString.h" |
17 #include "SkTime.h" | |
18 #include "LazyDecodeBitmap.h" | 18 #include "LazyDecodeBitmap.h" |
19 | 19 |
20 __SK_FORCE_IMAGE_DECODER_LINKING; | 20 __SK_FORCE_IMAGE_DECODER_LINKING; |
21 | 21 |
22 // Just reading all the SKPs takes about 2 seconds for me, which is the same as
about 100 loops of | 22 // 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 | 23 // 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. | 24 // recording, and this should take ~20 seconds to run. |
25 | 25 |
26 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record
."); | 26 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."); | 27 DEFINE_int32(loops, 900, "Number of times to re-record each SKP."); |
(...skipping 21 matching lines...) Expand all Loading... |
49 return SkNEW_ARGS(SkTileGridFactory, (info)); | 49 return SkNEW_ARGS(SkTileGridFactory, (info)); |
50 } | 50 } |
51 if (FLAGS_bbh.contains("quadtree")) { | 51 if (FLAGS_bbh.contains("quadtree")) { |
52 return SkNEW(SkQuadTreeFactory); | 52 return SkNEW(SkQuadTreeFactory); |
53 } | 53 } |
54 SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n",
FLAGS_bbh[0]); | 54 SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n",
FLAGS_bbh[0]); |
55 return NULL; | 55 return NULL; |
56 } | 56 } |
57 | 57 |
58 static void bench_record(SkPicture* src, const char* name, SkBBHFactory* bbhFact
ory) { | 58 static void bench_record(SkPicture* src, const char* name, SkBBHFactory* bbhFact
ory) { |
59 const SkMSec start = SkTime::GetMSecs(); | 59 BenchTimer timer; |
| 60 timer.start(); |
60 const int width = src ? src->width() : FLAGS_nullSize; | 61 const int width = src ? src->width() : FLAGS_nullSize; |
61 const int height = src ? src->height() : FLAGS_nullSize; | 62 const int height = src ? src->height() : FLAGS_nullSize; |
62 | 63 |
63 for (int i = 0; i < FLAGS_loops; i++) { | 64 for (int i = 0; i < FLAGS_loops; i++) { |
64 if (FLAGS_skr) { | 65 if (FLAGS_skr) { |
65 EXPERIMENTAL::SkRecording recording(width, height); | 66 EXPERIMENTAL::SkRecording recording(width, height); |
66 if (NULL != src) { | 67 if (NULL != src) { |
67 src->draw(recording.canvas()); | 68 src->draw(recording.canvas()); |
68 } | 69 } |
69 // Release and delete the SkPlayback so that recording optimizes its
SkRecord. | 70 // Release and delete the SkPlayback so that recording optimizes its
SkRecord. |
70 SkDELETE(recording.releasePlayback()); | 71 SkDELETE(recording.releasePlayback()); |
71 } else { | 72 } else { |
72 SkPictureRecorder recorder; | 73 SkPictureRecorder recorder; |
73 SkCanvas* canvas = recorder.beginRecording(width, height, bbhFactory
, FLAGS_flags); | 74 SkCanvas* canvas = recorder.beginRecording(width, height, bbhFactory
, FLAGS_flags); |
74 if (NULL != src) { | 75 if (NULL != src) { |
75 src->draw(canvas); | 76 src->draw(canvas); |
76 } | 77 } |
77 if (FLAGS_endRecording) { | 78 if (FLAGS_endRecording) { |
78 SkAutoTUnref<SkPicture> dst(recorder.endRecording()); | 79 SkAutoTUnref<SkPicture> dst(recorder.endRecording()); |
79 } | 80 } |
80 } | 81 } |
81 } | 82 } |
| 83 timer.end(); |
82 | 84 |
83 const SkMSec elapsed = SkTime::GetMSecs() - start; | 85 const double msPerLoop = timer.fCpu / (double)FLAGS_loops; |
84 const double msPerLoop = elapsed / (double)FLAGS_loops; | 86 printf("%u\t%s\n", unsigned(1000 * msPerLoop), name); |
85 printf("%.2g\t%s\n", msPerLoop, name); | |
86 } | 87 } |
87 | 88 |
88 int tool_main(int argc, char** argv); | 89 int tool_main(int argc, char** argv); |
89 int tool_main(int argc, char** argv) { | 90 int tool_main(int argc, char** argv) { |
90 SkCommandLineFlags::Parse(argc, argv); | 91 SkCommandLineFlags::Parse(argc, argv); |
91 SkAutoGraphics autoGraphics; | 92 SkAutoGraphics autoGraphics; |
92 | 93 |
93 if (FLAGS_bbh.count() > 1) { | 94 if (FLAGS_bbh.count() > 1) { |
94 SkDebugf("Multiple bbh arguments supplied.\n"); | 95 SkDebugf("Multiple bbh arguments supplied.\n"); |
95 return 1; | 96 return 1; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 bench_record(src, filename.c_str(), bbhFactory.get()); | 128 bench_record(src, filename.c_str(), bbhFactory.get()); |
128 } | 129 } |
129 return failed ? 1 : 0; | 130 return failed ? 1 : 0; |
130 } | 131 } |
131 | 132 |
132 #if !defined SK_BUILD_FOR_IOS | 133 #if !defined SK_BUILD_FOR_IOS |
133 int main(int argc, char * const argv[]) { | 134 int main(int argc, char * const argv[]) { |
134 return tool_main(argc, (char**) argv); | 135 return tool_main(argc, (char**) argv); |
135 } | 136 } |
136 #endif | 137 #endif |
OLD | NEW |