| 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 | 9 |
| 10 template <class T> | 10 template <class T> |
| 11 static void jsonify_tarray(SkString* json, const char* name, const SkTArray<T>&
array) { | 11 static void jsonify_tarray(SkString* json, const char* name, |
| 12 const SkTArray<SkAutoTDelete<T>, true>& array) { |
| 12 if (array.count()) { | 13 if (array.count()) { |
| 13 json->appendf("\"%s\": [", name); | 14 json->appendf("\"%s\": [", name); |
| 14 for (int i = 0; i < array.count(); i++) { | 15 for (int i = 0; i < array.count(); i++) { |
| 15 json->append(array[i].toJson()); | 16 json->append(array[i]->toJson()); |
| 16 if (i < array.count() - 1) { | 17 if (i < array.count() - 1) { |
| 17 json->append(","); | 18 json->append(","); |
| 18 } | 19 } |
| 19 } | 20 } |
| 20 json->append("]"); | 21 json->append("]"); |
| 21 } | 22 } |
| 22 } | 23 } |
| 23 | 24 |
| 24 // This will pretty print a very small subset of json | 25 // This will pretty print a very small subset of json |
| 25 // The parsing rules are straightforward, aside from the fact that we do not wan
t an extra newline | 26 // The parsing rules are straightforward, aside from the fact that we do not wan
t an extra newline |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 json.append("}"); | 96 json.append("}"); |
| 96 | 97 |
| 97 // TODO if this becomes a performance issue we should make pretty print conf
igurable | 98 // TODO if this becomes a performance issue we should make pretty print conf
igurable |
| 98 return pretty_print_json(json); | 99 return pretty_print_json(json); |
| 99 } | 100 } |
| 100 | 101 |
| 101 SkString GrAuditTrail::Frame::toJson() const { | 102 SkString GrAuditTrail::Frame::toJson() const { |
| 102 SkString json; | 103 SkString json; |
| 103 json.append("{"); | 104 json.append("{"); |
| 104 json.appendf("\"Name\": \"%s\",", fName); | 105 json.appendf("\"Name\": \"%s\",", fName); |
| 105 jsonify_tarray(&json, "Batches", fBatches); | |
| 106 jsonify_tarray(&json, "Frames", fChildren); | 106 jsonify_tarray(&json, "Frames", fChildren); |
| 107 json.append("}"); | 107 json.append("}"); |
| 108 return json; | 108 return json; |
| 109 } | 109 } |
| 110 | 110 |
| 111 SkString GrAuditTrail::Frame::Batch::toJson() const { | 111 SkString GrAuditTrail::Batch::toJson() const { |
| 112 SkString json; | 112 SkString json; |
| 113 json.append("{"); | 113 json.append("{"); |
| 114 json.appendf("\"Name\": \"%s\",", fName); | 114 json.appendf("\"Name\": \"%s\",", fName); |
| 115 json.append("\"Bounds\": {"); | 115 json.append("\"Bounds\": {"); |
| 116 json.appendf("\"Left\": %f,", fBounds.fLeft); | 116 json.appendf("\"Left\": %f,", fBounds.fLeft); |
| 117 json.appendf("\"Right\": %f,", fBounds.fRight); | 117 json.appendf("\"Right\": %f,", fBounds.fRight); |
| 118 json.appendf("\"Top\": %f,", fBounds.fTop); | 118 json.appendf("\"Top\": %f,", fBounds.fTop); |
| 119 json.appendf("\"Bottom\": %f", fBounds.fBottom); | 119 json.appendf("\"Bottom\": %f", fBounds.fBottom); |
| 120 json.append("}"); | 120 json.append("}"); |
| 121 json.append("}"); | 121 json.append("}"); |
| 122 return json; | 122 return json; |
| 123 } | 123 } |
| OLD | NEW |