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 void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const FrameAr
ray& array) { | 10 void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const FrameAr
ray& array) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 int fTabCount; | 80 int fTabCount; |
81 bool fFreshLine; | 81 bool fFreshLine; |
82 bool fCommaException; | 82 bool fCommaException; |
83 }; | 83 }; |
84 | 84 |
85 static SkString pretty_print_json(SkString json) { | 85 static SkString pretty_print_json(SkString json) { |
86 class PrettyPrintJson prettyPrintJson; | 86 class PrettyPrintJson prettyPrintJson; |
87 return prettyPrintJson.prettify(json); | 87 return prettyPrintJson.prettify(json); |
88 } | 88 } |
89 | 89 |
90 SkString GrAuditTrail::toJson() const { | 90 SkString GrAuditTrail::toJson(bool prettyPrint) const { |
91 SkString json; | 91 SkString json; |
92 json.append("{"); | 92 json.append("{"); |
93 JsonifyTArray(&json, "Stacks", fFrames); | 93 JsonifyTArray(&json, "Stacks", fFrames); |
94 json.append("}"); | 94 json.append("}"); |
95 | 95 |
96 // TODO if this becomes a performance issue we should make pretty print conf
igurable | 96 if (prettyPrint) { |
97 return pretty_print_json(json); | 97 return pretty_print_json(json); |
| 98 } else { |
| 99 return json; |
| 100 } |
98 } | 101 } |
99 | 102 |
100 SkString GrAuditTrail::Frame::toJson() const { | 103 SkString GrAuditTrail::Frame::toJson() const { |
101 SkString json; | 104 SkString json; |
102 json.append("{"); | 105 json.append("{"); |
103 json.appendf("\"Name\": \"%s\",", fName); | 106 json.appendf("\"Name\": \"%s\",", fName); |
104 JsonifyTArray(&json, "Frames", fChildren); | 107 JsonifyTArray(&json, "Frames", fChildren); |
105 json.append("}"); | 108 json.append("}"); |
106 return json; | 109 return json; |
107 } | 110 } |
108 | 111 |
109 SkString GrAuditTrail::Batch::toJson() const { | 112 SkString GrAuditTrail::Batch::toJson() const { |
110 SkString json; | 113 SkString json; |
111 json.append("{"); | 114 json.append("{"); |
112 json.appendf("\"Name\": \"%s\",", fName); | 115 json.appendf("\"Name\": \"%s\",", fName); |
113 json.append("\"Bounds\": {"); | 116 json.append("\"Bounds\": {"); |
114 json.appendf("\"Left\": %f,", fBounds.fLeft); | 117 json.appendf("\"Left\": %f,", fBounds.fLeft); |
115 json.appendf("\"Right\": %f,", fBounds.fRight); | 118 json.appendf("\"Right\": %f,", fBounds.fRight); |
116 json.appendf("\"Top\": %f,", fBounds.fTop); | 119 json.appendf("\"Top\": %f,", fBounds.fTop); |
117 json.appendf("\"Bottom\": %f", fBounds.fBottom); | 120 json.appendf("\"Bottom\": %f", fBounds.fBottom); |
118 json.append("}"); | 121 json.append("}"); |
119 json.append("}"); | 122 json.append("}"); |
120 return json; | 123 return json; |
121 } | 124 } |
OLD | NEW |