aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Osman <brianosman@google.com>2019-01-28 13:41:19 -0500
committerSkia Commit-Bot <skia-commit-bot@chromium.org>2019-01-28 19:06:06 +0000
commitd8a90f9be1f068dd8231cc6c9e9d490d17e7ece6 (patch)
tree50e719471da0dfd97378a7dcf888e4860bf1b193 /src
parent41f0e28fd5bd11a7ebf5400f1f046d882de1e4a7 (diff)
downloadskqp-d8a90f9be1f068dd8231cc6c9e9d490d17e7ece6.tar.gz
Converting more debug code to SkJSONWriter
All of SkDrawCommand / SkDebugCanvas now uses SkJSONWriter. Also removed the bespoke json generator and pretty-printer in GrAuditTrail. This was the largest volume of code still using JsonCPP. (There are other stragglers). Bug: skia: Change-Id: I3aee554764689ce50c8e707caf26c76093b9bb8f Reviewed-on: https://skia-review.googlesource.com/c/187040 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrAuditTrail.cpp168
-rw-r--r--src/utils/SkJSONWriter.h8
2 files changed, 41 insertions, 135 deletions
diff --git a/src/gpu/GrAuditTrail.cpp b/src/gpu/GrAuditTrail.cpp
index 411be3f428..750890a7e4 100644
--- a/src/gpu/GrAuditTrail.cpp
+++ b/src/gpu/GrAuditTrail.cpp
@@ -7,6 +7,7 @@
#include "GrAuditTrail.h"
#include "ops/GrOp.h"
+#include "SkJSONWriter.h"
const int GrAuditTrail::kGrAuditTrailInvalidID = -1;
@@ -136,159 +137,64 @@ void GrAuditTrail::fullReset() {
}
template <typename T>
-void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& array,
- bool addComma) {
+void GrAuditTrail::JsonifyTArray(SkJSONWriter& writer, const char* name, const T& array) {
if (array.count()) {
- if (addComma) {
- json->appendf(",");
- }
- json->appendf("\"%s\": [", name);
- const char* separator = "";
+ writer.beginArray(name);
for (int i = 0; i < array.count(); i++) {
// Handle sentinel nullptrs
if (array[i]) {
- json->appendf("%s", separator);
- json->append(array[i]->toJson());
- separator = ",";
- }
- }
- json->append("]");
- }
-}
-
-// This will pretty print a very small subset of json
-// The parsing rules are straightforward, aside from the fact that we do not want an extra newline
-// before ',' and after '}', so we have a comma exception rule.
-class PrettyPrintJson {
-public:
- SkString prettify(const SkString& json) {
- fPrettyJson.reset();
- fTabCount = 0;
- fFreshLine = false;
- fCommaException = false;
- for (size_t i = 0; i < json.size(); i++) {
- if ('[' == json[i] || '{' == json[i]) {
- this->newline();
- this->appendChar(json[i]);
- fTabCount++;
- this->newline();
- } else if (']' == json[i] || '}' == json[i]) {
- fTabCount--;
- this->newline();
- this->appendChar(json[i]);
- fCommaException = true;
- } else if (',' == json[i]) {
- this->appendChar(json[i]);
- this->newline();
- } else {
- this->appendChar(json[i]);
- }
- }
- return fPrettyJson;
- }
-private:
- void appendChar(char appendee) {
- if (fCommaException && ',' != appendee) {
- this->newline();
- }
- this->tab();
- fPrettyJson += appendee;
- fFreshLine = false;
- fCommaException = false;
- }
-
- void tab() {
- if (fFreshLine) {
- for (int i = 0; i < fTabCount; i++) {
- fPrettyJson += '\t';
+ array[i]->toJson(writer);
}
}
+ writer.endArray();
}
-
- void newline() {
- if (!fFreshLine) {
- fFreshLine = true;
- fPrettyJson += '\n';
- }
- }
-
- SkString fPrettyJson;
- int fTabCount;
- bool fFreshLine;
- bool fCommaException;
-};
-
-static SkString pretty_print_json(SkString json) {
- class PrettyPrintJson prettyPrintJson;
- return prettyPrintJson.prettify(json);
}
-SkString GrAuditTrail::toJson(bool prettyPrint) const {
- SkString json;
- json.append("{");
- JsonifyTArray(&json, "Ops", fOpList, false);
- json.append("}");
-
- if (prettyPrint) {
- return pretty_print_json(json);
- } else {
- return json;
- }
+void GrAuditTrail::toJson(SkJSONWriter& writer) const {
+ writer.beginObject();
+ JsonifyTArray(writer, "Ops", fOpList);
+ writer.endObject();
}
-SkString GrAuditTrail::toJson(int clientID, bool prettyPrint) const {
- SkString json;
- json.append("{");
+void GrAuditTrail::toJson(SkJSONWriter& writer, int clientID) const {
+ writer.beginObject();
Ops** ops = fClientIDLookup.find(clientID);
if (ops) {
- JsonifyTArray(&json, "Ops", **ops, false);
- }
- json.appendf("}");
-
- if (prettyPrint) {
- return pretty_print_json(json);
- } else {
- return json;
+ JsonifyTArray(writer, "Ops", **ops);
}
+ writer.endObject();
}
-static void skrect_to_json(SkString* json, const char* name, const SkRect& rect) {
- json->appendf("\"%s\": {", name);
- json->appendf("\"Left\": %f,", rect.fLeft);
- json->appendf("\"Right\": %f,", rect.fRight);
- json->appendf("\"Top\": %f,", rect.fTop);
- json->appendf("\"Bottom\": %f", rect.fBottom);
- json->append("}");
+static void skrect_to_json(SkJSONWriter& writer, const char* name, const SkRect& rect) {
+ writer.beginObject(name);
+ writer.appendFloat("Left", rect.fLeft);
+ writer.appendFloat("Right", rect.fRight);
+ writer.appendFloat("Top", rect.fTop);
+ writer.appendFloat("Bottom", rect.fBottom);
+ writer.endObject();
}
-SkString GrAuditTrail::Op::toJson() const {
- SkString json;
- json.append("{");
- json.appendf("\"Name\": \"%s\",", fName.c_str());
- json.appendf("\"ClientID\": \"%d\",", fClientID);
- json.appendf("\"OpListID\": \"%d\",", fOpListID);
- json.appendf("\"ChildID\": \"%d\",", fChildID);
- skrect_to_json(&json, "Bounds", fBounds);
+void GrAuditTrail::Op::toJson(SkJSONWriter& writer) const {
+ writer.beginObject();
+ writer.appendString("Name", fName.c_str());
+ writer.appendS32("ClientID", fClientID);
+ writer.appendS32("OpListID", fOpListID);
+ writer.appendS32("ChildID", fChildID);
+ skrect_to_json(writer, "Bounds", fBounds);
if (fStackTrace.count()) {
- json.append(",\"Stack\": [");
+ writer.beginArray("Stack");
for (int i = 0; i < fStackTrace.count(); i++) {
- json.appendf("\"%s\"", fStackTrace[i].c_str());
- if (i < fStackTrace.count() - 1) {
- json.append(",");
- }
+ writer.appendString(fStackTrace[i].c_str());
}
- json.append("]");
+ writer.endArray();
}
- json.append("}");
- return json;
+ writer.endObject();
}
-SkString GrAuditTrail::OpNode::toJson() const {
- SkString json;
- json.append("{");
- json.appendf("\"ProxyID\": \"%u\",", fProxyUniqueID.asUInt());
- skrect_to_json(&json, "Bounds", fBounds);
- JsonifyTArray(&json, "Ops", fChildren, true);
- json.append("}");
- return json;
+void GrAuditTrail::OpNode::toJson(SkJSONWriter& writer) const {
+ writer.beginObject();
+ writer.appendU32("ProxyID", fProxyUniqueID.asUInt());
+ skrect_to_json(writer, "Bounds", fBounds);
+ JsonifyTArray(writer, "Ops", fChildren);
+ writer.endObject();
}
diff --git a/src/utils/SkJSONWriter.h b/src/utils/SkJSONWriter.h
index 09db543c86..6907653cee 100644
--- a/src/utils/SkJSONWriter.h
+++ b/src/utils/SkJSONWriter.h
@@ -199,15 +199,15 @@ public:
void appendS64(int64_t value);
void appendU32(uint32_t value) { this->beginValue(); this->appendf("%u", value); }
void appendU64(uint64_t value);
- void appendFloat(float value) { this->beginValue(); this->appendf("%f", value); }
- void appendDouble(double value) { this->beginValue(); this->appendf("%f", value); }
+ void appendFloat(float value) { this->beginValue(); this->appendf("%g", value); }
+ void appendDouble(double value) { this->beginValue(); this->appendf("%g", value); }
void appendFloatDigits(float value, int digits) {
this->beginValue();
- this->appendf("%.*f", digits, value);
+ this->appendf("%.*g", digits, value);
}
void appendDoubleDigits(double value, int digits) {
this->beginValue();
- this->appendf("%.*f", digits, value);
+ this->appendf("%.*g", digits, value);
}
void appendHexU32(uint32_t value) { this->beginValue(); this->appendf("\"0x%x\"", value); }
void appendHexU64(uint64_t value);