Index: src/core/SkPatch.cpp |
diff --git a/src/core/SkPatch.cpp b/src/core/SkPatch.cpp |
index cc967d5ceece7d1698cbc0648c2f1ae39fc22b0c..422711cf3dc5afabdc043a6dd3329dec08c0f39a 100644 |
--- a/src/core/SkPatch.cpp |
+++ b/src/core/SkPatch.cpp |
@@ -9,6 +9,7 @@ |
#include "SkGeometry.h" |
#include "SkColorPriv.h" |
+#include "SkBuffer.h" |
//////////////////////////////////////////////////////////////////////////////// |
@@ -117,7 +118,7 @@ private: |
//////////////////////////////////////////////////////////////////////////////// |
-SkPatch::SkPatch(SkPoint points[12], SkColor colors[4]) { |
+SkPatch::SkPatch(const SkPoint points[12], const SkColor colors[4]) { |
for (int i = 0; i < 12; i++) { |
fCtrlPoints[i] = points[i]; |
@@ -236,3 +237,47 @@ bool SkPatch::getVertexData(SkPatch::VertexData* data, int lodX, int lodY) const |
} |
return true; |
} |
+ |
+size_t SkPatch::writeToMemory(void* storage) const { |
robertphillips
2014/08/04 18:44:18
12 -> kNumControlPts ?
4 -> kNumCornerColors ?
dandov
2014/08/04 19:59:27
Added constants and use them where they are needed
|
+ int byteCount = 12 * sizeof(SkPoint) + 4 * sizeof(SkColor); |
+ |
+ if (NULL == storage) { |
+ return SkAlign4(byteCount); |
+ } |
+ |
+ SkWBuffer buffer(storage); |
+ |
+ buffer.write(fCtrlPoints, 12 * sizeof(SkPoint)); |
+ buffer.write(fCornerColors, 4 * sizeof(SkColor)); |
+ |
+ buffer.padToAlign4(); |
+ return buffer.pos(); |
+} |
+ |
+size_t SkPatch::readFromMemory(const void* storage, size_t length) { |
+ SkRBufferWithSizeCheck buffer(storage, length); |
+ |
+ int byteCount = 0; |
+ |
robertphillips
2014/08/04 18:44:18
Can we not just read into fCtrlPoints & fCornerCol
dandov
2014/08/04 19:59:27
Done.
|
+ SkPoint pts[12]; |
+ if (!buffer.read(pts, 12 * sizeof(SkPoint))) { |
+ return byteCount; |
+ } |
+ for (int i = 0; i < 12; i++) { |
+ fCtrlPoints[i] = pts[i]; |
mtklein
2014/08/04 18:23:03
Is this redundant with this->reset(pts, colors) be
dandov
2014/08/04 19:59:27
Done. Changed it to read directly into fCtrlPoints
|
+ } |
+ byteCount += 12 * sizeof(SkPoint); |
+ |
+ SkColor colors[4]; |
+ if (!buffer.read(colors, 4 * sizeof(SkColor))) { |
+ return byteCount; |
+ } |
+ for (int i = 0; i < 12; i++) { |
+ fCtrlPoints[i] = pts[i]; |
mtklein
2014/08/04 18:23:03
Did you mean to copy the colors here?
dandov
2014/08/04 19:59:27
Also redundant because of this->reset, removed it
|
+ } |
+ byteCount += 12 * sizeof(SkPoint); |
+ |
+ this->reset(pts, colors); |
+ |
+ return byteCount; |
+} |