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

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

Issue 1745513002: Add abilitly to query audit trail for batches by draw op (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: tweaks Created 4 years, 9 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
« no previous file with comments | « include/private/GrAuditTrail.h ('k') | tools/debugger/SkDebugCanvas.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "batches/GrBatch.h" 9 #include "batches/GrBatch.h"
10 10
11 const int GrAuditTrail::kGrAuditTrailInvalidID = -1;
12
11 void GrAuditTrail::batchingResultCombined(GrBatch* combiner) { 13 void GrAuditTrail::batchingResultCombined(GrBatch* combiner) {
12 int* indexPtr = fIDLookup.find(combiner); 14 int* indexPtr = fIDLookup.find(combiner);
13 SkASSERT(indexPtr); 15 SkASSERT(indexPtr);
14 int index = *indexPtr; 16 int index = *indexPtr;
15 SkASSERT(index < fBatches.count()); 17 SkASSERT(index < fBatchList.count());
16 Batch& batch = *fBatches[index]; 18 BatchNode& batch = *fBatchList[index];
17 19
18 // if this is our first child, we also push back a copy of the original batc h and its 20 // set the ids for the child batch
19 // bounds 21 fCurrentBatch->fBatchListID = index;
20 if (batch.fChildren.empty()) { 22 fCurrentBatch->fChildID = batch.fChildren.count();
21 Batch* firstBatch = new Batch; 23
22 firstBatch->fName = batch.fName; 24 // Update the bounds and store a pointer to the new batch
23 firstBatch->fBounds = batch.fBounds;
24 fEvents.emplace_back(firstBatch);
25 batch.fChildren.push_back(firstBatch);
26 }
27 batch.fChildren.push_back(fCurrentBatch); 25 batch.fChildren.push_back(fCurrentBatch);
28 batch.fBounds = combiner->bounds(); 26 batch.fBounds = combiner->bounds();
29 } 27 }
30 28
31 void GrAuditTrail::batchingResultNew(GrBatch* batch) { 29 void GrAuditTrail::batchingResultNew(GrBatch* batch) {
32 fIDLookup.set(batch, fBatches.count()); 30 // Our algorithm doesn't bother to reorder inside of a BatchNode
33 fBatches.push_back(fCurrentBatch); 31 // so the ChildID will start at 0
32 fCurrentBatch->fBatchListID = fBatchList.count();
33 fCurrentBatch->fChildID = 0;
34
35 // We use the batch pointer as a key to find the batchnode we are 'glomming' batches onto
36 fIDLookup.set(batch, fCurrentBatch->fBatchListID);
37 BatchNode* batchNode = new BatchNode;
38 batchNode->fBounds = fCurrentBatch->fBounds;
39 batchNode->fChildren.push_back(fCurrentBatch);
40 fBatchList.emplace_back(batchNode);
34 } 41 }
35 42
36 template <typename T> 43 template <typename T>
37 void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& arra y, 44 void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& arra y,
38 bool addComma) { 45 bool addComma) {
39 if (array.count()) { 46 if (array.count()) {
40 if (addComma) { 47 if (addComma) {
41 json->appendf(","); 48 json->appendf(",");
42 } 49 }
43 json->appendf("\"%s\": [", name); 50 json->appendf("\"%s\": [", name);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 int fTabCount; 118 int fTabCount;
112 bool fFreshLine; 119 bool fFreshLine;
113 bool fCommaException; 120 bool fCommaException;
114 }; 121 };
115 122
116 static SkString pretty_print_json(SkString json) { 123 static SkString pretty_print_json(SkString json) {
117 class PrettyPrintJson prettyPrintJson; 124 class PrettyPrintJson prettyPrintJson;
118 return prettyPrintJson.prettify(json); 125 return prettyPrintJson.prettify(json);
119 } 126 }
120 127
121 SkString GrAuditTrail::toJson(bool batchList, bool prettyPrint) const { 128 SkString GrAuditTrail::toJson(bool prettyPrint) const {
122 SkString json; 129 SkString json;
123 json.append("{"); 130 json.append("{");
124 if (!batchList) { 131 JsonifyTArray(&json, "Batches", fBatchList, false);
125 JsonifyTArray(&json, "Stacks", fFrames, false);
126 } else {
127 JsonifyTArray(&json, "Batches", fBatches, false);
128 }
129 json.append("}"); 132 json.append("}");
130 133
131 if (prettyPrint) { 134 if (prettyPrint) {
132 return pretty_print_json(json); 135 return pretty_print_json(json);
136 } else {
137 return json;
138 }
139 }
140
141 SkString GrAuditTrail::toJson(int clientID, bool prettyPrint) const {
142 SkString json;
143 json.append("{");
144 Batches** batches = fClientIDLookup.find(clientID);
145 if (batches) {
146 JsonifyTArray(&json, "Batches", **batches, false);
147 }
148 json.appendf("}");
149
150 if (prettyPrint) {
151 return pretty_print_json(json);
133 } else { 152 } else {
134 return json; 153 return json;
135 } 154 }
136 } 155 }
137 156
138 SkString GrAuditTrail::Frame::toJson() const { 157 static void skrect_to_json(SkString* json, const char* name, const SkRect& rect) {
139 SkString json; 158 json->appendf("\"%s\": {", name);
140 json.append("{"); 159 json->appendf("\"Left\": %f,", rect.fLeft);
141 json.appendf("\"Name\": \"%s\"", fName); 160 json->appendf("\"Right\": %f,", rect.fRight);
142 JsonifyTArray(&json, "Frames", fChildren, true); 161 json->appendf("\"Top\": %f,", rect.fTop);
143 json.append("}"); 162 json->appendf("\"Bottom\": %f", rect.fBottom);
144 return json; 163 json->append("}");
145 } 164 }
146 165
147 SkString GrAuditTrail::Batch::toJson() const { 166 SkString GrAuditTrail::Batch::toJson() const {
148 SkString json; 167 SkString json;
149 json.append("{"); 168 json.append("{");
150 json.appendf("\"Name\": \"%s\",", fName); 169 json.appendf("\"Name\": \"%s\",", fName.c_str());
151 json.append("\"Bounds\": {"); 170 json.appendf("\"ClientID\": \"%d\",", fClientID);
152 json.appendf("\"Left\": %f,", fBounds.fLeft); 171 json.appendf("\"BatchListID\": \"%d\",", fBatchListID);
153 json.appendf("\"Right\": %f,", fBounds.fRight); 172 json.appendf("\"ChildID\": \"%d\",", fChildID);
154 json.appendf("\"Top\": %f,", fBounds.fTop); 173 skrect_to_json(&json, "Bounds", fBounds);
155 json.appendf("\"Bottom\": %f", fBounds.fBottom);
156 JsonifyTArray(&json, "Children", fChildren, true);
157 json.append("}");
158 json.append("}"); 174 json.append("}");
159 return json; 175 return json;
160 } 176 }
177
178 SkString GrAuditTrail::BatchNode::toJson() const {
179 SkString json;
180 json.append("{");
181 skrect_to_json(&json, "Bounds", fBounds);
182 JsonifyTArray(&json, "Batches", fChildren, true);
183 json.append("}");
184 return json;
185 }
OLDNEW
« no previous file with comments | « include/private/GrAuditTrail.h ('k') | tools/debugger/SkDebugCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698