2014-05-15 16:10:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "SkRecord.h"
|
|
|
|
#include "SkRecordDraw.h"
|
|
|
|
|
|
|
|
#include "DumpRecord.h"
|
2015-11-18 19:06:37 +00:00
|
|
|
#include "SkTime.h"
|
2014-05-15 16:10:37 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class Dumper {
|
|
|
|
public:
|
|
|
|
explicit Dumper(SkCanvas* canvas, int count, bool timeWithCommand)
|
|
|
|
: fDigits(0)
|
|
|
|
, fIndent(0)
|
2014-09-02 19:03:31 +00:00
|
|
|
, fIndex(0)
|
2015-08-27 14:41:13 +00:00
|
|
|
, fDraw(canvas, nullptr, nullptr, 0, nullptr)
|
2014-05-15 16:10:37 +00:00
|
|
|
, fTimeWithCommand(timeWithCommand) {
|
|
|
|
while (count > 0) {
|
|
|
|
count /= 10;
|
|
|
|
fDigits++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void operator()(const T& command) {
|
2015-11-18 19:06:37 +00:00
|
|
|
auto start = SkTime::GetNSecs();
|
|
|
|
fDraw(command);
|
|
|
|
this->print(command, SkTime::GetNSecs() - start);
|
2014-05-15 16:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void operator()(const SkRecords::NoOp&) {
|
|
|
|
// Move on without printing anything.
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2015-11-18 19:06:37 +00:00
|
|
|
void print(const T& command, double ns) {
|
|
|
|
this->printNameAndTime(command, ns);
|
2014-05-15 16:10:37 +00:00
|
|
|
}
|
|
|
|
|
2015-11-18 19:06:37 +00:00
|
|
|
void print(const SkRecords::Restore& command, double ns) {
|
2014-05-15 16:10:37 +00:00
|
|
|
--fIndent;
|
2015-11-18 19:06:37 +00:00
|
|
|
this->printNameAndTime(command, ns);
|
2014-05-15 16:10:37 +00:00
|
|
|
}
|
|
|
|
|
2015-11-18 19:06:37 +00:00
|
|
|
void print(const SkRecords::Save& command, double ns) {
|
|
|
|
this->printNameAndTime(command, ns);
|
2014-05-15 16:10:37 +00:00
|
|
|
++fIndent;
|
|
|
|
}
|
|
|
|
|
2015-11-18 19:06:37 +00:00
|
|
|
void print(const SkRecords::SaveLayer& command, double ns) {
|
|
|
|
this->printNameAndTime(command, ns);
|
2014-05-15 16:10:37 +00:00
|
|
|
++fIndent;
|
|
|
|
}
|
|
|
|
|
2016-01-20 16:46:40 +00:00
|
|
|
void print(const SkRecords::DrawPicture& command, double ns) {
|
|
|
|
this->printNameAndTime(command, ns);
|
|
|
|
|
|
|
|
if (auto bp = command.picture->asSkBigPicture()) {
|
|
|
|
++fIndent;
|
|
|
|
|
|
|
|
const SkRecord& record = *bp->record();
|
|
|
|
for (int i = 0; i < record.count(); i++) {
|
|
|
|
record.visit<void>(i, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
--fIndent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 16:10:37 +00:00
|
|
|
private:
|
|
|
|
template <typename T>
|
2015-11-18 19:06:37 +00:00
|
|
|
void printNameAndTime(const T& command, double ns) {
|
|
|
|
int us = (int)(ns * 1e-3);
|
2014-05-15 16:10:37 +00:00
|
|
|
if (!fTimeWithCommand) {
|
2015-11-18 19:06:37 +00:00
|
|
|
printf("%6dus ", us);
|
2014-05-15 16:10:37 +00:00
|
|
|
}
|
2014-09-02 19:03:31 +00:00
|
|
|
printf("%*d ", fDigits, fIndex++);
|
2014-05-15 16:10:37 +00:00
|
|
|
for (int i = 0; i < fIndent; i++) {
|
2015-11-18 19:06:37 +00:00
|
|
|
printf(" ");
|
2014-05-15 16:10:37 +00:00
|
|
|
}
|
|
|
|
if (fTimeWithCommand) {
|
2015-11-18 19:06:37 +00:00
|
|
|
printf("%6dus ", us);
|
2014-05-15 16:10:37 +00:00
|
|
|
}
|
|
|
|
puts(NameOf(command));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
static const char* NameOf(const T&) {
|
|
|
|
#define CASE(U) case SkRecords::U##_Type: return #U;
|
|
|
|
switch(T::kType) { SK_RECORD_TYPES(CASE); }
|
|
|
|
#undef CASE
|
|
|
|
SkDEBUGFAIL("Unknown T");
|
|
|
|
return "Unknown T";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* NameOf(const SkRecords::SaveLayer&) {
|
|
|
|
return "\x1b[31;1mSaveLayer\x1b[0m"; // Bold red.
|
|
|
|
}
|
|
|
|
|
|
|
|
int fDigits;
|
|
|
|
int fIndent;
|
2014-09-02 19:03:31 +00:00
|
|
|
int fIndex;
|
2014-05-15 16:10:37 +00:00
|
|
|
SkRecords::Draw fDraw;
|
|
|
|
const bool fTimeWithCommand;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void DumpRecord(const SkRecord& record,
|
|
|
|
SkCanvas* canvas,
|
|
|
|
bool timeWithCommand) {
|
2014-09-02 19:03:31 +00:00
|
|
|
Dumper dumper(canvas, record.count(), timeWithCommand);
|
2015-08-19 16:51:00 +00:00
|
|
|
for (int i = 0; i < record.count(); i++) {
|
2014-09-02 19:03:31 +00:00
|
|
|
record.visit<void>(i, dumper);
|
2014-05-15 16:10:37 +00:00
|
|
|
}
|
|
|
|
}
|