| 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::kInvalidID = -1; | |
| 12 | |
| 13 void GrAuditTrail::batchingResultCombined(GrBatch* combiner) { | 11 void GrAuditTrail::batchingResultCombined(GrBatch* combiner) { |
| 14 int* indexPtr = fIDLookup.find(combiner); | 12 int* indexPtr = fIDLookup.find(combiner); |
| 15 SkASSERT(indexPtr); | 13 SkASSERT(indexPtr); |
| 16 int index = *indexPtr; | 14 int index = *indexPtr; |
| 17 SkASSERT(index < fBatchList.count()); | 15 SkASSERT(index < fBatches.count()); |
| 18 BatchNode& batch = *fBatchList[index]; | 16 Batch& batch = *fBatches[index]; |
| 19 | 17 |
| 20 // set the ids for the child batch | 18 // if this is our first child, we also push back a copy of the original batc
h and its |
| 21 fCurrentBatch->fBatchListID = index; | 19 // bounds |
| 22 fCurrentBatch->fChildID = batch.fChildren.count(); | 20 if (batch.fChildren.empty()) { |
| 23 | 21 Batch* firstBatch = new Batch; |
| 24 // Update the bounds and store a pointer to the new batch | 22 firstBatch->fName = batch.fName; |
| 23 firstBatch->fBounds = batch.fBounds; |
| 24 fEvents.emplace_back(firstBatch); |
| 25 batch.fChildren.push_back(firstBatch); |
| 26 } |
| 25 batch.fChildren.push_back(fCurrentBatch); | 27 batch.fChildren.push_back(fCurrentBatch); |
| 26 batch.fBounds = combiner->bounds(); | 28 batch.fBounds = combiner->bounds(); |
| 27 } | 29 } |
| 28 | 30 |
| 29 void GrAuditTrail::batchingResultNew(GrBatch* batch) { | 31 void GrAuditTrail::batchingResultNew(GrBatch* batch) { |
| 30 // Our algorithm doesn't bother to reorder inside of a BatchNode | 32 fIDLookup.set(batch, fBatches.count()); |
| 31 // so the ChildID will start at 0 | 33 fBatches.push_back(fCurrentBatch); |
| 32 fCurrentBatch->fBatchListID = fBatchList.count(); | |
| 33 fCurrentBatch->fChildID = 0; | |
| 34 | |
| 35 // We use the batch pointer as a key to find the batchnode we are 'glomming'
batches onto | |
| 36 fIDLookup.set(batch, fCurrentBatch->fBatchListID); | |
| 37 BatchNode* batchNode = new BatchNode; | |
| 38 batchNode->fBounds = fCurrentBatch->fBounds; | |
| 39 batchNode->fChildren.push_back(fCurrentBatch); | |
| 40 fBatchList.emplace_back(batchNode); | |
| 41 } | 34 } |
| 42 | 35 |
| 43 template <typename T> | 36 template <typename T> |
| 44 void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& arra
y, | 37 void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& arra
y, |
| 45 bool addComma) { | 38 bool addComma) { |
| 46 if (array.count()) { | 39 if (array.count()) { |
| 47 if (addComma) { | 40 if (addComma) { |
| 48 json->appendf(","); | 41 json->appendf(","); |
| 49 } | 42 } |
| 50 json->appendf("\"%s\": [", name); | 43 json->appendf("\"%s\": [", name); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 int fTabCount; | 111 int fTabCount; |
| 119 bool fFreshLine; | 112 bool fFreshLine; |
| 120 bool fCommaException; | 113 bool fCommaException; |
| 121 }; | 114 }; |
| 122 | 115 |
| 123 static SkString pretty_print_json(SkString json) { | 116 static SkString pretty_print_json(SkString json) { |
| 124 class PrettyPrintJson prettyPrintJson; | 117 class PrettyPrintJson prettyPrintJson; |
| 125 return prettyPrintJson.prettify(json); | 118 return prettyPrintJson.prettify(json); |
| 126 } | 119 } |
| 127 | 120 |
| 128 SkString GrAuditTrail::toJson(bool prettyPrint) const { | 121 SkString GrAuditTrail::toJson(bool batchList, bool prettyPrint) const { |
| 129 SkString json; | 122 SkString json; |
| 130 json.append("{"); | 123 json.append("{"); |
| 131 JsonifyTArray(&json, "Batches", fBatchList, false); | 124 if (!batchList) { |
| 125 JsonifyTArray(&json, "Stacks", fFrames, false); |
| 126 } else { |
| 127 JsonifyTArray(&json, "Batches", fBatches, false); |
| 128 } |
| 132 json.append("}"); | 129 json.append("}"); |
| 133 | 130 |
| 134 if (prettyPrint) { | 131 if (prettyPrint) { |
| 135 return pretty_print_json(json); | 132 return pretty_print_json(json); |
| 136 } else { | 133 } else { |
| 137 return json; | 134 return json; |
| 138 } | 135 } |
| 139 } | 136 } |
| 140 | 137 |
| 141 SkString GrAuditTrail::toJson(int clientID, bool prettyPrint) const { | 138 SkString GrAuditTrail::Frame::toJson() const { |
| 142 SkString json; | 139 SkString json; |
| 143 json.append("{"); | 140 json.append("{"); |
| 144 Batches** batches = fClientIDLookup.find(clientID); | 141 json.appendf("\"Name\": \"%s\"", fName); |
| 145 if (batches) { | 142 JsonifyTArray(&json, "Frames", fChildren, true); |
| 146 JsonifyTArray(&json, "Batches", **batches, false); | 143 json.append("}"); |
| 147 } | 144 return json; |
| 148 json.appendf("}"); | |
| 149 | |
| 150 if (prettyPrint) { | |
| 151 return pretty_print_json(json); | |
| 152 } else { | |
| 153 return json; | |
| 154 } | |
| 155 } | |
| 156 | |
| 157 static void skrect_to_json(SkString* json, const char* name, const SkRect& rect)
{ | |
| 158 json->appendf("\"%s\": {", name); | |
| 159 json->appendf("\"Left\": %f,", rect.fLeft); | |
| 160 json->appendf("\"Right\": %f,", rect.fRight); | |
| 161 json->appendf("\"Top\": %f,", rect.fTop); | |
| 162 json->appendf("\"Bottom\": %f", rect.fBottom); | |
| 163 json->append("}"); | |
| 164 } | 145 } |
| 165 | 146 |
| 166 SkString GrAuditTrail::Batch::toJson() const { | 147 SkString GrAuditTrail::Batch::toJson() const { |
| 167 SkString json; | 148 SkString json; |
| 168 json.append("{"); | 149 json.append("{"); |
| 169 json.appendf("\"Name\": \"%s\",", fName.c_str()); | 150 json.appendf("\"Name\": \"%s\",", fName); |
| 170 json.appendf("\"ClientID\": \"%d\",", fClientID); | 151 json.append("\"Bounds\": {"); |
| 171 json.appendf("\"BatchListID\": \"%d\",", fBatchListID); | 152 json.appendf("\"Left\": %f,", fBounds.fLeft); |
| 172 json.appendf("\"ChildID\": \"%d\",", fChildID); | 153 json.appendf("\"Right\": %f,", fBounds.fRight); |
| 173 skrect_to_json(&json, "Bounds", fBounds); | 154 json.appendf("\"Top\": %f,", fBounds.fTop); |
| 155 json.appendf("\"Bottom\": %f", fBounds.fBottom); |
| 156 JsonifyTArray(&json, "Children", fChildren, true); |
| 157 json.append("}"); |
| 174 json.append("}"); | 158 json.append("}"); |
| 175 return json; | 159 return json; |
| 176 } | 160 } |
| 177 | |
| 178 SkString GrAuditTrail::BatchNode::toJson() const { | |
| 179 SkString json; | |
| 180 json.append("{"); | |
| 181 skrect_to_json(&json, "Bounds", fBounds); | |
| 182 JsonifyTArray(&json, "Batches", fChildren, true); | |
| 183 json.append("}"); | |
| 184 return json; | |
| 185 } | |
| OLD | NEW |