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