Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4a56f4c

Browse files
Mike KleinSkia Commit-Bot
authored andcommitted
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>
1 parent 356838b commit 4a56f4c

File tree

4 files changed

+128
-186
lines changed

4 files changed

+128
-186
lines changed

BUILD.gn

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,10 +2180,7 @@ if (skia_enable_tools) {
21802180
}
21812181

21822182
test_app("dump_record") {
2183-
sources = [
2184-
"tools/DumpRecord.cpp",
2185-
"tools/dump_record.cpp",
2186-
]
2183+
sources = [ "tools/dump_record.cpp" ]
21872184
deps = [
21882185
":flags",
21892186
":skia",

tools/DumpRecord.cpp

Lines changed: 0 additions & 144 deletions
This file was deleted.

tools/DumpRecord.h

Lines changed: 0 additions & 24 deletions
This file was deleted.

tools/dump_record.cpp

Lines changed: 127 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
#include "include/core/SkPicture.h"
1010
#include "include/core/SkPictureRecorder.h"
1111
#include "include/core/SkStream.h"
12+
#include "include/core/SkTime.h"
13+
#include "src/core/SkPicturePriv.h"
14+
#include "src/core/SkRecord.h"
1215
#include "src/core/SkRecordDraw.h"
1316
#include "src/core/SkRecordOpts.h"
1417
#include "src/core/SkRecorder.h"
15-
#include "tools/DumpRecord.h"
1618
#include "tools/flags/CommandLineFlags.h"
17-
1819
#include <stdio.h>
1920

2021
static DEFINE_string2(skps, r, "", ".SKPs to dump.");
@@ -26,17 +27,118 @@ static DEFINE_bool(timeWithCommand, false,
2627
"If true, print time next to command, else in first column.");
2728
static DEFINE_string2(write, w, "", "Write the (optimized) picture to the named file.");
2829

29-
static void dump(const char* name, int w, int h, const SkRecord& record) {
30-
SkBitmap bitmap;
31-
bitmap.allocN32Pixels(w, h);
32-
SkCanvas canvas(bitmap);
33-
canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile),
34-
SkIntToScalar(FLAGS_tile)));
30+
class Dumper {
31+
public:
32+
explicit Dumper(SkCanvas* canvas, int count)
33+
: fDigits(0)
34+
, fIndent(0)
35+
, fIndex(0)
36+
, fDraw(canvas, nullptr, nullptr, 0, nullptr)
37+
{
38+
while (count > 0) {
39+
count /= 10;
40+
fDigits++;
41+
}
42+
}
3543

36-
printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name);
44+
template <typename T>
45+
void operator()(const T& command) {
46+
auto start = SkTime::GetNSecs();
47+
fDraw(command);
48+
this->print(command, SkTime::GetNSecs() - start);
49+
}
3750

38-
DumpRecord(record, &canvas, FLAGS_timeWithCommand);
39-
}
51+
void operator()(const SkRecords::NoOp&) {
52+
// Move on without printing anything.
53+
}
54+
55+
template <typename T>
56+
void print(const T& command, double ns) {
57+
this->printNameAndTime(command, ns);
58+
}
59+
60+
void print(const SkRecords::Restore& command, double ns) {
61+
--fIndent;
62+
this->printNameAndTime(command, ns);
63+
}
64+
65+
void print(const SkRecords::Save& command, double ns) {
66+
this->printNameAndTime(command, ns);
67+
++fIndent;
68+
}
69+
70+
void print(const SkRecords::SaveLayer& command, double ns) {
71+
this->printNameAndTime(command, ns);
72+
++fIndent;
73+
}
74+
75+
void print(const SkRecords::DrawPicture& command, double ns) {
76+
this->printNameAndTime(command, ns);
77+
78+
if (auto bp = SkPicturePriv::AsSkBigPicture(command.picture)) {
79+
++fIndent;
80+
81+
const SkRecord& record = *bp->record();
82+
for (int i = 0; i < record.count(); i++) {
83+
record.visit(i, *this);
84+
}
85+
86+
--fIndent;
87+
}
88+
}
89+
90+
void print(const SkRecords::DrawAnnotation& command, double ns) {
91+
int us = (int)(ns * 1e-3);
92+
if (!FLAGS_timeWithCommand) {
93+
printf("%6dus ", us);
94+
}
95+
printf("%*d ", fDigits, fIndex++);
96+
for (int i = 0; i < fIndent; i++) {
97+
printf(" ");
98+
}
99+
if (FLAGS_timeWithCommand) {
100+
printf("%6dus ", us);
101+
}
102+
printf("DrawAnnotation [%g %g %g %g] %s\n",
103+
command.rect.left(), command.rect.top(), command.rect.right(), command.rect.bottom(),
104+
command.key.c_str());
105+
}
106+
107+
private:
108+
template <typename T>
109+
void printNameAndTime(const T& command, double ns) {
110+
int us = (int)(ns * 1e-3);
111+
if (!FLAGS_timeWithCommand) {
112+
printf("%6dus ", us);
113+
}
114+
printf("%*d ", fDigits, fIndex++);
115+
for (int i = 0; i < fIndent; i++) {
116+
printf(" ");
117+
}
118+
if (FLAGS_timeWithCommand) {
119+
printf("%6dus ", us);
120+
}
121+
puts(NameOf(command));
122+
}
123+
124+
template <typename T>
125+
static const char* NameOf(const T&) {
126+
#define CASE(U) case SkRecords::U##_Type: return #U;
127+
switch (T::kType) { SK_RECORD_TYPES(CASE) }
128+
#undef CASE
129+
SkDEBUGFAIL("Unknown T");
130+
return "Unknown T";
131+
}
132+
133+
static const char* NameOf(const SkRecords::SaveLayer&) {
134+
return "\x1b[31;1mSaveLayer\x1b[0m"; // Bold red.
135+
}
136+
137+
int fDigits;
138+
int fIndent;
139+
int fIndex;
140+
SkRecords::Draw fDraw;
141+
};
40142

41143
int main(int argc, char** argv) {
42144
CommandLineFlags::Parse(argc, argv);
@@ -60,8 +162,8 @@ int main(int argc, char** argv) {
60162
const int h = SkScalarCeilToInt(src->cullRect().height());
61163

62164
SkRecord record;
63-
SkRecorder canvas(&record, w, h);
64-
src->playback(&canvas);
165+
SkRecorder rec(&record, w, h);
166+
src->playback(&rec);
65167

66168
if (FLAGS_optimize) {
67169
SkRecordOptimize(&record);
@@ -70,7 +172,18 @@ int main(int argc, char** argv) {
70172
SkRecordOptimize2(&record);
71173
}
72174

73-
dump(FLAGS_skps[i], w, h, record);
175+
SkBitmap bitmap;
176+
bitmap.allocN32Pixels(w, h);
177+
SkCanvas canvas(bitmap);
178+
canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile),
179+
SkIntToScalar(FLAGS_tile)));
180+
181+
printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", FLAGS_skps[i]);
182+
183+
Dumper dumper(&canvas, record.count());
184+
for (int i = 0; i < record.count(); i++) {
185+
record.visit(i, dumper);
186+
}
74187

75188
if (FLAGS_write.count() > 0) {
76189
SkPictureRecorder r;

0 commit comments

Comments
 (0)