| 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 22 matching lines...) Expand all Loading... |
| 33 fCurrentBatch->fChildID = 0; | 33 fCurrentBatch->fChildID = 0; |
| 34 | 34 |
| 35 // We use the batch pointer as a key to find the batchnode we are 'glomming'
batches onto | 35 // We use the batch pointer as a key to find the batchnode we are 'glomming'
batches onto |
| 36 fIDLookup.set(batch, fCurrentBatch->fBatchListID); | 36 fIDLookup.set(batch, fCurrentBatch->fBatchListID); |
| 37 BatchNode* batchNode = new BatchNode; | 37 BatchNode* batchNode = new BatchNode; |
| 38 batchNode->fBounds = fCurrentBatch->fBounds; | 38 batchNode->fBounds = fCurrentBatch->fBounds; |
| 39 batchNode->fChildren.push_back(fCurrentBatch); | 39 batchNode->fChildren.push_back(fCurrentBatch); |
| 40 fBatchList.emplace_back(batchNode); | 40 fBatchList.emplace_back(batchNode); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void GrAuditTrail::getBoundsByClientID(SkTArray<BatchInfo>* outInfo, int clientI
D) { |
| 44 Batches** batchesLookup = fClientIDLookup.find(clientID); |
| 45 if (batchesLookup) { |
| 46 // We track which batchlistID we're currently looking at. If it changes
, then we |
| 47 // need to push back a new batch info struct. We happen to know that ba
tches are |
| 48 // in sequential order in the batchlist, otherwise we'd have to do more
bookkeeping |
| 49 int currentBatchListID = kGrAuditTrailInvalidID; |
| 50 for (int i = 0; i < (*batchesLookup)->count(); i++) { |
| 51 const Batch* batch = (**batchesLookup)[i]; |
| 52 |
| 53 // Because we will copy out all of the batches associated with a giv
en |
| 54 // batch list id everytime the id changes, we only have to update ou
r struct |
| 55 // when the id changes. |
| 56 if (kGrAuditTrailInvalidID == currentBatchListID || |
| 57 batch->fBatchListID != currentBatchListID) { |
| 58 BatchInfo& outBatchInfo = outInfo->push_back(); |
| 59 currentBatchListID = batch->fBatchListID; |
| 60 |
| 61 // copy out all of the batches so the client can display them ev
en if |
| 62 // they have a different clientID |
| 63 const BatchNode* bn = fBatchList[currentBatchListID]; |
| 64 outBatchInfo.fBounds = bn->fBounds; |
| 65 for (int j = 0; j < bn->fChildren.count(); j++) { |
| 66 BatchInfo::Batch& outBatch = outBatchInfo.fBatches.push_back
(); |
| 67 const Batch* currentBatch = bn->fChildren[j]; |
| 68 outBatch.fBounds = currentBatch->fBounds; |
| 69 outBatch.fClientID = currentBatch->fClientID; |
| 70 } |
| 71 } |
| 72 } |
| 73 } |
| 74 } |
| 75 |
| 76 |
| 43 template <typename T> | 77 template <typename T> |
| 44 void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& arra
y, | 78 void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& arra
y, |
| 45 bool addComma) { | 79 bool addComma) { |
| 46 if (array.count()) { | 80 if (array.count()) { |
| 47 if (addComma) { | 81 if (addComma) { |
| 48 json->appendf(","); | 82 json->appendf(","); |
| 49 } | 83 } |
| 50 json->appendf("\"%s\": [", name); | 84 json->appendf("\"%s\": [", name); |
| 51 for (int i = 0; i < array.count(); i++) { | 85 for (int i = 0; i < array.count(); i++) { |
| 52 json->append(array[i]->toJson()); | 86 json->append(array[i]->toJson()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 210 } |
| 177 | 211 |
| 178 SkString GrAuditTrail::BatchNode::toJson() const { | 212 SkString GrAuditTrail::BatchNode::toJson() const { |
| 179 SkString json; | 213 SkString json; |
| 180 json.append("{"); | 214 json.append("{"); |
| 181 skrect_to_json(&json, "Bounds", fBounds); | 215 skrect_to_json(&json, "Bounds", fBounds); |
| 182 JsonifyTArray(&json, "Batches", fChildren, true); | 216 JsonifyTArray(&json, "Batches", fChildren, true); |
| 183 json.append("}"); | 217 json.append("}"); |
| 184 return json; | 218 return json; |
| 185 } | 219 } |
| OLD | NEW |