OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "DMJsonWriter.h" |
| 9 |
| 10 #include "SkCommonFlags.h" |
| 11 #include "SkJSONCPP.h" |
| 12 #include "SkOSFile.h" |
| 13 #include "SkStream.h" |
| 14 #include "SkTArray.h" |
| 15 #include "SkThread.h" |
| 16 |
| 17 namespace DM { |
| 18 |
| 19 SkTArray<JsonWriter::BitmapResult> gBitmapResults; |
| 20 SK_DECLARE_STATIC_MUTEX(gBitmapResultLock); |
| 21 |
| 22 void JsonWriter::AddBitmapResult(const BitmapResult& result) { |
| 23 SkAutoMutexAcquire lock(&gBitmapResultLock); |
| 24 gBitmapResults.push_back(result); |
| 25 } |
| 26 |
| 27 void JsonWriter::DumpJson() { |
| 28 if (FLAGS_writePath.isEmpty()) { |
| 29 return; |
| 30 } |
| 31 |
| 32 Json::Value root; |
| 33 |
| 34 for (int i = 1; i < FLAGS_properties.count(); i += 2) { |
| 35 root[FLAGS_properties[i-1]] = FLAGS_properties[i]; |
| 36 } |
| 37 for (int i = 1; i < FLAGS_key.count(); i += 2) { |
| 38 root["key"][FLAGS_key[i-1]] = FLAGS_key[i]; |
| 39 } |
| 40 |
| 41 { |
| 42 SkAutoMutexAcquire lock(&gBitmapResultLock); |
| 43 for (int i = 0; i < gBitmapResults.count(); i++) { |
| 44 Json::Value result; |
| 45 result["key"]["name"] = gBitmapResults[i].name.c_str(); |
| 46 result["key"]["config"] = gBitmapResults[i].config.c_str(); |
| 47 result["key"]["mode"] = gBitmapResults[i].mode.c_str(); |
| 48 result["options"]["source_type"] = gBitmapResults[i].sourceType.c_st
r(); |
| 49 result["md5"] = gBitmapResults[i].md5.c_str(); |
| 50 |
| 51 root["results"].append(result); |
| 52 } |
| 53 } |
| 54 |
| 55 SkString path = SkOSPath::Join(FLAGS_writePath[0], "dm.json"); |
| 56 SkFILEWStream stream(path.c_str()); |
| 57 stream.writeText(Json::StyledWriter().write(root).c_str()); |
| 58 stream.flush(); |
| 59 } |
| 60 |
| 61 } // namespace DM |
OLD | NEW |