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 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 // We use the batch pointer as a key to find the batchnode we are 'glomming'
batches onto | 61 // We use the batch pointer as a key to find the batchnode we are 'glomming'
batches onto |
62 fIDLookup.set(batch, fCurrentBatch->fBatchListID); | 62 fIDLookup.set(batch, fCurrentBatch->fBatchListID); |
63 BatchNode* batchNode = new BatchNode; | 63 BatchNode* batchNode = new BatchNode; |
64 batchNode->fBounds = fCurrentBatch->fBounds; | 64 batchNode->fBounds = fCurrentBatch->fBounds; |
65 batchNode->fRenderTargetUniqueID = batch->renderTargetUniqueID(); | 65 batchNode->fRenderTargetUniqueID = batch->renderTargetUniqueID(); |
66 batchNode->fChildren.push_back(fCurrentBatch); | 66 batchNode->fChildren.push_back(fCurrentBatch); |
67 fBatchList.emplace_back(batchNode); | 67 fBatchList.emplace_back(batchNode); |
68 } | 68 } |
69 | 69 |
| 70 void GrAuditTrail::copyOutFromBatchList(BatchInfo* outBatchInfo, int batchListID
) { |
| 71 SkASSERT(batchListID < fBatchList.count()); |
| 72 const BatchNode* bn = fBatchList[batchListID]; |
| 73 outBatchInfo->fBounds = bn->fBounds; |
| 74 outBatchInfo->fRenderTargetUniqueID = bn->fRenderTargetUniqueID; |
| 75 for (int j = 0; j < bn->fChildren.count(); j++) { |
| 76 BatchInfo::Batch& outBatch = outBatchInfo->fBatches.push_back(); |
| 77 const Batch* currentBatch = bn->fChildren[j]; |
| 78 outBatch.fBounds = currentBatch->fBounds; |
| 79 outBatch.fClientID = currentBatch->fClientID; |
| 80 } |
| 81 } |
| 82 |
70 void GrAuditTrail::getBoundsByClientID(SkTArray<BatchInfo>* outInfo, int clientI
D) { | 83 void GrAuditTrail::getBoundsByClientID(SkTArray<BatchInfo>* outInfo, int clientI
D) { |
71 Batches** batchesLookup = fClientIDLookup.find(clientID); | 84 Batches** batchesLookup = fClientIDLookup.find(clientID); |
72 if (batchesLookup) { | 85 if (batchesLookup) { |
73 // We track which batchlistID we're currently looking at. If it changes
, then we | 86 // We track which batchlistID we're currently looking at. If it changes
, then we |
74 // need to push back a new batch info struct. We happen to know that ba
tches are | 87 // need to push back a new batch info struct. We happen to know that ba
tches are |
75 // in sequential order in the batchlist, otherwise we'd have to do more
bookkeeping | 88 // in sequential order in the batchlist, otherwise we'd have to do more
bookkeeping |
76 int currentBatchListID = kGrAuditTrailInvalidID; | 89 int currentBatchListID = kGrAuditTrailInvalidID; |
77 for (int i = 0; i < (*batchesLookup)->count(); i++) { | 90 for (int i = 0; i < (*batchesLookup)->count(); i++) { |
78 const Batch* batch = (**batchesLookup)[i]; | 91 const Batch* batch = (**batchesLookup)[i]; |
79 | 92 |
80 // Because we will copy out all of the batches associated with a giv
en | 93 // Because we will copy out all of the batches associated with a giv
en |
81 // batch list id everytime the id changes, we only have to update ou
r struct | 94 // batch list id everytime the id changes, we only have to update ou
r struct |
82 // when the id changes. | 95 // when the id changes. |
83 if (kGrAuditTrailInvalidID == currentBatchListID || | 96 if (kGrAuditTrailInvalidID == currentBatchListID || |
84 batch->fBatchListID != currentBatchListID) { | 97 batch->fBatchListID != currentBatchListID) { |
85 BatchInfo& outBatchInfo = outInfo->push_back(); | 98 BatchInfo& outBatchInfo = outInfo->push_back(); |
86 currentBatchListID = batch->fBatchListID; | |
87 | 99 |
88 // copy out all of the batches so the client can display them ev
en if | 100 // copy out all of the batches so the client can display them ev
en if |
89 // they have a different clientID | 101 // they have a different clientID |
90 const BatchNode* bn = fBatchList[currentBatchListID]; | 102 this->copyOutFromBatchList(&outBatchInfo, batch->fBatchListID); |
91 outBatchInfo.fBounds = bn->fBounds; | |
92 outBatchInfo.fRenderTargetUniqueID = bn->fRenderTargetUniqueID; | |
93 for (int j = 0; j < bn->fChildren.count(); j++) { | |
94 BatchInfo::Batch& outBatch = outBatchInfo.fBatches.push_back
(); | |
95 const Batch* currentBatch = bn->fChildren[j]; | |
96 outBatch.fBounds = currentBatch->fBounds; | |
97 outBatch.fClientID = currentBatch->fClientID; | |
98 } | |
99 } | 103 } |
100 } | 104 } |
101 } | 105 } |
102 } | 106 } |
103 | 107 |
| 108 void GrAuditTrail::getBoundsByBatchListID(BatchInfo* outInfo, int batchListID) { |
| 109 this->copyOutFromBatchList(outInfo, batchListID); |
| 110 } |
| 111 |
104 void GrAuditTrail::fullReset() { | 112 void GrAuditTrail::fullReset() { |
105 SkASSERT(fEnabled); | 113 SkASSERT(fEnabled); |
106 fBatchList.reset(); | 114 fBatchList.reset(); |
107 fIDLookup.reset(); | 115 fIDLookup.reset(); |
108 // free all client batches | 116 // free all client batches |
109 fClientIDLookup.foreach([](const int&, Batches** batches) { delete *batches;
}); | 117 fClientIDLookup.foreach([](const int&, Batches** batches) { delete *batches;
}); |
110 fClientIDLookup.reset(); | 118 fClientIDLookup.reset(); |
111 fBatchPool.reset(); // must be last, frees all of the memory | 119 fBatchPool.reset(); // must be last, frees all of the memory |
112 } | 120 } |
113 | 121 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 256 |
249 SkString GrAuditTrail::BatchNode::toJson() const { | 257 SkString GrAuditTrail::BatchNode::toJson() const { |
250 SkString json; | 258 SkString json; |
251 json.append("{"); | 259 json.append("{"); |
252 json.appendf("\"RenderTarget\": \"%u\",", fRenderTargetUniqueID); | 260 json.appendf("\"RenderTarget\": \"%u\",", fRenderTargetUniqueID); |
253 skrect_to_json(&json, "Bounds", fBounds); | 261 skrect_to_json(&json, "Bounds", fBounds); |
254 JsonifyTArray(&json, "Batches", fChildren, true); | 262 JsonifyTArray(&json, "Batches", fChildren, true); |
255 json.append("}"); | 263 json.append("}"); |
256 return json; | 264 return json; |
257 } | 265 } |
OLD | NEW |