Virtualize Frames in GrAuditTrail
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1581943004 Review URL: https://codereview.chromium.org/1581943004
This commit is contained in:
parent
8229fd5c75
commit
11fae87d39
@ -42,11 +42,11 @@ public:
|
||||
|
||||
void pushFrame(const char* name) {
|
||||
SkASSERT(GR_BATCH_DEBUGGING_OUTPUT);
|
||||
Frame* frame;
|
||||
Frame* frame = new Frame;
|
||||
if (fStack.empty()) {
|
||||
frame = &fFrames.push_back();
|
||||
fFrames.emplace_back(frame);
|
||||
} else {
|
||||
frame = &fStack.back()->fChildren.push_back();
|
||||
fStack.back()->fChildren.emplace_back(frame);
|
||||
}
|
||||
|
||||
frame->fUniqueID = fUniqueID++;
|
||||
@ -60,11 +60,11 @@ public:
|
||||
}
|
||||
|
||||
void addBatch(const char* name, const SkRect& bounds) {
|
||||
// TODO when every internal callsite pushes a frame, we can add the assert
|
||||
SkASSERT(GR_BATCH_DEBUGGING_OUTPUT /*&& !fStack.empty()*/);
|
||||
Frame::Batch& batch = fStack.back()->fBatches.push_back();
|
||||
batch.fName = name;
|
||||
batch.fBounds = bounds;
|
||||
SkASSERT(GR_BATCH_DEBUGGING_OUTPUT && !fStack.empty());
|
||||
Batch* batch = new Batch;
|
||||
fStack.back()->fChildren.emplace_back(batch);
|
||||
batch->fName = name;
|
||||
batch->fBounds = bounds;
|
||||
}
|
||||
|
||||
SkString toJson() const;
|
||||
@ -72,22 +72,29 @@ public:
|
||||
void reset() { SkASSERT(GR_BATCH_DEBUGGING_OUTPUT && fStack.empty()); fFrames.reset(); }
|
||||
|
||||
private:
|
||||
struct Frame {
|
||||
SkString toJson() const;
|
||||
struct Batch {
|
||||
SkString toJson() const;
|
||||
const char* fName;
|
||||
SkRect fBounds;
|
||||
};
|
||||
// TODO if performance becomes an issue, we can move to using SkVarAlloc
|
||||
struct Event {
|
||||
virtual ~Event() {}
|
||||
virtual SkString toJson() const=0;
|
||||
|
||||
const char* fName;
|
||||
// TODO combine these into a single array
|
||||
SkTArray<Batch> fBatches;
|
||||
SkTArray<Frame> fChildren;
|
||||
uint64_t fUniqueID;
|
||||
};
|
||||
|
||||
SkTArray<Frame> fFrames;
|
||||
typedef SkTArray<SkAutoTDelete<Event>, true> FrameArray;
|
||||
struct Frame : public Event {
|
||||
SkString toJson() const override;
|
||||
FrameArray fChildren;
|
||||
};
|
||||
|
||||
struct Batch : public Event {
|
||||
SkString toJson() const override;
|
||||
SkRect fBounds;
|
||||
};
|
||||
|
||||
static void JsonifyTArray(SkString* json, const char* name, const FrameArray& array);
|
||||
|
||||
FrameArray fFrames;
|
||||
SkTArray<Frame*> fStack;
|
||||
uint64_t fUniqueID;
|
||||
};
|
||||
|
@ -7,12 +7,11 @@
|
||||
|
||||
#include "GrAuditTrail.h"
|
||||
|
||||
template <class T>
|
||||
static void jsonify_tarray(SkString* json, const char* name, const SkTArray<T>& array) {
|
||||
void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const FrameArray& array) {
|
||||
if (array.count()) {
|
||||
json->appendf("\"%s\": [", name);
|
||||
for (int i = 0; i < array.count(); i++) {
|
||||
json->append(array[i].toJson());
|
||||
json->append(array[i]->toJson());
|
||||
if (i < array.count() - 1) {
|
||||
json->append(",");
|
||||
}
|
||||
@ -91,7 +90,7 @@ static SkString pretty_print_json(SkString json) {
|
||||
SkString GrAuditTrail::toJson() const {
|
||||
SkString json;
|
||||
json.append("{");
|
||||
jsonify_tarray(&json, "Stacks", fFrames);
|
||||
JsonifyTArray(&json, "Stacks", fFrames);
|
||||
json.append("}");
|
||||
|
||||
// TODO if this becomes a performance issue we should make pretty print configurable
|
||||
@ -102,13 +101,12 @@ SkString GrAuditTrail::Frame::toJson() const {
|
||||
SkString json;
|
||||
json.append("{");
|
||||
json.appendf("\"Name\": \"%s\",", fName);
|
||||
jsonify_tarray(&json, "Batches", fBatches);
|
||||
jsonify_tarray(&json, "Frames", fChildren);
|
||||
JsonifyTArray(&json, "Frames", fChildren);
|
||||
json.append("}");
|
||||
return json;
|
||||
}
|
||||
|
||||
SkString GrAuditTrail::Frame::Batch::toJson() const {
|
||||
SkString GrAuditTrail::Batch::toJson() const {
|
||||
SkString json;
|
||||
json.append("{");
|
||||
json.appendf("\"Name\": \"%s\",", fName);
|
||||
|
Loading…
Reference in New Issue
Block a user