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 | 10 |
10 void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const FrameAr
ray& array, | 11 void GrAuditTrail::batchingResultCombined(GrBatch* combiner) { |
| 12 int* indexPtr = fIDLookup.find(combiner); |
| 13 SkASSERT(indexPtr); |
| 14 int index = *indexPtr; |
| 15 SkASSERT(index < fBatches.count()); |
| 16 Batch& batch = *fBatches[index]; |
| 17 |
| 18 // if this is our first child, we also push back a copy of the original batc
h and its |
| 19 // bounds |
| 20 if (batch.fChildren.empty()) { |
| 21 Batch* firstBatch = new Batch; |
| 22 firstBatch->fName = batch.fName; |
| 23 firstBatch->fBounds = batch.fBounds; |
| 24 fEvents.emplace_back(firstBatch); |
| 25 batch.fChildren.push_back(firstBatch); |
| 26 } |
| 27 batch.fChildren.push_back(fCurrentBatch); |
| 28 batch.fBounds = combiner->bounds(); |
| 29 } |
| 30 |
| 31 void GrAuditTrail::batchingResultNew(GrBatch* batch) { |
| 32 fIDLookup.set(batch, fBatches.count()); |
| 33 fBatches.push_back(fCurrentBatch); |
| 34 } |
| 35 |
| 36 template <typename T> |
| 37 void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& arra
y, |
11 bool addComma) { | 38 bool addComma) { |
12 if (array.count()) { | 39 if (array.count()) { |
13 if (addComma) { | 40 if (addComma) { |
14 json->appendf(","); | 41 json->appendf(","); |
15 } | 42 } |
16 json->appendf("\"%s\": [", name); | 43 json->appendf("\"%s\": [", name); |
17 for (int i = 0; i < array.count(); i++) { | 44 for (int i = 0; i < array.count(); i++) { |
18 json->append(array[i]->toJson()); | 45 json->append(array[i]->toJson()); |
19 if (i < array.count() - 1) { | 46 if (i < array.count() - 1) { |
20 json->append(","); | 47 json->append(","); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 int fTabCount; | 111 int fTabCount; |
85 bool fFreshLine; | 112 bool fFreshLine; |
86 bool fCommaException; | 113 bool fCommaException; |
87 }; | 114 }; |
88 | 115 |
89 static SkString pretty_print_json(SkString json) { | 116 static SkString pretty_print_json(SkString json) { |
90 class PrettyPrintJson prettyPrintJson; | 117 class PrettyPrintJson prettyPrintJson; |
91 return prettyPrintJson.prettify(json); | 118 return prettyPrintJson.prettify(json); |
92 } | 119 } |
93 | 120 |
94 SkString GrAuditTrail::toJson(bool prettyPrint) const { | 121 SkString GrAuditTrail::toJson(bool batchList, bool prettyPrint) const { |
95 SkString json; | 122 SkString json; |
96 json.append("{"); | 123 json.append("{"); |
97 JsonifyTArray(&json, "Stacks", fFrames, false); | 124 if (!batchList) { |
| 125 JsonifyTArray(&json, "Stacks", fFrames, false); |
| 126 } else { |
| 127 JsonifyTArray(&json, "Batches", fBatches, false); |
| 128 } |
98 json.append("}"); | 129 json.append("}"); |
99 | 130 |
100 if (prettyPrint) { | 131 if (prettyPrint) { |
101 return pretty_print_json(json); | 132 return pretty_print_json(json); |
102 } else { | 133 } else { |
103 return json; | 134 return json; |
104 } | 135 } |
105 } | 136 } |
106 | 137 |
107 SkString GrAuditTrail::Frame::toJson() const { | 138 SkString GrAuditTrail::Frame::toJson() const { |
108 SkString json; | 139 SkString json; |
109 json.append("{"); | 140 json.append("{"); |
110 json.appendf("\"Name\": \"%s\"", fName); | 141 json.appendf("\"Name\": \"%s\"", fName); |
111 JsonifyTArray(&json, "Frames", fChildren, true); | 142 JsonifyTArray(&json, "Frames", fChildren, true); |
112 json.append("}"); | 143 json.append("}"); |
113 return json; | 144 return json; |
114 } | 145 } |
115 | 146 |
116 SkString GrAuditTrail::Batch::toJson() const { | 147 SkString GrAuditTrail::Batch::toJson() const { |
117 SkString json; | 148 SkString json; |
118 json.append("{"); | 149 json.append("{"); |
119 json.appendf("\"Name\": \"%s\",", fName); | 150 json.appendf("\"Name\": \"%s\",", fName); |
120 json.append("\"Bounds\": {"); | 151 json.append("\"Bounds\": {"); |
121 json.appendf("\"Left\": %f,", fBounds.fLeft); | 152 json.appendf("\"Left\": %f,", fBounds.fLeft); |
122 json.appendf("\"Right\": %f,", fBounds.fRight); | 153 json.appendf("\"Right\": %f,", fBounds.fRight); |
123 json.appendf("\"Top\": %f,", fBounds.fTop); | 154 json.appendf("\"Top\": %f,", fBounds.fTop); |
124 json.appendf("\"Bottom\": %f", fBounds.fBottom); | 155 json.appendf("\"Bottom\": %f", fBounds.fBottom); |
| 156 JsonifyTArray(&json, "Children", fChildren, true); |
125 json.append("}"); | 157 json.append("}"); |
126 json.append("}"); | 158 json.append("}"); |
127 return json; | 159 return json; |
128 } | 160 } |
OLD | NEW |