Flutter Engine
The Flutter Engine
JsonWriteBuffer.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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
9
15
16class SkImage;
17class SkMatrix;
18class SkPaint;
19class SkRegion;
20class SkStream;
21class SkTypeface;
22struct SkIRect;
23struct SkPoint3;
24struct SkRect;
25
26void JsonWriteBuffer::append(const char* type) {
27 SkString fullName = SkStringPrintf("%02d_%s", fCount++, type);
28 fWriter->appendName(fullName.c_str());
29}
30
31void JsonWriteBuffer::writePad32(const void* data, size_t size) {
32 this->append("rawBytes");
33 fWriter->beginArray();
34 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data);
35 for (size_t i = 0; i < size; ++i) {
36 SkString hexByte = SkStringPrintf("%02x", bytes[i]);
37 fWriter->appendString(hexByte);
38 }
39 fWriter->endArray();
40}
41
42void JsonWriteBuffer::writeByteArray(const void* data, size_t size) {
43 this->append("byteArray");
44 fWriter->beginArray();
45 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data);
46 for (size_t i = 0; i < size; ++i) {
47 SkString hexByte = SkStringPrintf("%02x", bytes[i]);
48 fWriter->appendString(hexByte);
49 }
50 fWriter->endArray();
51}
52
54 this->append("bool");
55 fWriter->appendBool(value);
56}
57
59 this->append("scalar");
60 fWriter->appendFloat(value);
61}
62
64 this->append("scalarArray");
65 fWriter->beginArray();
66 for (uint32_t i = 0; i < count; ++i) {
67 fWriter->appendFloat(value[i]);
68 }
69 fWriter->endArray();
70}
71
73 this->append("int");
74 fWriter->appendS32(value);
75}
76
77void JsonWriteBuffer::writeIntArray(const int32_t* value, uint32_t count) {
78 this->append("intArray");
79 fWriter->beginArray();
80 for (uint32_t i = 0; i < count; ++i) {
81 fWriter->appendS32(value[i]);
82 }
83 fWriter->endArray();
84}
85
87 this->append("uint");
88 fWriter->appendU32(value);
89}
90
91void JsonWriteBuffer::writeString(std::string_view value) {
92 this->append("string");
93 fWriter->appendString(value.data(), value.size());
94}
95
97 if (flattenable) {
98 this->append(flattenable->getTypeName());
99 fWriter->beginObject();
100 JsonWriteBuffer flattenableBuffer(fWriter, fUrlDataManager);
101 flattenable->flatten(flattenableBuffer);
102 fWriter->endObject();
103 } else {
104 this->append("flattenable");
105 fWriter->appendPointer(nullptr);
106 }
107}
108
110 this->append("color");
112}
113
115 this->append("colorArray");
116 fWriter->beginArray();
117 for (uint32_t i = 0; i < count; ++i) {
119 }
120 fWriter->endArray();
121}
122
124 this->append("color");
126}
127
129 this->append("colorArray");
130 fWriter->beginArray();
131 for (uint32_t i = 0; i < count; ++i) {
133 }
134 fWriter->endArray();
135}
136
138 this->append("point");
139 DrawCommand::MakeJsonPoint(*fWriter, point);
140}
141
143 this->append("point3");
144 DrawCommand::MakeJsonPoint3(*fWriter, point);
145}
146
147void JsonWriteBuffer::writePointArray(const SkPoint* point, uint32_t count) {
148 this->append("pointArray");
149 fWriter->beginArray();
150 for (uint32_t i = 0; i < count; ++i) {
151 DrawCommand::MakeJsonPoint(*fWriter, point[i]);
152 }
153 fWriter->endArray();
154}
155
157 this->append("matrix");
158 fWriter->beginArray();
159 for (int r = 0; r < 4; ++r) {
160 fWriter->beginArray(nullptr, false);
161 SkV4 v = matrix.row(r);
162 for (int c = 0; c < 4; ++c) {
163 fWriter->appendFloat(v[c]);
164 }
165 fWriter->endArray();
166 }
167 fWriter->endArray();
168}
169
171 this->append("matrix");
173}
174
176 this->append("irect");
178}
179
181 this->append("rect");
183}
184
186 this->append("region");
188}
189
191 this->append("path");
193}
194
196 this->append("sampling");
198}
199
201 // Contents not supported
202 this->append("stream");
203 fWriter->appendU64(static_cast<uint64_t>(length));
204 return 0;
205}
206
208 this->append("image");
209 fWriter->beginObject();
210 DrawCommand::flatten(*image, *fWriter, *fUrlDataManager);
211 fWriter->endObject();
212}
213
215 // Unsupported
216 this->append("typeface");
217 fWriter->appendPointer(typeface);
218}
219
221 this->append("paint");
222 DrawCommand::MakeJsonPaint(*fWriter, paint, *fUrlDataManager);
223}
int count
Definition: FontMgrTest.cpp:50
uint32_t SkColor
Definition: SkColor.h:37
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
GLenum type
static void MakeJsonPoint3(SkJSONWriter &, const SkPoint3 &point)
static void MakeJsonPoint(SkJSONWriter &, const SkPoint &point)
static void MakeJsonColor(SkJSONWriter &, const SkColor color)
static void MakeJsonPaint(SkJSONWriter &, const SkPaint &paint, UrlDataManager &urlDataManager)
static void MakeJsonRect(SkJSONWriter &, const SkRect &rect)
static void flatten(const SkFlattenable *flattenable, SkJSONWriter &writer, UrlDataManager &urlDataManager)
static void MakeJsonSampling(SkJSONWriter &, const SkSamplingOptions &sampling)
static void MakeJsonMatrix(SkJSONWriter &, const SkMatrix &)
static void MakeJsonIRect(SkJSONWriter &, const SkIRect &)
static void MakeJsonRegion(SkJSONWriter &, const SkRegion &region)
static void MakeJsonColor4f(SkJSONWriter &, const SkColor4f &color)
static void MakeJsonPath(SkJSONWriter &, const SkPath &path)
void writeIRect(const SkIRect &rect) override
void writeColorArray(const SkColor *color, uint32_t count) override
void writeRect(const SkRect &rect) override
void writeMatrix(const SkMatrix &matrix) override
void writeFlattenable(const SkFlattenable *flattenable) override
size_t writeStream(SkStream *stream, size_t length) override
void writeString(std::string_view value) override
void writeColor(SkColor color) override
void writeIntArray(const int32_t *value, uint32_t count) override
void writePointArray(const SkPoint *point, uint32_t count) override
void writeColor4fArray(const SkColor4f *color, uint32_t count) override
void writePath(const SkPath &path) override
void writeBool(bool value) override
void writeRegion(const SkRegion &region) override
void writeInt(int32_t value) override
void writeColor4f(const SkColor4f &color) override
void writeImage(const SkImage *) override
void writeScalar(SkScalar value) override
void writeSampling(const SkSamplingOptions &) override
void writeTypeface(SkTypeface *typeface) override
void writeUInt(uint32_t value) override
void writeByteArray(const void *data, size_t size) override
void writeScalarArray(const SkScalar *value, uint32_t count) override
void writePaint(const SkPaint &paint) override
void writePoint3(const SkPoint3 &point) override
void writePoint(const SkPoint &point) override
void writePad32(const void *buffer, size_t bytes) override
void write(const SkM44 &) override
virtual void flatten(SkWriteBuffer &) const
Definition: SkFlattenable.h:67
virtual const char * getTypeName() const =0
void appendS32(int32_t value)
Definition: SkJSONWriter.h:237
void beginArray(const char *name=nullptr, bool multiline=true)
Definition: SkJSONWriter.h:146
void appendU32(uint32_t value)
Definition: SkJSONWriter.h:239
void beginObject(const char *name=nullptr, bool multiline=true)
Definition: SkJSONWriter.h:114
void appendU64(uint64_t value)
void appendFloat(float value)
Definition: SkJSONWriter.h:241
void appendPointer(const void *value)
Definition: SkJSONWriter.h:228
void endObject()
Definition: SkJSONWriter.h:126
void appendBool(bool value)
Definition: SkJSONWriter.h:229
void appendName(const char *name)
Definition: SkJSONWriter.h:90
void endArray()
Definition: SkJSONWriter.h:158
void appendString(const char *value, size_t size)
Definition: SkJSONWriter.h:176
Definition: SkM44.h:150
Definition: SkPath.h:59
const char * c_str() const
Definition: SkString.h:133
const Paint & paint
Definition: color_source.cc:38
DlColor color
static void append(char **dst, size_t *count, const char *src, size_t n)
Definition: editor.cpp:211
float SkScalar
Definition: extension.cpp:12
uint8_t value
size_t length
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
sk_sp< const SkImage > image
Definition: SkRecords.h:269
ClipOpAndAA opAA SkRegion region
Definition: SkRecords.h:238
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
SkSamplingOptions sampling
Definition: SkRecords.h:337
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
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: SkRect.h:32
Definition: SkM44.h:98
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63