Convert DM's -r JSON parsing to SkJSON

Bug: skia:
Change-Id: I987f527dbd742453422073f8e2b28d824f8a62eb
Reviewed-on: https://skia-review.googlesource.com/c/186879
Commit-Queue: Brian Osman <brianosman@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Auto-Submit: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Brian Osman 2019-01-25 16:34:20 -05:00 committed by Skia Commit-Bot
parent f6a2348535
commit fad5c773f7

View File

@ -10,7 +10,7 @@
#include "ProcStats.h"
#include "SkCommonFlags.h"
#include "SkData.h"
#include "SkJSONCPP.h"
#include "SkJSON.h"
#include "SkJSONWriter.h"
#include "SkMutex.h"
#include "SkOSFile.h"
@ -116,32 +116,39 @@ void JsonWriter::DumpJson() {
stream.flush();
}
using namespace skjson;
bool JsonWriter::ReadJson(const char* path, void(*callback)(BitmapResult)) {
sk_sp<SkData> json(SkData::MakeFromFileName(path));
if (!json) {
return false;
}
Json::Reader reader;
Json::Value root;
const char* data = (const char*)json->data();
if (!reader.parse(data, data+json->size(), root)) {
DOM dom((const char*)json->data(), json->size());
const ObjectValue* root = dom.root();
if (!root) {
return false;
}
const Json::Value& results = root["results"];
BitmapResult br;
for (unsigned i = 0; i < results.size(); i++) {
const Json::Value& r = results[i];
br.name = r["key"]["name"].asCString();
br.config = r["key"]["config"].asCString();
br.sourceType = r["key"]["source_type"].asCString();
br.ext = r["options"]["ext"].asCString();
br.gammaCorrect = 0 == strcmp("yes", r["options"]["gamma_correct"].asCString());
br.md5 = r["md5"].asCString();
const ArrayValue* results = (*root)["results"];
if (!results) {
return false;
}
if (!r["key"]["source_options"].isNull()) {
br.sourceOptions = r["key"]["source_options"].asCString();
BitmapResult br;
for (const ObjectValue* r : *results) {
const ObjectValue& key = (*r)["key"].as<ObjectValue>();
const ObjectValue& options = (*r)["options"].as<ObjectValue>();
br.name = key["name"].as<StringValue>().begin();
br.config = key["config"].as<StringValue>().begin();
br.sourceType = key["source_type"].as<StringValue>().begin();
br.ext = options["ext"].as<StringValue>().begin();
br.gammaCorrect = 0 == strcmp("yes", options["gamma_correct"].as<StringValue>().begin());
br.md5 = (*r)["md5"].as<StringValue>().begin();
if (const StringValue* so = key["source_options"]) {
br.sourceOptions = so->begin();
}
callback(br);
}