Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Side by Side Diff: src/gpu/GrAuditTrail.cpp

Issue 1579193002: Convert GrAuditTrail to use scoped frames (Closed) Base URL: https://skia.googlesource.com/skia.git@audittrail-2-wireupbatchnames-andbounds
Patch Set: typo Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 SkTArray<T>& array) { 11 static void jsonify_tarray(SkString* json, const char* name, const SkTArray<T>& array) {
12 for (int i = 0; i < array.count(); i++) { 12 if (array.count()) {
13 json->append(array[i].toJson()); 13 json->appendf("\"%s\": [", name);
14 if (i < array.count() - 1) { 14 for (int i = 0; i < array.count(); i++) {
15 json->append(","); 15 json->append(array[i].toJson());
16 if (i < array.count() - 1) {
17 json->append(",");
18 }
16 } 19 }
20 json->append("]");
17 } 21 }
18 } 22 }
19 23
20 // This will pretty print a very small subset of json 24 // This will pretty print a very small subset of json
21 // The parsing rules are straightforward, aside from the fact that we do not wan t an extra newline 25 // The parsing rules are straightforward, aside from the fact that we do not wan t an extra newline
22 // before ',' and after '}', so we have a comma exception rule. 26 // before ',' and after '}', so we have a comma exception rule.
23 class PrettyPrintJson { 27 class PrettyPrintJson {
24 public: 28 public:
25 SkString prettify(const SkString& json) { 29 SkString prettify(const SkString& json) {
26 fPrettyJson.reset(); 30 fPrettyJson.reset();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 }; 84 };
81 85
82 static SkString pretty_print_json(SkString json) { 86 static SkString pretty_print_json(SkString json) {
83 class PrettyPrintJson prettyPrintJson; 87 class PrettyPrintJson prettyPrintJson;
84 return prettyPrintJson.prettify(json); 88 return prettyPrintJson.prettify(json);
85 } 89 }
86 90
87 SkString GrAuditTrail::toJson() const { 91 SkString GrAuditTrail::toJson() const {
88 SkString json; 92 SkString json;
89 json.append("{"); 93 json.append("{");
90 json.append("\"Ops\": ["); 94 jsonify_tarray(&json, "Stacks", fFrames);
91 jsonify_tarray(&json, fOps);
92 json.append("]");
93 json.append("}"); 95 json.append("}");
94 96
95 // TODO if this becomes a performance issue we should make pretty print conf igurable 97 // TODO if this becomes a performance issue we should make pretty print conf igurable
96 return pretty_print_json(json); 98 return pretty_print_json(json);
97 } 99 }
98 100
99 SkString GrAuditTrail::Op::toJson() const { 101 SkString GrAuditTrail::Frame::toJson() const {
100 SkString json; 102 SkString json;
101 json.append("{"); 103 json.append("{");
102 json.appendf("\"Name\": \"%s\",", fName.c_str()); 104 json.appendf("\"Name\": \"%s\",", fName);
103 json.append("\"Batches\": ["); 105 jsonify_tarray(&json, "Batches", fBatches);
104 jsonify_tarray(&json, fBatches); 106 jsonify_tarray(&json, "Frames", fChildren);
105 json.append("]");
106 json.append("}"); 107 json.append("}");
107 return json; 108 return json;
108 } 109 }
109 110
110 SkString GrAuditTrail::Op::Batch::toJson() const { 111 SkString GrAuditTrail::Frame::Batch::toJson() const {
111 SkString json; 112 SkString json;
112 json.append("{"); 113 json.append("{");
113 json.appendf("\"Name\": \"%s\",", fName.c_str()); 114 json.appendf("\"Name\": \"%s\",", fName);
114 json.append("\"Bounds\": {"); 115 json.append("\"Bounds\": {");
115 json.appendf("\"Left\": %f,", fBounds.fLeft); 116 json.appendf("\"Left\": %f,", fBounds.fLeft);
116 json.appendf("\"Right\": %f,", fBounds.fRight); 117 json.appendf("\"Right\": %f,", fBounds.fRight);
117 json.appendf("\"Top\": %f,", fBounds.fTop); 118 json.appendf("\"Top\": %f,", fBounds.fTop);
118 json.appendf("\"Bottom\": %f", fBounds.fBottom); 119 json.appendf("\"Bottom\": %f", fBounds.fBottom);
119 json.append("}"); 120 json.append("}");
120 json.append("}"); 121 json.append("}");
121 return json; 122 return json;
122 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698