| Index: tools/debugger/SkJsonWriteBuffer.cpp
|
| diff --git a/tools/debugger/SkJsonWriteBuffer.cpp b/tools/debugger/SkJsonWriteBuffer.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..02056316e758521cbde4371c1d4e94e59edf722a
|
| --- /dev/null
|
| +++ b/tools/debugger/SkJsonWriteBuffer.cpp
|
| @@ -0,0 +1,185 @@
|
| +/*
|
| + * 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* name, const Json::Value& value) {
|
| + SkString arrayName = SkStringPrintf("%s_array", name);
|
| + bool rawNamePresent = fJson.isMember(name);
|
| + bool arrayPresent = fJson.isMember(arrayName.c_str());
|
| +
|
| + if (arrayPresent) {
|
| + SkASSERT(!rawNamePresent);
|
| + // We've already seen this name more than once, append to the array
|
| + fJson[arrayName.c_str()].append(value);
|
| + } else if (rawNamePresent) {
|
| + SkASSERT(!arrayPresent);
|
| + // We've seen this name once. Convert to an array and see with the old and new values
|
| + Json::Value jsonArray;
|
| + jsonArray.append(fJson[name]);
|
| + jsonArray.append(value);
|
| + fJson[arrayName.c_str()] = jsonArray;
|
| + fJson.removeMember(name);
|
| + } else {
|
| + // First (and likely only) time to see this name. Just insert it
|
| + fJson[name] = value;
|
| + }
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeByteArray(const char* name, 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(name, jsonArray);
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeBool(const char* name, bool value) {
|
| + this->append(name, value);
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeScalar(const char* name, SkScalar value) {
|
| + this->append(name, value);
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeScalarArray(const char* name, const SkScalar* value, uint32_t count) {
|
| + Json::Value jsonArray;
|
| + for (uint32_t i = 0; i < count; ++i) {
|
| + jsonArray.append(value[i]);
|
| + }
|
| + this->append(name, jsonArray);
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeInt(const char* name, int32_t value) {
|
| + this->append(name, value);
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeIntArray(const char* name, const int32_t* value, uint32_t count) {
|
| + Json::Value jsonArray;
|
| + for (uint32_t i = 0; i < count; ++i) {
|
| + jsonArray.append(value[i]);
|
| + }
|
| + this->append(name, jsonArray);
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeUInt(const char* name, uint32_t value) {
|
| + this->append(name, value);
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::write32(const char* name, int32_t value) {
|
| + this->append(name, value);
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeString(const char* name, const char* value) {
|
| + this->append(name, value);
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeEncodedString(const char* name, const void* value, size_t byteLength,
|
| + SkPaint::TextEncoding encoding) {
|
| + SkAutoTDelete<SkString> string = SkObjectParser::TextToString(value, byteLength, encoding);
|
| + this->append(name, string->c_str());
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeFunctionPtr(const char* name, void* ptr) {
|
| + this->append(name, reinterpret_cast<uintptr_t>(ptr));
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeFlattenable(const char* name, const SkFlattenable* flattenable) {
|
| + SkJsonWriteBuffer flattenableBuffer;
|
| + flattenable->flatten(flattenableBuffer);
|
| + this->append(name, flattenableBuffer.getValue());
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeColor(const char* name, const SkColor& color) {
|
| + SkString hexColor = SkStringPrintf("#%08x", color);
|
| + this->append(name, hexColor.c_str());
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeColorArray(const char* name, const SkColor* color, uint32_t count) {
|
| + Json::Value jsonArray;
|
| + for (uint32_t i = 0; i < count; ++i) {
|
| + SkString hexColor = SkStringPrintf("#%08x", color[i]);
|
| + jsonArray.append(hexColor.c_str());
|
| + }
|
| + this->append(name, jsonArray);
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writePoint(const char* name, const SkPoint& point) {
|
| + Json::Value jsonPoint;
|
| + jsonPoint["x"] = point.fX;
|
| + jsonPoint["y"] = point.fY;
|
| + this->append(name, jsonPoint);
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writePointArray(const char* name, const SkPoint* point, uint32_t count) {
|
| + Json::Value jsonArray;
|
| + for (uint32_t i = 0; i < count; ++i) {
|
| + Json::Value jsonPoint;
|
| + jsonPoint["x"] = point[i].fX;
|
| + jsonPoint["y"] = point[i].fY;
|
| + jsonArray.append(jsonPoint);
|
| + }
|
| + this->append(name, jsonArray);
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeMatrix(const char* name, const SkMatrix& matrix) {
|
| + SkString matrixString;
|
| +#ifndef SK_IGNORE_TO_STRING
|
| + matrix.toString(&matrixString);
|
| +#endif
|
| + this->append(name, matrixString.c_str());
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeIRect(const char* name, const SkIRect& rect) {
|
| + SkAutoTDelete<SkString> rectString = SkObjectParser::IRectToString(rect);
|
| + this->append(name, rectString->c_str());
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeRect(const char* name, const SkRect& rect) {
|
| + SkAutoTDelete<SkString> rectString = SkObjectParser::RectToString(rect);
|
| + this->append(name, rectString->c_str());
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeRegion(const char* name, const SkRegion& region) {
|
| + // Unsupported
|
| + this->append(name, Json::Value());
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writePath(const char* name, const SkPath& path) {
|
| + SkAutoTDelete<SkString> pathString = SkObjectParser::PathToString(path);
|
| + this->append(name, pathString->c_str());
|
| +}
|
| +
|
| +size_t SkJsonWriteBuffer::writeStream(const char* name, SkStream* stream, size_t length) {
|
| + // Contents not supported
|
| + this->append(name, Json::Value(length));
|
| + return 0;
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeBitmap(const char* name, const SkBitmap& bitmap) {
|
| + SkAutoTDelete<SkString> bitmapString = SkObjectParser::BitmapToString(bitmap);
|
| + this->append(name, bitmapString->c_str());
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeImage(const char* name, const SkImage* image) {
|
| + SkAutoTDelete<SkString> imageString = SkObjectParser::ImageToString(image);
|
| + this->append(name, imageString->c_str());
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writeTypeface(const char* name, SkTypeface* typeface) {
|
| + // Unsupported
|
| + this->append(name, Json::Value());
|
| +}
|
| +
|
| +void SkJsonWriteBuffer::writePaint(const char* name, const SkPaint& paint) {
|
| + SkAutoTDelete<SkString> paintString = SkObjectParser::PaintToString(paint);
|
| + this->append(name, paintString->c_str());
|
| +}
|
|
|