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

Unified Diff: src/core/SkWriteBuffer.cpp

Issue 1911963008: DNC - JSON of flattenables, with field names. Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add names to call sites Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: src/core/SkWriteBuffer.cpp
diff --git a/src/core/SkWriteBuffer.cpp b/src/core/SkWriteBuffer.cpp
index b90a81e631593aab3cc53ddbc71e29a882a567f3..de7867265b70d742b487c34f69d5939543078d8b 100644
--- a/src/core/SkWriteBuffer.cpp
+++ b/src/core/SkWriteBuffer.cpp
@@ -35,93 +35,93 @@ SkWriteBuffer::~SkWriteBuffer() {
SkSafeUnref(fTFSet);
}
-void SkWriteBuffer::writeByteArray(const void* data, size_t size) {
+void SkWriteBuffer::writeByteArray(const char* name, const void* data, size_t size) {
fWriter.write32(SkToU32(size));
fWriter.writePad(data, size);
}
-void SkWriteBuffer::writeBool(bool value) {
+void SkWriteBuffer::writeBool(const char* name, bool value) {
fWriter.writeBool(value);
}
-void SkWriteBuffer::writeScalar(SkScalar value) {
+void SkWriteBuffer::writeScalar(const char* name, SkScalar value) {
fWriter.writeScalar(value);
}
-void SkWriteBuffer::writeScalarArray(const SkScalar* value, uint32_t count) {
+void SkWriteBuffer::writeScalarArray(const char* name, const SkScalar* value, uint32_t count) {
fWriter.write32(count);
fWriter.write(value, count * sizeof(SkScalar));
}
-void SkWriteBuffer::writeInt(int32_t value) {
+void SkWriteBuffer::writeInt(const char* name, int32_t value) {
fWriter.write32(value);
}
-void SkWriteBuffer::writeIntArray(const int32_t* value, uint32_t count) {
+void SkWriteBuffer::writeIntArray(const char* name, const int32_t* value, uint32_t count) {
fWriter.write32(count);
fWriter.write(value, count * sizeof(int32_t));
}
-void SkWriteBuffer::writeUInt(uint32_t value) {
+void SkWriteBuffer::writeUInt(const char* name, uint32_t value) {
fWriter.write32(value);
}
-void SkWriteBuffer::write32(int32_t value) {
+void SkWriteBuffer::write32(const char* name, int32_t value) {
fWriter.write32(value);
}
-void SkWriteBuffer::writeString(const char* value) {
+void SkWriteBuffer::writeString(const char* name, const char* value) {
fWriter.writeString(value);
}
-void SkWriteBuffer::writeEncodedString(const void* value, size_t byteLength,
- SkPaint::TextEncoding encoding) {
+void SkWriteBuffer::writeEncodedString(const char* name, const void* value, size_t byteLength,
+ SkPaint::TextEncoding encoding) {
fWriter.writeInt(encoding);
fWriter.writeInt(SkToU32(byteLength));
fWriter.write(value, byteLength);
}
-void SkWriteBuffer::writeColor(const SkColor& color) {
+void SkWriteBuffer::writeColor(const char* name, const SkColor& color) {
fWriter.write32(color);
}
-void SkWriteBuffer::writeColorArray(const SkColor* color, uint32_t count) {
+void SkWriteBuffer::writeColorArray(const char* name, const SkColor* color, uint32_t count) {
fWriter.write32(count);
fWriter.write(color, count * sizeof(SkColor));
}
-void SkWriteBuffer::writePoint(const SkPoint& point) {
+void SkWriteBuffer::writePoint(const char* name, const SkPoint& point) {
fWriter.writeScalar(point.fX);
fWriter.writeScalar(point.fY);
}
-void SkWriteBuffer::writePointArray(const SkPoint* point, uint32_t count) {
+void SkWriteBuffer::writePointArray(const char* name, const SkPoint* point, uint32_t count) {
fWriter.write32(count);
fWriter.write(point, count * sizeof(SkPoint));
}
-void SkWriteBuffer::writeMatrix(const SkMatrix& matrix) {
+void SkWriteBuffer::writeMatrix(const char* name, const SkMatrix& matrix) {
fWriter.writeMatrix(matrix);
}
-void SkWriteBuffer::writeIRect(const SkIRect& rect) {
+void SkWriteBuffer::writeIRect(const char* name, const SkIRect& rect) {
fWriter.write(&rect, sizeof(SkIRect));
}
-void SkWriteBuffer::writeRect(const SkRect& rect) {
+void SkWriteBuffer::writeRect(const char* name, const SkRect& rect) {
fWriter.writeRect(rect);
}
-void SkWriteBuffer::writeRegion(const SkRegion& region) {
+void SkWriteBuffer::writeRegion(const char* name, const SkRegion& region) {
fWriter.writeRegion(region);
}
-void SkWriteBuffer::writePath(const SkPath& path) {
+void SkWriteBuffer::writePath(const char* name, const SkPath& path) {
fWriter.writePath(path);
}
-size_t SkWriteBuffer::writeStream(SkStream* stream, size_t length) {
+size_t SkWriteBuffer::writeStream(const char* name, SkStream* stream, size_t length) {
fWriter.write32(SkToU32(length));
size_t bytesWritten = fWriter.readFromStream(stream, length);
if (bytesWritten < length) {
@@ -136,17 +136,17 @@ bool SkWriteBuffer::writeToStream(SkWStream* stream) {
static void write_encoded_bitmap(SkWriteBuffer* buffer, SkData* data,
const SkIPoint& origin) {
- buffer->writeUInt(SkToU32(data->size()));
+ buffer->writeUInt("size", SkToU32(data->size()));
buffer->getWriter32()->writePad(data->data(), data->size());
- buffer->write32(origin.fX);
- buffer->write32(origin.fY);
+ buffer->write32("x", origin.fX);
+ buffer->write32("y", origin.fY);
}
-void SkWriteBuffer::writeBitmap(const SkBitmap& bitmap) {
+void SkWriteBuffer::writeBitmap(const char* name, const SkBitmap& bitmap) {
// Record the width and height. This way if readBitmap fails a dummy bitmap can be drawn at the
// right size.
- this->writeInt(bitmap.width());
- this->writeInt(bitmap.height());
+ this->writeInt("width", bitmap.width());
+ this->writeInt("height", bitmap.height());
// Record information about the bitmap in one of three ways, in order of priority:
// 1. If there is an SkBitmapHeap, store it in the heap. The client can avoid serializing the
@@ -160,7 +160,7 @@ void SkWriteBuffer::writeBitmap(const SkBitmap& bitmap) {
bool useBitmapHeap = fBitmapHeap != nullptr;
// Write a bool: true if the SkBitmapHeap is to be used, in which case the reader must use an
// SkBitmapHeapReader to read the SkBitmap. False if the bitmap was serialized another way.
- this->writeBool(useBitmapHeap);
+ this->writeBool("useBitmapHeap", useBitmapHeap);
if (useBitmapHeap) {
SkASSERT(nullptr == fPixelSerializer);
int32_t slot = fBitmapHeap->insert(bitmap);
@@ -203,13 +203,13 @@ void SkWriteBuffer::writeBitmap(const SkBitmap& bitmap) {
}
}
- this->writeUInt(0); // signal raw pixels
+ this->writeUInt("rawPixelsTag", 0); // signal raw pixels
SkBitmap::WriteRawPixels(this, bitmap);
}
-void SkWriteBuffer::writeImage(const SkImage* image) {
- this->writeInt(image->width());
- this->writeInt(image->height());
+void SkWriteBuffer::writeImage(const char* name, const SkImage* image) {
+ this->writeInt("width", image->width());
+ this->writeInt("height", image->height());
SkAutoTUnref<SkData> encoded(image->encode(this->getPixelSerializer()));
if (encoded && encoded->size() > 0) {
@@ -217,10 +217,10 @@ void SkWriteBuffer::writeImage(const SkImage* image) {
return;
}
- this->writeUInt(0); // signal no pixels (in place of the size of the encoded data)
+ this->writeUInt("noPixelsTag", 0); // signal no pixels (in place of the size of the encoded data)
}
-void SkWriteBuffer::writeTypeface(SkTypeface* obj) {
+void SkWriteBuffer::writeTypeface(const char* name, SkTypeface* obj) {
if (nullptr == obj || nullptr == fTFSet) {
fWriter.write32(0);
} else {
@@ -256,7 +256,7 @@ void SkWriteBuffer::setPixelSerializer(SkPixelSerializer* serializer) {
}
}
-void SkWriteBuffer::writeFlattenable(const SkFlattenable* flattenable) {
+void SkWriteBuffer::writeFlattenable(const char* name, const SkFlattenable* flattenable) {
/*
* The first 32 bits tell us...
* 0: failure to write the flattenable
@@ -264,7 +264,7 @@ void SkWriteBuffer::writeFlattenable(const SkFlattenable* flattenable) {
* the first character of a string
*/
if (nullptr == flattenable) {
- this->write32(0);
+ this->write32("index", 0);
return;
}
@@ -282,7 +282,7 @@ void SkWriteBuffer::writeFlattenable(const SkFlattenable* flattenable) {
if (fFactorySet) {
SkFlattenable::Factory factory = flattenable->getFactory();
SkASSERT(factory);
- this->write32(fFactorySet->add(factory));
+ this->write32("factoryIndex", fFactorySet->add(factory));
} else {
const char* name = flattenable->getTypeName();
SkASSERT(name);
@@ -295,12 +295,12 @@ void SkWriteBuffer::writeFlattenable(const SkFlattenable* flattenable) {
// plenty to store the index. Note that this strategy depends on
// being little endian.
SkASSERT(0 == *indexPtr >> 24);
- this->write32(*indexPtr << 8);
+ this->write32("dictIndex", *indexPtr << 8);
} else {
// Otherwise write the string. Clients should not use the empty
// string as a name, or we will have a problem.
SkASSERT(strcmp("", name));
- this->writeString(name);
+ this->writeString("typeName", name);
// Add key to dictionary.
fFlattenableDict.set(key, fFlattenableDict.count() + 1);

Powered by Google App Engine
This is Rietveld 408576698