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);
|
|
|
|
|
2018-01-27 17:30:04 +00:00
|
|
|
if (auto bp = command.picture->asSkBigPicture()) {
|
2016-01-20 16:46:40 +00:00
|
|
|
++fIndent;
|
|
|
|
|
|
|
|
const SkRecord& record = *bp->record();
|
|
|
|
for (int i = 0; i < record.count(); i++) {
|
2016-03-22 18:46:53 +00:00
|
|
|
record.visit(i, *this);
|
2016-01-20 16:46:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
--fIndent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 18:52:50 +00:00
|
|
|
#if 1
|
2016-07-08 15:43:27 +00:00
|
|
|
void print(const SkRecords::DrawAnnotation& command, double ns) {
|
|
|
|
int us = (int)(ns * 1e-3);
|
|
|
|
if (!fTimeWithCommand) {
|
|
|
|
printf("%6dus ", us);
|
|
|
|
}
|
|
|
|
printf("%*d ", fDigits, fIndex++);
|
|
|
|
for (int i = 0; i < fIndent; i++) {
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
if (fTimeWithCommand) {
|
|
|
|
printf("%6dus ", us);
|
|
|
|
}
|
|
|
|
printf("DrawAnnotation [%g %g %g %g] %s\n",
|
|
|
|
command.rect.left(), command.rect.top(), command.rect.right(), command.rect.bottom(),
|
|
|
|
command.key.c_str());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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++) {
|
2016-03-22 18:46:53 +00:00
|
|
|
record.visit(i, dumper);
|
2014-05-15 16:10:37 +00:00
|
|
|
}
|
|
|
|
}
|