OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrAuditTrail.h" | 8 #include "GrAuditTrail.h" |
9 #include "batches/GrBatch.h" | 9 #include "batches/GrBatch.h" |
10 | 10 |
11 const int GrAuditTrail::kGrAuditTrailInvalidID = -1; | 11 const int GrAuditTrail::kGrAuditTrailInvalidID = -1; |
12 | 12 |
13 void GrAuditTrail::addBatch(const char* name, const SkRect& bounds) { | 13 void GrAuditTrail::addBatch(const GrBatch* batch) { |
14 SkASSERT(fEnabled); | 14 SkASSERT(fEnabled); |
15 Batch* batch = new Batch; | 15 Batch* auditBatch = new Batch; |
16 fBatchPool.emplace_back(batch); | 16 fBatchPool.emplace_back(auditBatch); |
17 batch->fName = name; | 17 auditBatch->fName = batch->name(); |
18 batch->fBounds = bounds; | 18 auditBatch->fBounds = batch->bounds(); |
19 batch->fClientID = kGrAuditTrailInvalidID; | 19 auditBatch->fClientID = kGrAuditTrailInvalidID; |
20 batch->fBatchListID = kGrAuditTrailInvalidID; | 20 auditBatch->fBatchListID = kGrAuditTrailInvalidID; |
21 batch->fChildID = kGrAuditTrailInvalidID; | 21 auditBatch->fChildID = kGrAuditTrailInvalidID; |
22 | 22 |
23 // consume the current stack trace if any | 23 // consume the current stack trace if any |
24 batch->fStackTrace = fCurrentStackTrace; | 24 auditBatch->fStackTrace = fCurrentStackTrace; |
25 fCurrentStackTrace.reset(); | 25 fCurrentStackTrace.reset(); |
26 fCurrentBatch = batch; | |
27 | 26 |
28 if (fClientID != kGrAuditTrailInvalidID) { | 27 if (fClientID != kGrAuditTrailInvalidID) { |
29 batch->fClientID = fClientID; | 28 auditBatch->fClientID = fClientID; |
30 Batches** batchesLookup = fClientIDLookup.find(fClientID); | 29 Batches** batchesLookup = fClientIDLookup.find(fClientID); |
31 Batches* batches = nullptr; | 30 Batches* batches = nullptr; |
32 if (!batchesLookup) { | 31 if (!batchesLookup) { |
33 batches = new Batches; | 32 batches = new Batches; |
34 fClientIDLookup.set(fClientID, batches); | 33 fClientIDLookup.set(fClientID, batches); |
35 } else { | 34 } else { |
36 batches = *batchesLookup; | 35 batches = *batchesLookup; |
37 } | 36 } |
38 | 37 |
39 batches->push_back(fCurrentBatch); | 38 batches->push_back(auditBatch); |
40 } | 39 } |
| 40 |
| 41 // Our algorithm doesn't bother to reorder inside of a BatchNode |
| 42 // so the ChildID will start at 0 |
| 43 auditBatch->fBatchListID = fBatchList.count(); |
| 44 auditBatch->fChildID = 0; |
| 45 |
| 46 // We use the batch pointer as a key to find the batchnode we are 'glomming'
batches onto |
| 47 fIDLookup.set(batch, auditBatch->fBatchListID); |
| 48 BatchNode* batchNode = new BatchNode; |
| 49 batchNode->fBounds = batch->bounds(); |
| 50 batchNode->fRenderTargetUniqueID = batch->renderTargetUniqueID(); |
| 51 batchNode->fChildren.push_back(auditBatch); |
| 52 fBatchList.emplace_back(batchNode); |
41 } | 53 } |
42 | 54 |
43 void GrAuditTrail::batchingResultCombined(GrBatch* combiner) { | 55 void GrAuditTrail::batchingResultCombined(const GrBatch* combineWith, const GrBa
tch* batch) { |
44 int* indexPtr = fIDLookup.find(combiner); | 56 // Look up the batch we are going to glom onto |
| 57 int* indexPtr = fIDLookup.find(combineWith); |
45 SkASSERT(indexPtr); | 58 SkASSERT(indexPtr); |
46 int index = *indexPtr; | 59 int index = *indexPtr; |
47 SkASSERT(index < fBatchList.count()); | 60 SkASSERT(index < fBatchList.count()); |
48 BatchNode& batch = *fBatchList[index]; | 61 BatchNode& combineWithBatch = *fBatchList[index]; |
49 | 62 |
50 // set the ids for the child batch | 63 // Look up the batch which will be glommed |
51 fCurrentBatch->fBatchListID = index; | 64 int* combineePtr = fIDLookup.find(batch); |
52 fCurrentBatch->fChildID = batch.fChildren.count(); | 65 SkASSERT(combineePtr); |
| 66 int combineeIndex = *combineePtr; |
| 67 SkASSERT(combineeIndex < fBatchList.count()); |
| 68 BatchNode& combinee = *fBatchList[combineeIndex]; |
53 | 69 |
54 // Update the bounds and store a pointer to the new batch | 70 // steal all of combinee's batches |
55 batch.fChildren.push_back(fCurrentBatch); | 71 for (int i = 0; i < combinee.fChildren.count(); i++) { |
56 batch.fBounds = combiner->bounds(); | 72 Batch* childBatch = combinee.fChildren[i]; |
57 } | 73 |
| 74 // set the ids for the child batch |
| 75 childBatch->fBatchListID = index; |
| 76 childBatch->fChildID = combineWithBatch.fChildren.count(); |
| 77 combineWithBatch.fChildren.push_back(childBatch); |
| 78 } |
| 79 |
| 80 // Update the bounds for the combineWith node |
| 81 combineWithBatch.fBounds = combineWith->bounds(); |
58 | 82 |
59 void GrAuditTrail::batchingResultNew(GrBatch* batch) { | 83 // remove the old node from our batchlist and clear the combinee's lookup |
60 // Our algorithm doesn't bother to reorder inside of a BatchNode | 84 fBatchList.removeShuffle(combineeIndex); |
61 // so the ChildID will start at 0 | 85 fIDLookup.remove(batch); |
62 fCurrentBatch->fBatchListID = fBatchList.count(); | |
63 fCurrentBatch->fChildID = 0; | |
64 | |
65 // We use the batch pointer as a key to find the batchnode we are 'glomming'
batches onto | |
66 fIDLookup.set(batch, fCurrentBatch->fBatchListID); | |
67 BatchNode* batchNode = new BatchNode; | |
68 batchNode->fBounds = fCurrentBatch->fBounds; | |
69 batchNode->fRenderTargetUniqueID = batch->renderTargetUniqueID(); | |
70 batchNode->fChildren.push_back(fCurrentBatch); | |
71 fBatchList.emplace_back(batchNode); | |
72 } | 86 } |
73 | 87 |
74 void GrAuditTrail::copyOutFromBatchList(BatchInfo* outBatchInfo, int batchListID
) { | 88 void GrAuditTrail::copyOutFromBatchList(BatchInfo* outBatchInfo, int batchListID
) { |
75 SkASSERT(batchListID < fBatchList.count()); | 89 SkASSERT(batchListID < fBatchList.count()); |
76 const BatchNode* bn = fBatchList[batchListID]; | 90 const BatchNode* bn = fBatchList[batchListID]; |
77 outBatchInfo->fBounds = bn->fBounds; | 91 outBatchInfo->fBounds = bn->fBounds; |
78 outBatchInfo->fRenderTargetUniqueID = bn->fRenderTargetUniqueID; | 92 outBatchInfo->fRenderTargetUniqueID = bn->fRenderTargetUniqueID; |
79 for (int j = 0; j < bn->fChildren.count(); j++) { | 93 for (int j = 0; j < bn->fChildren.count(); j++) { |
80 BatchInfo::Batch& outBatch = outBatchInfo->fBatches.push_back(); | 94 BatchInfo::Batch& outBatch = outBatchInfo->fBatches.push_back(); |
81 const Batch* currentBatch = bn->fChildren[j]; | 95 const Batch* currentBatch = bn->fChildren[j]; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 284 |
271 SkString GrAuditTrail::BatchNode::toJson() const { | 285 SkString GrAuditTrail::BatchNode::toJson() const { |
272 SkString json; | 286 SkString json; |
273 json.append("{"); | 287 json.append("{"); |
274 json.appendf("\"RenderTarget\": \"%u\",", fRenderTargetUniqueID); | 288 json.appendf("\"RenderTarget\": \"%u\",", fRenderTargetUniqueID); |
275 skrect_to_json(&json, "Bounds", fBounds); | 289 skrect_to_json(&json, "Bounds", fBounds); |
276 JsonifyTArray(&json, "Batches", fChildren, true); | 290 JsonifyTArray(&json, "Batches", fChildren, true); |
277 json.append("}"); | 291 json.append("}"); |
278 return json; | 292 return json; |
279 } | 293 } |
OLD | NEW |