commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | |
| 10 | #include "SkRecord.h" |
| 11 | #include "SkRecordDraw.h" |
| 12 | |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 13 | #include "DumpRecord.h" |
mtklein | 2f2903d | 2015-11-18 11:06:37 -0800 | [diff] [blame] | 14 | #include "SkTime.h" |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 15 | |
| 16 | namespace { |
| 17 | |
| 18 | class Dumper { |
| 19 | public: |
| 20 | explicit Dumper(SkCanvas* canvas, int count, bool timeWithCommand) |
| 21 | : fDigits(0) |
| 22 | , fIndent(0) |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 23 | , fIndex(0) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 24 | , fDraw(canvas, nullptr, nullptr, 0, nullptr) |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 25 | , fTimeWithCommand(timeWithCommand) { |
| 26 | while (count > 0) { |
| 27 | count /= 10; |
| 28 | fDigits++; |
| 29 | } |
| 30 | } |
| 31 | |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 32 | template <typename T> |
| 33 | void operator()(const T& command) { |
mtklein | 2f2903d | 2015-11-18 11:06:37 -0800 | [diff] [blame] | 34 | auto start = SkTime::GetNSecs(); |
| 35 | fDraw(command); |
| 36 | this->print(command, SkTime::GetNSecs() - start); |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void operator()(const SkRecords::NoOp&) { |
| 40 | // Move on without printing anything. |
| 41 | } |
| 42 | |
| 43 | template <typename T> |
mtklein | 2f2903d | 2015-11-18 11:06:37 -0800 | [diff] [blame] | 44 | void print(const T& command, double ns) { |
| 45 | this->printNameAndTime(command, ns); |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 46 | } |
| 47 | |
mtklein | 2f2903d | 2015-11-18 11:06:37 -0800 | [diff] [blame] | 48 | void print(const SkRecords::Restore& command, double ns) { |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 49 | --fIndent; |
mtklein | 2f2903d | 2015-11-18 11:06:37 -0800 | [diff] [blame] | 50 | this->printNameAndTime(command, ns); |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 51 | } |
| 52 | |
mtklein | 2f2903d | 2015-11-18 11:06:37 -0800 | [diff] [blame] | 53 | void print(const SkRecords::Save& command, double ns) { |
| 54 | this->printNameAndTime(command, ns); |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 55 | ++fIndent; |
| 56 | } |
| 57 | |
mtklein | 2f2903d | 2015-11-18 11:06:37 -0800 | [diff] [blame] | 58 | void print(const SkRecords::SaveLayer& command, double ns) { |
| 59 | this->printNameAndTime(command, ns); |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 60 | ++fIndent; |
| 61 | } |
| 62 | |
mtklein | 3425cba | 2016-01-20 08:46:40 -0800 | [diff] [blame] | 63 | void print(const SkRecords::DrawPicture& command, double ns) { |
| 64 | this->printNameAndTime(command, ns); |
| 65 | |
Mike Klein | 88d9071 | 2018-01-27 17:30:04 +0000 | [diff] [blame] | 66 | if (auto bp = command.picture->asSkBigPicture()) { |
mtklein | 3425cba | 2016-01-20 08:46:40 -0800 | [diff] [blame] | 67 | ++fIndent; |
| 68 | |
| 69 | const SkRecord& record = *bp->record(); |
| 70 | for (int i = 0; i < record.count(); i++) { |
mtklein | 343a63d | 2016-03-22 11:46:53 -0700 | [diff] [blame] | 71 | record.visit(i, *this); |
mtklein | 3425cba | 2016-01-20 08:46:40 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | --fIndent; |
| 75 | } |
| 76 | } |
| 77 | |
Mike Reed | 5cb7617 | 2016-10-05 14:52:50 -0400 | [diff] [blame] | 78 | #if 1 |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 79 | void print(const SkRecords::DrawAnnotation& command, double ns) { |
| 80 | int us = (int)(ns * 1e-3); |
| 81 | if (!fTimeWithCommand) { |
| 82 | printf("%6dus ", us); |
| 83 | } |
| 84 | printf("%*d ", fDigits, fIndex++); |
| 85 | for (int i = 0; i < fIndent; i++) { |
| 86 | printf(" "); |
| 87 | } |
| 88 | if (fTimeWithCommand) { |
| 89 | printf("%6dus ", us); |
| 90 | } |
| 91 | printf("DrawAnnotation [%g %g %g %g] %s\n", |
| 92 | command.rect.left(), command.rect.top(), command.rect.right(), command.rect.bottom(), |
| 93 | command.key.c_str()); |
| 94 | } |
| 95 | #endif |
| 96 | |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 97 | private: |
| 98 | template <typename T> |
mtklein | 2f2903d | 2015-11-18 11:06:37 -0800 | [diff] [blame] | 99 | void printNameAndTime(const T& command, double ns) { |
| 100 | int us = (int)(ns * 1e-3); |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 101 | if (!fTimeWithCommand) { |
mtklein | 2f2903d | 2015-11-18 11:06:37 -0800 | [diff] [blame] | 102 | printf("%6dus ", us); |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 103 | } |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 104 | printf("%*d ", fDigits, fIndex++); |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 105 | for (int i = 0; i < fIndent; i++) { |
mtklein | 2f2903d | 2015-11-18 11:06:37 -0800 | [diff] [blame] | 106 | printf(" "); |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 107 | } |
| 108 | if (fTimeWithCommand) { |
mtklein | 2f2903d | 2015-11-18 11:06:37 -0800 | [diff] [blame] | 109 | printf("%6dus ", us); |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 110 | } |
| 111 | puts(NameOf(command)); |
| 112 | } |
| 113 | |
| 114 | template <typename T> |
| 115 | static const char* NameOf(const T&) { |
| 116 | #define CASE(U) case SkRecords::U##_Type: return #U; |
| 117 | switch(T::kType) { SK_RECORD_TYPES(CASE); } |
| 118 | #undef CASE |
| 119 | SkDEBUGFAIL("Unknown T"); |
| 120 | return "Unknown T"; |
| 121 | } |
| 122 | |
| 123 | static const char* NameOf(const SkRecords::SaveLayer&) { |
| 124 | return "\x1b[31;1mSaveLayer\x1b[0m"; // Bold red. |
| 125 | } |
| 126 | |
| 127 | int fDigits; |
| 128 | int fIndent; |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 129 | int fIndex; |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 130 | SkRecords::Draw fDraw; |
| 131 | const bool fTimeWithCommand; |
| 132 | }; |
| 133 | |
| 134 | } // namespace |
| 135 | |
| 136 | void DumpRecord(const SkRecord& record, |
| 137 | SkCanvas* canvas, |
| 138 | bool timeWithCommand) { |
mtklein | 00f30bd | 2014-09-02 12:03:31 -0700 | [diff] [blame] | 139 | Dumper dumper(canvas, record.count(), timeWithCommand); |
mtklein | c6ad06a | 2015-08-19 09:51:00 -0700 | [diff] [blame] | 140 | for (int i = 0; i < record.count(); i++) { |
mtklein | 343a63d | 2016-03-22 11:46:53 -0700 | [diff] [blame] | 141 | record.visit(i, dumper); |
commit-bot@chromium.org | 85fd193 | 2014-05-15 16:10:37 +0000 | [diff] [blame] | 142 | } |
| 143 | } |