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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 140 } |
141 | 141 |
142 template <typename T> | 142 template <typename T> |
143 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, |
144 bool addComma) { | 144 bool addComma) { |
145 if (array.count()) { | 145 if (array.count()) { |
146 if (addComma) { | 146 if (addComma) { |
147 json->appendf(","); | 147 json->appendf(","); |
148 } | 148 } |
149 json->appendf("\"%s\": [", name); | 149 json->appendf("\"%s\": [", name); |
| 150 const char* separator = ""; |
150 for (int i = 0; i < array.count(); i++) { | 151 for (int i = 0; i < array.count(); i++) { |
151 // Handle sentinel nullptrs | 152 // Handle sentinel nullptrs |
152 if (!array[i]) { | 153 if (array[i]) { |
153 continue; | 154 json->appendf("%s", separator); |
154 } | 155 json->append(array[i]->toJson()); |
155 json->append(array[i]->toJson()); | 156 separator = ","; |
156 if (i < array.count() - 1) { | |
157 json->append(","); | |
158 } | 157 } |
159 } | 158 } |
160 json->append("]"); | 159 json->append("]"); |
161 } | 160 } |
162 } | 161 } |
163 | 162 |
164 // This will pretty print a very small subset of json | 163 // This will pretty print a very small subset of json |
165 // The parsing rules are straightforward, aside from the fact that we do not wan
t an extra newline | 164 // The parsing rules are straightforward, aside from the fact that we do not wan
t an extra newline |
166 // before ',' and after '}', so we have a comma exception rule. | 165 // before ',' and after '}', so we have a comma exception rule. |
167 class PrettyPrintJson { | 166 class PrettyPrintJson { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 289 |
291 SkString GrAuditTrail::BatchNode::toJson() const { | 290 SkString GrAuditTrail::BatchNode::toJson() const { |
292 SkString json; | 291 SkString json; |
293 json.append("{"); | 292 json.append("{"); |
294 json.appendf("\"RenderTarget\": \"%u\",", fRenderTargetUniqueID); | 293 json.appendf("\"RenderTarget\": \"%u\",", fRenderTargetUniqueID); |
295 skrect_to_json(&json, "Bounds", fBounds); | 294 skrect_to_json(&json, "Bounds", fBounds); |
296 JsonifyTArray(&json, "Batches", fChildren, true); | 295 JsonifyTArray(&json, "Batches", fChildren, true); |
297 json.append("}"); | 296 json.append("}"); |
298 return json; | 297 return json; |
299 } | 298 } |
OLD | NEW |