Index: src/core/SkFlattenableSerialization.cpp |
diff --git a/src/core/SkFlattenableSerialization.cpp b/src/core/SkFlattenableSerialization.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b74c82f051648f77dce5da97b26e21ba53b12e4b |
--- /dev/null |
+++ b/src/core/SkFlattenableSerialization.cpp |
@@ -0,0 +1,28 @@ |
+/* |
+ * Copyright 2013 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "SkFlattenableSerialization.h" |
+ |
+#include "SkData.h" |
+#include "SkFlattenable.h" |
+#include "SkOrderedReadBuffer.h" |
+#include "SkOrderedWriteBuffer.h" |
+ |
+SkData* SkSerializeFlattenable(SkFlattenable* flattenable) { |
+ SkOrderedWriteBuffer writer(1024); |
+ writer.setFlags(SkOrderedWriteBuffer::kCrossProcess_Flag); |
+ writer.writeFlattenable(flattenable); |
+ uint32_t size = writer.bytesWritten(); |
+ void* data = sk_malloc_throw(size); |
+ writer.writeToMemory(data); |
+ return SkData::NewFromMalloc(data, size); |
+} |
+ |
+SkFlattenable* SkDeserializeFlattenable(const void* data, size_t size) { |
+ SkOrderedReadBuffer buffer(data, size); |
+ return buffer.readFlattenable(); |
+} |