/src/skia/tools/debugger/JsonWriteBuffer.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
8 | | #include "tools/debugger/JsonWriteBuffer.h" |
9 | | |
10 | | #include "include/core/SkFlattenable.h" |
11 | | #include "include/core/SkPoint.h" |
12 | | #include "include/core/SkString.h" |
13 | | #include "src/utils/SkJSONWriter.h" |
14 | | #include "tools/debugger/DrawCommand.h" |
15 | | |
16 | | class SkImage; |
17 | | class SkMatrix; |
18 | | class SkPaint; |
19 | | class SkRegion; |
20 | | class SkStream; |
21 | | class SkTypeface; |
22 | | struct SkIRect; |
23 | | struct SkPoint3; |
24 | | struct SkRect; |
25 | | |
26 | 0 | void JsonWriteBuffer::append(const char* type) { |
27 | 0 | SkString fullName = SkStringPrintf("%02d_%s", fCount++, type); |
28 | 0 | fWriter->appendName(fullName.c_str()); |
29 | 0 | } |
30 | | |
31 | 0 | void JsonWriteBuffer::writePad32(const void* data, size_t size) { |
32 | 0 | this->append("rawBytes"); |
33 | 0 | fWriter->beginArray(); |
34 | 0 | const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data); |
35 | 0 | for (size_t i = 0; i < size; ++i) { |
36 | 0 | SkString hexByte = SkStringPrintf("%02x", bytes[i]); |
37 | 0 | fWriter->appendString(hexByte); |
38 | 0 | } |
39 | 0 | fWriter->endArray(); |
40 | 0 | } |
41 | | |
42 | 0 | void JsonWriteBuffer::writeByteArray(const void* data, size_t size) { |
43 | 0 | this->append("byteArray"); |
44 | 0 | fWriter->beginArray(); |
45 | 0 | const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data); |
46 | 0 | for (size_t i = 0; i < size; ++i) { |
47 | 0 | SkString hexByte = SkStringPrintf("%02x", bytes[i]); |
48 | 0 | fWriter->appendString(hexByte); |
49 | 0 | } |
50 | 0 | fWriter->endArray(); |
51 | 0 | } |
52 | | |
53 | 0 | void JsonWriteBuffer::writeBool(bool value) { |
54 | 0 | this->append("bool"); |
55 | 0 | fWriter->appendBool(value); |
56 | 0 | } |
57 | | |
58 | 0 | void JsonWriteBuffer::writeScalar(SkScalar value) { |
59 | 0 | this->append("scalar"); |
60 | 0 | fWriter->appendFloat(value); |
61 | 0 | } |
62 | | |
63 | 0 | void JsonWriteBuffer::writeScalarArray(const SkScalar* value, uint32_t count) { |
64 | 0 | this->append("scalarArray"); |
65 | 0 | fWriter->beginArray(); |
66 | 0 | for (uint32_t i = 0; i < count; ++i) { |
67 | 0 | fWriter->appendFloat(value[i]); |
68 | 0 | } |
69 | 0 | fWriter->endArray(); |
70 | 0 | } |
71 | | |
72 | 0 | void JsonWriteBuffer::writeInt(int32_t value) { |
73 | 0 | this->append("int"); |
74 | 0 | fWriter->appendS32(value); |
75 | 0 | } |
76 | | |
77 | 0 | void JsonWriteBuffer::writeIntArray(const int32_t* value, uint32_t count) { |
78 | 0 | this->append("intArray"); |
79 | 0 | fWriter->beginArray(); |
80 | 0 | for (uint32_t i = 0; i < count; ++i) { |
81 | 0 | fWriter->appendS32(value[i]); |
82 | 0 | } |
83 | 0 | fWriter->endArray(); |
84 | 0 | } |
85 | | |
86 | 0 | void JsonWriteBuffer::writeUInt(uint32_t value) { |
87 | 0 | this->append("uint"); |
88 | 0 | fWriter->appendU32(value); |
89 | 0 | } |
90 | | |
91 | 0 | void JsonWriteBuffer::writeString(std::string_view value) { |
92 | 0 | this->append("string"); |
93 | 0 | fWriter->appendString(value.data(), value.size()); |
94 | 0 | } |
95 | | |
96 | 0 | void JsonWriteBuffer::writeFlattenable(const SkFlattenable* flattenable) { |
97 | 0 | if (flattenable) { |
98 | 0 | this->append(flattenable->getTypeName()); |
99 | 0 | fWriter->beginObject(); |
100 | 0 | JsonWriteBuffer flattenableBuffer(fWriter, fUrlDataManager); |
101 | 0 | flattenable->flatten(flattenableBuffer); |
102 | 0 | fWriter->endObject(); |
103 | 0 | } else { |
104 | 0 | this->append("flattenable"); |
105 | 0 | fWriter->appendPointer(nullptr); |
106 | 0 | } |
107 | 0 | } |
108 | | |
109 | 0 | void JsonWriteBuffer::writeColor(SkColor color) { |
110 | 0 | this->append("color"); |
111 | 0 | DrawCommand::MakeJsonColor(*fWriter, color); |
112 | 0 | } |
113 | | |
114 | 0 | void JsonWriteBuffer::writeColorArray(const SkColor* color, uint32_t count) { |
115 | 0 | this->append("colorArray"); |
116 | 0 | fWriter->beginArray(); |
117 | 0 | for (uint32_t i = 0; i < count; ++i) { |
118 | 0 | DrawCommand::MakeJsonColor(*fWriter, color[i]); |
119 | 0 | } |
120 | 0 | fWriter->endArray(); |
121 | 0 | } |
122 | | |
123 | 0 | void JsonWriteBuffer::writeColor4f(const SkColor4f& color) { |
124 | 0 | this->append("color"); |
125 | 0 | DrawCommand::MakeJsonColor4f(*fWriter, color); |
126 | 0 | } |
127 | | |
128 | 0 | void JsonWriteBuffer::writeColor4fArray(const SkColor4f* color, uint32_t count) { |
129 | 0 | this->append("colorArray"); |
130 | 0 | fWriter->beginArray(); |
131 | 0 | for (uint32_t i = 0; i < count; ++i) { |
132 | 0 | DrawCommand::MakeJsonColor4f(*fWriter, color[i]); |
133 | 0 | } |
134 | 0 | fWriter->endArray(); |
135 | 0 | } |
136 | | |
137 | 0 | void JsonWriteBuffer::writePoint(const SkPoint& point) { |
138 | 0 | this->append("point"); |
139 | 0 | DrawCommand::MakeJsonPoint(*fWriter, point); |
140 | 0 | } |
141 | | |
142 | 0 | void JsonWriteBuffer::writePoint3(const SkPoint3& point) { |
143 | 0 | this->append("point3"); |
144 | 0 | DrawCommand::MakeJsonPoint3(*fWriter, point); |
145 | 0 | } |
146 | | |
147 | 0 | void JsonWriteBuffer::writePointArray(const SkPoint* point, uint32_t count) { |
148 | 0 | this->append("pointArray"); |
149 | 0 | fWriter->beginArray(); |
150 | 0 | for (uint32_t i = 0; i < count; ++i) { |
151 | 0 | DrawCommand::MakeJsonPoint(*fWriter, point[i]); |
152 | 0 | } |
153 | 0 | fWriter->endArray(); |
154 | 0 | } |
155 | | |
156 | 0 | void JsonWriteBuffer::write(const SkM44& matrix) { |
157 | 0 | this->append("matrix"); |
158 | 0 | fWriter->beginArray(); |
159 | 0 | for (int r = 0; r < 4; ++r) { |
160 | 0 | fWriter->beginArray(nullptr, false); |
161 | 0 | SkV4 v = matrix.row(r); |
162 | 0 | for (int c = 0; c < 4; ++c) { |
163 | 0 | fWriter->appendFloat(v[c]); |
164 | 0 | } |
165 | 0 | fWriter->endArray(); |
166 | 0 | } |
167 | 0 | fWriter->endArray(); |
168 | 0 | } |
169 | | |
170 | 0 | void JsonWriteBuffer::writeMatrix(const SkMatrix& matrix) { |
171 | 0 | this->append("matrix"); |
172 | 0 | DrawCommand::MakeJsonMatrix(*fWriter, matrix); |
173 | 0 | } |
174 | | |
175 | 0 | void JsonWriteBuffer::writeIRect(const SkIRect& rect) { |
176 | 0 | this->append("irect"); |
177 | 0 | DrawCommand::MakeJsonIRect(*fWriter, rect); |
178 | 0 | } |
179 | | |
180 | 0 | void JsonWriteBuffer::writeRect(const SkRect& rect) { |
181 | 0 | this->append("rect"); |
182 | 0 | DrawCommand::MakeJsonRect(*fWriter, rect); |
183 | 0 | } |
184 | | |
185 | 0 | void JsonWriteBuffer::writeRegion(const SkRegion& region) { |
186 | 0 | this->append("region"); |
187 | 0 | DrawCommand::MakeJsonRegion(*fWriter, region); |
188 | 0 | } |
189 | | |
190 | 0 | void JsonWriteBuffer::writePath(const SkPath& path) { |
191 | 0 | this->append("path"); |
192 | 0 | DrawCommand::MakeJsonPath(*fWriter, path); |
193 | 0 | } |
194 | | |
195 | 0 | void JsonWriteBuffer::writeSampling(const SkSamplingOptions& sampling) { |
196 | 0 | this->append("sampling"); |
197 | 0 | DrawCommand::MakeJsonSampling(*fWriter, sampling); |
198 | 0 | } |
199 | | |
200 | 0 | size_t JsonWriteBuffer::writeStream(SkStream* stream, size_t length) { |
201 | | // Contents not supported |
202 | 0 | this->append("stream"); |
203 | 0 | fWriter->appendU64(static_cast<uint64_t>(length)); |
204 | 0 | return 0; |
205 | 0 | } |
206 | | |
207 | 0 | void JsonWriteBuffer::writeImage(const SkImage* image) { |
208 | 0 | this->append("image"); |
209 | 0 | fWriter->beginObject(); |
210 | 0 | DrawCommand::flatten(*image, *fWriter, *fUrlDataManager); |
211 | 0 | fWriter->endObject(); |
212 | 0 | } |
213 | | |
214 | 0 | void JsonWriteBuffer::writeTypeface(SkTypeface* typeface) { |
215 | | // Unsupported |
216 | 0 | this->append("typeface"); |
217 | 0 | fWriter->appendPointer(typeface); |
218 | 0 | } |
219 | | |
220 | 0 | void JsonWriteBuffer::writePaint(const SkPaint& paint) { |
221 | 0 | this->append("paint"); |
222 | 0 | DrawCommand::MakeJsonPaint(*fWriter, paint, *fUrlDataManager); |
223 | 0 | } |