aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/private/GrAuditTrail.h74
-rw-r--r--src/gpu/GrAuditTrail.cpp38
-rw-r--r--src/gpu/GrDrawTarget.cpp2
3 files changed, 102 insertions, 12 deletions
diff --git a/include/private/GrAuditTrail.h b/include/private/GrAuditTrail.h
index 52a7c9031d..72708644a5 100644
--- a/include/private/GrAuditTrail.h
+++ b/include/private/GrAuditTrail.h
@@ -12,6 +12,9 @@
#include "SkRect.h"
#include "SkString.h"
#include "SkTArray.h"
+#include "SkTHash.h"
+
+class GrBatch;
/*
* GrAuditTrail collects a list of draw ops, detailed information about those ops, and can dump them
@@ -64,13 +67,30 @@ public:
GrAuditTrail* fAuditTrail;
};
+ class AutoManageBatchList {
+ public:
+ AutoManageBatchList(GrAuditTrail* auditTrail)
+ : fAutoEnable(auditTrail)
+ , fAuditTrail(auditTrail) {
+ }
+
+ ~AutoManageBatchList() {
+ fAuditTrail->fullReset();
+ }
+
+ private:
+ AutoEnable fAutoEnable;
+ GrAuditTrail* fAuditTrail;
+ };
+
void pushFrame(const char* name) {
SkASSERT(fEnabled);
Frame* frame = new Frame;
+ fEvents.emplace_back(frame);
if (fStack.empty()) {
- fFrames.emplace_back(frame);
+ fFrames.push_back(frame);
} else {
- fStack.back()->fChildren.emplace_back(frame);
+ fStack.back()->fChildren.push_back(frame);
}
frame->fUniqueID = fUniqueID++;
@@ -86,17 +106,39 @@ public:
void addBatch(const char* name, const SkRect& bounds) {
SkASSERT(fEnabled && !fStack.empty());
Batch* batch = new Batch;
- fStack.back()->fChildren.emplace_back(batch);
+ fEvents.emplace_back(batch);
+ fStack.back()->fChildren.push_back(batch);
batch->fName = name;
batch->fBounds = bounds;
+ fCurrentBatch = batch;
}
- SkString toJson(bool prettyPrint = false) const;
+ void batchingResultCombined(GrBatch* combiner);
+
+ void batchingResultNew(GrBatch* batch);
+
+ SkString toJson(bool batchList = false, bool prettyPrint = false) const;
bool isEnabled() { return fEnabled; }
void setEnabled(bool enabled) { fEnabled = enabled; }
- void reset() { SkASSERT(fEnabled && fStack.empty()); fFrames.reset(); }
+ void reset() {
+ SkASSERT(fEnabled && fStack.empty());
+ fFrames.reset();
+ }
+
+ void resetBatchList() {
+ SkASSERT(fEnabled);
+ fBatches.reset();
+ fIDLookup.reset();
+ }
+
+ void fullReset() {
+ SkASSERT(fEnabled);
+ this->reset();
+ this->resetBatchList();
+ fEvents.reset(); // must be last, frees all of the memory
+ }
private:
// TODO if performance becomes an issue, we can move to using SkVarAlloc
@@ -108,24 +150,32 @@ private:
uint64_t fUniqueID;
};
- typedef SkTArray<SkAutoTDelete<Event>, true> FrameArray;
struct Frame : public Event {
SkString toJson() const override;
- FrameArray fChildren;
+ SkTArray<Event*> fChildren;
};
struct Batch : public Event {
SkString toJson() const override;
SkRect fBounds;
+ SkTArray<Batch*> fChildren;
};
+ typedef SkTArray<SkAutoTDelete<Event>, true> EventArrayPool;
- static void JsonifyTArray(SkString* json, const char* name, const FrameArray& array,
+ template <typename T>
+ static void JsonifyTArray(SkString* json, const char* name, const T& array,
bool addComma);
+ // We store both an array of frames, and also a flatter array just of the batches
bool fEnabled;
- FrameArray fFrames;
+ EventArrayPool fEvents; // manages the lifetimes of the events
+ SkTArray<Event*> fFrames;
SkTArray<Frame*> fStack;
uint64_t fUniqueID;
+
+ Batch* fCurrentBatch;
+ SkTHashMap<GrBatch*, int> fIDLookup;
+ SkTArray<Batch*> fBatches;
};
#define GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, invoke, ...) \
@@ -142,4 +192,10 @@ private:
#define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \
GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, addBatch, batchname, bounds);
+#define GR_AUDIT_TRAIL_BATCHING_RESULT_COMBINED(audit_trail, combiner) \
+ GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, batchingResultCombined, combiner);
+
+#define GR_AUDIT_TRAIL_BATCHING_RESULT_NEW(audit_trail, batch) \
+ GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, batchingResultNew, batch);
+
#endif
diff --git a/src/gpu/GrAuditTrail.cpp b/src/gpu/GrAuditTrail.cpp
index aa527fb4b0..59201f4450 100644
--- a/src/gpu/GrAuditTrail.cpp
+++ b/src/gpu/GrAuditTrail.cpp
@@ -6,8 +6,35 @@
*/
#include "GrAuditTrail.h"
+#include "batches/GrBatch.h"
-void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const FrameArray& array,
+void GrAuditTrail::batchingResultCombined(GrBatch* combiner) {
+ int* indexPtr = fIDLookup.find(combiner);
+ SkASSERT(indexPtr);
+ int index = *indexPtr;
+ SkASSERT(index < fBatches.count());
+ Batch& batch = *fBatches[index];
+
+ // if this is our first child, we also push back a copy of the original batch and its
+ // bounds
+ if (batch.fChildren.empty()) {
+ Batch* firstBatch = new Batch;
+ firstBatch->fName = batch.fName;
+ firstBatch->fBounds = batch.fBounds;
+ fEvents.emplace_back(firstBatch);
+ batch.fChildren.push_back(firstBatch);
+ }
+ batch.fChildren.push_back(fCurrentBatch);
+ batch.fBounds = combiner->bounds();
+}
+
+void GrAuditTrail::batchingResultNew(GrBatch* batch) {
+ fIDLookup.set(batch, fBatches.count());
+ fBatches.push_back(fCurrentBatch);
+}
+
+template <typename T>
+void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& array,
bool addComma) {
if (array.count()) {
if (addComma) {
@@ -91,10 +118,14 @@ static SkString pretty_print_json(SkString json) {
return prettyPrintJson.prettify(json);
}
-SkString GrAuditTrail::toJson(bool prettyPrint) const {
+SkString GrAuditTrail::toJson(bool batchList, bool prettyPrint) const {
SkString json;
json.append("{");
- JsonifyTArray(&json, "Stacks", fFrames, false);
+ if (!batchList) {
+ JsonifyTArray(&json, "Stacks", fFrames, false);
+ } else {
+ JsonifyTArray(&json, "Batches", fBatches, false);
+ }
json.append("}");
if (prettyPrint) {
@@ -122,6 +153,7 @@ SkString GrAuditTrail::Batch::toJson() const {
json.appendf("\"Right\": %f,", fBounds.fRight);
json.appendf("\"Top\": %f,", fBounds.fTop);
json.appendf("\"Bottom\": %f", fBounds.fBottom);
+ JsonifyTArray(&json, "Children", fChildren, true);
json.append("}");
json.append("}");
return json;
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index b9edabeafe..173617ebe6 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -460,6 +460,7 @@ void GrDrawTarget::recordBatch(GrBatch* batch) {
if (candidate->combineIfPossible(batch, *this->caps())) {
GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", candidate->name(),
candidate->uniqueID());
+ GR_AUDIT_TRAIL_BATCHING_RESULT_COMBINED(fAuditTrail, candidate);
return;
}
// Stop going backwards if we would cause a painter's order violation.
@@ -479,6 +480,7 @@ void GrDrawTarget::recordBatch(GrBatch* batch) {
} else {
GrBATCH_INFO("\t\tFirstBatch\n");
}
+ GR_AUDIT_TRAIL_BATCHING_RESULT_NEW(fAuditTrail, batch);
fBatches.push_back().reset(SkRef(batch));
}