densify dump_record

I don't know why the meat is in a separate file.

Change-Id: I9bbc475d1644dd1d596cb7c98ae0e0292846e5d5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/311585
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2020-08-18 16:02:52 -05:00 committed by Skia Commit-Bot
parent 356838b9f8
commit 4a56f4c29e
4 changed files with 128 additions and 186 deletions

View File

@ -2180,10 +2180,7 @@ if (skia_enable_tools) {
} }
test_app("dump_record") { test_app("dump_record") {
sources = [ sources = [ "tools/dump_record.cpp" ]
"tools/DumpRecord.cpp",
"tools/dump_record.cpp",
]
deps = [ deps = [
":flags", ":flags",
":skia", ":skia",

View File

@ -1,144 +0,0 @@
/*
* 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 "src/core/SkPicturePriv.h"
#include "src/core/SkRecord.h"
#include "src/core/SkRecordDraw.h"
#include "include/core/SkTime.h"
#include "tools/DumpRecord.h"
namespace {
class Dumper {
public:
explicit Dumper(SkCanvas* canvas, int count, bool timeWithCommand)
: fDigits(0)
, fIndent(0)
, fIndex(0)
, fDraw(canvas, nullptr, nullptr, 0, nullptr)
, fTimeWithCommand(timeWithCommand) {
while (count > 0) {
count /= 10;
fDigits++;
}
}
template <typename T>
void operator()(const T& command) {
auto start = SkTime::GetNSecs();
fDraw(command);
this->print(command, SkTime::GetNSecs() - start);
}
void operator()(const SkRecords::NoOp&) {
// Move on without printing anything.
}
template <typename T>
void print(const T& command, double ns) {
this->printNameAndTime(command, ns);
}
void print(const SkRecords::Restore& command, double ns) {
--fIndent;
this->printNameAndTime(command, ns);
}
void print(const SkRecords::Save& command, double ns) {
this->printNameAndTime(command, ns);
++fIndent;
}
void print(const SkRecords::SaveLayer& command, double ns) {
this->printNameAndTime(command, ns);
++fIndent;
}
void print(const SkRecords::DrawPicture& command, double ns) {
this->printNameAndTime(command, ns);
if (auto bp = SkPicturePriv::AsSkBigPicture(command.picture)) {
++fIndent;
const SkRecord& record = *bp->record();
for (int i = 0; i < record.count(); i++) {
record.visit(i, *this);
}
--fIndent;
}
}
#if 1
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
private:
template <typename T>
void printNameAndTime(const T& 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);
}
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;
int fIndex;
SkRecords::Draw fDraw;
const bool fTimeWithCommand;
};
} // namespace
void DumpRecord(const SkRecord& record,
SkCanvas* canvas,
bool timeWithCommand) {
Dumper dumper(canvas, record.count(), timeWithCommand);
for (int i = 0; i < record.count(); i++) {
record.visit(i, dumper);
}
}

View File

@ -1,24 +0,0 @@
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef DumpRecord_DEFINED
#define DumpRecord_DEFINED
class SkRecord;
class SkCanvas;
/**
* Draw the record to the supplied canvas via SkRecords::Draw, while
* printing each draw command and run time in microseconds to stdout.
*
* @param timeWithCommand If true, print time next to command, else in
* first column.
*/
void DumpRecord(const SkRecord& record,
SkCanvas* canvas,
bool timeWithCommand);
#endif // DumpRecord_DEFINED

View File

@ -9,12 +9,13 @@
#include "include/core/SkPicture.h" #include "include/core/SkPicture.h"
#include "include/core/SkPictureRecorder.h" #include "include/core/SkPictureRecorder.h"
#include "include/core/SkStream.h" #include "include/core/SkStream.h"
#include "include/core/SkTime.h"
#include "src/core/SkPicturePriv.h"
#include "src/core/SkRecord.h"
#include "src/core/SkRecordDraw.h" #include "src/core/SkRecordDraw.h"
#include "src/core/SkRecordOpts.h" #include "src/core/SkRecordOpts.h"
#include "src/core/SkRecorder.h" #include "src/core/SkRecorder.h"
#include "tools/DumpRecord.h"
#include "tools/flags/CommandLineFlags.h" #include "tools/flags/CommandLineFlags.h"
#include <stdio.h> #include <stdio.h>
static DEFINE_string2(skps, r, "", ".SKPs to dump."); static DEFINE_string2(skps, r, "", ".SKPs to dump.");
@ -26,17 +27,118 @@ static DEFINE_bool(timeWithCommand, false,
"If true, print time next to command, else in first column."); "If true, print time next to command, else in first column.");
static DEFINE_string2(write, w, "", "Write the (optimized) picture to the named file."); static DEFINE_string2(write, w, "", "Write the (optimized) picture to the named file.");
static void dump(const char* name, int w, int h, const SkRecord& record) { class Dumper {
SkBitmap bitmap; public:
bitmap.allocN32Pixels(w, h); explicit Dumper(SkCanvas* canvas, int count)
SkCanvas canvas(bitmap); : fDigits(0)
canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), , fIndent(0)
SkIntToScalar(FLAGS_tile))); , fIndex(0)
, fDraw(canvas, nullptr, nullptr, 0, nullptr)
{
while (count > 0) {
count /= 10;
fDigits++;
}
}
printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name); template <typename T>
void operator()(const T& command) {
auto start = SkTime::GetNSecs();
fDraw(command);
this->print(command, SkTime::GetNSecs() - start);
}
DumpRecord(record, &canvas, FLAGS_timeWithCommand); void operator()(const SkRecords::NoOp&) {
} // Move on without printing anything.
}
template <typename T>
void print(const T& command, double ns) {
this->printNameAndTime(command, ns);
}
void print(const SkRecords::Restore& command, double ns) {
--fIndent;
this->printNameAndTime(command, ns);
}
void print(const SkRecords::Save& command, double ns) {
this->printNameAndTime(command, ns);
++fIndent;
}
void print(const SkRecords::SaveLayer& command, double ns) {
this->printNameAndTime(command, ns);
++fIndent;
}
void print(const SkRecords::DrawPicture& command, double ns) {
this->printNameAndTime(command, ns);
if (auto bp = SkPicturePriv::AsSkBigPicture(command.picture)) {
++fIndent;
const SkRecord& record = *bp->record();
for (int i = 0; i < record.count(); i++) {
record.visit(i, *this);
}
--fIndent;
}
}
void print(const SkRecords::DrawAnnotation& command, double ns) {
int us = (int)(ns * 1e-3);
if (!FLAGS_timeWithCommand) {
printf("%6dus ", us);
}
printf("%*d ", fDigits, fIndex++);
for (int i = 0; i < fIndent; i++) {
printf(" ");
}
if (FLAGS_timeWithCommand) {
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());
}
private:
template <typename T>
void printNameAndTime(const T& command, double ns) {
int us = (int)(ns * 1e-3);
if (!FLAGS_timeWithCommand) {
printf("%6dus ", us);
}
printf("%*d ", fDigits, fIndex++);
for (int i = 0; i < fIndent; i++) {
printf(" ");
}
if (FLAGS_timeWithCommand) {
printf("%6dus ", us);
}
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;
int fIndex;
SkRecords::Draw fDraw;
};
int main(int argc, char** argv) { int main(int argc, char** argv) {
CommandLineFlags::Parse(argc, argv); CommandLineFlags::Parse(argc, argv);
@ -60,8 +162,8 @@ int main(int argc, char** argv) {
const int h = SkScalarCeilToInt(src->cullRect().height()); const int h = SkScalarCeilToInt(src->cullRect().height());
SkRecord record; SkRecord record;
SkRecorder canvas(&record, w, h); SkRecorder rec(&record, w, h);
src->playback(&canvas); src->playback(&rec);
if (FLAGS_optimize) { if (FLAGS_optimize) {
SkRecordOptimize(&record); SkRecordOptimize(&record);
@ -70,7 +172,18 @@ int main(int argc, char** argv) {
SkRecordOptimize2(&record); SkRecordOptimize2(&record);
} }
dump(FLAGS_skps[i], w, h, record); SkBitmap bitmap;
bitmap.allocN32Pixels(w, h);
SkCanvas canvas(bitmap);
canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile),
SkIntToScalar(FLAGS_tile)));
printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", FLAGS_skps[i]);
Dumper dumper(&canvas, record.count());
for (int i = 0; i < record.count(); i++) {
record.visit(i, dumper);
}
if (FLAGS_write.count() > 0) { if (FLAGS_write.count() > 0) {
SkPictureRecorder r; SkPictureRecorder r;