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->uniqueID(), 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* consumer, const GrBatch
* consumed) { |
44 int* indexPtr = fIDLookup.find(combiner); | 56 // Look up the batch we are going to glom onto |
| 57 int* indexPtr = fIDLookup.find(consumer->uniqueID()); |
45 SkASSERT(indexPtr); | 58 SkASSERT(indexPtr); |
46 int index = *indexPtr; | 59 int index = *indexPtr; |
47 SkASSERT(index < fBatchList.count()); | 60 SkASSERT(index < fBatchList.count() && fBatchList[index]); |
48 BatchNode& batch = *fBatchList[index]; | 61 BatchNode& consumerBatch = *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* consumedPtr = fIDLookup.find(consumed->uniqueID()); |
52 fCurrentBatch->fChildID = batch.fChildren.count(); | 65 SkASSERT(consumedPtr); |
| 66 int consumedIndex = *consumedPtr; |
| 67 SkASSERT(consumedIndex < fBatchList.count() && fBatchList[consumedIndex]); |
| 68 BatchNode& consumedBatch = *fBatchList[consumedIndex]; |
53 | 69 |
54 // Update the bounds and store a pointer to the new batch | 70 // steal all of consumed's batches |
55 batch.fChildren.push_back(fCurrentBatch); | 71 for (int i = 0; i < consumedBatch.fChildren.count(); i++) { |
56 batch.fBounds = combiner->bounds(); | 72 Batch* childBatch = consumedBatch.fChildren[i]; |
57 } | 73 |
| 74 // set the ids for the child batch |
| 75 childBatch->fBatchListID = index; |
| 76 childBatch->fChildID = consumerBatch.fChildren.count(); |
| 77 consumerBatch.fChildren.push_back(childBatch); |
| 78 } |
| 79 |
| 80 // Update the bounds for the combineWith node |
| 81 consumerBatch.fBounds = consumer->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 // NOTE: because we can't change the shape of the batchlist, we use a sentin
el |
61 // so the ChildID will start at 0 | 85 fBatchList[consumedIndex].reset(nullptr); |
62 fCurrentBatch->fBatchListID = fBatchList.count(); | 86 fIDLookup.remove(consumed->uniqueID()); |
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 } | 87 } |
73 | 88 |
74 void GrAuditTrail::copyOutFromBatchList(BatchInfo* outBatchInfo, int batchListID
) { | 89 void GrAuditTrail::copyOutFromBatchList(BatchInfo* outBatchInfo, int batchListID
) { |
75 SkASSERT(batchListID < fBatchList.count()); | 90 SkASSERT(batchListID < fBatchList.count()); |
76 const BatchNode* bn = fBatchList[batchListID]; | 91 const BatchNode* bn = fBatchList[batchListID]; |
| 92 SkASSERT(bn); |
77 outBatchInfo->fBounds = bn->fBounds; | 93 outBatchInfo->fBounds = bn->fBounds; |
78 outBatchInfo->fRenderTargetUniqueID = bn->fRenderTargetUniqueID; | 94 outBatchInfo->fRenderTargetUniqueID = bn->fRenderTargetUniqueID; |
79 for (int j = 0; j < bn->fChildren.count(); j++) { | 95 for (int j = 0; j < bn->fChildren.count(); j++) { |
80 BatchInfo::Batch& outBatch = outBatchInfo->fBatches.push_back(); | 96 BatchInfo::Batch& outBatch = outBatchInfo->fBatches.push_back(); |
81 const Batch* currentBatch = bn->fChildren[j]; | 97 const Batch* currentBatch = bn->fChildren[j]; |
82 outBatch.fBounds = currentBatch->fBounds; | 98 outBatch.fBounds = currentBatch->fBounds; |
83 outBatch.fClientID = currentBatch->fClientID; | 99 outBatch.fClientID = currentBatch->fClientID; |
84 } | 100 } |
85 } | 101 } |
86 | 102 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 141 |
126 template <typename T> | 142 template <typename T> |
127 void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& arra
y, | 143 void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& arra
y, |
128 bool addComma) { | 144 bool addComma) { |
129 if (array.count()) { | 145 if (array.count()) { |
130 if (addComma) { | 146 if (addComma) { |
131 json->appendf(","); | 147 json->appendf(","); |
132 } | 148 } |
133 json->appendf("\"%s\": [", name); | 149 json->appendf("\"%s\": [", name); |
134 for (int i = 0; i < array.count(); i++) { | 150 for (int i = 0; i < array.count(); i++) { |
| 151 // Handle sentinel nullptrs |
| 152 if (!array[i]) { |
| 153 continue; |
| 154 } |
135 json->append(array[i]->toJson()); | 155 json->append(array[i]->toJson()); |
136 if (i < array.count() - 1) { | 156 if (i < array.count() - 1) { |
137 json->append(","); | 157 json->append(","); |
138 } | 158 } |
139 } | 159 } |
140 json->append("]"); | 160 json->append("]"); |
141 } | 161 } |
142 } | 162 } |
143 | 163 |
144 // This will pretty print a very small subset of json | 164 // This will pretty print a very small subset of json |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 290 |
271 SkString GrAuditTrail::BatchNode::toJson() const { | 291 SkString GrAuditTrail::BatchNode::toJson() const { |
272 SkString json; | 292 SkString json; |
273 json.append("{"); | 293 json.append("{"); |
274 json.appendf("\"RenderTarget\": \"%u\",", fRenderTargetUniqueID); | 294 json.appendf("\"RenderTarget\": \"%u\",", fRenderTargetUniqueID); |
275 skrect_to_json(&json, "Bounds", fBounds); | 295 skrect_to_json(&json, "Bounds", fBounds); |
276 JsonifyTArray(&json, "Batches", fChildren, true); | 296 JsonifyTArray(&json, "Batches", fChildren, true); |
277 json.append("}"); | 297 json.append("}"); |
278 return json; | 298 return json; |
279 } | 299 } |
OLD | NEW |