Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Side by Side Diff: tools/DumpRecord.cpp

Issue 527423002: SkRecordPartialDraw with less code duplication (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: test Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/RecordDrawTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkRecord.h" 10 #include "SkRecord.h"
11 #include "SkRecordDraw.h" 11 #include "SkRecordDraw.h"
12 12
13 #include "DumpRecord.h" 13 #include "DumpRecord.h"
14 #include "Timer.h" 14 #include "Timer.h"
15 15
16 namespace { 16 namespace {
17 17
18 class Dumper { 18 class Dumper {
19 public: 19 public:
20 explicit Dumper(SkCanvas* canvas, int count, bool timeWithCommand) 20 explicit Dumper(SkCanvas* canvas, int count, bool timeWithCommand)
21 : fDigits(0) 21 : fDigits(0)
22 , fIndent(0) 22 , fIndent(0)
23 , fIndex(0)
23 , fDraw(canvas) 24 , fDraw(canvas)
24 , fTimeWithCommand(timeWithCommand) { 25 , fTimeWithCommand(timeWithCommand) {
25 while (count > 0) { 26 while (count > 0) {
26 count /= 10; 27 count /= 10;
27 fDigits++; 28 fDigits++;
28 } 29 }
29 } 30 }
30 31
31 unsigned index() const { return fDraw.index(); }
32 void next() { fDraw.next(); }
33
34 template <typename T> 32 template <typename T>
35 void operator()(const T& command) { 33 void operator()(const T& command) {
36 Timer timer; 34 Timer timer;
37 timer.start(); 35 timer.start();
38 fDraw(command); 36 fDraw(command);
39 timer.end(); 37 timer.end();
40 38
41 this->print(command, timer.fCpu); 39 this->print(command, timer.fCpu);
42 } 40 }
43 41
(...skipping 20 matching lines...) Expand all
64 this->printNameAndTime(command, time); 62 this->printNameAndTime(command, time);
65 ++fIndent; 63 ++fIndent;
66 } 64 }
67 65
68 private: 66 private:
69 template <typename T> 67 template <typename T>
70 void printNameAndTime(const T& command, double time) { 68 void printNameAndTime(const T& command, double time) {
71 if (!fTimeWithCommand) { 69 if (!fTimeWithCommand) {
72 printf("%6.1f ", time * 1000); 70 printf("%6.1f ", time * 1000);
73 } 71 }
74 printf("%*d ", fDigits, fDraw.index()); 72 printf("%*d ", fDigits, fIndex++);
75 for (int i = 0; i < fIndent; i++) { 73 for (int i = 0; i < fIndent; i++) {
76 putchar('\t'); 74 putchar('\t');
77 } 75 }
78 if (fTimeWithCommand) { 76 if (fTimeWithCommand) {
79 printf("%6.1f ", time * 1000); 77 printf("%6.1f ", time * 1000);
80 } 78 }
81 puts(NameOf(command)); 79 puts(NameOf(command));
82 } 80 }
83 81
84 template <typename T> 82 template <typename T>
85 static const char* NameOf(const T&) { 83 static const char* NameOf(const T&) {
86 #define CASE(U) case SkRecords::U##_Type: return #U; 84 #define CASE(U) case SkRecords::U##_Type: return #U;
87 switch(T::kType) { SK_RECORD_TYPES(CASE); } 85 switch(T::kType) { SK_RECORD_TYPES(CASE); }
88 #undef CASE 86 #undef CASE
89 SkDEBUGFAIL("Unknown T"); 87 SkDEBUGFAIL("Unknown T");
90 return "Unknown T"; 88 return "Unknown T";
91 } 89 }
92 90
93 static const char* NameOf(const SkRecords::SaveLayer&) { 91 static const char* NameOf(const SkRecords::SaveLayer&) {
94 return "\x1b[31;1mSaveLayer\x1b[0m"; // Bold red. 92 return "\x1b[31;1mSaveLayer\x1b[0m"; // Bold red.
95 } 93 }
96 94
97 int fDigits; 95 int fDigits;
98 int fIndent; 96 int fIndent;
97 int fIndex;
99 SkRecords::Draw fDraw; 98 SkRecords::Draw fDraw;
100 const bool fTimeWithCommand; 99 const bool fTimeWithCommand;
101 }; 100 };
102 101
103 } // namespace 102 } // namespace
104 103
105 void DumpRecord(const SkRecord& record, 104 void DumpRecord(const SkRecord& record,
106 SkCanvas* canvas, 105 SkCanvas* canvas,
107 bool timeWithCommand) { 106 bool timeWithCommand) {
108 for (Dumper dumper(canvas, record.count(), timeWithCommand); 107 Dumper dumper(canvas, record.count(), timeWithCommand);
109 dumper.index() < record.count(); 108 for (unsigned i = 0; i < record.count(); i++) {
110 dumper.next()) { 109 record.visit<void>(i, dumper);
111 record.visit<void>(dumper.index(), dumper);
112 } 110 }
113 } 111 }
OLDNEW
« no previous file with comments | « tests/RecordDrawTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698