Flutter Engine
The Flutter Engine
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
33 gBitmapResults.push_back(result);
34}
35
36void JsonWriter::DumpJson(const char* dir,
39 if (0 == strcmp(dir, "")) {
40 return;
41 }
42
43 SkString path = SkOSPath::Join(dir, "dm.json");
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)
const void * data() const
Definition: SkData.h:37
static sk_sp< SkData > MakeFromFileName(const char path[])
Definition: SkData.cpp:148
size_t size() const
Definition: SkData.h:30
void appendS32(int32_t value)
Definition: SkJSONWriter.h:237
void beginArray(const char *name=nullptr, bool multiline=true)
Definition: SkJSONWriter.h:146
void beginObject(const char *name=nullptr, bool multiline=true)
Definition: SkJSONWriter.h:114
void endObject()
Definition: SkJSONWriter.h:126
void appendCString(const char *value)
Definition: SkJSONWriter.h:224
void endArray()
Definition: SkJSONWriter.h:158
void flush()
Definition: SkJSONWriter.h:78
void appendString(const char *value, size_t size)
Definition: SkJSONWriter.h:176
static SkString Join(const char *rootPath, const char *relativePath)
Definition: SkOSPath.cpp:14
static const char * begin(const StringSlice &s)
Definition: editor.cpp:252
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
GAsyncResult * result
TArray< JsonWriter::BitmapResult > gBitmapResults
static SkMutex & bitmap_result_mutex()
Definition: dom.py:1
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145
string root
Definition: scale_cpu.py:20
int getMaxResidentSetSizeMB()
Definition: ProcStats.cpp:87