Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
DMJsonWriter.cpp
Go to the documentation of this file.
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 "dm/DMJsonWriter.h"
9
10#include "include/core/SkData.h"
14#include "src/core/SkOSFile.h"
15#include "src/utils/SkJSON.h"
17#include "src/utils/SkOSPath.h"
18#include "tools/ProcStats.h"
19
20using namespace skia_private;
21
22namespace DM {
23
25static SkMutex& bitmap_result_mutex() {
26 static SkMutex& mutex = *(new SkMutex);
27 return mutex;
28}
29
30
35
36void JsonWriter::DumpJson(const char* dir,
39 if (0 == strcmp(dir, "")) {
40 return;
41 }
42
43 SkString path = SkOSPath::Join(dir, "dm.json");
44 sk_mkdir(dir);
45 SkFILEWStream stream(path.c_str());
47
48 writer.beginObject(); // root
49
50 for (int i = 1; i < properties.size(); i += 2) {
51 writer.appendCString(properties[i-1], properties[i]);
52 }
53
54 writer.beginObject("key");
55 for (int i = 1; i < key.size(); i += 2) {
56 writer.appendCString(key[i-1], key[i]);
57 }
58 writer.endObject();
59
60 int maxResidentSetSizeMB = sk_tools::getMaxResidentSetSizeMB();
61 if (maxResidentSetSizeMB != -1) {
62 writer.appendS32("max_rss_MB", maxResidentSetSizeMB);
63 }
64
65 {
67 writer.beginArray("results");
68 for (int i = 0; i < gBitmapResults.size(); i++) {
69 writer.beginObject();
70
71 writer.beginObject("key");
72 writer.appendString("name" , gBitmapResults[i].name);
73 writer.appendString("config" , gBitmapResults[i].config);
74 writer.appendString("source_type", gBitmapResults[i].sourceType);
75
76 // Source options only need to be part of the key if they exist.
77 // Source type by source type, we either always set options or never set options.
78 if (!gBitmapResults[i].sourceOptions.isEmpty()) {
79 writer.appendString("source_options", gBitmapResults[i].sourceOptions);
80 }
81 writer.endObject(); // key
82
83 writer.beginObject("options");
84 writer.appendString("ext" , gBitmapResults[i].ext);
85 writer.appendString("gamut", gBitmapResults[i].gamut);
86 writer.appendString("transfer_fn", gBitmapResults[i].transferFn);
87 writer.appendString("color_type", gBitmapResults[i].colorType);
88 writer.appendString("alpha_type", gBitmapResults[i].alphaType);
89 writer.appendString("color_depth", gBitmapResults[i].colorDepth);
90 writer.endObject(); // options
91
92 writer.appendString("md5", gBitmapResults[i].md5);
93
94 writer.endObject(); // 1 result
95 }
96 writer.endArray(); // results
97 }
98
99 writer.endObject(); // root
100 writer.flush();
101 stream.flush();
102}
103
104using namespace skjson;
105
106bool JsonWriter::ReadJson(const char* path, void(*callback)(BitmapResult)) {
108 if (!json) {
109 return false;
110 }
111
112 DOM dom((const char*)json->data(), json->size());
113 const ObjectValue* root = dom.root();
114 if (!root) {
115 return false;
116 }
117
118 const ArrayValue* results = (*root)["results"];
119 if (!results) {
120 return false;
121 }
122
123 BitmapResult br;
124 for (const ObjectValue* r : *results) {
125 const ObjectValue& key = (*r)["key"].as<ObjectValue>();
126 const ObjectValue& options = (*r)["options"].as<ObjectValue>();
127
128 br.name = key["name"].as<StringValue>().begin();
129 br.config = key["config"].as<StringValue>().begin();
130 br.sourceType = key["source_type"].as<StringValue>().begin();
131 br.ext = options["ext"].as<StringValue>().begin();
132 br.gamut = options["gamut"].as<StringValue>().begin();
133 br.transferFn = options["transfer_fn"].as<StringValue>().begin();
134 br.colorType = options["color_type"].as<StringValue>().begin();
135 br.alphaType = options["alpha_type"].as<StringValue>().begin();
136 br.colorDepth = options["color_depth"].as<StringValue>().begin();
137 br.md5 = (*r)["md5"].as<StringValue>().begin();
138
139 if (const StringValue* so = key["source_options"]) {
140 br.sourceOptions = so->begin();
141 }
142 callback(br);
143 }
144 return true;
145}
146
147} // namespace DM
static SkMD5::Digest md5(const SkBitmap &bm)
Definition CodecTest.cpp:77
const char * options
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
bool sk_mkdir(const char *path)
static void AddBitmapResult(const BitmapResult &)
static bool ReadJson(const char *path, void(*callback)(BitmapResult))
static void DumpJson(const char *dir, CommandLineFlags::StringArray key, CommandLineFlags::StringArray properties)
static sk_sp< SkData > MakeFromFileName(const char path[])
Definition SkData.cpp:148
void appendS32(int32_t value)
void beginArray(const char *name=nullptr, bool multiline=true)
void beginObject(const char *name=nullptr, bool multiline=true)
void appendCString(const char *value)
void appendString(const char *value, size_t size)
static SkString Join(const char *rootPath, const char *relativePath)
Definition SkOSPath.cpp:14
const T & as() const
Definition SkJSON.h:85
static const char * begin(const StringSlice &s)
Definition editor.cpp:252
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
GAsyncResult * result
const char * name
Definition fuchsia.cc:50
TArray< JsonWriter::BitmapResult > gBitmapResults
static SkMutex & bitmap_result_mutex()
Definition dom.py:1
int getMaxResidentSetSizeMB()
Definition ProcStats.cpp:87