| 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" |
| 12 #include "SkCommandLineFlags.h" | 12 #include "SkCommandLineFlags.h" |
| 13 #include "SkGraphics.h" | 13 #include "SkGraphics.h" |
| 14 #include "SkOSFile.h" | 14 #include "SkOSFile.h" |
| 15 #include "SkPicture.h" | 15 #include "SkPicture.h" |
| 16 #include "SkRecord.h" | 16 #include "SkRecord.h" |
| 17 #include "SkRecordDraw.h" | 17 #include "SkRecordDraw.h" |
| 18 #include "SkRecordOpts.h" | 18 #include "SkRecordOpts.h" |
| 19 #include "SkRecorder.h" | 19 #include "SkRecorder.h" |
| 20 #include "SkStream.h" | 20 #include "SkStream.h" |
| 21 | 21 |
| 22 #include "DumpRecord.h" |
| 23 |
| 22 DEFINE_string2(skps, r, "", ".SKPs to dump."); | 24 DEFINE_string2(skps, r, "", ".SKPs to dump."); |
| 23 DEFINE_string(match, "", "The usual filters on file names to dump."); | 25 DEFINE_string(match, "", "The usual filters on file names to dump."); |
| 24 DEFINE_bool2(optimize, O, false, "Run SkRecordOptimize before dumping."); | 26 DEFINE_bool2(optimize, O, false, "Run SkRecordOptimize before dumping."); |
| 25 DEFINE_int32(tile, 1000000000, "Simulated tile size."); | 27 DEFINE_int32(tile, 1000000000, "Simulated tile size."); |
| 26 DEFINE_bool(timeWithCommand, false, "If true, print time next to command, else i
n first column."); | 28 DEFINE_bool(timeWithCommand, false, "If true, print time next to command, else i
n first column."); |
| 27 | 29 |
| 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) { | 30 static void dump(const char* name, int w, int h, const SkRecord& record) { |
| 110 SkBitmap bitmap; | 31 SkBitmap bitmap; |
| 111 bitmap.allocN32Pixels(w, h); | 32 bitmap.allocN32Pixels(w, h); |
| 112 SkCanvas canvas(bitmap); | 33 SkCanvas canvas(bitmap); |
| 113 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLAG
S_tile))); | 34 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), |
| 35 SkIntToScalar(FLAGS_tile))); |
| 114 | 36 |
| 115 printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name); | 37 printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name); |
| 116 | 38 |
| 117 for (Dumper dumper(&canvas, record.count()); dumper.index() < record.count()
; dumper.next()) { | 39 DumpRecord(record, &canvas, FLAGS_timeWithCommand); |
| 118 record.visit<void>(dumper.index(), dumper); | |
| 119 } | |
| 120 } | 40 } |
| 121 | 41 |
| 42 |
| 122 int tool_main(int argc, char** argv); | 43 int tool_main(int argc, char** argv); |
| 123 int tool_main(int argc, char** argv) { | 44 int tool_main(int argc, char** argv) { |
| 124 SkCommandLineFlags::Parse(argc, argv); | 45 SkCommandLineFlags::Parse(argc, argv); |
| 125 SkAutoGraphics ag; | 46 SkAutoGraphics ag; |
| 126 | 47 |
| 127 for (int i = 0; i < FLAGS_skps.count(); i++) { | 48 for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 128 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) { | 49 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) { |
| 129 continue; | 50 continue; |
| 130 } | 51 } |
| 131 | 52 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 155 } | 76 } |
| 156 | 77 |
| 157 return 0; | 78 return 0; |
| 158 } | 79 } |
| 159 | 80 |
| 160 #if !defined SK_BUILD_FOR_IOS | 81 #if !defined SK_BUILD_FOR_IOS |
| 161 int main(int argc, char * const argv[]) { | 82 int main(int argc, char * const argv[]) { |
| 162 return tool_main(argc, (char**) argv); | 83 return tool_main(argc, (char**) argv); |
| 163 } | 84 } |
| 164 #endif | 85 #endif |
| OLD | NEW |