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)
24 , fTimeWithCommand(timeWithCommand) {
31 unsigned index() const { return fDraw.index(); }
32 void next() { fDraw.next(); }
35 void operator()(const T& command) {
41 this->print(command, timer.fCpu);
44 void operator()(const SkRecords::NoOp&) {
45 // Move on without printing anything.
49 void print(const T& command, double time) {
50 this->printNameAndTime(command, time);
53 void print(const SkRecords::Restore& command, double time) {
55 this->printNameAndTime(command, time);
58 void print(const SkRecords::Save& command, double time) {
59 this->printNameAndTime(command, time);
63 void print(const SkRecords::SaveLayer& command, double time) {
64 this->printNameAndTime(command, time);
70 void printNameAndTime(const T& command, double time) {
71 if (!fTimeWithCommand) {
72 printf("%6.1f ", time * 1000);
74 printf("%*d ", fDigits, fDraw.index());
75 for (int i = 0; i < fIndent; i++) {
78 if (fTimeWithCommand) {
79 printf("%6.1f ", time * 1000);
81 puts(NameOf(command));
85 static const char* NameOf(const T&) {
86 #define CASE(U) case SkRecords::U##_Type: return #U;
87 switch(T::kType) { SK_RECORD_TYPES(CASE); }
89 SkDEBUGFAIL("Unknown T");
93 static const char* NameOf(const SkRecords::SaveLayer&) {
94 return "\x1b[31;1mSaveLayer\x1b[0m"; // Bold red.
99 SkRecords::Draw fDraw;
100 const bool fTimeWithCommand;
105 void DumpRecord(const SkRecord& record,
107 bool timeWithCommand) {
108 for (Dumper dumper(canvas, record.count(), timeWithCommand);
109 dumper.index() < record.count();
111 record.visit<void>(dumper.index(), dumper);