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