Index: src/gpu/GrAuditTrail.cpp |
diff --git a/src/gpu/GrAuditTrail.cpp b/src/gpu/GrAuditTrail.cpp |
index 752074de9c0ac1ed1b33b093a90e066c33d563fb..8edbb1996c13b399572ae03e99acbb83ee85d7c3 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,41 +35,56 @@ 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, 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* combineWith, const GrBatch* batch) { |
+ // Look up the batch we are going to glom onto |
+ int* indexPtr = fIDLookup.find(combineWith); |
+ SkASSERT(indexPtr); |
+ int index = *indexPtr; |
+ SkASSERT(index < fBatchList.count()); |
+ BatchNode& combineWithBatch = *fBatchList[index]; |
+ |
+ // Look up the batch which will be glommed |
+ int* combineePtr = fIDLookup.find(batch); |
+ SkASSERT(combineePtr); |
+ int combineeIndex = *combineePtr; |
+ SkASSERT(combineeIndex < fBatchList.count()); |
+ BatchNode& combinee = *fBatchList[combineeIndex]; |
+ |
+ // steal all of combinee's batches |
+ for (int i = 0; i < combinee.fChildren.count(); i++) { |
+ Batch* childBatch = combinee.fChildren[i]; |
+ |
+ // set the ids for the child batch |
+ childBatch->fBatchListID = index; |
+ childBatch->fChildID = combineWithBatch.fChildren.count(); |
+ combineWithBatch.fChildren.push_back(childBatch); |
+ } |
+ |
+ // Update the bounds for the combineWith node |
+ combineWithBatch.fBounds = combineWith->bounds(); |
+ |
+ // remove the old node from our batchlist and clear the combinee's lookup |
+ fBatchList.removeShuffle(combineeIndex); |
+ fIDLookup.remove(batch); |
+} |
+ |
void GrAuditTrail::copyOutFromBatchList(BatchInfo* outBatchInfo, int batchListID) { |
SkASSERT(batchListID < fBatchList.count()); |
const BatchNode* bn = fBatchList[batchListID]; |