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" | 10 #include "BenchTimer.h" |
11 #include "LazyDecodeBitmap.h" | 11 #include "LazyDecodeBitmap.h" |
mtklein
2014/05/15 15:44:08
Should be you can prune a bunch of these includes
hal.canary
2014/05/15 15:59:27
Done.
| |
12 #include "SkCommandLineFlags.h" | |
13 #include "SkGraphics.h" | 12 #include "SkGraphics.h" |
14 #include "SkOSFile.h" | 13 #include "SkOSFile.h" |
15 #include "SkPicture.h" | 14 #include "SkPicture.h" |
16 #include "SkRecord.h" | 15 #include "SkRecord.h" |
17 #include "SkRecordDraw.h" | 16 #include "SkRecordDraw.h" |
18 #include "SkRecordOpts.h" | 17 #include "SkRecordOpts.h" |
19 #include "SkRecorder.h" | 18 #include "SkRecorder.h" |
20 #include "SkStream.h" | 19 #include "SkStream.h" |
21 | 20 |
22 DEFINE_string2(skps, r, "", ".SKPs to dump."); | 21 #include "DumpRecord.h" |
23 DEFINE_string(match, "", "The usual filters on file names to dump."); | 22 |
24 DEFINE_bool2(optimize, O, false, "Run SkRecordOptimize before dumping."); | 23 namespace { |
25 DEFINE_int32(tile, 1000000000, "Simulated tile size."); | |
26 DEFINE_bool(timeWithCommand, false, "If true, print time next to command, else i n first column."); | |
27 | 24 |
28 class Dumper { | 25 class Dumper { |
29 public: | 26 public: |
30 explicit Dumper(SkCanvas* canvas, int count) : fDigits(0), fIndent(0), fDraw (canvas) { | 27 explicit Dumper(SkCanvas* canvas, int count, bool timeWithCommand) |
28 : fDigits(0) | |
29 , fIndent(0) | |
30 , fDraw(canvas) | |
31 , fTimeWithCommand(timeWithCommand) { | |
31 while (count > 0) { | 32 while (count > 0) { |
32 count /= 10; | 33 count /= 10; |
33 fDigits++; | 34 fDigits++; |
34 } | 35 } |
35 } | 36 } |
36 | 37 |
37 unsigned index() const { return fDraw.index(); } | 38 unsigned index() const { return fDraw.index(); } |
38 void next() { fDraw.next(); } | 39 void next() { fDraw.next(); } |
39 | 40 |
40 template <typename T> | 41 template <typename T> |
(...skipping 26 matching lines...) Expand all Loading... | |
67 } | 68 } |
68 | 69 |
69 void print(const SkRecords::SaveLayer& command, double time) { | 70 void print(const SkRecords::SaveLayer& command, double time) { |
70 this->printNameAndTime(command, time); | 71 this->printNameAndTime(command, time); |
71 ++fIndent; | 72 ++fIndent; |
72 } | 73 } |
73 | 74 |
74 private: | 75 private: |
75 template <typename T> | 76 template <typename T> |
76 void printNameAndTime(const T& command, double time) { | 77 void printNameAndTime(const T& command, double time) { |
77 if (!FLAGS_timeWithCommand) { | 78 if (!fTimeWithCommand) { |
78 printf("%6.1f ", time * 1000); | 79 printf("%6.1f ", time * 1000); |
79 } | 80 } |
80 printf("%*d ", fDigits, fDraw.index()); | 81 printf("%*d ", fDigits, fDraw.index()); |
81 for (int i = 0; i < fIndent; i++) { | 82 for (int i = 0; i < fIndent; i++) { |
82 putchar('\t'); | 83 putchar('\t'); |
83 } | 84 } |
84 if (FLAGS_timeWithCommand) { | 85 if (fTimeWithCommand) { |
85 printf("%6.1f ", time * 1000); | 86 printf("%6.1f ", time * 1000); |
86 } | 87 } |
87 puts(NameOf(command)); | 88 puts(NameOf(command)); |
88 } | 89 } |
89 | 90 |
90 template <typename T> | 91 template <typename T> |
91 static const char* NameOf(const T&) { | 92 static const char* NameOf(const T&) { |
92 #define CASE(U) case SkRecords::U##_Type: return #U; | 93 #define CASE(U) case SkRecords::U##_Type: return #U; |
93 switch(T::kType) { SK_RECORD_TYPES(CASE); } | 94 switch(T::kType) { SK_RECORD_TYPES(CASE); } |
94 #undef CASE | 95 #undef CASE |
95 SkDEBUGFAIL("Unknown T"); | 96 SkDEBUGFAIL("Unknown T"); |
96 return "Unknown T"; | 97 return "Unknown T"; |
97 } | 98 } |
98 | 99 |
99 static const char* NameOf(const SkRecords::SaveLayer&) { | 100 static const char* NameOf(const SkRecords::SaveLayer&) { |
100 return "\x1b[31;1mSaveLayer\x1b[0m"; // Bold red. | 101 return "\x1b[31;1mSaveLayer\x1b[0m"; // Bold red. |
101 } | 102 } |
102 | 103 |
103 int fDigits; | 104 int fDigits; |
104 int fIndent; | 105 int fIndent; |
105 SkRecords::Draw fDraw; | 106 SkRecords::Draw fDraw; |
107 const bool fTimeWithCommand; | |
106 }; | 108 }; |
107 | 109 |
110 } // namespace | |
108 | 111 |
109 static void dump(const char* name, int w, int h, const SkRecord& record) { | 112 //////////////////////////////////////////////////////////////////////////////// |
mtklein
2014/05/15 15:44:08
These things are just noise :(
hal.canary
2014/05/15 15:59:27
Done.
| |
110 SkBitmap bitmap; | |
111 bitmap.allocN32Pixels(w, h); | |
112 SkCanvas canvas(bitmap); | |
113 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLAG S_tile))); | |
114 | 113 |
115 printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name); | 114 void DumpRecord(const SkRecord& record, |
116 | 115 SkCanvas* canvas, |
117 for (Dumper dumper(&canvas, record.count()); dumper.index() < record.count() ; dumper.next()) { | 116 bool timeWithCommand) { |
117 for (Dumper dumper(canvas, record.count(), timeWithCommand); | |
118 dumper.index() < record.count(); | |
119 dumper.next()) { | |
118 record.visit<void>(dumper.index(), dumper); | 120 record.visit<void>(dumper.index(), dumper); |
119 } | 121 } |
120 } | 122 } |
121 | |
122 int tool_main(int argc, char** argv); | |
123 int tool_main(int argc, char** argv) { | |
124 SkCommandLineFlags::Parse(argc, argv); | |
125 SkAutoGraphics ag; | |
126 | |
127 for (int i = 0; i < FLAGS_skps.count(); i++) { | |
128 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) { | |
129 continue; | |
130 } | |
131 | |
132 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(FLAGS_skps[i])); | |
133 if (!stream) { | |
134 SkDebugf("Could not read %s.\n", FLAGS_skps[i]); | |
135 exit(1); | |
136 } | |
137 SkAutoTUnref<SkPicture> src( | |
138 SkPicture::CreateFromStream(stream, sk_tools::LazyDecodeBitmap)) ; | |
139 if (!src) { | |
140 SkDebugf("Could not read %s as an SkPicture.\n", FLAGS_skps[i]); | |
141 exit(1); | |
142 } | |
143 const int w = src->width(), h = src->height(); | |
144 | |
145 SkRecord record; | |
146 SkRecorder canvas(SkRecorder::kWriteOnly_Mode, &record, w, h); | |
147 src->draw(&canvas); | |
148 | |
149 | |
150 if (FLAGS_optimize) { | |
151 SkRecordOptimize(&record); | |
152 } | |
153 | |
154 dump(FLAGS_skps[i], w, h, record); | |
155 } | |
156 | |
157 return 0; | |
158 } | |
159 | |
160 #if !defined SK_BUILD_FOR_IOS | |
161 int main(int argc, char * const argv[]) { | |
162 return tool_main(argc, (char**) argv); | |
163 } | |
164 #endif | |
OLD | NEW |