2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
11 #include "SkRecordDraw.h"
13 #include "DumpRecord.h"
20 explicit Dumper(SkCanvas* canvas, int count, bool timeWithCommand)
25 , fTimeWithCommand(timeWithCommand) {
33 void operator()(const T& command) {
39 this->print(command, timer.fCpu);
42 void operator()(const SkRecords::NoOp&) {
43 // Move on without printing anything.
47 void print(const T& command, double time) {
48 this->printNameAndTime(command, time);
51 void print(const SkRecords::Restore& command, double time) {
53 this->printNameAndTime(command, time);
56 void print(const SkRecords::Save& command, double time) {
57 this->printNameAndTime(command, time);
61 void print(const SkRecords::SaveLayer& command, double time) {
62 this->printNameAndTime(command, time);
68 void printNameAndTime(const T& command, double time) {
69 if (!fTimeWithCommand) {
70 printf("%6.1f ", time * 1000);
72 printf("%*d ", fDigits, fIndex++);
73 for (int i = 0; i < fIndent; i++) {
76 if (fTimeWithCommand) {
77 printf("%6.1f ", time * 1000);
79 puts(NameOf(command));
83 static const char* NameOf(const T&) {
84 #define CASE(U) case SkRecords::U##_Type: return #U;
85 switch(T::kType) { SK_RECORD_TYPES(CASE); }
87 SkDEBUGFAIL("Unknown T");
91 static const char* NameOf(const SkRecords::SaveLayer&) {
92 return "\x1b[31;1mSaveLayer\x1b[0m"; // Bold red.
98 SkRecords::Draw fDraw;
99 const bool fTimeWithCommand;
104 void DumpRecord(const SkRecord& record,
106 bool timeWithCommand) {
107 Dumper dumper(canvas, record.count(), timeWithCommand);
108 for (unsigned i = 0; i < record.count(); i++) {
109 record.visit<void>(i, dumper);