Index: tools/debugger/SkJsonWriteBuffer.cpp |
diff --git a/tools/debugger/SkJsonWriteBuffer.cpp b/tools/debugger/SkJsonWriteBuffer.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..24a107a27302f44fbe762fc4bd715cf0051e3148 |
--- /dev/null |
+++ b/tools/debugger/SkJsonWriteBuffer.cpp |
@@ -0,0 +1,204 @@ |
+/* |
+ * Copyright 2012 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "SkJsonWriteBuffer.h" |
+ |
+#include "SkObjectParser.h" |
+ |
+void SkJsonWriteBuffer::append(const char* type, const Json::Value& value) { |
+ SkString fullName = SkStringPrintf("%02d_%s", fFieldCount++, type); |
+ fJson[fullName.c_str()] = value; |
+} |
+ |
+void SkJsonWriteBuffer::writeByteArray(const void* data, size_t size) { |
+ Json::Value jsonArray; |
+ const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data); |
+ for (size_t i = 0; i < size; ++i) { |
+ SkString hexByte = SkStringPrintf("%02x", bytes[i]); |
+ jsonArray.append(hexByte.c_str()); |
+ } |
+ this->append("byteArray", jsonArray); |
+} |
+ |
+void SkJsonWriteBuffer::writeDataAsByteArray(SkData* data) { |
+ Json::Value jsonArray; |
+ const uint8_t* bytes = data->bytes(); |
+ for (size_t i = 0; i < data->size(); ++i) { |
+ SkString hexByte = SkStringPrintf("%02x", bytes[i]); |
+ jsonArray.append(hexByte.c_str()); |
+ } |
+ this->append("data", jsonArray); |
+} |
+ |
+void SkJsonWriteBuffer::writeBool(bool value) { |
+ this->append("bool", value); |
+} |
+ |
+void SkJsonWriteBuffer::writeScalar(SkScalar value) { |
+ this->append("scalar", value); |
+} |
+ |
+void SkJsonWriteBuffer::writeScalarArray(const SkScalar* value, uint32_t count) { |
+ Json::Value jsonArray; |
+ for (uint32_t i = 0; i < count; ++i) { |
+ jsonArray.append(value[i]); |
+ } |
+ this->append("scalarArray", jsonArray); |
+} |
+ |
+void SkJsonWriteBuffer::writeInt(int32_t value) { |
+ this->append("int", value); |
+} |
+ |
+void SkJsonWriteBuffer::writeIntArray(const int32_t* value, uint32_t count) { |
+ Json::Value jsonArray; |
+ for (uint32_t i = 0; i < count; ++i) { |
+ jsonArray.append(value[i]); |
+ } |
+ this->append("intArray", jsonArray); |
+} |
+ |
+void SkJsonWriteBuffer::writeUInt(uint32_t value) { |
+ this->append("uint", value); |
+} |
+ |
+void SkJsonWriteBuffer::write32(int32_t value) { |
+ this->append("int32", value); |
+} |
+ |
+void SkJsonWriteBuffer::writeString(const char* value) { |
+ this->append("string", value); |
+} |
+ |
+void SkJsonWriteBuffer::writeEncodedString(const void* value, size_t byteLength, |
+ SkPaint::TextEncoding encoding) { |
+ SkAutoTDelete<SkString> string = SkObjectParser::TextToString(value, byteLength, encoding); |
+ this->append("encodedString", string->c_str()); |
+} |
+ |
+void SkJsonWriteBuffer::writeFunctionPtr(void* ptr) { |
+ SkString ptrString = SkStringPrintf("%p", ptr); |
+ this->append("functionPtr", ptrString.c_str()); |
+} |
+ |
+void SkJsonWriteBuffer::writeFlattenable(const SkFlattenable* flattenable) { |
+ if (flattenable) { |
+ SkJsonWriteBuffer flattenableBuffer(fUrlDataManager); |
+ flattenable->flatten(flattenableBuffer); |
+ this->append(flattenable->getTypeName(), flattenableBuffer.getValue()); |
+ } else { |
+ this->append("flattenable", Json::Value()); |
+ } |
+} |
+ |
+void SkJsonWriteBuffer::writeColor(const SkColor& color) { |
+ SkString colorString = SkStringPrintf("rgba(%d, %d, %d, %f)", |
+ SkColorGetR(color), |
+ SkColorGetG(color), |
+ SkColorGetB(color), |
+ SkColorGetA(color) / 255.0f); |
+ this->append("color", colorString.c_str()); |
+} |
+ |
+void SkJsonWriteBuffer::writeColorArray(const SkColor* color, uint32_t count) { |
+ Json::Value jsonArray; |
+ for (uint32_t i = 0; i < count; ++i) { |
+ SkString colorString = SkStringPrintf("rgba(%d, %d, %d, %f)", |
+ SkColorGetR(color[i]), |
+ SkColorGetG(color[i]), |
+ SkColorGetB(color[i]), |
+ SkColorGetA(color[i]) / 255.0f); |
+ jsonArray.append(colorString.c_str()); |
+ } |
+ this->append("colorArray", jsonArray); |
+} |
+ |
+void SkJsonWriteBuffer::writePoint(const SkPoint& point) { |
+ Json::Value jsonPoint; |
+ jsonPoint.append(point.fX); |
+ jsonPoint.append(point.fY); |
+ this->append("point", jsonPoint); |
+} |
+ |
+void SkJsonWriteBuffer::writePointArray(const SkPoint* point, uint32_t count) { |
+ Json::Value jsonArray; |
+ for (uint32_t i = 0; i < count; ++i) { |
+ Json::Value jsonPoint; |
+ jsonPoint.append(point[i].fX); |
+ jsonPoint.append(point[i].fY); |
+ jsonArray.append(jsonPoint); |
+ } |
+ this->append("pointArray", jsonArray); |
+} |
+ |
+void SkJsonWriteBuffer::writeMatrix(const SkMatrix& matrix) { |
+ Json::Value jsonMatrix; |
+ for (int i = 0; i < 9; ++i) { |
+ jsonMatrix.append(matrix[i]); |
+ } |
+ this->append("matrix", jsonMatrix); |
+} |
+ |
+void SkJsonWriteBuffer::writeIRect(const SkIRect& rect) { |
+ Json::Value jsonRect; |
+ jsonRect.append(rect.fLeft); |
+ jsonRect.append(rect.fTop); |
+ jsonRect.append(rect.fRight); |
+ jsonRect.append(rect.fBottom); |
+ this->append("irect", jsonRect); |
+} |
+ |
+void SkJsonWriteBuffer::writeRect(const SkRect& rect) { |
+ Json::Value jsonRect; |
+ jsonRect.append(rect.fLeft); |
+ jsonRect.append(rect.fTop); |
+ jsonRect.append(rect.fRight); |
+ jsonRect.append(rect.fBottom); |
+ this->append("rect", jsonRect); |
+} |
+ |
+void SkJsonWriteBuffer::writeRegion(const SkRegion& region) { |
+ // Unsupported |
+ this->append("region", Json::Value()); |
+} |
+ |
+void SkJsonWriteBuffer::writePath(const SkPath& path) { |
+ SkAutoTDelete<SkString> pathString = SkObjectParser::PathToString(path); |
+ this->append("path", pathString->c_str()); |
+} |
+ |
+size_t SkJsonWriteBuffer::writeStream(SkStream* stream, size_t length) { |
+ // Contents not supported |
+ SkASSERT(length < Json::Value::maxUInt); |
+ this->append("stream", static_cast<Json::UInt>(length)); |
+ return 0; |
+} |
+ |
+void SkJsonWriteBuffer::writeBitmap(const SkBitmap& bitmap) { |
+ extern bool flatten(const SkBitmap& bitmap, Json::Value* target, |
+ UrlDataManager& urlDataManager); |
+ Json::Value jsonBitmap; |
+ flatten(bitmap, &jsonBitmap, *fUrlDataManager); |
+ this->append("bitmap", jsonBitmap); |
+} |
+ |
+void SkJsonWriteBuffer::writeImage(const SkImage* image) { |
+ extern bool flatten(const SkImage& image, Json::Value* target, UrlDataManager& urlDataManager); |
mtklein
2016/04/29 20:05:13
Let's put these declarations in SkDrawCommand.h?
|
+ Json::Value jsonImage; |
+ flatten(*image, &jsonImage, *fUrlDataManager); |
+ this->append("image", jsonImage); |
+} |
+ |
+void SkJsonWriteBuffer::writeTypeface(SkTypeface* typeface) { |
+ // Unsupported |
+ this->append("typeface", Json::Value()); |
+} |
+ |
+void SkJsonWriteBuffer::writePaint(const SkPaint& paint) { |
+ extern Json::Value make_json_paint(const SkPaint& paint, UrlDataManager& urlDataManager); |
+ this->append("paint", make_json_paint(paint, *fUrlDataManager)); |
+} |