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 <stdio.h> | 8 #include <stdio.h> |
9 | 9 |
10 #include "BenchTimer.h" | |
11 #include "LazyDecodeBitmap.h" | |
12 #include "SkCommandLineFlags.h" | 10 #include "SkCommandLineFlags.h" |
13 #include "SkGraphics.h" | 11 #include "SkGraphics.h" |
14 #include "SkOSFile.h" | |
15 #include "SkPicture.h" | 12 #include "SkPicture.h" |
16 #include "SkRecord.h" | |
17 #include "SkRecordDraw.h" | |
18 #include "SkRecordOpts.h" | 13 #include "SkRecordOpts.h" |
19 #include "SkRecorder.h" | 14 #include "SkRecorder.h" |
20 #include "SkStream.h" | 15 #include "SkStream.h" |
21 | 16 |
| 17 #include "DumpRecord.h" |
| 18 #include "LazyDecodeBitmap.h" |
| 19 |
22 DEFINE_string2(skps, r, "", ".SKPs to dump."); | 20 DEFINE_string2(skps, r, "", ".SKPs to dump."); |
23 DEFINE_string(match, "", "The usual filters on file names to dump."); | 21 DEFINE_string(match, "", "The usual filters on file names to dump."); |
24 DEFINE_bool2(optimize, O, false, "Run SkRecordOptimize before dumping."); | 22 DEFINE_bool2(optimize, O, false, "Run SkRecordOptimize before dumping."); |
25 DEFINE_int32(tile, 1000000000, "Simulated tile size."); | 23 DEFINE_int32(tile, 1000000000, "Simulated tile size."); |
26 DEFINE_bool(timeWithCommand, false, "If true, print time next to command, else i
n first column."); | 24 DEFINE_bool(timeWithCommand, false, "If true, print time next to command, else i
n first column."); |
27 | 25 |
28 class Dumper { | |
29 public: | |
30 explicit Dumper(SkCanvas* canvas, int count) : fDigits(0), fIndent(0), fDraw
(canvas) { | |
31 while (count > 0) { | |
32 count /= 10; | |
33 fDigits++; | |
34 } | |
35 } | |
36 | |
37 unsigned index() const { return fDraw.index(); } | |
38 void next() { fDraw.next(); } | |
39 | |
40 template <typename T> | |
41 void operator()(const T& command) { | |
42 BenchTimer timer; | |
43 timer.start(); | |
44 fDraw(command); | |
45 timer.end(); | |
46 | |
47 this->print(command, timer.fCpu); | |
48 } | |
49 | |
50 void operator()(const SkRecords::NoOp&) { | |
51 // Move on without printing anything. | |
52 } | |
53 | |
54 template <typename T> | |
55 void print(const T& command, double time) { | |
56 this->printNameAndTime(command, time); | |
57 } | |
58 | |
59 void print(const SkRecords::Restore& command, double time) { | |
60 --fIndent; | |
61 this->printNameAndTime(command, time); | |
62 } | |
63 | |
64 void print(const SkRecords::Save& command, double time) { | |
65 this->printNameAndTime(command, time); | |
66 ++fIndent; | |
67 } | |
68 | |
69 void print(const SkRecords::SaveLayer& command, double time) { | |
70 this->printNameAndTime(command, time); | |
71 ++fIndent; | |
72 } | |
73 | |
74 private: | |
75 template <typename T> | |
76 void printNameAndTime(const T& command, double time) { | |
77 if (!FLAGS_timeWithCommand) { | |
78 printf("%6.1f ", time * 1000); | |
79 } | |
80 printf("%*d ", fDigits, fDraw.index()); | |
81 for (int i = 0; i < fIndent; i++) { | |
82 putchar('\t'); | |
83 } | |
84 if (FLAGS_timeWithCommand) { | |
85 printf("%6.1f ", time * 1000); | |
86 } | |
87 puts(NameOf(command)); | |
88 } | |
89 | |
90 template <typename T> | |
91 static const char* NameOf(const T&) { | |
92 #define CASE(U) case SkRecords::U##_Type: return #U; | |
93 switch(T::kType) { SK_RECORD_TYPES(CASE); } | |
94 #undef CASE | |
95 SkDEBUGFAIL("Unknown T"); | |
96 return "Unknown T"; | |
97 } | |
98 | |
99 static const char* NameOf(const SkRecords::SaveLayer&) { | |
100 return "\x1b[31;1mSaveLayer\x1b[0m"; // Bold red. | |
101 } | |
102 | |
103 int fDigits; | |
104 int fIndent; | |
105 SkRecords::Draw fDraw; | |
106 }; | |
107 | |
108 | |
109 static void dump(const char* name, int w, int h, const SkRecord& record) { | 26 static void dump(const char* name, int w, int h, const SkRecord& record) { |
110 SkBitmap bitmap; | 27 SkBitmap bitmap; |
111 bitmap.allocN32Pixels(w, h); | 28 bitmap.allocN32Pixels(w, h); |
112 SkCanvas canvas(bitmap); | 29 SkCanvas canvas(bitmap); |
113 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLAG
S_tile))); | 30 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), |
| 31 SkIntToScalar(FLAGS_tile))); |
114 | 32 |
115 printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name); | 33 printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name); |
116 | 34 |
117 for (Dumper dumper(&canvas, record.count()); dumper.index() < record.count()
; dumper.next()) { | 35 DumpRecord(record, &canvas, FLAGS_timeWithCommand); |
118 record.visit<void>(dumper.index(), dumper); | |
119 } | |
120 } | 36 } |
121 | 37 |
| 38 |
122 int tool_main(int argc, char** argv); | 39 int tool_main(int argc, char** argv); |
123 int tool_main(int argc, char** argv) { | 40 int tool_main(int argc, char** argv) { |
124 SkCommandLineFlags::Parse(argc, argv); | 41 SkCommandLineFlags::Parse(argc, argv); |
125 SkAutoGraphics ag; | 42 SkAutoGraphics ag; |
126 | 43 |
127 for (int i = 0; i < FLAGS_skps.count(); i++) { | 44 for (int i = 0; i < FLAGS_skps.count(); i++) { |
128 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) { | 45 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) { |
129 continue; | 46 continue; |
130 } | 47 } |
131 | 48 |
(...skipping 23 matching lines...) Expand all Loading... |
155 } | 72 } |
156 | 73 |
157 return 0; | 74 return 0; |
158 } | 75 } |
159 | 76 |
160 #if !defined SK_BUILD_FOR_IOS | 77 #if !defined SK_BUILD_FOR_IOS |
161 int main(int argc, char * const argv[]) { | 78 int main(int argc, char * const argv[]) { |
162 return tool_main(argc, (char**) argv); | 79 return tool_main(argc, (char**) argv); |
163 } | 80 } |
164 #endif | 81 #endif |
OLD | NEW |