Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: tools/debugger/SkJsonWriteBuffer.cpp

Issue 1920423002: Prototype code that turns any/every flattenable into JSON (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Share lots more code with SkDrawCommand Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "SkDrawCommand.h"
11 #include "SkObjectParser.h"
12
13 void SkJsonWriteBuffer::append(const char* type, const Json::Value& value) {
14 SkString fullName = SkStringPrintf("%02d_%s", fFieldCount++, type);
15 fJson[fullName.c_str()] = value;
16 }
17
18 void SkJsonWriteBuffer::writeByteArray(const void* data, size_t size) {
19 Json::Value jsonArray(Json::arrayValue);
20 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data);
21 for (size_t i = 0; i < size; ++i) {
22 SkString hexByte = SkStringPrintf("%02x", bytes[i]);
23 jsonArray.append(hexByte.c_str());
24 }
25 this->append("byteArray", jsonArray);
26 }
27
28 void SkJsonWriteBuffer::writeDataAsByteArray(SkData* data) {
29 Json::Value jsonArray(Json::arrayValue);
30 const uint8_t* bytes = data->bytes();
31 for (size_t i = 0; i < data->size(); ++i) {
32 SkString hexByte = SkStringPrintf("%02x", bytes[i]);
33 jsonArray.append(hexByte.c_str());
34 }
35 this->append("data", jsonArray);
36 }
37
38 void SkJsonWriteBuffer::writeBool(bool value) {
39 this->append("bool", value);
40 }
41
42 void SkJsonWriteBuffer::writeScalar(SkScalar value) {
43 this->append("scalar", value);
44 }
45
46 void SkJsonWriteBuffer::writeScalarArray(const SkScalar* value, uint32_t count) {
47 Json::Value jsonArray(Json::arrayValue);
48 for (uint32_t i = 0; i < count; ++i) {
49 jsonArray.append(value[i]);
50 }
51 this->append("scalarArray", jsonArray);
52 }
53
54 void SkJsonWriteBuffer::writeInt(int32_t value) {
55 this->append("int", value);
56 }
57
58 void SkJsonWriteBuffer::writeIntArray(const int32_t* value, uint32_t count) {
59 Json::Value jsonArray(Json::arrayValue);
60 for (uint32_t i = 0; i < count; ++i) {
61 jsonArray.append(value[i]);
62 }
63 this->append("intArray", jsonArray);
64 }
65
66 void SkJsonWriteBuffer::writeUInt(uint32_t value) {
67 this->append("uint", value);
68 }
69
70 void SkJsonWriteBuffer::write32(int32_t value) {
71 this->append("int32", value);
72 }
73
74 void SkJsonWriteBuffer::writeString(const char* value) {
75 this->append("string", value);
76 }
77
78 void SkJsonWriteBuffer::writeEncodedString(const void* value, size_t byteLength,
79 SkPaint::TextEncoding encoding) {
80 SkAutoTDelete<SkString> string = SkObjectParser::TextToString(value, byteLen gth, encoding);
81 this->append("encodedString", string->c_str());
82 }
83
84 void SkJsonWriteBuffer::writeFunctionPtr(void* ptr) {
85 SkString ptrString = SkStringPrintf("%p", ptr);
86 this->append("functionPtr", ptrString.c_str());
87 }
88
89 void SkJsonWriteBuffer::writeFlattenable(const SkFlattenable* flattenable) {
90 if (flattenable) {
91 SkJsonWriteBuffer flattenableBuffer(fUrlDataManager);
92 flattenable->flatten(flattenableBuffer);
93 this->append(flattenable->getTypeName(), flattenableBuffer.getValue());
94 } else {
95 this->append("flattenable", Json::Value());
96 }
97 }
98
99 void SkJsonWriteBuffer::writeColor(const SkColor& color) {
100 this->append("color", SkDrawCommand::MakeJsonColor(color));
101 }
102
103 void SkJsonWriteBuffer::writeColorArray(const SkColor* color, uint32_t count) {
104 Json::Value jsonArray(Json::arrayValue);
105 for (uint32_t i = 0; i < count; ++i) {
106 jsonArray.append(SkDrawCommand::MakeJsonColor(color[i]));
107 }
108 this->append("colorArray", jsonArray);
109 }
110
111 void SkJsonWriteBuffer::writePoint(const SkPoint& point) {
112 this->append("point", SkDrawCommand::MakeJsonPoint(point));
113 }
114
115 void SkJsonWriteBuffer::writePointArray(const SkPoint* point, uint32_t count) {
116 Json::Value jsonArray(Json::arrayValue);
117 for (uint32_t i = 0; i < count; ++i) {
118 jsonArray.append(SkDrawCommand::MakeJsonPoint(point[i]));
119 }
120 this->append("pointArray", jsonArray);
121 }
122
123 void SkJsonWriteBuffer::writeMatrix(const SkMatrix& matrix) {
124 this->append("matrix", SkDrawCommand::MakeJsonMatrix(matrix));
125 }
126
127 void SkJsonWriteBuffer::writeIRect(const SkIRect& rect) {
128 this->append("irect", SkDrawCommand::MakeJsonIRect(rect));
129 }
130
131 void SkJsonWriteBuffer::writeRect(const SkRect& rect) {
132 this->append("rect", SkDrawCommand::MakeJsonRect(rect));
133 }
134
135 void SkJsonWriteBuffer::writeRegion(const SkRegion& region) {
136 this->append("region", SkDrawCommand::MakeJsonRegion(region));
137 }
138
139 void SkJsonWriteBuffer::writePath(const SkPath& path) {
140 this->append("path", SkDrawCommand::MakeJsonPath(path));
141 }
142
143 size_t SkJsonWriteBuffer::writeStream(SkStream* stream, size_t length) {
144 // Contents not supported
145 SkASSERT(length < Json::Value::maxUInt);
146 this->append("stream", static_cast<Json::UInt>(length));
147 return 0;
148 }
149
150 void SkJsonWriteBuffer::writeBitmap(const SkBitmap& bitmap) {
151 Json::Value jsonBitmap;
152 SkDrawCommand::flatten(bitmap, &jsonBitmap, *fUrlDataManager);
153 this->append("bitmap", jsonBitmap);
154 }
155
156 void SkJsonWriteBuffer::writeImage(const SkImage* image) {
157 Json::Value jsonImage;
158 SkDrawCommand::flatten(*image, &jsonImage, *fUrlDataManager);
159 this->append("image", jsonImage);
160 }
161
162 void SkJsonWriteBuffer::writeTypeface(SkTypeface* typeface) {
163 // Unsupported
164 this->append("typeface", Json::Value());
165 }
166
167 void SkJsonWriteBuffer::writePaint(const SkPaint& paint) {
168 this->append("paint", SkDrawCommand::MakeJsonPaint(paint, *fUrlDataManager)) ;
169 }
OLDNEW
« include/core/SkWriteBuffer.h ('K') | « tools/debugger/SkJsonWriteBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698