Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Unified Diff: src/gpu/GrAuditTrail.cpp

Issue 1765123002: Fix up GrAuditTrail to allow arbitrary reordering (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: fix up audit trail Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/private/GrAuditTrail.h ('k') | src/gpu/GrDrawTarget.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrAuditTrail.cpp
diff --git a/src/gpu/GrAuditTrail.cpp b/src/gpu/GrAuditTrail.cpp
index 752074de9c0ac1ed1b33b093a90e066c33d563fb..21b7a29251ae64d2768a4cc3020aebde0e9b81c8 100644
--- a/src/gpu/GrAuditTrail.cpp
+++ b/src/gpu/GrAuditTrail.cpp
@@ -10,23 +10,22 @@
const int GrAuditTrail::kGrAuditTrailInvalidID = -1;
-void GrAuditTrail::addBatch(const char* name, const SkRect& bounds) {
+void GrAuditTrail::addBatch(const GrBatch* batch) {
SkASSERT(fEnabled);
- Batch* batch = new Batch;
- fBatchPool.emplace_back(batch);
- batch->fName = name;
- batch->fBounds = bounds;
- batch->fClientID = kGrAuditTrailInvalidID;
- batch->fBatchListID = kGrAuditTrailInvalidID;
- batch->fChildID = kGrAuditTrailInvalidID;
+ Batch* auditBatch = new Batch;
+ fBatchPool.emplace_back(auditBatch);
+ auditBatch->fName = batch->name();
+ auditBatch->fBounds = batch->bounds();
+ auditBatch->fClientID = kGrAuditTrailInvalidID;
+ auditBatch->fBatchListID = kGrAuditTrailInvalidID;
+ auditBatch->fChildID = kGrAuditTrailInvalidID;
// consume the current stack trace if any
- batch->fStackTrace = fCurrentStackTrace;
+ auditBatch->fStackTrace = fCurrentStackTrace;
fCurrentStackTrace.reset();
- fCurrentBatch = batch;
if (fClientID != kGrAuditTrailInvalidID) {
- batch->fClientID = fClientID;
+ auditBatch->fClientID = fClientID;
Batches** batchesLookup = fClientIDLookup.find(fClientID);
Batches* batches = nullptr;
if (!batchesLookup) {
@@ -36,44 +35,61 @@ void GrAuditTrail::addBatch(const char* name, const SkRect& bounds) {
batches = *batchesLookup;
}
- batches->push_back(fCurrentBatch);
+ batches->push_back(auditBatch);
}
-}
-
-void GrAuditTrail::batchingResultCombined(GrBatch* combiner) {
- int* indexPtr = fIDLookup.find(combiner);
- SkASSERT(indexPtr);
- int index = *indexPtr;
- SkASSERT(index < fBatchList.count());
- BatchNode& batch = *fBatchList[index];
-
- // set the ids for the child batch
- fCurrentBatch->fBatchListID = index;
- fCurrentBatch->fChildID = batch.fChildren.count();
- // Update the bounds and store a pointer to the new batch
- batch.fChildren.push_back(fCurrentBatch);
- batch.fBounds = combiner->bounds();
-}
-
-void GrAuditTrail::batchingResultNew(GrBatch* batch) {
// Our algorithm doesn't bother to reorder inside of a BatchNode
// so the ChildID will start at 0
- fCurrentBatch->fBatchListID = fBatchList.count();
- fCurrentBatch->fChildID = 0;
+ auditBatch->fBatchListID = fBatchList.count();
+ auditBatch->fChildID = 0;
// We use the batch pointer as a key to find the batchnode we are 'glomming' batches onto
- fIDLookup.set(batch, fCurrentBatch->fBatchListID);
+ fIDLookup.set(batch->uniqueID(), auditBatch->fBatchListID);
BatchNode* batchNode = new BatchNode;
- batchNode->fBounds = fCurrentBatch->fBounds;
+ batchNode->fBounds = batch->bounds();
batchNode->fRenderTargetUniqueID = batch->renderTargetUniqueID();
- batchNode->fChildren.push_back(fCurrentBatch);
+ batchNode->fChildren.push_back(auditBatch);
fBatchList.emplace_back(batchNode);
}
+void GrAuditTrail::batchingResultCombined(const GrBatch* consumer, const GrBatch* consumed) {
+ // Look up the batch we are going to glom onto
+ int* indexPtr = fIDLookup.find(consumer->uniqueID());
+ SkASSERT(indexPtr);
+ int index = *indexPtr;
+ SkASSERT(index < fBatchList.count() && fBatchList[index]);
+ BatchNode& consumerBatch = *fBatchList[index];
+
+ // Look up the batch which will be glommed
+ int* consumedPtr = fIDLookup.find(consumed->uniqueID());
+ SkASSERT(consumedPtr);
+ int consumedIndex = *consumedPtr;
+ SkASSERT(consumedIndex < fBatchList.count() && fBatchList[consumedIndex]);
+ BatchNode& consumedBatch = *fBatchList[consumedIndex];
+
+ // steal all of consumed's batches
+ for (int i = 0; i < consumedBatch.fChildren.count(); i++) {
+ Batch* childBatch = consumedBatch.fChildren[i];
+
+ // set the ids for the child batch
+ childBatch->fBatchListID = index;
+ childBatch->fChildID = consumerBatch.fChildren.count();
+ consumerBatch.fChildren.push_back(childBatch);
+ }
+
+ // Update the bounds for the combineWith node
+ consumerBatch.fBounds = consumer->bounds();
+
+ // remove the old node from our batchlist and clear the combinee's lookup
+ // NOTE: because we can't change the shape of the batchlist, we use a sentinel
+ fBatchList[consumedIndex].reset(nullptr);
+ fIDLookup.remove(consumed->uniqueID());
+}
+
void GrAuditTrail::copyOutFromBatchList(BatchInfo* outBatchInfo, int batchListID) {
SkASSERT(batchListID < fBatchList.count());
const BatchNode* bn = fBatchList[batchListID];
+ SkASSERT(bn);
outBatchInfo->fBounds = bn->fBounds;
outBatchInfo->fRenderTargetUniqueID = bn->fRenderTargetUniqueID;
for (int j = 0; j < bn->fChildren.count(); j++) {
@@ -132,6 +148,10 @@ void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& arra
}
json->appendf("\"%s\": [", name);
for (int i = 0; i < array.count(); i++) {
+ // Handle sentinel nullptrs
+ if (!array[i]) {
+ continue;
+ }
json->append(array[i]->toJson());
if (i < array.count() - 1) {
json->append(",");
« no previous file with comments | « include/private/GrAuditTrail.h ('k') | src/gpu/GrDrawTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698