OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2012 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 "SkJsonWriteBuffer.h" | |
9 | |
10 #include "SkObjectParser.h" | |
11 | |
12 void SkJsonWriteBuffer::append(const char* type, const Json::Value& value) { | |
13 SkString fullName = SkStringPrintf("%02d_%s", fFieldCount++, type); | |
14 fJson[fullName.c_str()] = value; | |
15 } | |
16 | |
17 void SkJsonWriteBuffer::writeByteArray(const void* data, size_t size) { | |
18 Json::Value jsonArray; | |
19 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data); | |
20 for (size_t i = 0; i < size; ++i) { | |
21 SkString hexByte = SkStringPrintf("%02x", bytes[i]); | |
22 jsonArray.append(hexByte.c_str()); | |
23 } | |
24 this->append("byteArray", jsonArray); | |
25 } | |
26 | |
27 void SkJsonWriteBuffer::writeDataAsByteArray(SkData* data) { | |
28 Json::Value jsonArray; | |
29 const uint8_t* bytes = data->bytes(); | |
30 for (size_t i = 0; i < data->size(); ++i) { | |
31 SkString hexByte = SkStringPrintf("%02x", bytes[i]); | |
32 jsonArray.append(hexByte.c_str()); | |
33 } | |
34 this->append("data", jsonArray); | |
35 } | |
36 | |
37 void SkJsonWriteBuffer::writeBool(bool value) { | |
38 this->append("bool", value); | |
39 } | |
40 | |
41 void SkJsonWriteBuffer::writeScalar(SkScalar value) { | |
42 this->append("scalar", value); | |
43 } | |
44 | |
45 void SkJsonWriteBuffer::writeScalarArray(const SkScalar* value, uint32_t count) { | |
46 Json::Value jsonArray; | |
47 for (uint32_t i = 0; i < count; ++i) { | |
48 jsonArray.append(value[i]); | |
49 } | |
50 this->append("scalarArray", jsonArray); | |
51 } | |
52 | |
53 void SkJsonWriteBuffer::writeInt(int32_t value) { | |
54 this->append("int", value); | |
55 } | |
56 | |
57 void SkJsonWriteBuffer::writeIntArray(const int32_t* value, uint32_t count) { | |
58 Json::Value jsonArray; | |
59 for (uint32_t i = 0; i < count; ++i) { | |
60 jsonArray.append(value[i]); | |
61 } | |
62 this->append("intArray", jsonArray); | |
63 } | |
64 | |
65 void SkJsonWriteBuffer::writeUInt(uint32_t value) { | |
66 this->append("uint", value); | |
67 } | |
68 | |
69 void SkJsonWriteBuffer::write32(int32_t value) { | |
70 this->append("int32", value); | |
71 } | |
72 | |
73 void SkJsonWriteBuffer::writeString(const char* value) { | |
74 this->append("string", value); | |
75 } | |
76 | |
77 void SkJsonWriteBuffer::writeEncodedString(const void* value, size_t byteLength, | |
78 SkPaint::TextEncoding encoding) { | |
79 SkAutoTDelete<SkString> string = SkObjectParser::TextToString(value, byteLen gth, encoding); | |
80 this->append("encodedString", string->c_str()); | |
81 } | |
82 | |
83 void SkJsonWriteBuffer::writeFunctionPtr(void* ptr) { | |
84 SkString ptrString = SkStringPrintf("%p", ptr); | |
85 this->append("functionPtr", ptrString.c_str()); | |
86 } | |
87 | |
88 void SkJsonWriteBuffer::writeFlattenable(const SkFlattenable* flattenable) { | |
89 if (flattenable) { | |
90 SkJsonWriteBuffer flattenableBuffer(fUrlDataManager); | |
91 flattenable->flatten(flattenableBuffer); | |
92 this->append(flattenable->getTypeName(), flattenableBuffer.getValue()); | |
93 } else { | |
94 this->append("flattenable", Json::Value()); | |
95 } | |
96 } | |
97 | |
98 void SkJsonWriteBuffer::writeColor(const SkColor& color) { | |
99 SkString colorString = SkStringPrintf("rgba(%d, %d, %d, %f)", | |
100 SkColorGetR(color), | |
101 SkColorGetG(color), | |
102 SkColorGetB(color), | |
103 SkColorGetA(color) / 255.0f); | |
104 this->append("color", colorString.c_str()); | |
105 } | |
106 | |
107 void SkJsonWriteBuffer::writeColorArray(const SkColor* color, uint32_t count) { | |
108 Json::Value jsonArray; | |
109 for (uint32_t i = 0; i < count; ++i) { | |
110 SkString colorString = SkStringPrintf("rgba(%d, %d, %d, %f)", | |
111 SkColorGetR(color[i]), | |
112 SkColorGetG(color[i]), | |
113 SkColorGetB(color[i]), | |
114 SkColorGetA(color[i]) / 255.0f); | |
115 jsonArray.append(colorString.c_str()); | |
116 } | |
117 this->append("colorArray", jsonArray); | |
118 } | |
119 | |
120 void SkJsonWriteBuffer::writePoint(const SkPoint& point) { | |
121 Json::Value jsonPoint; | |
122 jsonPoint.append(point.fX); | |
123 jsonPoint.append(point.fY); | |
124 this->append("point", jsonPoint); | |
125 } | |
126 | |
127 void SkJsonWriteBuffer::writePointArray(const SkPoint* point, uint32_t count) { | |
128 Json::Value jsonArray; | |
129 for (uint32_t i = 0; i < count; ++i) { | |
130 Json::Value jsonPoint; | |
131 jsonPoint.append(point[i].fX); | |
132 jsonPoint.append(point[i].fY); | |
133 jsonArray.append(jsonPoint); | |
134 } | |
135 this->append("pointArray", jsonArray); | |
136 } | |
137 | |
138 void SkJsonWriteBuffer::writeMatrix(const SkMatrix& matrix) { | |
139 Json::Value jsonMatrix; | |
140 for (int i = 0; i < 9; ++i) { | |
141 jsonMatrix.append(matrix[i]); | |
142 } | |
143 this->append("matrix", jsonMatrix); | |
144 } | |
145 | |
146 void SkJsonWriteBuffer::writeIRect(const SkIRect& rect) { | |
147 Json::Value jsonRect; | |
148 jsonRect.append(rect.fLeft); | |
149 jsonRect.append(rect.fTop); | |
150 jsonRect.append(rect.fRight); | |
151 jsonRect.append(rect.fBottom); | |
152 this->append("irect", jsonRect); | |
153 } | |
154 | |
155 void SkJsonWriteBuffer::writeRect(const SkRect& rect) { | |
156 Json::Value jsonRect; | |
157 jsonRect.append(rect.fLeft); | |
158 jsonRect.append(rect.fTop); | |
159 jsonRect.append(rect.fRight); | |
160 jsonRect.append(rect.fBottom); | |
161 this->append("rect", jsonRect); | |
162 } | |
163 | |
164 void SkJsonWriteBuffer::writeRegion(const SkRegion& region) { | |
165 // Unsupported | |
166 this->append("region", Json::Value()); | |
167 } | |
168 | |
169 void SkJsonWriteBuffer::writePath(const SkPath& path) { | |
170 SkAutoTDelete<SkString> pathString = SkObjectParser::PathToString(path); | |
171 this->append("path", pathString->c_str()); | |
172 } | |
173 | |
174 size_t SkJsonWriteBuffer::writeStream(SkStream* stream, size_t length) { | |
175 // Contents not supported | |
176 SkASSERT(length < Json::Value::maxUInt); | |
177 this->append("stream", static_cast<Json::UInt>(length)); | |
178 return 0; | |
179 } | |
180 | |
181 void SkJsonWriteBuffer::writeBitmap(const SkBitmap& bitmap) { | |
182 extern bool flatten(const SkBitmap& bitmap, Json::Value* target, | |
183 UrlDataManager& urlDataManager); | |
184 Json::Value jsonBitmap; | |
185 flatten(bitmap, &jsonBitmap, *fUrlDataManager); | |
186 this->append("bitmap", jsonBitmap); | |
187 } | |
188 | |
189 void SkJsonWriteBuffer::writeImage(const SkImage* image) { | |
190 extern bool flatten(const SkImage& image, Json::Value* target, UrlDataManage r& urlDataManager); | |
mtklein
2016/04/29 20:05:13
Let's put these declarations in SkDrawCommand.h?
| |
191 Json::Value jsonImage; | |
192 flatten(*image, &jsonImage, *fUrlDataManager); | |
193 this->append("image", jsonImage); | |
194 } | |
195 | |
196 void SkJsonWriteBuffer::writeTypeface(SkTypeface* typeface) { | |
197 // Unsupported | |
198 this->append("typeface", Json::Value()); | |
199 } | |
200 | |
201 void SkJsonWriteBuffer::writePaint(const SkPaint& paint) { | |
202 extern Json::Value make_json_paint(const SkPaint& paint, UrlDataManager& url DataManager); | |
203 this->append("paint", make_json_paint(paint, *fUrlDataManager)); | |
204 } | |
OLD | NEW |