185fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org/* 285fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org * Copyright 2014 Google Inc. 385fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org * 485fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be 585fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org * found in the LICENSE file. 685fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org */ 785fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 885fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org#include <stdio.h> 985fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 1085fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org#include "SkRecord.h" 1185fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org#include "SkRecordDraw.h" 1285fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 1385fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org#include "DumpRecord.h" 149ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein#include "Timer.h" 1585fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 1685fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.orgnamespace { 1785fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 1885fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.orgclass Dumper { 1985fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.orgpublic: 2085fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org explicit Dumper(SkCanvas* canvas, int count, bool timeWithCommand) 2185fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org : fDigits(0) 2285fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org , fIndent(0) 2385fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org , fDraw(canvas) 2485fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org , fTimeWithCommand(timeWithCommand) { 2585fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org while (count > 0) { 2685fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org count /= 10; 2785fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org fDigits++; 2885fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 2985fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 3085fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 3185fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org unsigned index() const { return fDraw.index(); } 3285fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org void next() { fDraw.next(); } 3385fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 3485fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org template <typename T> 3585fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org void operator()(const T& command) { 369ac68ee2594f28dfc1bd16a4bf004b1a4f6f228dmtklein Timer timer; 3785fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org timer.start(); 3885fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org fDraw(command); 3985fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org timer.end(); 4085fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 4185fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org this->print(command, timer.fCpu); 4285fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 4385fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 4485fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org void operator()(const SkRecords::NoOp&) { 4585fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org // Move on without printing anything. 4685fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 4785fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 4885fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org template <typename T> 4985fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org void print(const T& command, double time) { 5085fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org this->printNameAndTime(command, time); 5185fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 5285fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 5385fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org void print(const SkRecords::Restore& command, double time) { 5485fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org --fIndent; 5585fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org this->printNameAndTime(command, time); 5685fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 5785fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 5885fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org void print(const SkRecords::Save& command, double time) { 5985fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org this->printNameAndTime(command, time); 6085fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org ++fIndent; 6185fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 6285fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 6385fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org void print(const SkRecords::SaveLayer& command, double time) { 6485fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org this->printNameAndTime(command, time); 6585fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org ++fIndent; 6685fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 6785fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 6885fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.orgprivate: 6985fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org template <typename T> 7085fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org void printNameAndTime(const T& command, double time) { 7185fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org if (!fTimeWithCommand) { 7285fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org printf("%6.1f ", time * 1000); 7385fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 7485fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org printf("%*d ", fDigits, fDraw.index()); 7585fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org for (int i = 0; i < fIndent; i++) { 7685fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org putchar('\t'); 7785fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 7885fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org if (fTimeWithCommand) { 7985fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org printf("%6.1f ", time * 1000); 8085fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 8185fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org puts(NameOf(command)); 8285fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 8385fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 8485fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org template <typename T> 8585fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org static const char* NameOf(const T&) { 8685fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org #define CASE(U) case SkRecords::U##_Type: return #U; 8785fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org switch(T::kType) { SK_RECORD_TYPES(CASE); } 8885fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org #undef CASE 8985fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org SkDEBUGFAIL("Unknown T"); 9085fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org return "Unknown T"; 9185fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 9285fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 9385fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org static const char* NameOf(const SkRecords::SaveLayer&) { 9485fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org return "\x1b[31;1mSaveLayer\x1b[0m"; // Bold red. 9585fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 9685fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 9785fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org int fDigits; 9885fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org int fIndent; 9985fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org SkRecords::Draw fDraw; 10085fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org const bool fTimeWithCommand; 10185fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org}; 10285fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 10385fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org} // namespace 10485fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org 10585fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.orgvoid DumpRecord(const SkRecord& record, 10685fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org SkCanvas* canvas, 10785fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org bool timeWithCommand) { 10885fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org for (Dumper dumper(canvas, record.count(), timeWithCommand); 10985fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org dumper.index() < record.count(); 11085fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org dumper.next()) { 11185fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org record.visit<void>(dumper.index(), dumper); 11285fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org } 11385fd1932231e21703fc4e1846a3769b5a5119c77commit-bot@chromium.org} 114