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

Side by Side Diff: dm/DMJsonWriter.cpp

Issue 702513003: Separate JSON functions from DMWriteTask. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Modify comment to be more accurate. Created 6 years, 1 month 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 | « dm/DMJsonWriter.h ('k') | dm/DMWriteTask.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « dm/DMJsonWriter.h ('k') | dm/DMWriteTask.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698